public void TC_Transitions()
        {
            var problem = new Planner.SAS.Problem(new SASInputData(GetFilePath("TC_Gripper.sas")));

            ISuccessor successor = problem.GetSuccessors(problem.InitialState).First();

            Assert.IsFalse(successor.IsComplexTransition());
            Assert.IsTrue(successor.GetSuccessorState().Equals(successor.GetTransitionResult()));
            var successorResults = successor.GetComplexTransitionResults().ToList();

            Assert.AreEqual(1, successorResults.Count);
            Assert.IsTrue(successorResults.First().Equals(successor.GetTransitionResult()));

            IPredecessor predecessor = problem.GetPredecessors(problem.GoalConditions).First();

            Assert.IsFalse(predecessor.IsComplexTransition());
            Assert.IsTrue(predecessor.GetPredecessorConditions().Equals(predecessor.GetTransitionResult()));
            var predecessorResults = predecessor.GetComplexTransitionResults().ToList();

            Assert.AreEqual(1, predecessorResults.Count);
            Assert.IsTrue(predecessorResults.First().Equals(predecessor.GetTransitionResult()));

            IPredecessor predecessor2 = problem.GetPredecessors(problem.GoalConditions.GetCorrespondingRelativeStates(problem).First()).First();

            Assert.IsTrue(predecessor2.IsComplexTransition());
            Assert.IsTrue(CollectionsEquality.Equals(predecessor2.GetPredecessorRelativeStates(), predecessor2.GetComplexTransitionResults()));
            var predecessorResults2 = predecessor2.GetComplexTransitionResults().ToList();

            Assert.AreEqual(1, predecessorResults2.Count);
            Assert.IsTrue(predecessorResults2.First().Equals(predecessor2.GetTransitionResult()));
        }
Example #2
0
 internal bool ProcessEvent(Node parentNode, ISuccessor successor)
 {
     var state = parentNode.State as IAdversarialState;
     var args = new StateExpansionEventArgs(state, successor, parentNode.Cost, parentNode.Depth);
     OnSuccessorExpanded(this, args);
     return !args.CancelExpansion;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="StateExpansionEventArgs"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="successor">The successor.</param>
 /// <param name="cost">The cost.</param>
 /// <param name="depth">The depth.</param>
 public StateExpansionEventArgs(IState parent, ISuccessor successor, double cost, int depth)
     : base(parent)
 {
     Depth = depth;
     Cost = cost;
     Successor = successor;
     CancelExpansion = false;
 }
Example #4
0
        internal bool ProcessEvent(Node parentNode, ISuccessor successor)
        {
            var state = parentNode.State as IAdversarialState;
            var args  = new StateExpansionEventArgs(state, successor, parentNode.Cost, parentNode.Depth);

            OnSuccessorExpanded(this, args);
            return(!args.CancelExpansion);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="StateExpansionEventArgs"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="successor">The successor.</param>
 /// <param name="cost">The cost.</param>
 /// <param name="depth">The depth.</param>
 public StateExpansionEventArgs(IState parent, ISuccessor successor, double cost, int depth)
     : base(parent)
 {
     Depth           = depth;
     Cost            = cost;
     Successor       = successor;
     CancelExpansion = false;
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Node"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="successor">The successor.</param>
 public Node(Node parent, ISuccessor successor)
 {
     State          = successor.State;
     Parent         = parent;
     Successor      = successor;
     Cost           = parent.Cost + successor.Cost;
     Depth          = parent.Depth + 1;
     Path           = false;
     Children       = new List <Node>();
     _stateComparer = new StateComparer();
 }
Example #7
0
 public Node(Node parent, ISuccessor successor)
 {
     State = successor.State;
     Parent = parent;
     Successor = successor;
     Cost = parent.Cost + successor.Cost;
     Depth = parent.Depth + 1;
     Path = false;
     Children = new List<Node>();
     _stateComparer = new StateComparer();
 }
Example #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 public SuccessorEnumerable(ISuccessor <TPayload> primer)
 {
     _primer = primer;
 }
Example #9
0
 public static IPredecessor <TPayload> Decorate(ILink <TPayload> decorated, ISuccessor <TPayload> next)
 => new LinkWrapper(decorated, next);
Example #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 public SuccessorWrapper(ISuccessor <TPayload> decorated, ISuccessor <TPayload> next)
 {
     _decorated = decorated;
     Next       = next;
 }
Example #11
0
 public static IDoubleChainedLink <TPayload> Decorate(ISuccessor <TPayload> decorated, ISuccessor <TPayload> next)
 => new SuccessorWrapper(decorated, next);
Example #12
0
 /// <inheritdoc />
 public bool MoveNext()
 {
     Current = _next.Payload;
     _next   = _next.Previous as ISuccessor <TPayload>;
     return(_next is null);
 }
Example #13
0
 private static void PrintSuccessor(ISuccessor successor)
 {
     Console.WriteLine("{0}\n{1}", successor.Action, successor.State);
     Console.WriteLine("{0} {1}\n--------\n", successor.State.IsTerminal, (successor.State as IAdversarialState).Utility);
 }
Example #14
0
 public EndLink(ISuccessor <TPayload> previous)
 {
     Previous = LinkPredecessorDecorator <TPayload> .Decorate(previous, this);
 }
Example #15
0
 /// <inheritdoc />
 public void Reset()
 {
     Current = default;
     _next   = _start;
 }
Example #16
0
 private static void PrintSuccessor(ISuccessor successor)
 {
     Console.WriteLine("{0}\n{1}", successor.Action, successor.State);
     Console.WriteLine("{0} {1}\n--------\n", successor.State.IsTerminal, (successor.State as IAdversarialState).Utility);
 }
Example #17
0
 /// <summary>
 /// Constructor
 /// </summary>
 public SuccessorEnumerator(ISuccessor <TPayload> start)
 {
     _start = start;
     Reset();
 }