public bool ValidatePlan(PartiallySpecifiedState pssCurrent) { if (pssCurrent == null) { return(false); } if (pssCurrent.IsGoalState()) { return(true); } if (Action == null) { return(false); } Formula fObserved = null; PartiallySpecifiedState psTrueState, psFalseState; pssCurrent.ApplyOffline(Action, out fObserved, out psTrueState, out psFalseState); if (Action.Observe == null) { return(SingleChild.ValidatePlan(psTrueState)); } bool bTrueOk = TrueObservationChild.ValidatePlan(psTrueState); bool bFalseOk = FalseObservationChild.ValidatePlan(psFalseState); return(bTrueOk && bFalseOk); }
private NodeAnalogInput(ReadOnlyDictionary<FieldIdentifier, FieldBase> Fields, ReadOnlyCollection<NodeBase> Children) : base(Fields, Children) { m_Signal = new SingleChild<NodeSignal, NodeAnalogInput>(this); // Validation if (Code == null) { throw new ArgumentNullException(m_CodeName); } if (Address == null) { throw new ArgumentNullException(m_AddressName); } if (Forced == null) { throw new ArgumentNullException(m_ForcedName); } if (ForcedValue == null) { throw new ArgumentNullException(m_ForcedValueName); } if (Signal == null) { throw new ArgumentNullException(m_SignalName); } if (InputName == null) { throw new ArgumentNullException(m_InputNameName); } }
public Dictionary <int, List <Formula> > ScanEffects(Dictionary <int, List <Formula> > CollectedEffects) { if (Action != null) { int time = Action.GetTime(); Formula currEffects = Action.Effects; if (!CollectedEffects.ContainsKey(time)) { CollectedEffects.Add(time, new List <Formula>()); } CollectedEffects[time].Add(currEffects); } if (SingleChild != null) { SingleChild.ScanEffects(CollectedEffects); } if (FalseObservationChild != null) { FalseObservationChild.ScanEffects(CollectedEffects); } if (TrueObservationChild != null) { TrueObservationChild.ScanEffects(CollectedEffects); } return(CollectedEffects); }
private NodeRuntimeApplication(ReadOnlyDictionary <FieldIdentifier, FieldBase> Fields, ReadOnlyCollection <NodeBase> Children) : base(Fields, Children) { m_Logic = new SingleChild <NodePageCollection, NodeRuntimeApplication>(this); m_DeviceConfiguration = new SingleChild <NodeDeviceConfiguration, NodeRuntimeApplication>(this); //validation if (Code == null) { throw new ArgumentNullException(m_CodeName); } if (TypeId == null) { throw new ArgumentNullException(m_TypeIdName); } if (RuntimeId == null) { throw new ArgumentNullException(m_RuntimeIdName); } if (Address == null) { throw new ArgumentNullException(m_AddressName); } if (Configuration == null) { throw new ArgumentNullException(m_ConfigurationName); } if (ExecuteOnStartup == null) { throw new ArgumentNullException(m_ExecuteOnStartupName); } if (Logic == null) { throw new ArgumentNullException(m_LogicName); } if (DeviceConfiguration == null) { throw new ArgumentNullException(m_DeviceConfigurationName); } if (TryMode == null) { throw new ArgumentNullException(m_TryModeName); } // Build the signal lookup table // (lazy evaluating it in a threadsafe way gets messy) var allChildren = GetChildrenRecursive(); var dict = new Dictionary <string, NodeSignal>(); foreach (var child in allChildren.Values) { var signal = child as NodeSignal; if (signal != null) { dict.Add(signal.SignalId.ToString(), signal); } } m_signalLookup = new ReadOnlyDictionary <string, NodeSignal>(dict); }
private NodeAnalogInput(ReadOnlyDictionary <FieldIdentifier, FieldBase> Fields, ReadOnlyCollection <NodeBase> Children) : base(Fields, Children) { m_Signal = new SingleChild <NodeSignal, NodeAnalogInput>(this); // Validation if (Code == null) { throw new ArgumentNullException(m_CodeName); } if (Address == null) { throw new ArgumentNullException(m_AddressName); } if (Forced == null) { throw new ArgumentNullException(m_ForcedName); } if (ForcedValue == null) { throw new ArgumentNullException(m_ForcedValueName); } if (Signal == null) { throw new ArgumentNullException(m_SignalName); } if (InputName == null) { throw new ArgumentNullException(m_InputNameName); } }
private NodeRuntimeApplication(ReadOnlyDictionary<FieldIdentifier, FieldBase> Fields, ReadOnlyCollection<NodeBase> Children) : base(Fields, Children) { m_Logic = new SingleChild<NodePageCollection, NodeRuntimeApplication>(this); m_DeviceConfiguration = new SingleChild<NodeDeviceConfiguration, NodeRuntimeApplication>(this); //validation if (Code == null) { throw new ArgumentNullException(m_CodeName); } if (TypeId == null) { throw new ArgumentNullException(m_TypeIdName); } if (RuntimeId == null) { throw new ArgumentNullException(m_RuntimeIdName); } if (Address == null) { throw new ArgumentNullException(m_AddressName); } if (Configuration == null) { throw new ArgumentNullException(m_ConfigurationName); } if (ExecuteOnStartup == null) { throw new ArgumentNullException(m_ExecuteOnStartupName); } if (Logic == null) { throw new ArgumentNullException(m_LogicName); } if (DeviceConfiguration == null) { throw new ArgumentNullException(m_DeviceConfigurationName); } if (TryMode == null) { throw new ArgumentNullException(m_TryModeName); } // Build the signal lookup table // (lazy evaluating it in a threadsafe way gets messy) var allChildren = GetChildrenRecursive(); var dict = new Dictionary<string, NodeSignal>(); foreach (var child in allChildren.Values) { var signal = child as NodeSignal; if (signal != null) { dict.Add(signal.SignalId.ToString(), signal); } } m_signalLookup = new ReadOnlyDictionary<string, NodeSignal>(dict); }
private List <IMAP.Action> ScanEffectsForConst(Predicate goal) { List <IMAP.Action> ans = new List <IMAP.Action>(); if (Action != null) { string actionName = Action.Name.Split('_')[0]; if (!actionName.StartsWith("wait-goal")) { if (Action.Effects != null) { Formula fEffects = Action.Effects; if (fEffects is CompoundFormula) { CompoundFormula cf = (CompoundFormula)fEffects; foreach (Formula formula in cf.Operands) { if (formula is PredicateFormula) { PredicateFormula pf = (PredicateFormula)formula; if (pf.Predicate.ToString() == goal.ToString()) { ans.Add(Action); } } } } else if (fEffects is PredicateFormula) { PredicateFormula pf = (PredicateFormula)fEffects; if (pf.Predicate.ToString() == goal.ToString()) { ans.Add(Action); } } else { throw new Exception(); } } } } if (SingleChild != null) { ans.AddRange(SingleChild.ScanEffectsForConst(goal)); } if (FalseObservationChild != null) { ans.AddRange(FalseObservationChild.ScanEffectsForConst(goal)); } if (TrueObservationChild != null) { ans.AddRange(TrueObservationChild.ScanEffectsForConst(goal)); } return(ans); }
public void SingleChild() { bool pc = false; bool cc = false; var root = new SingleChild(); root.PropertyChanged += (o, e) => { pc = true; }; root.ChildChanged += (o, e) => { cc = true; }; root.Child.Name = "abc"; Assert.IsFalse(pc, "PropertyChanged should not have fired"); Assert.IsTrue(cc, "ChildChanged should have fired"); }
public void GetActionUsed(ref List <Action> usedActions) { if (Action != null) { usedActions.Add(Action); } if (SingleChild != null) { SingleChild.GetActionUsed(ref usedActions); } if (FalseObservationChild != null) { FalseObservationChild.GetActionUsed(ref usedActions); } if (TrueObservationChild != null) { TrueObservationChild.GetActionUsed(ref usedActions); } }
private string ToString(string sIndent) { if (Action == null) { return(""); } string s = sIndent + ID + ") " + Action.Name + "\n"; if (SingleChild != null) { s += SingleChild.ToString(sIndent); } else { s += FalseObservationChild.ToString(sIndent + "\t"); s += "\n"; s += TrueObservationChild.ToString(sIndent + "\t"); } return(s); }
private string ToString(string sIndent, HashSet <int> lHistory) { if (lHistory.Contains(ID)) { return(")connect to " + ID); } //HashSet<int> lNewHistory = new HashSet<int>(lHistory); lHistory.Add(ID); if (Action == null) { return(")goal"); } string s = sIndent + ID + ") " + Action.Name + "\n"; if (SingleChild != null) { s += SingleChild.ToString(sIndent, lHistory); } else { s += "branching...\n"; if (FalseObservationChild != null) { s += FalseObservationChild.ToString(sIndent + "\t", lHistory); } else { s += "Can't be false"; } s += "\n"; if (TrueObservationChild != null) { s += TrueObservationChild.ToString(sIndent + "\t", lHistory); } else { s += "Can't be true"; } } return(s); }
private NodeInstructionGroup(ReadOnlyDictionary<FieldIdentifier, FieldBase> Fields, ReadOnlyCollection<NodeBase> Children) : base(Fields, Children) { NodeInstructionChildren = new TypedChildCollection<NodeInstruction, NodeInstructionGroup>(this); m_InstructionGroupTry = new SingleChild<NodeInstructionGroupTry, NodeInstructionGroup>(this); // validation if (Language == null) { throw new ArgumentNullException(m_LanguageName); } if (InstructionGroupTry == null) { throw new ArgumentNullException(m_InstructionGroupTryName); } if (Comment == null) { throw new ArgumentNullException(m_CommentName); } }
private NodeInstructionGroup(ReadOnlyDictionary <FieldIdentifier, FieldBase> Fields, ReadOnlyCollection <NodeBase> Children) : base(Fields, Children) { NodeInstructionChildren = new TypedChildCollection <NodeInstruction, NodeInstructionGroup>(this); m_InstructionGroupTry = new SingleChild <NodeInstructionGroupTry, NodeInstructionGroup>(this); // validation if (Language == null) { throw new ArgumentNullException(m_LanguageName); } if (InstructionGroupTry == null) { throw new ArgumentNullException(m_InstructionGroupTryName); } if (Comment == null) { throw new ArgumentNullException(m_CommentName); } }
public void ExtractMultipleChildrenInvalid() { SingleChild root = new SingleChild(); MultipleChildren extractMe = new MultipleChildren(); root.AddChild(extractMe); SingleChild child1 = new SingleChild(); SingleChild child2 = new SingleChild(); extractMe.AddChild(child1); extractMe.AddChild(child2); Assert.That(!extractMe.ExtractNode(), "Node was extracted although not allowed"); Assert.That(extractMe.Parent == root, "Parent was modified"); Assert.That(extractMe.ParentConnector == root.DefaultConnector, "Parent connector was modified"); Assert.That(child1.Parent == extractMe, "Parent was modified on children"); Assert.That(child1.ParentConnector == extractMe.DefaultConnector, "Parent connector modified on children"); Assert.That(child2.Parent == extractMe, "Parent was modified on children"); Assert.That(child2.ParentConnector == extractMe.DefaultConnector, "Parent connector was modified on children"); }
public void ExtractMultipleChildrenValid() { MultipleChildren root = new MultipleChildren(); MultipleChildren extractMe = new MultipleChildren(); root.AddChild(extractMe); SingleChild child1 = new SingleChild(); SingleChild child2 = new SingleChild(); extractMe.AddChild(child1); extractMe.AddChild(child2); Assert.That(extractMe.ExtractNode(), "Could not extract node"); Assert.That(extractMe.Parent == null, "Parent was not cleared"); Assert.That(extractMe.ParentConnector == null, "Parent connector was not cleared"); Assert.That(child1.Parent == root, "Parent was not updated on children"); Assert.That(child1.ParentConnector == root.DefaultConnector, "Parent connector was not updated on children"); Assert.That(child2.Parent == root, "Parent was not updated on children"); Assert.That(child2.ParentConnector == root.DefaultConnector, "Parent connector was not updated on children"); }
public int MaxOperatingTime() { int maxTime = 0; if (Action != null) { int time = Action.GetTime(); if (maxTime < time) { maxTime = time; } } if (SingleChild != null) { int time = SingleChild.MaxOperatingTime(); if (maxTime < time) { maxTime = time; } } if (FalseObservationChild != null) { int time = FalseObservationChild.MaxOperatingTime(); if (maxTime < time) { maxTime = time; } } if (TrueObservationChild != null) { int time = TrueObservationChild.MaxOperatingTime(); if (maxTime < time) { maxTime = time; } } return(maxTime); }
private NodeSignal(ReadOnlyDictionary <FieldIdentifier, FieldBase> Fields, ReadOnlyCollection <NodeBase> Children) : base(Fields, Children) { m_Storage = new SingleChild <NodeValue, NodeSignal>(this); //validation if (SignalId == null) { throw new ArgumentNullException(m_SignalIdName); } if (SignalName == null) { throw new ArgumentNullException(m_SignalNameName); } if (Storage == null) { throw new ArgumentNullException(m_StorageName); } if (Forced == null) { throw new ArgumentNullException(m_ForcedName); } if (ForcedValue == null) { throw new ArgumentNullException(m_ForcedValueName); } if (Comment == null) { throw new ArgumentNullException(m_CommentName); } if (Storage.DataType.DataType != ForcedValue.DataType) { throw new ArgumentOutOfRangeException(m_ForcedValueName); } }
public void ScanLeafDepth(ref List <int> leafsDepth) { if (SingleChild != null) { if (SingleChild.Action == null) { leafsDepth.Add(Action.GetTime()); } else { SingleChild.ScanLeafDepth(ref leafsDepth); } } if (FalseObservationChild != null) { if (FalseObservationChild.Action == null) { leafsDepth.Add(Action.GetTime()); } else { FalseObservationChild.ScanLeafDepth(ref leafsDepth); } } if (TrueObservationChild != null) { if (TrueObservationChild.Action == null) { leafsDepth.Add(Action.GetTime()); } else { TrueObservationChild.ScanLeafDepth(ref leafsDepth); } } }
private Dictionary <Action, int> CollectJointActionsWithTime(List <string> jointActions) { Dictionary <Action, int> ans = new Dictionary <Action, int>(); if (Action != null) { foreach (var action in jointActions) { if (Action.Name.StartsWith(action)) { if (!ans.ContainsKey(Action)) { ans.Add(Action, Action.GetTime()); } if (ans[Action] > Action.GetTime()) { ans[Action] = Action.GetTime(); } } } } if (SingleChild != null) { foreach (var item in SingleChild.CollectJointActionsWithTime(jointActions)) { if (!ans.ContainsKey(item.Key)) { ans.Add(item.Key, item.Value); } if (ans[item.Key] > item.Value) { ans[item.Key] = item.Value; } } } if (FalseObservationChild != null) { foreach (var item in FalseObservationChild.CollectJointActionsWithTime(jointActions)) { if (!ans.ContainsKey(item.Key)) { ans.Add(item.Key, item.Value); } if (ans[item.Key] > item.Value) { ans[item.Key] = item.Value; } } } if (TrueObservationChild != null) { foreach (var item in TrueObservationChild.CollectJointActionsWithTime(jointActions)) { if (!ans.ContainsKey(item.Key)) { ans.Add(item.Key, item.Value); } if (ans[item.Key] > item.Value) { ans[item.Key] = item.Value; } } } return(ans); }