SHARE
TWEET

Untitled

a guest Jun 20th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Operation;
  2.  
  3. enum LTLFormula {
  4.     BinOp(Operation, Box<LTLFormula>, Box<LTLFormula>),
  5.     UnaryOp(Operation, Box<LTLFormula>),
  6.     Terminal(String),
  7. }
  8.  
  9. struct Automaton<'a> {
  10.     subformulas: Vec<&'a LTLFormula>,
  11.     combinations: Vec<usize>,
  12.     graph: Graph,
  13. }
  14.  
  15. struct Graph {
  16.     nodes: Vec<Node>,
  17. }
  18.  
  19. struct Node {
  20.     subformulas: usize,
  21.     neighbors: Vec<usize>,
  22. }
  23. impl Node {
  24.     fn iter_terminals<'a>(&self, a: &'a Automaton) -> impl Iterator<Item=&'a str> {
  25.         materialize_subformulas(&a.subformulas, self.subformulas).filter_map(|x| match x {
  26.             LTLFormula::Terminal(s) => Some(s.as_str()),
  27.             _ => None,
  28.         })
  29.     }
  30. }
  31.  
  32. fn decompose_formula<'a>(f: &'a LTLFormula) -> impl Iterator<Item=&'a LTLFormula> {
  33.     unimplemented!();
  34.     Vec::new().into_iter()
  35. }
  36. fn is_cool<'a>(x: impl Iterator<Item=&'a LTLFormula>) -> bool {
  37.     unimplemented!();
  38. }
  39.  
  40. impl<'a> Automaton<'a> {
  41.     fn new(full_formula: &'a LTLFormula) -> Self {
  42.         let subformulas: Vec<_> = decompose_formula(full_formula).collect();
  43.         let combinations: Vec<_> = make_combinations(subformulas.len())
  44.             .filter(|&x| is_cool(materialize_subformulas(&subformulas, x))).collect();
  45.         let nodes = combinations.iter().map(|&x| {
  46.             let neighbors = combinations.iter().enumerate().filter(|(_, &y)| is_connected(&subformulas, x, y)).map(|(i, _)| i).collect();
  47.             Node {
  48.                 subformulas: x,
  49.                 neighbors,
  50.             }
  51.         }).collect();
  52.         let graph = Graph { nodes };
  53.         Automaton {
  54.             subformulas,
  55.             combinations,
  56.             graph,
  57.         }
  58.     }
  59. }
  60. fn is_connected(subformulas: &Vec<&LTLFormula>, combinations_a: usize, combinations_b: usize) -> bool {
  61.     unimplemented!();
  62. }
  63.  
  64. fn make_combinations(number_of_subformulas: usize) -> impl Iterator<Item=usize> {
  65.     let max = 1 << number_of_subformulas;
  66.     (0..max)
  67. }
  68. fn materialize_subformulas<'a>(subformulas: &'a Vec<&'a LTLFormula>, index: usize) -> impl Iterator<Item=&'a LTLFormula> {
  69.     subformulas.iter().cloned().enumerate().filter(move |(i, x)| {
  70.         (index & (1usize << i)) != 0
  71.     }).map(|(_, x)| x)
  72. }
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