Exemplo n.º 1
0
        private static void DFSVisit(ExperimentNode node, bool pathFromDecision, IExperiment graph, Dictionary <ExperimentNode, GraphNodeStatus> verticesStatuses, ref List <ExperimentNode> vertices, ref List <ExperimentNodeConnection> edges, ref bool noErrors)
        {
            verticesStatuses.Add(node, GraphNodeStatus.Visiting);

            GraphNodeStatus status = GraphNodeStatus.HasNoPathToEnd;

            bool isDecision         = (node.Data.Metadata is DecisionMetadata);
            bool comingFromDecision = isDecision || pathFromDecision;

            if (graph.OutEdges(node).Count <ExperimentNodeConnection>() > 0)
            {
                foreach (ExperimentNodeConnection edge in graph.OutEdges(node))
                {
                    if (verticesStatuses.ContainsKey(edge.Target) == false)
                    {
                        DFSVisit(edge.Target, comingFromDecision, graph, verticesStatuses, ref vertices, ref edges, ref noErrors);
                    }
                    if (verticesStatuses[edge.Target].Equals(GraphNodeStatus.Visiting) == true && comingFromDecision == false)
                    {
                        noErrors = false;
                        SetErrorOnNode(node, "Circular link detected.");
                    }
                    else if (verticesStatuses[edge.Target].Equals(GraphNodeStatus.HasPathToEnd) == true ||
                             (verticesStatuses[edge.Target].Equals(GraphNodeStatus.Visiting) == true && comingFromDecision == true))
                    {
                        // Add EDGE and its SOURCE and TARGET vertices only if Path was completed to END.
                        // or if it is circular link that is coming from the decision

                        status = GraphNodeStatus.HasPathToEnd;
                        if (vertices.Contains(edge.Target) == false)
                        {
                            vertices.Add(edge.Target);
                        }
                        if (vertices.Contains(edge.Source) == false) //current node, ie. node == edge.Source
                        {
                            vertices.Add(edge.Source);
                        }
                        edges.Add(edge);
                    }
                }
            }
            else
            {
                if (node.Data.Metadata is EndNodeMetadata)
                {
                    status = GraphNodeStatus.HasPathToEnd;
                }
                else
                {
                    noErrors = false;
                    SetErrorOnNode(node, "Unable to detect path to the END node.");
                }
            }
            verticesStatuses[node] = status;
        }
        private static void DFSVisit(ExperimentNode node, bool pathFromDecision, IExperiment graph, Dictionary<ExperimentNode, GraphNodeStatus> verticesStatuses, ref List<ExperimentNode> vertices, ref List<ExperimentNodeConnection> edges, ref bool noErrors)
        {
            verticesStatuses.Add(node, GraphNodeStatus.Visiting);

            GraphNodeStatus status = GraphNodeStatus.HasNoPathToEnd;

            bool isDecision = (node.Data.Metadata is DecisionMetadata);
            bool comingFromDecision = isDecision || pathFromDecision;

            if (graph.OutEdges(node).Count<ExperimentNodeConnection>() > 0)
            {
                foreach (ExperimentNodeConnection edge in graph.OutEdges(node))
                {
                    if (verticesStatuses.ContainsKey(edge.Target) == false)
                    {
                        DFSVisit(edge.Target, comingFromDecision, graph, verticesStatuses, ref vertices, ref edges, ref noErrors);
                    }
                    if (verticesStatuses[edge.Target].Equals(GraphNodeStatus.Visiting) == true && comingFromDecision == false)
                    {
                        noErrors = false;
                        SetErrorOnNode(node, "Circular link detected.");
                    } 
                    else if (verticesStatuses[edge.Target].Equals(GraphNodeStatus.HasPathToEnd) == true ||
                            (verticesStatuses[edge.Target].Equals(GraphNodeStatus.Visiting) == true && comingFromDecision == true))
                    {
                        // Add EDGE and its SOURCE and TARGET vertices only if Path was completed to END.
                        // or if it is circular link that is coming from the decision

                        status = GraphNodeStatus.HasPathToEnd;
                        if (vertices.Contains(edge.Target) == false)
                            vertices.Add(edge.Target);
                        if (vertices.Contains(edge.Source) == false) //current node, ie. node == edge.Source
                            vertices.Add(edge.Source);
                        edges.Add(edge);
                    }
                }
            }
            else
            {
                if (node.Data.Metadata is EndNodeMetadata)
                {
                    status = GraphNodeStatus.HasPathToEnd;
                }
                else
                {
                    noErrors = false;
                    SetErrorOnNode(node, "Unable to detect path to the END node.");
                }
            }
            verticesStatuses[node] = status;
        }
Exemplo n.º 3
0
        internal static void BFSTraverseExperiment(IExperiment experiment, ExperimentNode startFromNode, TraverseTask Task)
        {
            //traverse graph down from the node
            Queue <ExperimentNode>   traversingQueue = new Queue <ExperimentNode>();
            HashSet <ExperimentNode> foundVertices   = new HashSet <ExperimentNode>();

            traversingQueue.Enqueue(startFromNode);

            while (traversingQueue.Count > 0)
            {
                ExperimentNode currentNode = traversingQueue.Dequeue();

                //do some stuff
                Task(currentNode);

                foreach (ExperimentNodeConnection edge in experiment.OutEdges(currentNode))
                {
                    if (foundVertices.Contains(edge.Target) == false)
                    {
                        traversingQueue.Enqueue(edge.Target);
                        foundVertices.Add(edge.Target);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Fills the items with next nodes labels.
        /// </summary>
        /// <param name="comboBox">The combo box.</param>
        private void FillItemsWithNextNodesLabels(ComboBox comboBox)
        {
            comboBox.Items.Clear();
            ExperimentNodeInfo decisionNodeInfo = DataContext as ExperimentNodeInfo;
            ExperimentNode     currentNode      = decisionNodeInfo.Node;

            foreach (ExperimentNodeConnection outEdge in m_experiment.OutEdges(currentNode))
            {
                comboBox.Items.Add(outEdge.Target.Data.Metadata.Label);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Prepares the lookup of the successor nodes label to their ids.
        /// </summary>
        /// <param name="decisionNode">The decision node for which the lookup is created</param>
        /// <param name="experiment">The experiment - needed to find outgoing edges</param>
        /// <returns>lookup of the labels of the successor nodes to their guids. the key is the node label, and the value is the node id</returns>
        public static Dictionary <string, string> PrepareSuccessorNodesLabelIdLookup(ExperimentNode decisionNode, IExperiment experiment)
        {
            Dictionary <string, string> successorNodeLabelIdLookup = new Dictionary <string, string>();

            foreach (ExperimentNodeConnection outEdge in experiment.OutEdges(decisionNode))
            {
                try
                {
                    successorNodeLabelIdLookup.Add(outEdge.Target.Data.Metadata.Label, outEdge.Target.ID);
                }
                catch (ArgumentException ex)
                {
                    throw new DecisionCodeParserException(String.Format(Messages.DecisionErrorAmbigousChoiceOfTwoNodes + "{0}", outEdge.Target.Data.Metadata.Label), ex);
                }
            }
            return(successorNodeLabelIdLookup);
        }
        internal static void BFSTraverseExperiment(IExperiment experiment, ExperimentNode startFromNode, TraverseTask Task)
        {
            //traverse graph down from the node
            Queue<ExperimentNode> traversingQueue = new Queue<ExperimentNode>();
            HashSet<ExperimentNode> foundVertices = new HashSet<ExperimentNode>();
            traversingQueue.Enqueue(startFromNode);

            while (traversingQueue.Count > 0)
            {
                ExperimentNode currentNode = traversingQueue.Dequeue();

                //do some stuff
                Task(currentNode);

                foreach (ExperimentNodeConnection edge in experiment.OutEdges(currentNode))
                {
                    if (foundVertices.Contains(edge.Target) == false)
                    {
                        traversingQueue.Enqueue(edge.Target);
                        foundVertices.Add(edge.Target);
                    }
                }
            }
        }
 /// <summary>
 /// Prepares the lookup of the successor nodes label to their ids.
 /// </summary>
 /// <param name="decisionNode">The decision node for which the lookup is created</param>
 /// <param name="experiment">The experiment - needed to find outgoing edges</param>
 /// <returns>lookup of the labels of the successor nodes to their guids. the key is the node label, and the value is the node id</returns>
 public static Dictionary<string, string> PrepareSuccessorNodesLabelIdLookup(ExperimentNode decisionNode, IExperiment experiment)
 {
     Dictionary<string, string> successorNodeLabelIdLookup = new Dictionary<string, string>();
     foreach (ExperimentNodeConnection outEdge in experiment.OutEdges(decisionNode))
     {
         try
         {
             successorNodeLabelIdLookup.Add(outEdge.Target.Data.Metadata.Label, outEdge.Target.ID);
         }
         catch (ArgumentException ex)
         {
             throw new DecisionCodeParserException(String.Format(Messages.DecisionErrorAmbigousChoiceOfTwoNodes + "{0}", outEdge.Target.Data.Metadata.Label), ex);
         }
     }
     return successorNodeLabelIdLookup;
 }
 public IEnumerable <ExperimentNodeConnection> OutEdges(ExperimentNode v)
 {
     return(m_experiment.OutEdges(v));
 }