コード例 #1
0
        public void Insert(IEnumerable <Tuple <object, object> > kt)
        {
            //start node
            var startState =
                new BehaviorGraphNode(new OuterLoopBehaviorState());

            _nodes.Add(startState);

            Debug.Assert(kt != null);

            BehaviorGraphNode source = startState;

            foreach (var tuple in kt)
            {
                var strategy = tuple.Item1 as string;
                var tsExpr   = tuple.Item2 as List <TraceStepExpr>;
                Debug.Assert(strategy != null);
                Debug.Assert(tsExpr != null);

                var traceSteps    = tsExpr.Select(tse => tse.TraceStep).ToList();
                var outerEdgeProp = new OuterLoopEdgeProperty(strategy);
                var nodeState     = new OuterLoopBehaviorState(traceSteps);
                var target        = new BehaviorGraphNode(nodeState);
                _nodes.Add(target);

                var newEdge = new BehaviorGraphEdge(source, target, outerEdgeProp);
                source.OutEdges.Add(newEdge);
                target.InEdges.Add(newEdge);

                source = target;
            }
        }
コード例 #2
0
        private void ConnectNextNode(TraceStepExpr tsExpr, BehaviorGraphNode gn2)
        {
            var newNodeProp = new InnerLoopBehaviorState(tsExpr.TraceStep.Source);
            var newNode     = new BehaviorGraphNode(newNodeProp);
            InnerLoopEdgeProperty newEdgeProp;

            if (tsExpr.TraceStep.WrongStep)
            {
                newEdgeProp = new InnerLoopEdgeProperty();
            }
            else
            {
                newEdgeProp = new InnerLoopEdgeProperty((string)tsExpr.TraceStep.Rule, (string)tsExpr.TraceStep.AppliedRule);
            }
            var newEdge = new BehaviorGraphEdge(newNode, gn2, newEdgeProp);

            /*foreach (var edge in gn2.InEdges)
             * {
             *  var prevNode = edge.Source;
             *  prevNode.OutEdges.Add(newEdge);
             * }*/
            gn2.InEdges.Add(newEdge);
            newNode.OutEdges.Add(newEdge);
            BehaviorGraphNode parentNode = SearchOuterLoopNode(gn2);

            parentNode.SubGraph.Nodes.Add(newNode);
        }
コード例 #3
0
        private void ConnectRootNode(TraceStepExpr tsExpr, BehaviorGraphNode parentNode)
        {
            Debug.Assert(parentNode != null);

            var newNodeProp1 = new InnerLoopBehaviorState(tsExpr.TraceStep.Source);
            var newNode1     = new BehaviorGraphNode(newNodeProp1);

            var newNodeProp2 = new InnerLoopBehaviorState(tsExpr.TraceStep.Target);
            var newNode2     = new BehaviorGraphNode(newNodeProp2);

            InnerLoopEdgeProperty newEdgeProp;

            if (tsExpr.TraceStep.WrongStep)
            {
                newEdgeProp = new InnerLoopEdgeProperty();
            }
            else
            {
                newEdgeProp = new InnerLoopEdgeProperty((string)tsExpr.TraceStep.Rule, (string)tsExpr.TraceStep.AppliedRule);
            }
            var newEdge = new BehaviorGraphEdge(newNode1, newNode2, newEdgeProp);

            newNode1.OutEdges.Add(newEdge);
            newNode2.InEdges.Add(newEdge);

            parentNode.SubGraph.Nodes.Add(newNode1);
            parentNode.SubGraph.Nodes.Add(newNode2);
        }
コード例 #4
0
        //multiple strategy
        public void Update(IEnumerable <Tuple <object, object> > traces)
        {
            Debug.Assert(Nodes[0] != null);
            BehaviorGraphNode source = Nodes[0];

            foreach (var tuple in traces)
            {
                var strategy = tuple.Item1 as string;
                var tsExpr   = tuple.Item2 as List <TraceStepExpr>;
                Debug.Assert(strategy != null);
                Debug.Assert(tsExpr != null);

                var traceSteps = tsExpr.Select(tse => tse.TraceStep).ToList();

                var outerNode = SearchOuterLoopNode(strategy);
                if (outerNode == null)
                {
                    var outerEdgeProp = new OuterLoopEdgeProperty(strategy);
                    var nodeState     = new OuterLoopBehaviorState(traceSteps);
                    outerNode = new BehaviorGraphNode(nodeState);
                    _nodes.Add(outerNode);
                    var newEdge = new BehaviorGraphEdge(source, outerNode, outerEdgeProp);
                    source.OutEdges.Add(newEdge);
                    outerNode.InEdges.Add(newEdge);
                    source = outerNode;
                }
                else
                {
                    Update(tsExpr, outerNode);
                }
            }
        }
コード例 #5
0
        private void ConnectTwoNodes(TraceStepExpr tsExpr, BehaviorGraphNode gn1, BehaviorGraphNode gn2)
        {
            bool findTarget = false;

            foreach (var edge in gn1.OutEdges)
            {
                if (edge.Target == null)
                {
                    continue;
                }

                if (edge.Target.Equals(gn2))
                {
                    findTarget = true;
                }
            }

            if (!findTarget)
            {
                InnerLoopEdgeProperty newEdgeProp1;
                if (tsExpr.TraceStep.WrongStep)
                {
                    newEdgeProp1 = new InnerLoopEdgeProperty();
                }
                else
                {
                    newEdgeProp1 = new InnerLoopEdgeProperty((string)tsExpr.TraceStep.Rule, (string)tsExpr.TraceStep.AppliedRule);
                }
                var newEdge1 = new BehaviorGraphEdge(gn1, gn2, newEdgeProp1);

                gn1.OutEdges.Add(newEdge1);
                gn2.InEdges.Add(newEdge1);
            }
        }
コード例 #6
0
        private void InitSubGraph()
        {
            var outerState = _state as OuterLoopBehaviorState;
            if (outerState == null) return;

            var steps = outerState.Traces;
            if (steps == null || steps.Count == 0) return;

            _subGraph = new BehaviorGraph();          
            var ts1 = steps[0];
            var startState =
                new BehaviorGraphNode(new InnerLoopBehaviorState(ts1.Source));
            _subGraph.Nodes.Add(startState);

            BehaviorGraphNode source = startState;
            for(int i = 0; i < outerState.Traces.Count; i++)
            {
                var ts = outerState.Traces[i];
                var nodeState = new InnerLoopBehaviorState(ts.Target);
                var target = new BehaviorGraphNode(nodeState);
                _subGraph.Nodes.Add(target);

                var innerEdgeProp = new InnerLoopEdgeProperty((string)ts.Rule, (string)ts.AppliedRule);
                var newEdge = new BehaviorGraphEdge(source, target, innerEdgeProp);
                source.OutEdges.Add(newEdge);
                target.InEdges.Add(newEdge);

                source = target;
            }
        }
コード例 #7
0
        private void InitSubGraph()
        {
            var outerState = _state as OuterLoopBehaviorState;

            if (outerState == null)
            {
                return;
            }

            var steps = outerState.Traces;

            if (steps == null || steps.Count == 0)
            {
                return;
            }

            _subGraph = new BehaviorGraph();
            var ts1        = steps[0];
            var startState =
                new BehaviorGraphNode(new InnerLoopBehaviorState(ts1.Source));

            _subGraph.Nodes.Add(startState);

            BehaviorGraphNode source = startState;

            for (int i = 0; i < outerState.Traces.Count; i++)
            {
                var ts        = outerState.Traces[i];
                var nodeState = new InnerLoopBehaviorState(ts.Target);
                var target    = new BehaviorGraphNode(nodeState);
                _subGraph.Nodes.Add(target);

                var innerEdgeProp = new InnerLoopEdgeProperty((string)ts.Rule, (string)ts.AppliedRule);
                var newEdge       = new BehaviorGraphEdge(source, target, innerEdgeProp);
                source.OutEdges.Add(newEdge);
                target.InEdges.Add(newEdge);

                source = target;
            }
        }
コード例 #8
0
        //multiple strategy
        public void Update(IEnumerable<Tuple<object, object>> traces)
        {
            Debug.Assert(Nodes[0] != null);
            BehaviorGraphNode source = Nodes[0];
            foreach (var tuple in traces)
            {
                var strategy = tuple.Item1 as string;
                var tsExpr = tuple.Item2 as List<TraceStepExpr>;
                Debug.Assert(strategy != null);
                Debug.Assert(tsExpr != null);

                var traceSteps = tsExpr.Select(tse => tse.TraceStep).ToList();

                var outerNode = SearchOuterLoopNode(strategy);
                if (outerNode == null)
                {
                    var outerEdgeProp = new OuterLoopEdgeProperty(strategy);
                    var nodeState = new OuterLoopBehaviorState(traceSteps);
                    outerNode = new BehaviorGraphNode(nodeState);
                    _nodes.Add(outerNode);
                    var newEdge = new BehaviorGraphEdge(source, outerNode, outerEdgeProp);
                    source.OutEdges.Add(newEdge);
                    outerNode.InEdges.Add(newEdge);
                    source = outerNode;
                }
                else
                {
                    Update(tsExpr, outerNode);
                }               
            }
        }
コード例 #9
0
        public void Insert(IEnumerable<Tuple<object, object>> kt)
        {
            //start node
            var startState =
                new BehaviorGraphNode(new OuterLoopBehaviorState());
            _nodes.Add(startState);

            Debug.Assert(kt != null);

            BehaviorGraphNode source = startState;
            foreach (var tuple in kt)
            {
                var strategy = tuple.Item1 as string;
                var tsExpr = tuple.Item2 as List<TraceStepExpr>;
                Debug.Assert(strategy != null);
                Debug.Assert(tsExpr != null);

                var traceSteps = tsExpr.Select(tse => tse.TraceStep).ToList();
                var outerEdgeProp = new OuterLoopEdgeProperty(strategy);
                var nodeState = new OuterLoopBehaviorState(traceSteps);
                var target = new BehaviorGraphNode(nodeState);
                _nodes.Add(target);

                var newEdge = new BehaviorGraphEdge(source, target, outerEdgeProp);
                source.OutEdges.Add(newEdge);
                target.InEdges.Add(newEdge);

                source = target;
            }
        }
コード例 #10
0
        private void ConnectRootNode(TraceStepExpr tsExpr, BehaviorGraphNode parentNode)
        {
            Debug.Assert(parentNode != null);

            var newNodeProp1 = new InnerLoopBehaviorState(tsExpr.TraceStep.Source);
            var newNode1 = new BehaviorGraphNode(newNodeProp1);

            var newNodeProp2 = new InnerLoopBehaviorState(tsExpr.TraceStep.Target);
            var newNode2 = new BehaviorGraphNode(newNodeProp2);

            InnerLoopEdgeProperty newEdgeProp;
            if (tsExpr.TraceStep.WrongStep)
            {
                newEdgeProp = new InnerLoopEdgeProperty();
            }
            else
            {
                newEdgeProp = new InnerLoopEdgeProperty((string)tsExpr.TraceStep.Rule, (string)tsExpr.TraceStep.AppliedRule);
            }
            var newEdge = new BehaviorGraphEdge(newNode1, newNode2, newEdgeProp);

            newNode1.OutEdges.Add(newEdge);
            newNode2.InEdges.Add(newEdge);

            parentNode.SubGraph.Nodes.Add(newNode1);
            parentNode.SubGraph.Nodes.Add(newNode2);
        }
コード例 #11
0
 private void ConnectNextNode(TraceStepExpr tsExpr, BehaviorGraphNode gn2)
 {
     var newNodeProp = new InnerLoopBehaviorState(tsExpr.TraceStep.Source);
     var newNode = new BehaviorGraphNode(newNodeProp);
     InnerLoopEdgeProperty newEdgeProp;
     if (tsExpr.TraceStep.WrongStep)
     {
         newEdgeProp = new InnerLoopEdgeProperty();
     }
     else
     {
         newEdgeProp = new InnerLoopEdgeProperty((string)tsExpr.TraceStep.Rule, (string)tsExpr.TraceStep.AppliedRule);
     }
     var newEdge = new BehaviorGraphEdge(newNode, gn2, newEdgeProp);
     /*foreach (var edge in gn2.InEdges)
     {
         var prevNode = edge.Source;
         prevNode.OutEdges.Add(newEdge);
     }*/
     gn2.InEdges.Add(newEdge);
     newNode.OutEdges.Add(newEdge);
     BehaviorGraphNode parentNode = SearchOuterLoopNode(gn2);
     parentNode.SubGraph.Nodes.Add(newNode);
 }
コード例 #12
0
        private void ConnectTwoNodes(TraceStepExpr tsExpr, BehaviorGraphNode gn1, BehaviorGraphNode gn2)
        {
            bool findTarget = false;
            foreach (var edge in gn1.OutEdges)
            {
                if (edge.Target == null) continue;

                if (edge.Target.Equals(gn2))
                {
                    findTarget = true;
                }
            }

            if (!findTarget)
            {
                InnerLoopEdgeProperty newEdgeProp1;
                if (tsExpr.TraceStep.WrongStep)
                {
                    newEdgeProp1 = new InnerLoopEdgeProperty();
                }
                else
                {
                    newEdgeProp1 = new InnerLoopEdgeProperty((string)tsExpr.TraceStep.Rule, (string)tsExpr.TraceStep.AppliedRule);
                }
                var newEdge1 = new BehaviorGraphEdge(gn1, gn2, newEdgeProp1);

                gn1.OutEdges.Add(newEdge1);
                gn2.InEdges.Add(newEdge1);
            }
        }