Пример #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);
        }
Пример #2
0
        private void StealNode(StealCandidate candidate, WorkingSet workingSet)
        {
            if (candidate == null)
            {
                return;
            }

            var walk       = workingSet.CurrentWalk;
            var toBeStolen = candidate.ToBeStolen;

            walk.Remove(toBeStolen.EdgeA);
            walk.Remove(toBeStolen.EdgeB);
            walk.Add(new Edge(candidate.ToBeStolen.AtoCenter, candidate.ToBeStolen.BtoCenter));
            workingSet.SplitEdge(candidate.ToBeStolen.Center, candidate.StealingEdge);

            AddToHistory(workingSet);
            NotifyChange(workingSet);
        }