Esempio n. 1
0
        public bool TrySolve(Graph graph, Action <Node[]> registerAttempt, Dictionary <string, object> runDetails)
        {
            Reset();
            _edgeHistory = new List <Node[]>();

            var workingSet = new WorkingSet(graph);

            try
            {
                var firstEdge = GetFirstEdge(workingSet);
                workingSet.AddToWalk(firstEdge); //1D line
                workingSet.AddToWalk(firstEdge); //2D line
                AddToHistory(workingSet);

                while (workingSet.NodesNotInGraph.Count > 0)
                {
                    var nextNode    = GetNextNode(workingSet);
                    var edgeToSplit = GetEdgeToSplit(workingSet.CurrentWalk, nextNode);
                    workingSet.SplitEdge(nextNode.Node, edgeToSplit);
                    AddToHistory(workingSet);
                    NotifyChange(workingSet);
                }

                var walk = FormatWalk(workingSet.CurrentWalk);
                registerAttempt(walk);
            }
            finally
            {
                runDetails["history"] = _edgeHistory;
            }

            return(true);
        }