daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     (* ajout x à l si x n'existe pas déjà dans l *)
  64.     let ( +: ) x l = if x <+ l then l else x::l;;
  65.      
  66.         let actionEpsiImmediats transitions etat =
  67.           fold_left (fun l (e1,action,e2) -> if e1 = etat && isActionAPI(action) = false  then e2 +: l else l)
  68.                     [] transitions ;;
  69.  
  70.         let getEpsiSucc listeTransition etat =
  71.           let rec parcours etat acc =
  72.             let immediats = actionEpsiImmediats listeTransition etat in
  73.             let etats = filter (fun x -> not (x <+ acc)) immediats in
  74.             fold_left (fun l e -> parcours e l) (acc @ immediats) immediats
  75.           in
  76.           parcours etat [];;
  77.  
  78.     let rec getEpsilons listeTransition acc =
  79.        match listeTransition with
  80.        | [] -> acc
  81.        | hd::tl -> match hd with
  82.        | (etat1,action,etat2) when isActionAPI(action) = true -> getEpsilons tl ((etat1,[])::acc)
  83.        | (etat1,action,etat2) when isActionAPI(action) = false -> getEpsilons tl ((etat1,(getEpsiSucc listeTransition etat1))::acc) ;;
  84.  
  85.     let epsilonAtteignable pgm =
  86.       match pgm with
  87.       | (listeTransition,_)->  getEpsilons listeTransition  [];;
  88.  
  89.     (* 30 points *)
  90.     let supprimeEpsilon pgm =
  91.         raise (Non_Implante "supprimeEpsilon a completer");;
  92.  
  93.     (* 20 points *)
  94.     let similaire pgm1 pgm2 =
  95.         raise (Non_Implante "similaire a completer");;
  96.  
  97.     (* 5 points *)
  98.     let bisimilaire pgm1 pgm2 =
  99.         raise (Non_Implante "bisimilaire a completer");;
  100.  
  101.     (* 10 points *)
  102.     let estSousPgm pgm1 pgm2 =
  103.         raise (Non_Implante "estSousPgm a completer");;
  104.  
  105. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top