public static void Main(string[] args) { Console.WriteLine ("Hello World!"); LTLFormula formula = new Until(new Proposition("P1"), new Proposition("P2")); Automaton automaton = new Automaton(); Node initialNode = new Node(); initialNode.Incoming.Enqueue("init"); initialNode.New.Enqueue(formula); automaton = initialNode.Expand(automaton); System.Console.WriteLine ("Automaton has {0} states", automaton.Nodes.Count); System.Console.WriteLine ("digraph G {"); System.Console.WriteLine ("\tinit [shape=plaintext label=\"\"];"); foreach (Node n1 in automaton.Nodes) { System.Console.WriteLine ("\t{0};", n1.Name); } foreach (Node n1 in automaton.Nodes) { foreach (string n2 in n1.Incoming) { System.Console.WriteLine ("\t{0} -> {1};", n2, n1.Name); } } System.Console.WriteLine ("}"); }
/// <summary> /// Expand the current node into the given automaton. /// </summary> /// <param name='automaton'> /// A given automaton to expand incoming within. /// </param> public Automaton Expand(Automaton automaton) { if (this.New.Count == 0) { Node node = automaton.Similar(this); if (node != default(Node)) { foreach (string incomingNode in Incoming) { QueueUtils.AddsUnique(node.Incoming, incomingNode); } return automaton; } else { Node n = new Node(this, Next); QueueUtils.AddsUnique(automaton.Nodes, this); return n.Expand(automaton); } } else { LTLFormula n = New.Dequeue(); if (n is Literal) { LTLFormula notN = n.Negate(); if (Old.Contains(notN)) { return automaton; } else { QueueUtils.AddsUnique(Old, n); return this.Expand(automaton); } } else if (n is Until | n is Release | n is Or) { Node n1 = new Node(Incoming, New, Old, Next); Node n2 = new Node(Incoming, New, Old, Next); LTLFormula new1 = null; LTLFormula new2 = null; LTLFormula next = null; if (n is Until) { new1 = ((Until) n).Left; next = n; new2 = ((Until) n).Right; } else if (n is Release) { new1 = ((Release) n).Right; next = n; new2 = ((Release) n).Left; } else if (n is Or) { new1 = ((Or) n).Left; new2 = ((Or) n).Right; } if (!Old.Contains(new1)) { QueueUtils.AddsUnique(n1.New, new1); } if (!Old.Contains(new2)) { QueueUtils.AddsUnique(n2.New, new2); } QueueUtils.AddsUnique(n1.Old, n); QueueUtils.AddsUnique(n2.Old, n); QueueUtils.AddsUnique(n1.Next, next); return n2.Expand(n1.Expand(automaton)); } else if (n is And) { And andN = (And) n; Node newNode = new Node(Name, Incoming, New, Old, Next); if (!Old.Contains(andN.Left)) { QueueUtils.AddsUnique(newNode.New, andN.Left); } if (!Old.Contains(andN.Right)) { QueueUtils.AddsUnique(newNode.New, andN.Right); } QueueUtils.AddsUnique(newNode.Old, n); return newNode.Expand(automaton); } return null; } }