Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. #use "tp2.mli";;
  2.  
  3.  
  4. module Tp2 : TP2 = struct
  5.  
  6. exception Non_Implante of string
  7.  
  8. (* Principaux types du Tp ------------------------------------------------ *)
  9. (* ----------------------------------------------------------------------- *)
  10. type programme = transition list * etat
  11. and transition = etat * action * etat
  12. and action = Epsilon | Api of string
  13. and etat = int;;
  14.  
  15. open List
  16.  
  17. let pgm1 =
  18. ([(1, Api "a", 2); (2, Epsilon, 6); (2, Epsilon, 6); (6, Api "e", 7);
  19. (7, Epsilon, 7); (7, Api "exit", 10)],1);;
  20.  
  21. let pgm2 =
  22. ([(1, Api "a", 2); (2, Epsilon, 5); (5, Epsilon, 6); (6, Api "c", 7);
  23. (7, Epsilon, 7); (1, Epsilon, 3); (3, Api "a", 4); (4, Epsilon, 4);
  24. (4, Api "b", 8)],1);;
  25.  
  26. let pgm3 =
  27. ([(1, Epsilon, 2); (2, Api "a", 6); (6, Epsilon, 7); (7, Api "b", 10);
  28. (10, Epsilon, 10); (6, Api "c", 8); (1, Epsilon, 4);
  29. (4, Epsilon, 1)], 1);;
  30.  
  31. let pgm4 =
  32. ([(0, Api "a", 6); (0, Epsilon, 3); (6, Api "b", 10); (6, Api "c", 8);
  33. (8, Epsilon, 8)],0);;
  34.  
  35.  
  36. (* Fonctions du Tp à implanter ------------------------------------------- *)
  37. let isActionAPI (action : action) = match action with
  38. | Epsilon -> false
  39. | Api(_) -> true;;
  40.  
  41. let rec getTransition listeTransition etatRecherche listeAPI listeEpsi =
  42. match listeTransition with
  43. | [] -> (listeAPI,listeEpsi)
  44. | hd::tl -> match hd with
  45. | (etat1,action,etat2) when etat1 = etatRecherche && isActionAPI(action) = true-> getTransition tl etatRecherche (hd::listeAPI) listeEpsi
  46. | (etat1,action,etat2) when etat1 = etatRecherche && isActionAPI(action) = false -> getTransition tl etatRecherche listeAPI (hd::listeEpsi)
  47. | (_,_,_) -> getTransition tl etatRecherche listeAPI listeEpsi;;
  48.  
  49.  
  50. (* ----------------------------------------------------------------------- *)
  51.  
  52. (* 5 points *)
  53.  
  54. let transitionsImmediates pgm etat =
  55. match pgm with
  56. | (listeTransition,_)-> getTransition listeTransition etat [] [];;
  57.  
  58. (* 30 points *)
  59.  
  60. (* x appartient à l? *)
  61. let ( <+ ) x l = exists (fun y -> x = y) l;;
  62.  
  63. let ( <++ ) etat l = exists (fun y -> etat = fst(y)) l;;
  64. let pgm30 = [ (7,[1;2]) ; (4, [3;4])];;
  65. let pgm32 = [(1, Epsilon, 2) ; (2, Api "a", 6) ; (6, Epsilon, 7) ; (7, Api "b", 10) ; (10, Epsilon, 10) ;(6, Api "c", 8) ; (1, Epsilon, 4) ; (4, Epsilon, 1)] ;;
  66. (* ajout x à l si x n'existe pas déjà dans l *)
  67. let ( +: ) x l = if x <+ l then l else x::l;;
  68.  
  69. let actionEpsiImmediats transitions etat =
  70. fold_left (fun l (e1,action,e2) -> if e1 = etat && isActionAPI(action) = false then e2 +: l else l)
  71. [] transitions ;;
  72.  
  73. let getEpsiSucc listeTransition etat =
  74. let rec parcours etat acc =
  75. let immediats = actionEpsiImmediats listeTransition etat in
  76. let etats = filter (fun x -> not (x <+ acc)) immediats in
  77. fold_left (fun l e -> parcours e l) (acc @ etats) etats
  78. in
  79. parcours etat [];;
  80.  
  81. let rec getEtatsListeTransition listeTransition acc = match listeTransition with
  82. | [] -> acc
  83. | hd::tl -> match hd with
  84. | (etat1,action,etat2) -> getEtats tl (etat2+:(etat1+:acc));;
  85.  
  86. (*Manque à ajouter les états qui ne sont pas présent à la toute fin ! Je planifiais de comparer la liste des EtatsPossibles et celle de l'accumulateur final*)
  87. let getEpsilons listeTransition =
  88. let rec parcoursListe listeAjuste acc =
  89. match listeAjuste with
  90. | [] -> if(eql (getEtatsListeTransition listeTransition []) ())
  91. | hd::tl -> match hd with
  92. | (etat1,action,etat2) when isActionAPI(action) = true -> if (etat1 <++ acc) = true then parcoursListe tl acc else parcoursListe tl ((etat1,[])::acc)
  93. | (etat1,action,etat2) when isActionAPI(action) = false ->if (etat1 <++ acc) = true then parcoursListe tl acc else parcoursListe tl ((etat1,(getEpsiSucc listeTransition etat1))::acc)
  94. in parcoursListe listeEtats [];;
  95.  
  96.  
  97.  
  98. let epsilonAtteignable (pgm: programme) =
  99. match pgm with
  100. | (listeTransition,_)-> getEpsilons (listeTransition);;
  101.  
  102. (* 30 points *)
  103. let supprimeEpsilon pgm =
  104. raise (Non_Implante "supprimeEpsilon a completer");;
  105.  
  106. (* 20 points *)
  107. let similaire pgm1 pgm2 =
  108. raise (Non_Implante "similaire a completer");;
  109.  
  110. (* 5 points *)
  111. let bisimilaire pgm1 pgm2 =
  112. raise (Non_Implante "bisimilaire a completer");;
  113.  
  114. (* 10 points *)
  115. let estSousPgm pgm1 pgm2 =
  116. raise (Non_Implante "estSousPgm a completer");;
  117.  
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement