/// <summary> /// Creates a new instance of the <see cref="T:PfcElement"/> class. /// </summary> /// <param name="parent">The parent.</param> /// <param name="name">The name of this node.</param> /// <param name="description">The description for this node.</param> /// <param name="guid">The GUID of this node.</param> public PfcElement(IProcedureFunctionChart parent, string name, string description, Guid guid) { m_parent = parent; InitializeIdentity(parent.Model, name, description, guid); m_userData = null; IMOHelper.RegisterWithModel(this); }
static void DumpElementContents(IProcedureFunctionChart pfc, StringBuilder sb, int indent) { foreach (IPfcElement element in pfc.Elements) { DumpElementContents(element, sb, indent); } }
public static string GetDeepStructure(IProcedureFunctionChart ipfc) { StringBuilder sb = new StringBuilder(); GetDeepStructure(ipfc, 0, ref sb); return(sb.ToString()); }
} // Statics only. /// <summary> /// Gets the SFC's diagnostic report. /// </summary> /// <param name="pfc">The ProcedureFunctionChart to be reported on.</param> /// <returns></returns> public string PfcDiagnosticReport(IProcedureFunctionChart pfc) { StringBuilder sb = new StringBuilder(); sb.Append(PfcSummaryInfo(pfc)); return(sb.ToString()); }
/// <summary> /// Gets the finish step from the provided PFC. Assumes that there is only one. /// </summary> /// <param name="pfc">The PFC.</param> /// <returns>The finish step.</returns> public static IPfcStepNode GetFinishStep(IProcedureFunctionChart pfc) { foreach (IPfcStepNode step in pfc.Steps) { if (step.PredecessorNodes.Count == 0) { return(step); } } return(null); }
public static bool IsTargetNodeLegal(IPfcNode origin, IPfcNode target) { bool retval = false; IProcedureFunctionChart parent = origin.Parent; // We only evaluate step-to-step links, or transition-to-transition links, // meaning that we must always add a shim node between them. if (origin.ElementType.Equals(target.ElementType)) { if (s_diagnostics) { Console.WriteLine("Before: " + StringOperations.ToCommasAndAndedListOfNames <IPfcNode>(parent.Nodes)); } IPfcLinkElement link1, link2; IPfcNode shimNode; parent.Bind(origin, target, out link1, out shimNode, out link2, false); if (s_diagnostics) { Console.WriteLine("During: " + StringOperations.ToCommasAndAndedListOfNames <IPfcNode>(parent.Nodes)); } PfcValidator validator = new PfcValidator(parent); retval = validator.PfcIsValid(); if (shimNode != null) { parent.Unbind(origin, shimNode, true); parent.Unbind(shimNode, target, true); parent.UpdateStructure(); } else { parent.Unbind(origin, target); } if (s_diagnostics) { Console.WriteLine("After: " + StringOperations.ToCommasAndAndedListOfNames <IPfcNode>(parent.Nodes)); } parent.ElementFactory.Retract(); } else { return(false); } return(retval); }
public PfcValidator(IProcedureFunctionChart pfc) { m_errorList = new List <PfcValidationError>(); m_pfc = (IProcedureFunctionChart)pfc.Clone(); Reduce(); try { m_pfc.UpdateStructure(); Validate(); } catch (PFCValidityException) { m_pfcIsValid = false; } }
private static void GetDeepStructure(IProcedureFunctionChart ipfc, int indent, ref StringBuilder sb) { string indents = Utility.StringOperations.Spaces(indent * 3); foreach (IPfcStepNode step in ipfc.Steps) { sb.Append(indents + step.Name + "\r\n"); if (step.Actions != null) { foreach (string key in step.Actions.Keys) { sb.Append(indents + "[" + key + "]\r\n"); GetDeepStructure(step.Actions[key], indent + 1, ref sb); } } } }
public void TestCreationOfABazillionEECs() { Assert.Fail(); DateTime start = DateTime.Now; ExecutionEngineConfiguration eec = new ExecutionEngineConfiguration(); IProcedureFunctionChart pfc = CreatePfc(new Model(), "RootPfc", 15.0, eec); PfcExecutionContext pfcec = new PfcExecutionContext(pfc, "MyPfcExecutionContext_0", "", Guid.NewGuid(), null); while (nECs < nSteps) { Propagate(pfc, pfcec); } DateTime finish = DateTime.Now; Console.WriteLine("The test took " + ((TimeSpan)(finish - start)) + " to create " + nECs + " execution contexts."); }
public static string GetStructure(IProcedureFunctionChart pfc) { StringBuilder sb = new StringBuilder(); PfcLinkElementList llist = pfc.Links; llist.Sort(delegate(IPfcLinkElement le1, IPfcLinkElement le2) { return(Comparer.Default.Compare(le1.Name, le2.Name)); }); foreach (IPfcLinkElement linkElement in llist) { string predName = linkElement.Predecessor == null ? "<null>" : linkElement.Predecessor.Name; string linkName = linkElement.Name; string parentName = linkElement.Parent == null ? "<null>" : linkElement.Parent.Name; string succName = linkElement.Successor == null ? "<null>" : linkElement.Successor.Name; sb.Append("{" + predName + "-->[" + linkName + "(" + /*parentName*/ "SFC 1.Root" + ")]-->" + succName + "}\r\n"); } return(sb.ToString()); }
/// <summary> /// Gets the PFC's summary info in string format. /// </summary> /// <param name="pfc">The pfc.</param> /// <returns></returns> public static string PfcSummaryInfo(IProcedureFunctionChart pfc) { StringBuilder sb = new StringBuilder(); sb.Append(pfc.GetType().FullName + " : " + pfc.Name + "\r\n"); sb.Append("\tSteps : " + pfc.Steps.Count + "\r\n"); sb.Append("\tLinks : " + pfc.Edges.Count + "\r\n"); sb.Append("\tTransitions : " + pfc.Transitions.Count + "\r\n"); sb.Append("\tNodes : " + pfc.Nodes.Count + "\r\n"); sb.Append("\tNode Hierarchy\r\n"); DumpElementContents(pfc, sb, 1); sb.Append("\r\n"); return(sb.ToString()); }
private void Propagate(IProcedureFunctionChart pfc, PfcExecutionContext pfcec) { List <PfcExecutionContext> readyToProcreate = new List <PfcExecutionContext>(); foreach (PfcExecutionContext node in pfcec.DescendantNodesDepthFirst(true)) { if (node.Children.Count() == 0) { readyToProcreate.Add(node); } } foreach (PfcExecutionContext kid in readyToProcreate) { for (int i = 1; i < nAvgKids && nECs < nSteps; i++) { PfcExecutionContext kidEC = new PfcExecutionContext(pfc, "MyPfcExecutionContext_" + (nECs++), "", Guid.NewGuid(), pfcec); } } }
public PfcExecutionContext(IProcedureFunctionChart pfc, string name, string description, Guid guid, PfcExecutionContext parent) : base(pfc.Model, name, description, guid, parent) { if (s_diagnostics) { string parentName = (parent == null ? "<null>" : parent.Name); Console.WriteLine("Creating PFCEC \"" + name + "\" under PFCEC \"" + parentName + "\" For parent " + pfc.Name + " and numbered " + guid); } m_pfc = pfc; m_step = null; m_timePeriod = new TimePeriodEnvelope(name, GuidOps.XOR(guid, s_time_Period_Mask)); m_timePeriod.Subject = this; if (parent != null) { ((TimePeriodEnvelope)parent.TimePeriod).AddTimePeriod(m_timePeriod); } m_timePeriod.ChangeEvent += new ObservableChangeHandler(m_timePeriod_ChangeEvent); }
public void TestSmallLoopback() { Assert.Fail(); Model model = new Model("MyTestModel"); IProcedureFunctionChart pfc = CreatePfc(model, "RootPfc", 1.0, new ExecutionEngineConfiguration()); Hashtable ht = new Hashtable(); ht.Add("StringBuilder", new StringBuilder()); pfc.Model.Executive.RequestEvent(new ExecEventReceiver(pfc.Run), DateTime.MinValue, 0.0, ht, ExecEventType.Detachable); pfc.Model.Start(); int resultHashCode = ht["StringBuilder"].ToString().GetHashCode(); System.Diagnostics.Debug.Assert(resultHashCode == 1263719327, "Result value did not match expected value."); Console.WriteLine(ht["StringBuilder"]); }
/// <summary> /// Creates pfc execution contexts, one per action under the step that is currently running. Each /// is given an instance count of zero, as a step can run its action only once, currently. /// </summary> /// <param name="parentContext">The parent context, that of the step that is currently running.</param> /// <param name="kids">The procedure function charts that live in the actions under the step that is currently running.</param> /// <param name="kidContexts">The pfc execution contexts that will correspond to the running of each of the child PFCs.</param> protected virtual void CreateChildContexts(PfcExecutionContext parentContext, out IProcedureFunctionChart[] kids, out PfcExecutionContext[] kidContexts) { int kidCount = MyStep.Actions.Count; kids = new ProcedureFunctionChart[kidCount]; kidContexts = new PfcExecutionContext[kidCount]; int i = 0; foreach (KeyValuePair <string, IProcedureFunctionChart> kvp in MyStep.Actions) { IProcedureFunctionChart kid = kvp.Value; kids[i] = kid; Guid kidGuid = GuidOps.XOR(parentContext.Guid, kid.Guid); while (parentContext.Contains(kidGuid)) { kidGuid = GuidOps.Increment(kidGuid); } kidContexts[i] = new PfcExecutionContext(kid, kvp.Key, null, kidGuid, parentContext); kidContexts[i].InstanceCount = 0; i++; } }
public void TestSmallLoopbackHierarchical() { DateTime start = DateTime.Now; Model model = new Model("MyTestModel"); ExecutionEngineConfiguration eec = new ExecutionEngineConfiguration(); eec.ScanningPeriod = TimeSpan.FromSeconds(60.0); IProcedureFunctionChart pfc = CreatePfc(model, "RootPfc", 15.0, eec); IProcedureFunctionChart pfcChild1 = CreatePfc(model, "Step1Child", 15.0, eec); ((PfcStep)pfc.Nodes["RootPfc" + "Step1"]).AddAction("Alice", pfcChild1); IProcedureFunctionChart pfcGrandChild1 = CreatePfc(model, "Step1GrandChild", 15.0, eec); ((PfcStep)pfcChild1.Nodes["Step1Child" + "Step1"]).AddAction("Bob", pfcGrandChild1); PfcExecutionContext dictionary = new PfcExecutionContext(pfc, "MyPfcExecutionContext", "", Guid.NewGuid(), null); dictionary.Add("StringBuilder", new StringBuilder()); pfc.Model.Executive.RequestEvent(new ExecEventReceiver(pfc.Run), DateTime.MinValue, 0.0, dictionary, ExecEventType.Detachable); pfc.Model.Start(); int resultHashCode = dictionary["StringBuilder"].ToString().GetHashCode(); foreach (object obj in dictionary.Values) { if (obj is PfcExecutionContext) { Console.WriteLine(obj.ToString() + " contains " + ((PfcExecutionContext)obj).Values.Count + " members."); } } Console.WriteLine(dictionary["StringBuilder"]); DateTime finish = DateTime.Now; Console.WriteLine("The test took " + ((TimeSpan)(finish - start))); }
public PfcExecutionContext(IPfcStepNode stepNode, string name, string description, Guid guid, PfcExecutionContext parent) : base(stepNode.Parent.Model, name, description, guid, parent) { if (s_diagnostics) { Console.WriteLine("Creating PfcEC \"" + name + "\" under PfcEC \"" + parent.Name + "\" For parent " + stepNode.Name + " and numbered " + guid); } m_pfc = stepNode.Parent; m_step = stepNode; if (stepNode.Actions.Count == 0) { m_timePeriod = new TimePeriod(name, GuidOps.XOR(guid, s_time_Period_Mask), TimeAdjustmentMode.InferDuration); m_timePeriod.Subject = this; ((TimePeriodEnvelope)parent.TimePeriod).AddTimePeriod(m_timePeriod); } else { m_timePeriod = new TimePeriodEnvelope(name, GuidOps.XOR(guid, s_time_Period_Mask)); m_timePeriod.Subject = this; ((TimePeriodEnvelope)parent.TimePeriod).AddTimePeriod(m_timePeriod); } m_timePeriod.ChangeEvent += new ObservableChangeHandler(m_timePeriod_ChangeEvent); }
public ExecutionEngine(IProcedureFunctionChart pfc) : this(pfc, new ExecutionEngineConfiguration()) { }
/// <summary> /// Creates a new instance of the <see cref="T:PfcTransition"/> class. /// </summary> /// <param name="parent">The ProcedureFunctionChart this transition runs in.</param> /// <param name="name">The name of this transition.</param> /// <param name="description">The description for this transition.</param> /// <param name="guid">The GUID of this transition.</param> public PfcTransition(IProcedureFunctionChart parent, string name, string description, Guid guid) : base(parent, name, description, guid) { m_expression = Expressions.Expression.FromUf(DefaultExpression, parent.ParticipantDirectory, this); m_executableExpression = DefaultExecutableExpression; }
internal PfcLink(IProcedureFunctionChart parent, string name, string description, Guid guid) : base(parent, name, description, guid) { }
/// <summary> /// Adds a child Pfc into the actions list under this step. /// </summary> /// <param name="actionName">The name of this action.</param> /// <param name="pfc">The Pfc that contains procedural details of this action.</param> public void AddAction(string actionName, IProcedureFunctionChart pfc) { Actions.Add(actionName, pfc); }
public ExecutionEngine(IProcedureFunctionChart pfc, ExecutionEngineConfiguration eec) { m_executionEngineConfiguration = eec; m_model = pfc.Model; m_stepStateMachines = new Dictionary <IPfcStepNode, StepStateMachine>(); m_transitionStateMachines = new Dictionary <IPfcTransitionNode, TransitionStateMachine>(); foreach (IPfcStepNode pfcStepNode in pfc.Steps) { StepStateMachine ssm = new StepStateMachine(pfcStepNode); ssm.StructureLocked = m_executionEngineConfiguration.StructureLockedDuringRun; m_stepStateMachines.Add(pfcStepNode, ssm); ssm.MyStep = pfcStepNode; ((PfcStep)pfcStepNode).MyStepStateMachine = ssm; } foreach (IPfcTransitionNode pfcTransNode in pfc.Transitions) { TransitionStateMachine tsm = new TransitionStateMachine(pfcTransNode); tsm.ScanningPeriod = m_executionEngineConfiguration.ScanningPeriod; m_transitionStateMachines.Add(pfcTransNode, tsm); tsm.MyTransition = pfcTransNode; ((PfcTransition)pfcTransNode).MyTransitionStateMachine = tsm; } StepStateMachineEvent ssme = new StepStateMachineEvent(anSSM_StepStateChanged); foreach (IPfcStepNode step in pfc.Steps) { step.MyStepStateMachine.StepStateChanged += ssme; foreach (IPfcTransitionNode transNode in step.SuccessorNodes) { step.MyStepStateMachine.SuccessorStateMachines.Add(transNode.MyTransitionStateMachine); } if (step.MyStepStateMachine.SuccessorStateMachines.Count == 0) { string message = $"Step {step.Name} in PFC {step.Parent.Name} has no successor transition. A PFC must end with a termination transition. (Did you acquire an Execution Engine while the Pfc was still under construction?)"; throw new ApplicationException(message); } } TransitionStateMachineEvent tsme = new TransitionStateMachineEvent(aTSM_TransitionStateChanged); foreach (IPfcTransitionNode trans in pfc.Transitions) { TransitionStateMachine thisTsm = m_transitionStateMachines[trans]; thisTsm.TransitionStateChanged += tsme; foreach (IPfcStepNode stepNode in trans.SuccessorNodes) { thisTsm.SuccessorStateMachines.Add(m_stepStateMachines[stepNode]); } foreach (IPfcStepNode stepNode in trans.PredecessorNodes) { thisTsm.PredecessorStateMachines.Add(m_stepStateMachines[stepNode]); } } List <IPfcStepNode> startSteps = pfc.GetStartSteps(); _Debug.Assert(startSteps.Count == 1); m_startStep = m_stepStateMachines[startSteps[0]]; }
/// <summary> /// Creates a new instance of this class with a specific message and an inner exception. /// </summary> /// <param name="pfc">The members of the cycle.</param> /// <param name="message">The exception message.</param> /// <param name="innerException">The inner exception.</param> public PFCValidityException(IProcedureFunctionChart pfc, string message, Exception innerException) : base(message, innerException) { m_pfc = pfc; }
/// <summary> /// Creates a new instance of this class. /// </summary> public PFCValidityException(IProcedureFunctionChart pfc) { m_pfc = pfc; }
/// <summary> /// Creates a new instance of the <see cref="T:PfcStep"/> class. /// </summary> /// <param name="parent">The parent Pfc of this step.</param> /// <param name="name">The name of this step.</param> /// <param name="description">The description for this step.</param> /// <param name="guid">The GUID of this step.</param> public PfcStep(IProcedureFunctionChart parent, string name, string description, Guid guid) : base(parent, name, description, guid) { m_actions = new Dictionary <string, IProcedureFunctionChart>(); m_labelManager = new Utility.LabelManager(); }
/// <summary> /// Creates a new instance of the <see cref="T:PfcNode"/> class. /// </summary> /// <param name="parent">The PFC this step runs as a part of.</param> /// <param name="name">The name of this step.</param> /// <param name="description">The description for this step.</param> /// <param name="guid">The GUID of this step.</param> public PfcNode(IProcedureFunctionChart parent, string name, string description, Guid guid) : base(parent, name, description, guid) { m_predecessors = new PfcLinkElementList(); m_successors = new PfcLinkElementList(); }