コード例 #1
0
        /// <summary>
        ///     Adds a model element in this model element
        /// </summary>
        /// <param name="copy"></param>
        public override void AddModelElement(IModelElement element)
        {
            {
                State item = element as State;
                if (item != null)
                {
                    appendStates(item);
                }
            }
            {
                Rule item = element as Rule;
                if (item != null)
                {
                    appendRules(item);
                }
            }

            base.AddModelElement(element);
        }
コード例 #2
0
        /// <summary>
        ///     Instanciates this state machine for the instanciation of a StructureProcedure into a Procedure
        /// </summary>
        /// <returns></returns>
        public StateMachine instanciate()
        {
            StateMachine retVal = (StateMachine)acceptor.getFactory().createStateMachine();

            retVal.Name = Name;
            retVal.setFather(getFather());
            retVal.Default = Default;
            foreach (State state in States)
            {
                State newState = state.duplicate();
                retVal.appendStates(newState);
            }
            foreach (Rule rule in Rules)
            {
                Rule newRule = rule.duplicate();
                retVal.appendRules(newRule);
            }

            return(retVal);
        }
コード例 #3
0
ファイル: Runner.cs プロジェクト: fakoor/ERTMSFormalSpecs
 /// <summary>
 ///     Try to find a rule, in this state machine, or in a sub state machine
 ///     which
 /// </summary>
 /// <param name="activations"></param>
 /// <param name="priority">The priority when this evaluation occurs</param>
 /// <param name="currentStateVariable">The variable which holds the current state of the procedure</param>
 /// <param name="explanation">The explanation part to be filled</param>
 private void EvaluateStateMachine(HashSet <Activation> activations, acceptor.RulePriority priority,
                                   IVariable currentStateVariable, ExplanationPart explanation)
 {
     if (currentStateVariable != null)
     {
         State currentState = currentStateVariable.Value as State;
         if (currentState != null)
         {
             StateMachine currentStateMachine = currentState.StateMachine;
             while (currentStateMachine != null)
             {
                 foreach (Rules.Rule rule in currentStateMachine.Rules)
                 {
                     rule.Evaluate(this, priority, currentStateVariable, activations, explanation);
                 }
                 currentStateMachine = currentStateMachine.EnclosingStateMachine;
             }
         }
     }
 }
コード例 #4
0
        /// <summary>
        ///     Provides the values whose name matches the name provided
        /// </summary>
        /// <param name="index">the index in names to consider</param>
        /// <param name="names">the simple value names</param>
        public IValue findValue(string[] names, int index)
        {
            State retVal = null;

            if (index < names.Length)
            {
                retVal = (State)NamableUtils.FindByName(names[index], States);
                ;

                if (retVal != null && index < names.Length - 1)
                {
                    StateMachine stateMachine = retVal.StateMachine;
                    if (stateMachine != null)
                    {
                        retVal = (State)stateMachine.findValue(names, index + 1);
                    }
                }
            }

            return(retVal);
        }
コード例 #5
0
        /// <summary>
        /// Indicates that the state machine contains (either directly or indirectly) the state
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        internal Constants.State StateInThisStateMachine(DataDictionary.Constants.State state)
        {
            Constants.State retVal = null;

            foreach (Constants.State other in States)
            {
                if (other == state)
                {
                    retVal = state;
                    break;
                }

                retVal = other.StateMachine.StateInThisStateMachine(state);
                if (retVal != null)
                {
                    retVal = other;
                    break;
                }
            }

            return(retVal);
        }
コード例 #6
0
        /// <summary>
        ///     Indicates that the state machine contains (either directly or indirectly) the state
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        internal State StateInThisStateMachine(State state)
        {
            State retVal = null;

            foreach (State other in States)
            {
                if (other == state)
                {
                    retVal = state;
                    break;
                }

                retVal = other.StateMachine.StateInThisStateMachine(state);
                if (retVal != null)
                {
                    retVal = other;
                    break;
                }
            }

            return(retVal);
        }
コード例 #7
0
        /// <summary>
        ///     Sets the update information for this state machine (this state machine updates source)
        /// </summary>
        /// <param name="source"></param>
        public override void SetUpdateInformation(ModelElement source)
        {
            base.SetUpdateInformation(source);
            StateMachine sourceStateMachine = (StateMachine)source;

            foreach (State state in States)
            {
                State baseState = sourceStateMachine.FindState(state.Name);
                if (baseState != null)
                {
                    state.SetUpdateInformation(baseState);
                }
            }

            foreach (Rule rule in Rules)
            {
                Rule baseRule = sourceStateMachine.FindRule(rule.Name);
                if (baseRule != null)
                {
                    rule.SetUpdateInformation(baseRule);
                }
            }
        }
コード例 #8
0
        public override bool Contains(IValue first, IValue other)
        {
            bool retVal = false;

            State state1 = first as State;
            State state2 = other as State;

            if (state1 != null && state2 != null)
            {
                if (state1.Type == state2.Type)
                {
                    State current = state2;
                    while (current != null & retVal == false)
                    {
                        // HaCK: compare the names of states to determine compatibility
                        retVal  = (current.FullName == state1.FullName);
                        current = current.EnclosingState;
                    }
                }
            }

            return(retVal);
        }
コード例 #9
0
        /// <summary>
        ///     Provides the update of the state machine enclosing a rule or state.
        /// </summary>
        /// <param name="dictionary"></param>
        /// <returns></returns>
        public StateMachine CreateSubStateMachineUpdate(Dictionary dictionary)
        {
            StateMachine retVal = null;

            if (this != FindTopLevelStateMachine())
            {
                State refState = EnclosingStateUpdate(dictionary);
                retVal = refState.StateMachine;
            }
            else
            {
                StateMachine updateSm = dictionary.FindByFullName(FullName) as StateMachine;
                if (updateSm == null)
                {
                    // If the element does not already exist in the patch, add a copy to it
                    updateSm = CreateStateMachineUpdate(dictionary);
                }

                retVal = updateSm;
            }

            return(retVal);
        }
コード例 #10
0
        /// <summary>
        ///     Add actions when leaving a state
        /// </summary>
        /// <param name="priority"></param>
        /// <param name="updates"></param>
        /// <param name="variable"></param>
        /// <param name="leaveState"></param>
        /// <param name="enterState"></param>
        private void HandleLeaveState(acceptor.RulePriority priority, List<VariableUpdate> updates, IVariable variable,
            State leaveState, State enterState)
        {
            if (!_processedStates.Contains(leaveState))
            {
                _processedStates.Add(leaveState);

                if (!leaveState.getStateMachine().Contains(leaveState, enterState))
                {
                    if (leaveState.getLeaveAction() != null)
                    {
                        Rules.Rule rule = (Rules.Rule) leaveState.getLeaveAction();
                        ExplanationPart explanation = new ExplanationPart(rule, "Rule evaluation");
                        HashSet<Activation> newActivations = new HashSet<Activation>();
                        List<VariableUpdate> newUpdates = new List<VariableUpdate>();
                        // the priority is not specified for the rule evaluation since
                        // the rules of the leave states have to be executed regardless the priority
                        rule.Evaluate(this, null, variable, newActivations, explanation);
                        EvaluateActivations(newActivations, priority, ref newUpdates);
                        updates.AddRange(newUpdates);
                    }

                    if (leaveState.EnclosingState != null)
                    {
                        HandleLeaveState(priority, updates, variable, leaveState.EnclosingState, enterState);
                    }
                }

                _processedStates.Remove(leaveState);
            }
        }
コード例 #11
0
        /// <summary>
        ///     Add actions when entering a state
        /// </summary>
        /// <param name="priority"></param>
        /// <param name="updates"></param>
        /// <param name="variable"></param>
        /// <param name="leaveState"></param>
        /// <param name="enterState"></param>
        private void HandleEnterState(acceptor.RulePriority priority, List<VariableUpdate> updates, IVariable variable,
            State leaveState, State enterState)
        {
            if (!_processedStates.Contains(enterState))
            {
                _processedStates.Add(enterState);

                if (!enterState.getStateMachine().Contains(enterState, leaveState))
                {
                    if (enterState.getEnterAction() != null)
                    {
                        Rules.Rule rule = (Rules.Rule) enterState.getEnterAction();
                        ExplanationPart explanation = new ExplanationPart(rule, "Rule evaluation");
                        HashSet<Activation> newActivations = new HashSet<Activation>();
                        List<VariableUpdate> newUpdates = new List<VariableUpdate>();
                        rule.Evaluate(this, priority, variable, newActivations, explanation);
                        EvaluateActivations(newActivations, priority, ref newUpdates);
                        updates.AddRange(newUpdates);
                    }

                    if (enterState.EnclosingState != null)
                    {
                        HandleEnterState(priority, updates, variable, leaveState, enterState.EnclosingState);
                    }
                }

                _processedStates.Remove(enterState);
            }
        }
コード例 #12
0
 /// <summary>
 /// Sets the target state of the transition controlled by this transition control
 /// </summary>
 /// <param name="state"></param>
 public void SetTargetState(DataDictionary.Constants.State state)
 {
     Transition.SetTargetState(state);
     RefreshControl();
 }
コード例 #13
0
 /// <summary>
 /// Adds a new state
 /// </summary>
 /// <param name="state"></param>
 public StateTreeNode AddState(DataDictionary.Constants.State state)
 {
     return(states.AddState(state));
 }
コード例 #14
0
        /// <summary>
        ///     Converts a DataDictionary.Values.IValue into an EFSIPCInterface.Value
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public Value ConvertOut(IValue value)
        {
            // Handles the boolean case
            {
                BoolValue v = value as BoolValue;
                if (v != null)
                {
                    return(new Values.BoolValue(v.Val));
                }
            }

            // Handles the integer case
            {
                IntValue v = value as IntValue;
                if (v != null)
                {
                    return(new Values.IntValue(v.Val));
                }
            }

            // Handles the double case
            {
                DoubleValue v = value as DoubleValue;
                if (v != null)
                {
                    return(new Values.DoubleValue(v.Val));
                }
            }

            // Handles the string case
            {
                StringValue v = value as StringValue;
                if (v != null)
                {
                    return(new Values.StringValue(v.Val));
                }
            }

            // Handles the state case
            {
                State v = value as State;
                if (v != null)
                {
                    return(new StateValue(v.FullName));
                }
            }

            // Handles the enumeration value case
            {
                EnumValue v = value as EnumValue;
                if (v != null)
                {
                    return(new Values.EnumValue(v.FullName));
                }
            }

            // Handles the list case
            {
                ListValue v = value as ListValue;
                if (v != null)
                {
                    List <Value> list = new List <Value>();

                    foreach (IValue item in v.Val)
                    {
                        list.Add(ConvertOut(item));
                    }

                    return(new Values.ListValue(list));
                }
            }

            // Handles the structure case
            {
                StructureValue v = value as StructureValue;
                if (v != null)
                {
                    Dictionary <string, Value> record = new Dictionary <string, Value>();

                    foreach (KeyValuePair <string, INamable> pair in v.Val)
                    {
                        IVariable variable = pair.Value as IVariable;
                        if (variable != null)
                        {
                            record.Add(variable.Name, ConvertOut(variable.Value));
                        }
                    }

                    return(new Values.StructureValue(record));
                }
            }

            // Handles the function case
            {
                DataDictionary.Functions.Function v = value as DataDictionary.Functions.Function;
                if (v != null)
                {
                    List <Segment> segments = new List <Segment>();

                    if (v.FormalParameters.Count == 1)
                    {
                        Graph graph = v.CreateGraph(new InterpretationContext(), (Parameter)v.FormalParameters[0], null);

                        if (graph != null)
                        {
                            foreach (Graph.Segment segment in graph.Segments)
                            {
                                double length = segment.End - segment.Start;
                                segments.Add(new Segment
                                {
                                    A      = segment.Expression.A,
                                    V0     = segment.Expression.V0,
                                    D0     = segment.Start,
                                    Length = length
                                });
                            }
                        }
                    }

                    return(new FunctionValue(segments));
                }
            }

            // Handles the 'empty' value
            {
                EmptyValue emptyValue = value as EmptyValue;
                if (emptyValue != null)
                {
                    return(null);
                }
            }

            throw new FaultException <EFSServiceFault>(new EFSServiceFault("Cannot convert value " + value));
        }
コード例 #15
0
 /// <summary>
 ///     Indicates that the two states have the same outermost state machine
 /// </summary>
 /// <param name="state1"></param>
 /// <param name="state2"></param>
 /// <returns></returns>
 private bool SameParentStateMachine(State state1, State state2)
 {
     return GetParentStateMachine(state1) == GetParentStateMachine(state2);
 }
コード例 #16
0
            /// <summary>
            ///     Finds a transition which matches the initial state, target state and rule condition in the existing transitions
            /// </summary>
            /// <param name="condition"></param>
            /// <param name="initialState"></param>
            /// <param name="targetState"></param>
            /// <returns></returns>
            private bool findMatchingTransition(Rules.RuleCondition condition, State initialState, State targetState)
            {
                bool retVal = false;

                foreach (Transition t in Transitions)
                {
                    if (t.RuleCondition == condition && t.Source == initialState && t.Target == targetState)
                    {
                        retVal = true;
                        break;
                    }
                }

                return retVal;
            }
コード例 #17
0
 public void AddHandler(object sender, EventArgs args)
 {
     DataDictionary.Constants.State state = (DataDictionary.Constants.State)DataDictionary.Generated.acceptor.getFactory().createState();
     state.Name = "<State" + (GetNodeCount(false) + 1) + ">";
     AddState(state);
 }
コード例 #18
0
 public StandardValuesCollection GetValues(DataDictionary.Constants.State State)
 {
     return(GetValues(State.StateMachine));
 }
コード例 #19
0
            /// <summary>
            ///     Adds a transition in the transitions sets
            /// </summary>
            /// <param name="update">The update state which provides the target of the transition</param>
            /// <param name="target">The target state, as determined by the update statement</param>
            /// <param name="filteredOut"></param>
            /// <param name="preCondition">the precondition (if any) which is used to determine the initial state</param>
            /// <param name="initial">The initial state</param>
            /// <returns>
            ///     true if the transition has been filtered out. A transition can be filtered out if the target state is equal to the
            ///     initial state or the initial state is null
            /// </returns>
            private bool AddTransition(VariableUpdateStatement update, State target, PreCondition preCondition,
                State initial)
            {
                bool retVal = false;

                if (SameParentStateMachine(initial, target))
                {
                    State initialState = StateMachine.StateInThisStateMachine(initial);
                    // TargetState is the target state either in this state machine or in a sub state machine
                    State targetState = StateMachine.StateInThisStateMachine(target);

                    // Determine the rule condition (if any) related to this state machine
                    Rules.RuleCondition condition = null;
                    if (update != null)
                    {
                        Action action = update.Root as Action;
                        condition = action.RuleCondition;
                    }

                    if (targetState != null || initialState != null)
                    {
                        // This transition is about this state machine.
                        if (initialState != targetState && initialState != null)
                        {
                            // Check that the transition is not yet present
                            // This case can occur when the same RuleCondition references two different states
                            // in a substate machine. Only draws the transition once.
                            if (!findMatchingTransition(condition, initialState, targetState))
                            {
                                Transitions.Add(new Transition(preCondition, initialState, update, targetState));
                            }
                        }
                        else
                        {
                            if (initialState == initial)
                            {
                                retVal = true;
                            }
                        }
                    }
                }

                return retVal;
            }
コード例 #20
0
            /// <summary>
            ///     Check if this rule corresponds to a transition for this state machine
            /// </summary>
            /// <param name="obj"></param>
            /// <param name="visitSubNodes"></param>
            public override void visit(RuleCondition obj, bool visitSubNodes)
            {
                Rules.RuleCondition ruleCondition = (Rules.RuleCondition)obj;

                foreach (Action action in ruleCondition.Actions)
                {
                    try
                    {
                        foreach (VariableUpdateStatement update in action.UpdateStatements)
                        {
                            Type targetType = update.TargetType;
                            if (targetType is StateMachine)
                            {
                                Expression expressionTree = update.Expression;
                                if (expressionTree != null)
                                {
                                    // HaCK: This is a bit rough, but should be sufficient for now...
                                    foreach (State stt1 in GetStates(expressionTree))
                                    {
                                        // TargetState is the target state either in this state machine or in a sub state machine
                                        State targetState = StateMachine.StateInThisStateMachine(stt1);

                                        int  transitionCount = Transitions.Count;
                                        bool filteredOut     = false;

                                        // Finds the enclosing state of this action to determine the source state of this transition
                                        State enclosingState = EnclosingFinder <State> .find(action);

                                        if (enclosingState != null)
                                        {
                                            filteredOut = filteredOut ||
                                                          AddTransition(update, stt1, null, enclosingState);
                                        }

                                        if (!filteredOut)
                                        {
                                            foreach (PreCondition preCondition in ruleCondition.AllPreConditions)
                                            {
                                                // A transition from one state to another has been found
                                                foreach (State stt2 in GetStates(preCondition.Expression))
                                                {
                                                    filteredOut = filteredOut ||
                                                                  AddTransition(update, stt1, preCondition, stt2);
                                                }
                                            }
                                        }

                                        if (Transitions.Count == transitionCount)
                                        {
                                            if (targetState == stt1 && targetState.EnclosingStateMachine == StateMachine)
                                            {
                                                if (!filteredOut)
                                                {
                                                    Action enclosingAction = update.Root as Action;

                                                    if (enclosingAction != null)
                                                    {
                                                        // No precondition could be found => one can reach this state at anytime
                                                        if (
                                                            !findMatchingTransition(enclosingAction.RuleCondition, null,
                                                                                    targetState))
                                                        {
                                                            Transitions.Add(new Transition(null, null, update,
                                                                                           targetState));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    action.AddError("Cannot parse expression");
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }

                base.visit(obj, visitSubNodes);
            }
コード例 #21
0
            /// <summary>
            ///     Provides the outermost state machine enclosing the state provided
            /// </summary>
            /// <param name="state"></param>
            /// <returns></returns>
            private StateMachine GetParentStateMachine(State state)
            {
                StateMachine retVal = state.EnclosingStateMachine;

                while (retVal.EnclosingStateMachine != null)
                {
                    retVal = retVal.EnclosingStateMachine;
                }

                return retVal;
            }
コード例 #22
0
 /// <summary>
 ///     Indicates that the two states have the same outermost state machine
 /// </summary>
 /// <param name="state1"></param>
 /// <param name="state2"></param>
 /// <returns></returns>
 private bool SameParentStateMachine(State state1, State state2)
 {
     return(GetParentStateMachine(state1) == GetParentStateMachine(state2));
 }
コード例 #23
0
        /// <summary>
        ///     Indicates that the state machine contains (either directly or indirectly) the state
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        internal State StateInThisStateMachine(State state)
        {
            State retVal = null;

            foreach (State other in States)
            {
                if (other == state)
                {
                    retVal = state;
                    break;
                }

                retVal = other.StateMachine.StateInThisStateMachine(state);
                if (retVal != null)
                {
                    retVal = other;
                    break;
                }
            }

            return retVal;
        }
コード例 #24
0
            /// <summary>
            ///     Finds a transition which matches the initial state, target state and rule condition in the existing transitions
            /// </summary>
            /// <param name="condition"></param>
            /// <param name="initialState"></param>
            /// <param name="targetState"></param>
            /// <returns></returns>
            private bool findMatchingTransition(Rules.RuleCondition condition, State initialState, State targetState)
            {
                bool retVal = false;

                foreach (Transition t in Transitions)
                {
                    if (t.RuleCondition == condition && t.Source == initialState && t.Target == targetState)
                    {
                        retVal = true;
                        break;
                    }
                }

                return(retVal);
            }