/// <summary> /// Converts an interface priority to a Runner priority /// </summary> /// <param name="priority"></param> private acceptor.RulePriority convertStep2Priority(Step priority) { acceptor.RulePriority retVal = acceptor.RulePriority.defaultRulePriority; switch (priority) { case Step.Verification: retVal = acceptor.RulePriority.aVerification; break; case Step.UpdateInternal: retVal = acceptor.RulePriority.aUpdateINTERNAL; break; case Step.Process: retVal = acceptor.RulePriority.aProcessing; break; case Step.UpdateOutput: retVal = acceptor.RulePriority.aUpdateOUT; break; case Step.CleanUp: retVal = acceptor.RulePriority.aCleanUp; break; } return(retVal); }
/// <summary> /// Indicates that a rule is applicable for this type at the provided priority /// </summary> /// <returns></returns> public override bool ApplicableRule(acceptor.RulePriority priority) { if (ApplicableRules == null) { ApplicableRules = new HashSet <acceptor.RulePriority>(); // Consider the rules at this level foreach (Rule rule in Rules) { foreach (acceptor.RulePriority active in rule.ActivationPriorities) { ApplicableRules.Add(active); } } // Consider the rules in inner states foreach (State state in States) { if (state.StateMachine != null) { foreach (acceptor.RulePriority active in System.Enum.GetValues(typeof(acceptor.RulePriority))) { if (state.StateMachine.ApplicableRule(active)) { ApplicableRules.Add(active); } } } } } return(ApplicableRules.Contains(priority)); }
/// <summary> /// Executes a single rule priority (shared version of the method) /// </summary> /// <param name="priority"></param> private void InnerExecuteOnePriority(acceptor.RulePriority priority) { Util.DontNotify(() => { CacheImpact = new CacheImpact(); CurrentPriority = priority; // Activates the processing engine HashSet <Activation> activations = new HashSet <Activation>(); foreach (Dictionary dictionary in EfsSystem.Instance.Dictionaries) { foreach (NameSpace nameSpace in dictionary.NameSpaces) { SetupNameSpaceActivations(priority, activations, nameSpace); } } List <VariableUpdate> updates = new List <VariableUpdate>(); EvaluateActivations(activations, priority, updates); CheckUpdatesCompatibility(updates); ApplyUpdates(updates); ClearCaches(); CheckExpectationsState(priority); }); }
/// <summary> /// Indicates that a rule is applicable for this type at the provided priority /// </summary> /// <returns></returns> public override bool ApplicableRule(acceptor.RulePriority priority) { if (ApplicableRules == null) { ApplicableRules = new HashSet <acceptor.RulePriority>(); // Consider the rules at this level foreach (Rule rule in Rules) { foreach (acceptor.RulePriority active in rule.ActivationPriorities) { ApplicableRules.Add(active); } } // Consider the structure elements foreach (ITypedElement element in Elements) { if (element.Type != null) { foreach (acceptor.RulePriority active in System.Enum.GetValues(typeof(acceptor.RulePriority))) { if (element.Type.ApplicableRule(active)) { ApplicableRules.Add(active); } } } } } return(ApplicableRules.Contains(priority)); }
/// <summary> /// Indicates that a rule is applicable for this type at the provided priority /// </summary> /// <returns></returns> public override bool ApplicableRule(acceptor.RulePriority priority) { bool retVal = false; if (Type != null) { retVal = Type.ApplicableRule(priority); } return(retVal); }
/// <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; } } } }
/// <summary> /// Determines the set of rules in a specific namespace to be applied. /// </summary> /// <param name="priority">The priority for which this activation is requested</param> /// <param name="activations">The set of activations to be filled</param> /// <param name="nameSpace">The namespace to consider</param> /// <returns></returns> protected void SetupNameSpaceActivations(acceptor.RulePriority priority, HashSet <Activation> activations, NameSpace nameSpace) { // Finds all activations in sub namespaces foreach (NameSpace subNameSpace in nameSpace.NameSpaces) { SetupNameSpaceActivations(priority, activations, subNameSpace); } foreach (Rules.Rule rule in nameSpace.Rules) { // We only apply rules that have not been updated ExplanationPart explanation = new ExplanationPart(rule, "Rule evaluation"); rule.Evaluate(this, priority, rule, activations, explanation); } foreach (IVariable variable in nameSpace.Variables) { EvaluateVariable(priority, activations, variable, new ExplanationPart(variable as ModelElement, "Evaluating variable")); } }
/// <summary> /// Executes the interpretation machine for one priority /// </summary> /// <param name="priority"></param> public void ExecuteOnePriority(acceptor.RulePriority priority) { try { ControllersManager.NamableController.DesactivateNotification(); LastActivationTime = Time; Utils.ModelElement.Errors = new Dictionary <Utils.ModelElement, List <ElementLog> >(); // Executes a single rule priority InnerExecuteOnePriority(priority); EventTimeLine.GarbageCollect(); } finally { ControllersManager.NamableController.ActivateNotification(); } if (priority == acceptor.RulePriority.aCleanUp) { NextCycle(); } }
public void setPriority(acceptor.RulePriority v) { aPriority = v; __setDirty(true); NotifyControllers(null); }
public Rule() { Rule obj = this; aPriority=(0); aConditions=(null); aWidth=(0); aHeight=(0); aX=(0); aY=(0); aHidden=(false); aPinned=(false); }
public void setCyclePhase(acceptor.RulePriority v) { aCyclePhase = v; __setDirty(true); NotifyControllers(null); }
public Expectation() { Expectation obj = this; aValue=(null); aBlocking=(false); aKind=(0); aDeadLine=(0.0); aCondition=(null); aComment=(null); aCyclePhase=(0); }
/// <summary> /// Updates the expectation state according to the variables' value /// </summary> /// <param name="priority">The priority for which this check is performed</param> private void CheckExpectationsState(acceptor.RulePriority priority) { // Update the state of the expectation according to system's state foreach (Expect expect in ActiveExpectations()) { Expectation expectation = expect.Expectation; // Determine if the deadline is reached if (expect.TimeOut < EventTimeLine.CurrentTime) { switch (expect.Expectation.getKind()) { case acceptor.ExpectationKind.aInstantaneous: case acceptor.ExpectationKind.defaultExpectationKind: // Instantaneous expectation who raised its deadling EventTimeLine.AddModelEvent(new FailedExpectation(expect, CurrentPriority, null), true); break; case acceptor.ExpectationKind.aContinuous: // Continuous expectation who raised its deadline EventTimeLine.AddModelEvent(new ExpectationReached(expect, CurrentPriority, null), true); break; } } else { ExplanationPart explanation = new ExplanationPart(expectation, "Expectation " + expectation.Expression); try { if (expectation.getCyclePhase() == acceptor.RulePriority.defaultRulePriority || expectation.getCyclePhase() == priority) { switch (expectation.getKind()) { case acceptor.ExpectationKind.aInstantaneous: case acceptor.ExpectationKind.defaultExpectationKind: if (getBoolValue(expectation, expectation.Expression, explanation)) { // An instantaneous expectation who reached its satisfactory condition EventTimeLine.AddModelEvent( new ExpectationReached(expect, priority, explanation), true); } else { expectation.Explain = explanation; } break; case acceptor.ExpectationKind.aContinuous: if (expectation.getCondition() != null) { if (!getBoolValue(expectation, expectation.ConditionTree, explanation)) { // An continuous expectation who reached its satisfactory condition EventTimeLine.AddModelEvent( new ExpectationReached(expect, priority, explanation), true); } else { if (!getBoolValue(expectation, expectation.Expression, explanation)) { // A continuous expectation who reached a case where it is not satisfied EventTimeLine.AddModelEvent( new FailedExpectation(expect, priority, explanation), true); } else { expectation.Explain = explanation; } } } else { if (!getBoolValue(expectation, expectation.Expression, explanation)) { // A continuous expectation who reached a case where it is not satisfied EventTimeLine.AddModelEvent( new FailedExpectation(expect, priority, explanation), true); } else { expectation.Explain = explanation; } } break; } } } catch (Exception e) { expectation.AddErrorAndExplain(e.Message, explanation); } } } }
/// <summary> /// Evaluates the rules associated to a single variable /// </summary> /// <param name="priority">The priority in which this variable is evaluated</param> /// <param name="activations">The activation list result of this evaluation</param> /// <param name="variable">The variable to evaluate</param> /// <param name="explanation">The explanation part to be filled</param> private void EvaluateVariable(acceptor.RulePriority priority, HashSet <Activation> activations, IVariable variable, ExplanationPart explanation) { if (variable != null && variable.Value != EfsSystem.Instance.EmptyValue) { if (variable.Type != null && variable.Type.ApplicableRule(priority)) { if (variable.Type is Structure) { Structure structure = variable.Type as Structure; foreach (Rules.Rule rule in structure.Rules) { rule.Evaluate(this, priority, variable, activations, explanation); } StructureValue value = variable.Value as StructureValue; if (value != null) { foreach (IVariable subVariable in value.SubVariables.Values) { EvaluateVariable(priority, activations, subVariable, explanation); } } } else if (variable.Type is StateMachine) { EvaluateStateMachine(activations, priority, variable, explanation); } else if (variable.Type is Collection) { Collection collectionType = variable.Type as Collection; if (variable.Value != EfsSystem.Instance.EmptyValue) { ListValue val = variable.Value as ListValue; if (val != null) { foreach (IValue subVal in val.Val) { Variables.Variable tmp = new Variables.Variable { Name = "list_entry", Type = collectionType.Type, Value = subVal }; EvaluateVariable(priority, activations, tmp, explanation); } } else { ModelElement element = variable as ModelElement; if (element != null) { element.AddError("Variable " + variable.Name + " does not hold a collection but " + variable.Value); } else { throw new Exception("Variable " + variable.Name + " does not hold a collection but " + variable.Value); } } } } } } }
public bool setPriority_AsString( string v) { acceptor.RulePriority temp = acceptor.StringTo_Enum_RulePriority(v); if (temp >= 0){ aPriority = temp; __setDirty(true); NotifyControllers(null); return true; } // If return false; }
/// <summary> /// Indicates that a rule is applicable for this type at the provided priority /// </summary> /// <returns></returns> public virtual bool ApplicableRule(acceptor.RulePriority priority) { return(false); }
public Rule() { Rule obj = this; aPriority=(0); aConditions=(null); }