public static TlaAutomaton TranslateToTlaAutomaton(this automaton root, bool useTransitionConditions, AutomatonParsingContext ctx) { var automaton = new TlaAutomaton(); foreach (var state in root.states) { var name = state.stateName.identifier.@string; automaton.CreateState(name, name.EndsWith("_init"), name.StartsWith("accept_")); } foreach (var state in root.states) { foreach (var target in state.transitions) { var condition = target.condition.Translate(useTransitionConditions, ctx); automaton.CreateTransition(state.stateName.identifier.@string, target.stateName.identifier.@string, condition); } if (state.skip != null) { automaton.CreateTransition( state.stateName.identifier.@string, state.stateName.identifier.@string, useTransitionConditions ? new TlaTransitionConditionFormula(new Model.TransitionConditionExpr.ConstExpr(true)) : (TlaFormula) new TlaExprFormula(new TlaExpr.Const(true)) ); } } return(automaton); }
private TlaAutomaton Intersect(TlaAutomaton sm, TlaAutomaton ltl) { var states = Enumerable.Range(0, 3).SelectMany(n => sm.AllStates.SelectMany(modelState => ltl.AllStates.Select(ltlState => new { name = string.Format("{0}x{1}x{2}", modelState.Id, ltlState.Id, n), tag = modelState.Name }))).ToArray(); var transitions = Enumerable.Range(0, 3).SelectMany( x => sm.AllTransitions.SelectMany(mt => ltl.AllTransitions.Select(ft => new { modelTransition = mt, ltlTransition = ft })) .Where(tt => TransitionConditionsIntersects(tt.modelTransition.FromState, tt.modelTransition.Condition, tt.ltlTransition.Condition)) .Select(tt => new { from = string.Format("{0}x{1}x{2}", tt.modelTransition.FromState.Id, tt.ltlTransition.FromState.Id, x), to = string.Format("{0}x{1}x{2}", tt.modelTransition.ToState.Id, tt.ltlTransition.ToState.Id, ComputeTransitionY(tt.modelTransition.ToState, tt.ltlTransition.ToState, x)), modelSymbol = tt.modelTransition.Condition, ltlSymbol = tt.ltlTransition.Condition, condition = new TlaTransitionConditionFormula(new TransitionConditionExpr.BinaryExpr( TransitionConditionBinaryExprKind.BoolAnd, new TransitionConditionExpr.VarExpr(tt.modelTransition.FromState.Name), (tt.modelTransition.Condition as TlaTransitionConditionFormula).Expression )) }) ).ToArray(); var initialStates = new SortedSet <string>(sm.InitialStates.SelectMany(modelState => ltl.InitialStates.Select(ltlState => string.Format("{0}x{1}x0", modelState.Id, ltlState.Id)))); var acceptingStates = new SortedSet <string>(sm.AllStates.SelectMany(modelState => ltl.AllStates.Select(ltlState => string.Format("{0}x{1}x2", modelState.Id, ltlState.Id)))); var result = new TlaAutomaton(); foreach (var state in states) { result.CreateState(state.name, initialStates.Contains(state.name), acceptingStates.Contains(state.name)).Tag = state.tag; } foreach (var t in transitions) { result.CreateTransition(t.from, t.to, t.condition); } return(result); }