public void AnalyzeTransitionSystem <T>(TransitionSystem <T> transitionSystem, ModelProperty[] properties) // called from Program.cs where T : struct, Modest.Exploration.IState <T> { /* * // Implement your transition system analysis procedures here * // For illustration, let's count the immediate successors of the initial state: * var successors = new HashSet<T>(); // the state types implement proper .GetHashCode and .Equals methods based on structural equality * T initialState, successorState; * transitionSystem.GetInitialState(out initialState); * foreach(var transition in transitionSystem.GetTransitions(ref initialState)) * { * transitionSystem.GetTargetState(ref initialState, transition, out successorState); * successors.Add(successorState); * // We could evaluate properties using transitionSystem.HasAtomicProposition(ref successorState, ...) here; * // also see the class diagram for properties (file Properties-Classes.png). * } * Console.WriteLine("The initial state has " + successors.Count.ToString(CI.InvariantCulture) + " distinct immediate successor state" + (successors.Count == 1 ? string.Empty : "s") + "."); */ // Write Tests into Files //var testAnalyzer = new TestAnalyzer(); //testAnalyzer.writeTestFiles<T>(transitionSystem, properties); T initialState; transitionSystem.GetInitialState(out initialState); var newStates = new Queue <T>(); newStates.Enqueue(initialState); /* * Use this factory to pre_compute everything * See class implementation for more information */ Pre_Compute_Factory <T> factory = new Pre_Compute_Factory <T>(transitionSystem); HashSet <T> states = factory.getStates(); Console.WriteLine("States: " + factory.number_states + "\n"); if (factory.terminal_encountered) { Console.WriteLine("Error: deadlocks detected\n"); return; } // Transform properties in State_Formulas; var state_formulas = new Dictionary <String, StateFormula>(); foreach (var model_property in properties) { Property property = model_property.Property; String name = model_property.Name; StateFormula complete_formula = new SError(); bool is_ctl = true; parseStateFormula(property, out complete_formula, ref is_ctl); if (!is_ctl) { Console.WriteLine(name + ": not supported \n"); } else { state_formulas.Add(name, complete_formula); } } //Transform into ENF var state_ENF = new Dictionary <String, StateFormula>(); foreach (var key_formula in state_formulas) { String name = key_formula.Key; StateFormula enf_formula = key_formula.Value.existentialNormalForm(); state_ENF.Add(key_formula.Key, enf_formula); } // Now do the model checking foreach (var entry in state_ENF) { String name = entry.Key; StateFormula state_formula = entry.Value; bool isSatisfied; LinkedList <T> linked_states = new LinkedList <T>(); foreach (var entry_state in states) { linked_states.AddLast(entry_state); } ModelChecker <T>(transitionSystem, linked_states, state_formula, out isSatisfied, ref factory); if (isSatisfied) { Console.WriteLine(name + ": true \n"); } else { Console.WriteLine(name + ": false \n"); } } Environment.Exit(0); }
/* * Uses the factory which we created at the very beginning to * do the actual modelchecking * For each state formula it gets the satisfaction set * by using the state forumla class' method * Then it checks whether the initial state is in that set or not */ public void ModelChecker <T>(TransitionSystem <T> transition_system, LinkedList <T> states, StateFormula state_formula, out bool isSatiesfied, ref Pre_Compute_Factory <T> factory) where T : struct, Modest.Exploration.IState <T> { HashSet <T> sat; state_formula.isSatiesfied <T>(transition_system, states, out sat, ref factory); T initialState; transition_system.GetInitialState(out initialState); if (sat.Contains(initialState)) { isSatiesfied = true; } else { isSatiesfied = false; } }
abstract public void isSatiesfied <T>(TransitionSystem <T> transition_system, LinkedList <T> states, out HashSet <T> sat, ref Pre_Compute_Factory <T> factory) where T : struct, Modest.Exploration.IState <T>;