/// <summary> /// Indicates whether a rule condition has been activated at the time provided /// </summary> /// <param name="ruleCondition">The rule condition that should be activated</param> /// <param name="time">the time when the rule condition should be activated</param> /// <param name="variable">The variable impacted by this rule condition, if any</param> /// <returns>True if the provided rule condition has been activated</returns> public bool RuleActivatedAtTime(Rules.RuleCondition ruleCondition, double time, IVariable variable) { bool retVal = false; if (variable != null) { foreach (ModelEvent modelEvent in Events) { RuleFired ruleFired = modelEvent as RuleFired; if (modelEvent.Time == time && ruleFired != null) { if (ruleFired.RuleCondition == ruleCondition) { retVal = ruleFired.ImpactVariable(variable); if (retVal) { break; } } } } } return(retVal); }
/// <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, Constants.State initialState, Constants.State targetState) { bool retVal = false; foreach (Rules.Transition t in Transitions) { if (t.RuleCondition == condition && t.InitialState == initialState && t.TargetState == targetState) { retVal = true; break; } } return(retVal); }
/// <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(Interpreter.Statement.VariableUpdateStatement update, Constants.State target, Rules.PreCondition preCondition, Constants.State initial) { bool retVal = false; Constants.State initialState = StateMachine.StateInThisStateMachine(initial); // TargetState is the target state either in this state machine or in a sub state machine Constants.State targetState = StateMachine.StateInThisStateMachine(target); // Determine the rule condition (if any) related to this state machine Rules.RuleCondition condition = null; if (update != null) { Rules.Action action = update.Root as Rules.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 Rules.Transition(preCondition, initialState, update, targetState)); } } else { if (initialState == initial) { retVal = true; } } } return(retVal); }
public override Generated.RuleCondition createRuleCondition() { Rules.RuleCondition retVal = new Rules.RuleCondition(); return retVal; }
/// <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(Generated.RuleCondition obj, bool visitSubNodes) { Rules.RuleCondition ruleCondition = (Rules.RuleCondition)obj; foreach (Rules.Action action in ruleCondition.Actions) { foreach (Interpreter.Statement.VariableUpdateStatement update in action.UpdateStatements) { Types.Type targetType = update.TargetType; if (targetType is StateMachine) { Interpreter.Expression expressionTree = update.Expression; if (expressionTree != null) { // HaCK: This is a bit rough, but should be sufficient for now... foreach (Constants.State stt1 in GetStates(expressionTree)) { // TargetState is the target state either in this state machine or in a sub state machine Constants.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 Constants.State enclosingState = Utils.EnclosingFinder <Constants.State> .find(action); if (enclosingState != null) { filteredOut = filteredOut || AddTransition(update, stt1, null, enclosingState); } if (!filteredOut) { foreach (Rules.PreCondition preCondition in ruleCondition.AllPreConditions) { // A transition from one state to another has been found foreach (Constants.State stt2 in GetStates(preCondition.ExpressionTree)) { filteredOut = filteredOut || AddTransition(update, stt1, preCondition, stt2); } } } if (Transitions.Count == transitionCount) { if (targetState == stt1 && targetState.EnclosingStateMachine == StateMachine) { if (!filteredOut) { // No precondition could be found => one can reach this state at anytime Transitions.Add(new Rules.Transition(null, null, update, targetState)); } } } } } else { action.AddError("Cannot parse expression"); } } } } base.visit(obj, visitSubNodes); }
/// <summary> /// Constructor /// </summary> /// <param name="id"></param> public RuleFired(Rules.RuleCondition ruleCondition) : base(ruleCondition.Name, ruleCondition) { RuleCondition = ruleCondition; Updates = new List <VariableUpdate>(); }
/// <summary> /// Constructor /// </summary> /// <param name="ruleCondition">The rule condition which leads to this activation</param> /// <param name="instance">The instance on which this rule condition's preconditions are evaluated to true</param> public Activation(Rules.RuleCondition ruleCondition, Utils.IModelElement instance) { RuleCondition = ruleCondition; Instance = instance; }
public override Generated.RuleCondition createRuleCondition() { Rules.RuleCondition retVal = new Rules.RuleCondition(); return(retVal); }