Exemple #1
0
        private GraphPath MarkAsResult(GraphPathNode maxPath)
        {
            var res = new GraphPath();

            if (maxPath != null && maxPath.Current != null)
            {
                Color nextColor = maxPath.Current.GetCurrentColor();
                var   current   = maxPath.Prev;
                while (current != null && current.Current != null)
                {
                    res.NodePath.Add(current.Current);
                    Color prevColor = current.Current.GetCurrentColor();
                    if (nextColor == null)
                    {
                        var signal      = current.Current.GetSignal();
                        var errorSignal = signal as ErrorSignal;
                        if (errorSignal != null)
                        {
                            res.Exception = errorSignal.Error;
                        }
                        nextColor = prevColor;
                    }
                    else
                    {
                        if (prevColor != null)
                        {
                            //if color contains previous color
                            if (!nextColor.Contains(prevColor))
                            {
                                res.ColorPath.Add(nextColor);
                                nextColor = prevColor;
                            }
                        }

                        var undoable = current.Current as IUndoable;
                        if (undoable != null)
                        {
                            undoable.SetAlreadyUndone(true);
                        }
                    }
                    current = current.Prev;
                }
                res.ColorPath.Add(nextColor);
            }
            res.ColorPath.Reverse();
            res.NodePath.Reverse();
            return(res);
        }
Exemple #2
0
        private void Finish()
        {
            var dic = new GraphResult();

            lock (CollectionLock)
            {
                foreach (ConnectionPoint connectionPoint in NodesToNotify)
                {
                    GraphPath colorList = GetColorList(connectionPoint);
                    dic.Add(connectionPoint, colorList);
                }
            }

            InvokeOnFinish(dic);
            Undo();
            StartedEvent.Set();
        }
Exemple #3
0
        /* private IEnumerable<GraphPath> GetPossibleOutputs(GraphNode graphNode)
         * {
         *   if (Color.NullOrBlack(graphNode.Result))
         *       return new GraphPath[] { };
         *
         *   var allConnections =
         *       graphNode.GetAllOutConnections().Where(
         *           graphConnection =>
         *           !Color.NullOrBlack(graphConnection.CurrentColor) &&
         *           (graphConnection.To != null) &&
         *           (graphConnection.To.Parent != null) &&
         *           !(graphConnection.To.Parent is FinishNode) &&
         *           (graphConnection.To.CurrentColor == graphConnection.CurrentColor));
         *   return allConnections.Select(
         *       graphConnection => new GraphPath(graphConnection.To.Parent, graphConnection.Length, graphConnection.To.Parent.Result));
         *
         * }*/
        private GraphPath GetColorList(IColorable connectionPoint)
        {
            GraphPathNode maxPath = new GraphPathNode(null, null);
            var           queue   = new Queue <GraphPathNode>();

            //adding first item to queue
            queue.Enqueue(new GraphPathNode(null, connectionPoint));
            //work while queue not empty - width search
            do
            {
                //get next item
                GraphPathNode current = queue.Dequeue();


                IColorable[] graphPaths = null;

                //setMax = true if we need to compare current length with max
                IColorable last = current.Current;

                bool setMax = (last is FinishNode);
                if (!setMax)
                {
                    //increase length

                    //get all outputs
                    IEnumerable <IColorable> possibleOutputs = last.GetNextPaths();

                    //null check
                    graphPaths = possibleOutputs as IColorable[] ?? possibleOutputs.ToArray();

                    //if there is no output from current node or node have no color - we nedd to compare current length with max
                    setMax = !graphPaths.Any() || (last.GetCurrentColor() == null);
                }
                if (setMax)
                {
                    //compare maximal path with current
                    if (maxPath < current)
                    {
                        maxPath = current;
                    }
                }
                else
                {
                    //we have node to explore
                    //get current color


                    //for all branches out of this node
                    foreach (IColorable t in graphPaths)
                    {
                        //make new path to branch
                        GraphPathNode newPath = new GraphPathNode(current, t);

                        /*
                         * //get color of branch
                         * Color newColor = t.GetCurrentColor();
                         * if (newColor != null)
                         * {
                         *  //if color contains previous color
                         *  if (newColor.Contains(currentColor))
                         *      //then we set it al last color in path
                         *      newPath.LastColor = newColor;
                         *  else
                         *      //else - color changed and we add it
                         *      newPath.PathTo.Add(newColor);
                         *
                         * }*/
                        //add new path to que to analize
                        if (t != null)
                        {
                            queue.Enqueue(newPath);
                        }
                    }
                }
            } while (queue.Count != 0);

            GraphPath res = MarkAsResult(maxPath);

            return(res);
        }