public BehaviorGraphEdge(BehaviorGraphNode source, 
         BehaviorGraphNode target, BehaviorGraphEdgeProperty prop)
 {
     _node1 = source;
     _node2 = target;
     _property = prop;
 }
Esempio n. 2
0
 public BehaviorGraphEdge(BehaviorGraphNode source,
                          BehaviorGraphNode target, BehaviorGraphEdgeProperty prop)
 {
     _node1    = source;
     _node2    = target;
     _property = prop;
 }
Esempio n. 3
0
        /// <summary>
        /// Demonstration Mode
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="msg"></param>
        /// <param name="output"></param>
        /// <returns></returns>
        private QueryFeedbackState QueryObjectiveGraph(object obj, out string msg, out object output)
        {
            output = null;
            msg    = null;

            if (ObjectGraph == null)
            {
                msg = "You do not select the answer successfully.";
                QueriedKnowledge = null;
                return(QueryFeedbackState.QueryFailed);
            }

            if (ObjectGraph.Nodes.Count == 0 || ObjectGraph.Nodes.Count == 1)
            {
                msg = "No internal procedural knowledge to present.";
                QueriedKnowledge = null;
                return(QueryFeedbackState.QueryFailed);
            }

            if (obj != null)
            {
                //verify user's own step
                var matchedNode = ObjectGraph.SearchInnerLoopNode(obj);

                msg = matchedNode == null ?
                      AGTutorMessage.VerifyWrong : AGTutorMessage.VerifyCorrect;

                if (matchedNode == null)
                {
                    return(QueryFeedbackState.DemonQueryVerify);
                }

                Debug.Assert(matchedNode != null);

                var nextTuple1 = ObjectGraph.SearchNextInnerLoopNode(matchedNode);
                if (nextTuple1 == null)
                {
                    msg = AGTutorMessage.SolvedProblem;
                }
                CurrentStateNode = matchedNode;
                return(QueryFeedbackState.DemonQueryVerify);
            }

            if (CurrentStateNode == null) // QueryNotStart
            {
                CurrentStateNode = ObjectGraph.RetrieveInitInnerNode();

                /*                object obj2 = ObjectGraph.SearchInnerLoopNode(parentNode);
                 *              var behaviorNode = obj2 as BehaviorGraphNode;
                 *              var lstNode = obj2 as List<BehaviorGraphNode>;
                 *              if (behaviorNode != null)
                 *              {
                 *                  _currentStateNode = behaviorNode;
                 *              }
                 *              if (lstNode != null)
                 *              {
                 *                  //TODO
                 *                  _currentStateNode = lstNode[0];
                 *              }*/

                Debug.Assert(_currentStateNode != null);

                msg = AGDemonstrationMessage.QueryAnswer;

                var lst    = ObjectGraph.SearchAllOuterEdgeInfos();
                int number = ObjectGraph.PathFinding(CurrentStateNode);

                output = new Tuple <object, object>(lst, number);

                return(QueryFeedbackState.DemonQueryStarted);
            }

            Debug.Assert(_currentStateNode != null);

            //direct query without verification
            object            edgeInfo = null;
            BehaviorGraphNode nextNode = null;
            var nextTuple2             = ObjectGraph.SearchNextInnerLoopNode(_currentStateNode);

            if (nextTuple2 == null) // query-end
            {
                msg = AGDemonstrationMessage.QueryEnd;
                return(QueryFeedbackState.DemonQueryEnded);
            }
            var tuple22    = nextTuple2 as Tuple <object, object>;
            var tuple22Lst = nextTuple2 as List <Tuple <object, object> >;

            if (tuple22 != null)
            {
                edgeInfo = tuple22.Item1;
                nextNode = tuple22.Item2 as BehaviorGraphNode;
            }
            if (tuple22Lst != null)
            {
                var tupleTemp = tuple22Lst[0];
                edgeInfo = tupleTemp.Item1;
                nextNode = tupleTemp.Item2 as BehaviorGraphNode;
            }

            Debug.Assert(nextNode != null);
            var nodeState = nextNode.State as InnerLoopBehaviorState;

            Debug.Assert(nodeState != null);
            var    expr          = IKnowledgeGenerator.Generate(nodeState.UserKnowledge);
            var    innerEdgeProp = edgeInfo as InnerLoopEdgeProperty;
            var    outerEdgeProp = edgeInfo as OuterLoopEdgeProperty;
            string appliedRule   = null;

            if (innerEdgeProp != null)
            {
                appliedRule = innerEdgeProp.AppliedRule;
            }
            if (outerEdgeProp != null)
            {
                appliedRule = outerEdgeProp.Strategy;
            }
            int leftTraceCount = ObjectGraph.PathFinding(nextNode);

            int parentIndex = ObjectGraph.SearchOuterLoopNodeIndex(nextNode);
            var lst1        = ObjectGraph.SearchAllOuterEdgeInfos();
            var tuple1      = new Tuple <object, object>(lst1, parentIndex);

            output = new Tuple <object, object, object, object>(appliedRule, expr, leftTraceCount, tuple1);

            CurrentStateNode = nextNode;
            return(QueryFeedbackState.DemonQueryProcessed);
        }
Esempio n. 4
0
        private QueryFeedbackState QueryBehaviorGraph(object obj, out string msg, out object output)
        {
            msg    = null;
            output = null;
            if (UserGraph == null)
            {
                return(QueryFeedbackState.QueryFailed);
            }
            if (UserGraph.Nodes.Count == 0 || UserGraph.Nodes.Count == 1)
            {
                msg = "TODO";
                return(QueryFeedbackState.QueryFailed);
            }

/*            if (!_queryProcessed)
 *          {
 *              _queryProcessed = true;
 *              output = UserGraph.SearchAllOuterEdgeInfos();
 *              msg = AGTutorMessage.InputQuery;
 *              return QueryFeedbackState.TutorQueryStarted;
 *          }*/

            if (obj != null)
            {
                return(VerifyBehaviorGraph(obj, out msg, out output));
            }
            Debug.Assert(obj == null);
            Debug.Assert(_currentStateNode != null);

            object            edgeInfo = null;
            BehaviorGraphNode nextNode = null;
            var nextTuple1             = UserGraph.SearchNextInnerLoopNode(_currentStateNode);

            if (nextTuple1 == null) // query-end
            {
                //partial checking
                BehaviorGraph.SolvingStatus ss = UserGraph.CheckSolvingStatus();
                if (ss == BehaviorGraph.SolvingStatus.Complete)
                {
                    msg = AGDemonstrationMessage.QueryEnd;
                    return(QueryFeedbackState.TutorQueryEnded);
                }
                else if (ss == BehaviorGraph.SolvingStatus.Partial)
                {
                    int nextGoalIndex = UserGraph.FindGoalIndex();
                    _currentStateNode = UserGraph.RetrieveInitInnerNode(nextGoalIndex);
                    nextTuple1        = UserGraph.SearchNextInnerLoopNode(_currentStateNode);
                    if (nextTuple1 == null)
                    {
                        msg = AGDemonstrationMessage.QueryEnd;
                        return(QueryFeedbackState.TutorQueryEnded);
                    }
                    CurrentStepHintRequired = true;
                }
                else
                {
                    msg = AGDemonstrationMessage.QueryEnd;
                    return(QueryFeedbackState.TutorQueryEnded);
                }
            }

            #region Path Selection

            var tuple11    = nextTuple1 as Tuple <object, object>;
            var tuple11Lst = nextTuple1 as List <Tuple <object, object> >;

            if (tuple11 != null)
            {
                edgeInfo = tuple11.Item1;
                nextNode = tuple11.Item2 as BehaviorGraphNode;
                //_currentStateNode = nextNode;
            }
            if (tuple11Lst != null)
            {
                var tupleTemp = tuple11Lst[0];
                edgeInfo = tupleTemp.Item1;
                nextNode = tupleTemp.Item2 as BehaviorGraphNode;
                //_currentStateNode = nextNode;
            }

            #endregion

            if (_currentStepHintRequired)
            {
                if (edgeInfo != null)
                {
                    var innerEdgeProp = edgeInfo as InnerLoopEdgeProperty;
                    Debug.Assert(innerEdgeProp != null);
                    msg = AGTutorMessage.QueryIntermediate;
                    _currentStepHintRequired = false;
                    //int parentIndex = UserGraph.SearchOuterLoopNodeIndex(_currentStateNode);
                    int parentIndex = UserGraph.SearchOuterLoopNodeIndex(nextNode);
                    var lst1        = UserGraph.SearchAllOuterEdgeInfos();
                    var tuple       = new Tuple <object, object, object>(innerEdgeProp.MetaRule, lst1, parentIndex);
                    output = tuple;
                }
                return(QueryFeedbackState.TutorQueryProcessedHint);
            }
            Debug.Assert(nextNode != null);
            _currentStepHintRequired = true;
            var nodeState = nextNode.State as InnerLoopBehaviorState;
            Debug.Assert(nodeState != null);
            var expr           = IKnowledgeGenerator.Generate(nodeState.UserKnowledge);
            var innerEdgeProp1 = edgeInfo as InnerLoopEdgeProperty;
            Debug.Assert(innerEdgeProp1 != null);
            var appliedRule = innerEdgeProp1.AppliedRule;
            //int parentIndex1 = UserGraph.SearchOuterLoopNodeIndex(_currentStateNode);
            int parentIndex1 = UserGraph.SearchOuterLoopNodeIndex(nextNode);
            var lst2         = UserGraph.SearchAllOuterEdgeInfos();
            output           = new Tuple <object, object, object, object>(appliedRule, expr, lst2, parentIndex1);
            CurrentStateNode = nextNode;
            return(QueryFeedbackState.TutorQueryProcessedAnswer);
        }