private TransitionSystem CreateTransitionSystem1() { HashSet <State> states = new HashSet <State>() { new State("Wait"), new State("Act"), }; HashSet <Transition> transitions = new HashSet <Transition>() { new ReactiveTransition <NewItem>( states.First(x => x.Name == "Wait"), states.First(x => x.Name == "Act"), (variables, action) => { return(1 <= action.Id && action.Id <= guids.Length); }, (variables, action) => { int id = action.Id; variables.SetValue(nameof(id), id); } ), new ProactiveTransition <ItemEventArgsNew>( states.First(x => x.Name == "Act"), states.First(x => x.Name == "Wait"), (variables) => { return(true); }, (variables) => { int id = variables.GetValue <int>(nameof(id)); return(new ItemEventArgsNew() { GUID = guids[id - 1], SystemName = systemNames[id - 1], Position = positions[id - 1], Rotation = rotations[id - 1], ModelGroup = modelGroups[id - 1], Model = models[id - 1], }); }, (variables, action) => { variables.ClearValue("id"); } ), }; TransitionSystem system = new TransitionSystem(states, states.First(x => x.Name == "Wait"), transitions); // Have the properties been initialized correctly? CollectionAssert.AreEqual(states.ToList(), system.States.ToList()); Assert.AreEqual(states.ElementAt(0), system.InitialState); Assert.AreEqual(states.ElementAt(0), system.CurrentState); CollectionAssert.AreEqual(transitions.ToList(), system.Transitions.ToList()); return(system); }
/// <summary>adds all steps to the state transition system</summary> private void BuildTransitionSystem(TransitionSystem transitionSystem, Proposition[] propositions, Step step, List <Step> addedSteps) { // already added? if (FindStep(step.node, step.state, addedSteps) != null) { return; } addedSteps.Add(step); var state = step.state; for (int i = 0; i < state.numValues; i++) { if (state.Get(i)) { // variable i is true in this state propositions[i].Set(step.id); } } // recurse foreach (var nextStep in step.Successors) { transitionSystem.AddTransition(step.id, nextStep.id); BuildTransitionSystem(transitionSystem, propositions, nextStep, addedSteps); } }
public override void isSatiesfied <T>(TransitionSystem <T> transition_system, LinkedList <T> states, out HashSet <T> sat, ref Pre_Compute_Factory <T> factory) { if (factory.prop_sats.ContainsKey(this)) { factory.prop_sats.TryGetValue(this, out sat); return; } HashSet <T> res = new HashSet <T>(); foreach (var entry in states) { T state = entry; bool satisfied = transition_system.HasAtomicProposition(ref state, atomic.PropositionIndex); if (satisfied) { res.Add(state); } } //Console.WriteLine("atomic"); factory.prop_sats.Add(this, res); sat = res; }
/// <summary>enumerates the state transitions of the process</summary> public TransitionSystem BuildTransitionSystem(string[] variables, int initialNode, int finalNode, out int[] intialStates, out int[] finalStates, out IProposition[] propositions) { // crawl var numVariables = variables.Length; var steps = new List <Step>(); var initialState = new State(numVariables); var initialStep = Crawl(initialNode, initialState, steps); // create transition system and proposition var transitionSystem = new TransitionSystem(steps.Count); var props = new Proposition[numVariables]; for (int i = 0; i < numVariables; i++) { props[i] = new Proposition(transitionSystem.numStates, variables[i]); } // convert steps to state transitions var addedSteps = new List <Step>(); BuildTransitionSystem(transitionSystem, props, initialStep, addedSteps); // export initial and final states intialStates = new[] { initialStep.id }; finalStates = steps.Where(p => p.node == finalNode).Select(p => p.id).ToArray(); propositions = props; return(transitionSystem); }
public bool Evaluate(TransitionSystem transitionSystem, int[] initialStates) { var a = f.Evaluate(transitionSystem, initialStates); var b = g.Evaluate(transitionSystem, initialStates); return(a && b); }
public void RefinementFramework() { FileInfo model = new FileInfo(@"..\..\..\TorXakisDotNetAdapter.Models\Models\Reference.txs"); RefinementFramework framework = new RefinementFramework(model); Assert.AreEqual(model, framework.Connector.Model.File); TransitionSystem system1 = CreateTransitionSystem1(); framework.AddSystem(system1); Assert.AreEqual(system1, framework.Systems.ElementAt(0)); TransitionSystem system2 = CreateTransitionSystem2(); framework.AddSystem(system2); Assert.AreEqual(system2, framework.Systems.ElementAt(1)); Console.WriteLine(framework); // Trigger a reactive transition, which should activate a proactive one next. if (true) { NewItem modelInput = new NewItem() { Id = 1, }; Console.WriteLine("Using model input: " + modelInput); HashSet <Tuple <TransitionSystem, ReactiveTransition> > reactives = framework.PossibleReactiveTransitions(modelInput); Console.WriteLine("Possible reactives transitions: " + string.Join(", ", reactives.Select(x => x.Item1.ModelAction.Name + ": " + x.Item2).ToArray())); Assert.AreEqual(1, reactives.Count); framework.HandleModelInput(modelInput); Console.WriteLine(framework); Assert.AreEqual(system1.States.ElementAt(0), system1.CurrentState); } // Trigger a reactive transition, which should activate a proactive one next. if (true) { ItemEventArgsNew systemEvent = new ItemEventArgsNew() { GUID = guids[0], SystemName = systemNames[0], Position = positions[0], Rotation = rotations[0], ModelGroup = modelGroups[0], Model = models[0], }; Console.WriteLine("Using system event: " + systemEvent); HashSet <Tuple <TransitionSystem, ReactiveTransition> > reactives = framework.PossibleReactiveTransitions(systemEvent); Console.WriteLine("Possible reactives transitions: " + string.Join(", ", reactives.Select(x => x.Item1.ModelAction.Name + ": " + x.Item2).ToArray())); Assert.AreEqual(1, reactives.Count); framework.HandleSystemEvent(systemEvent); Console.WriteLine(framework); Assert.AreEqual(system2.States.ElementAt(0), system2.CurrentState); } }
private void EvaluatePredecessors(TransitionSystem transitionSystem, int state) { for (int i = 0; i < numStates; i++) { if (transitionSystem.HasTransition(i, state)) { Evaluate(transitionSystem, i); } } }
private TransitionSystem CreateTransitionSystem2() { HashSet <State> states = new HashSet <State>() { new State("Wait"), new State("Act"), }; HashSet <Transition> transitions = new HashSet <Transition>() { new ReactiveTransition <ItemEventArgsNew>( states.First(x => x.Name == "Wait"), states.First(x => x.Name == "Act"), (variables, action) => { return(guids.ToList().IndexOf(action.GUID) != -1); }, (variables, action) => { int id = guids.ToList().IndexOf(action.GUID) + 1; variables.SetValue(nameof(id), id); } ), new ProactiveTransition <NewItem>( states.First(x => x.Name == "Act"), states.First(x => x.Name == "Wait"), (variables) => { return(true); }, (variables) => { int id = variables.GetValue <int>(nameof(id)); return(new NewItem() { Id = id, }); }, (variables, action) => { variables.ClearValue("id"); } ), }; TransitionSystem system = new TransitionSystem(states, states.First(x => x.Name == "Wait"), transitions); // Have the properties been initialized correctly? CollectionAssert.AreEqual(states.ToList(), system.States.ToList()); Assert.AreEqual(states.ElementAt(0), system.InitialState); Assert.AreEqual(states.ElementAt(0), system.CurrentState); CollectionAssert.AreEqual(transitions.ToList(), system.Transitions.ToList()); return(system); }
public void TransitionSystem() { const int numNodes = 7; const int numBits = 3; Assert.Less(numNodes, 1 << (numBits + 1)); var ts = new TransitionSystem(numNodes); ts.AddTransition(0, 1); ts.AddTransition(0, 2); ts.AddTransition(1, 3); ts.AddTransition(2, 4); ts.AddTransition(3, 3); ts.AddTransition(3, 5); ts.AddTransition(4, 4); ts.AddTransition(4, 5); ts.AddTransition(5, 5); ts.AddTransition(5, 6); ts.AddTransition(6, 6); var obdd = new OBDD(); var root = BDDNode.False; for (int i = 0; i < numNodes; i++) { for (int j = 0; j < numNodes; j++) { if (!ts.HasTransition(i, j)) { continue; } var transition = AddTransition(obdd, i, j, numBits); root = obdd.MakeOr(root, transition); } } using (var writer = new StringWriter()) { ts.ExportToGraphviz(writer, new IProposition[0]); Debug.Log(writer); } using (var writer = new StringWriter()) { root.ExportToGraphviz(writer); Debug.Log(writer); } using (var writer = new StringWriter()) { obdd.ExportToGraphviz(writer); Debug.Log(writer); } }
private void Evaluate(TransitionSystem transitionSystem) { isEvaluated = true; var checkedStates = new bool[numStates]; // already computed EG(f) var markedStates = new bool[numStates]; // in the process of computing EG(f) for (int i = 0; i < numStates; i++) { Evaluate(transitionSystem, checkedStates, markedStates, i); } }
private void Evaluate(TransitionSystem transitionSystem) { isEvaluated = true; for (int i = 0; i < numStates; i++) { if (g.Get(i)) { Set(i); EvaluatePredecessors(transitionSystem, i); } } }
public Pre_Compute_Factory(TransitionSystem <T> transition_system) { this.terminal_encountered = false; this.array = new DynamicArray <T>(); this.prop_sats = new Dictionary <StateFormula, HashSet <T> >(); this.transition_system = transition_system; // Count states, set pre/post sets compute_pre_post_list(); this.number_states = array.next_index; }
public void TransitionSystem2() { TransitionSystem system = CreateTransitionSystem2(); Console.WriteLine(system); // Determine possible reactive transitions. ItemEventArgsNew systemEvent = new ItemEventArgsNew() { GUID = guids[0], SystemName = systemNames[0], Position = positions[0], Rotation = rotations[0], ModelGroup = modelGroups[0], Model = models[0], }; Console.WriteLine("Using system event: " + systemEvent); HashSet <ReactiveTransition> reactives = system.PossibleReactiveTransitions(systemEvent); Console.WriteLine("Possible reactive transitions: " + string.Join(", ", reactives.Select(x => x.ToString()).ToArray())); Assert.AreEqual(1, reactives.Count); Assert.AreEqual(system.Transitions.ElementAt(0), reactives.First()); // Execute and check reactive transition. system.ExecuteReactiveTransition(systemEvent, reactives.First()); Console.WriteLine(system); Assert.AreEqual(system.States.ElementAt(1), system.CurrentState); // Determine possible proactive transitions. HashSet <ProactiveTransition> proactives = system.PossibleProactiveTransitions(); Console.WriteLine("Possible proactive transitions: " + string.Join(", ", proactives.Select(x => x.ToString()).ToArray())); Assert.AreEqual(1, proactives.Count); Assert.AreEqual(system.Transitions.ElementAt(1), proactives.First()); // Execute and check proactive transition. IAction generatedAction = system.ExecuteProactiveTransition(proactives.First()); Console.WriteLine("Generated action: " + generatedAction); Assert.AreEqual(typeof(NewItem), generatedAction.GetType()); Assert.AreEqual(1, (generatedAction as NewItem).Id); Console.WriteLine(system); Assert.AreEqual(system.States.ElementAt(0), system.CurrentState); }
private void Evaluate(TransitionSystem transitionSystem, int state) { if (Get(state)) { // we have already evaluated this state return; } if (!f.Get(state)) { // f does not hold (bad) return; } // f holds in this state (good) Set(state); EvaluatePredecessors(transitionSystem, state); }
/* * 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; } }
private bool Evaluate(TransitionSystem transitionSystem, bool[] checkedStates, bool[] markedStates, int state) { if (checkedStates[state]) { // we have already evaluated this state return(Get(state)); } if (markedStates[state]) { // we have reached a previously marked state // therefore detecting a cycle along which f holds return(true); } if (!f.Get(state)) { // f does not hold here (bad) return(false); } // check if there is a path starting in the current state along which f holds for every state markedStates[state] = true; for (int i = 0; i < numStates; i++) { if (transitionSystem.HasTransition(state, i)) { if (Evaluate(transitionSystem, checkedStates, markedStates, i)) { // found a path along which f holds for every state // therefore prepend the current state Set(state); break; } } } markedStates[state] = false; checkedStates[state] = true; return(Get(state)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public LWDeterministicParser(LWSingleMalt lwSingleMalt, org.maltparser.core.symbol.SymbolTableHandler symbolTableHandler) throws org.maltparser.core.exception.MaltChainedException public LWDeterministicParser(LWSingleMalt lwSingleMalt, SymbolTableHandler symbolTableHandler) { manager = lwSingleMalt; registry = new ParserRegistry(); registry.SymbolTableHandler = symbolTableHandler; registry.DataFormatInstance = manager.DataFormatInstance; registry.setAbstractParserFeatureFactory(manager.ParserFactory); registry.Algorithm = this; transitionSystem = manager.ParserFactory.makeTransitionSystem(); transitionSystem.initTableHandlers(lwSingleMalt.DecisionSettings, symbolTableHandler); tableHandlers = transitionSystem.TableHandlers; kBestSize = lwSingleMalt.getkBestSize(); decisionTables = new List <TableContainer>(); actionTables = new List <TableContainer>(); initDecisionSettings(lwSingleMalt.DecisionSettings, lwSingleMalt.Classitem_separator); transitionSystem.initTransitionSystem(this); config = manager.ParserFactory.makeParserConfiguration(); featureModel = manager.FeatureModelManager.getFeatureModel(lwSingleMalt.FeatureModelURL, 0, registry, manager.DataSplitColumn, manager.DataSplitStructure); currentAction = new ComplexDecisionAction(this); }
public void TransitionSystem1() { TransitionSystem system = CreateTransitionSystem1(); Console.WriteLine(system); // Determine possible reactive transitions. NewItem modelInput = new NewItem() { Id = 1, }; Console.WriteLine("Using model input: " + modelInput); HashSet <ReactiveTransition> reactives = system.PossibleReactiveTransitions(modelInput); Console.WriteLine("Possible reactive transitions: " + string.Join(", ", reactives.Select(x => x.ToString()).ToArray())); Assert.AreEqual(1, reactives.Count); Assert.AreEqual(system.Transitions.ElementAt(0), reactives.First()); // Execute and check reactive transition. system.ExecuteReactiveTransition(modelInput, reactives.First()); Console.WriteLine(system); Assert.AreEqual(system.States.ElementAt(1), system.CurrentState); // Determine possible proactive transitions. HashSet <ProactiveTransition> proactives = system.PossibleProactiveTransitions(); Console.WriteLine("Possible proactive transitions: " + string.Join(", ", proactives.Select(x => x.ToString()).ToArray())); Assert.AreEqual(1, proactives.Count); Assert.AreEqual(system.Transitions.ElementAt(1), proactives.First()); // Execute and check proactive transition. IAction generatedAction = system.ExecuteProactiveTransition(proactives.First()); Console.WriteLine("Generated action: " + generatedAction); Assert.AreEqual(typeof(ItemEventArgsNew), generatedAction.GetType()); Assert.AreEqual(guids[0], (generatedAction as ItemEventArgsNew).GUID); Console.WriteLine(system); Assert.AreEqual(system.States.ElementAt(0), system.CurrentState); }
public void writeTestFiles <T>(TransitionSystem <T> transitionSystem, ModelProperty[] properties) where T : struct, Modest.Exploration.IState <T> { String text1 = "TransitionSystem: \n"; String text2 = transitionSystem.ToString() + " \n" + " \n" + " \n"; String text3 = "Properties: \n"; String text4 = ""; for (int i = 0; i < properties.Count(); i++) { Property property = properties[i].Property; String name = properties[i].Name; String prop = property.ToString(); String loc = property.Location.ToString(); text4 = text4 + "Name: " + name + " \n" + prop + " Location: " + loc + " \n"; } String text = text1 + text2 + text3 + text4; String nextFileName = getNextFileName("property_location"); System.IO.File.WriteAllText(nextFileName, text); }
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>;
public void AlternatingBitProtocolSender() { // 0* --> 1 <-> 2 g* --> s <-> w // ^ | ^ | // | v | v // 5 <-> 4 <-- 3* bw <-> bs <-- bg* const int numNodes = 6; var ts = new TransitionSystem(numNodes); ts.AddTransition(0, 0); ts.AddTransition(0, 1); ts.AddTransition(1, 2); ts.AddTransition(2, 1); ts.AddTransition(2, 3); ts.AddTransition(3, 3); ts.AddTransition(3, 4); ts.AddTransition(4, 5); ts.AddTransition(5, 4); ts.AddTransition(5, 0); var initial = new[] { 0, 3 }; // initial states var g = new Proposition(numNodes, "g"); // getting data from user g.Set(0, 3); var s = new Proposition(numNodes, "s"); // sending message s.Set(1, 4); var w = new Proposition(numNodes, "w"); // waiting for acknowledgement w.Set(2, 5); var b = new Proposition(numNodes, "b"); // control bit b.Set(3, 4, 5); using (var writer = new StringWriter()) { ts.ExportToGraphviz(writer, new[] { g, s, w, b }); Debug.Log(writer); } // AG(s || w || g) -- the sender is always in one of these three states var or1 = new OrProposition(s, w); var or2 = new OrProposition(or1, g); var ag = new AllGlobalProposition(numNodes, or2); Debug.Log(ag); Assert.IsTrue(ag.Evaluate(ts, initial)); // EG(!s && !w) -- there is a path where the sender is never sending nor waiting var notS = new NotProposition(s); var notW = new NotProposition(w); var and = new AndProposition(notS, notW); var eg = new ExistsGlobalProposition(numNodes, and); Debug.Log(eg); Assert.IsTrue(eg.Evaluate(ts, initial)); }
public void KeyDoor() { // process // // 0 <--door--> 1 <--door--> 2 // key x2 // transition system // // 1 --> 3* // ^ | // | v // 0 5 --> 6* // | ^ // v | // 2 --> 4* const int numNodes = 7; var ts = new TransitionSystem(numNodes); ts.AddTransition(0, 1); ts.AddTransition(0, 2); ts.AddTransition(1, 3); ts.AddTransition(2, 4); ts.AddTransition(3, 3); ts.AddTransition(3, 5); ts.AddTransition(4, 4); ts.AddTransition(4, 5); ts.AddTransition(5, 5); ts.AddTransition(5, 6); ts.AddTransition(6, 6); var initial = new[] { 0 }; // initial states var a = new Proposition(numNodes, "a"); // has a key a.Set(1, 2, 5); var b = new Proposition(numNodes, "b"); //key1 acquired b.Set(1, 3, 5, 6); var c = new Proposition(numNodes, "c"); // key2 acquired c.Set(2, 4, 5, 6); var d = new Proposition(numNodes, "d"); // door1 open d.Set(3, 4, 5, 6); var e = new Proposition(numNodes, "e"); //door2 open e.Set(6); var f = new Proposition(numNodes, "f"); // goal f.Set(6); using (var writer = new StringWriter()) { ts.ExportToGraphviz(writer, new[] { a, b, c, d, e, f }); Debug.Log(writer); } // EF(f) -- there exists a path starting at the initial states where f eventually holds (goal is reachable) var ef = new ExistsFutureProposition(numNodes, f); Debug.Log(ef); Assert.IsTrue(ef.Evaluate(ts, initial)); // AG(EF(f)) -- from all reachable states there exists a path to the goal var ag = new AllGlobalProposition(numNodes, ef); Debug.Log(ag); Assert.IsTrue(ag.Evaluate(ts, initial)); }
public override void isSatiesfied <T>(TransitionSystem <T> transition_system, LinkedList <T> states, out HashSet <T> sat, ref Pre_Compute_Factory <T> factory) { sat = new HashSet <T>(); }
public bool Evaluate(TransitionSystem transitionSystem, int[] initialStates) { return(existsUntil.Evaluate(transitionSystem, initialStates)); }
// Use this for initialization void Start() { transSys = GameObject.FindObjectOfType <TransitionSystem>(); transform.parent = transSys.transform; }
public bool Evaluate(TransitionSystem transitionSystem, int[] initialStates) { return(true); }
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); }
public bool Evaluate(TransitionSystem transitionSystem, int[] initialStates) { return(PropositionUtils.Evaluate(this, initialStates)); }
public bool Evaluate(TransitionSystem transitionSystem, int[] initialStates) { return(!existsFuture.Evaluate(transitionSystem, initialStates)); }