示例#1
0
        public override void visualize(State s)
        {
            this.problem = (TSPProblem)s.p;
            TSPState state = (TSPState)s;
            int maxValueX = problem.positions.Max(x => x.x),
                maxValueY = problem.positions.Max(x => x.y);

            if (clear)
                g.Clear(Color.WhiteSmoke);
            xStretch = width / (maxValueX + 20);
            yStretch = height / (maxValueY + 20);
            if (problem.citiesCount > 2000)
                nodeSize--;
            if (problem.citiesCount > 10000)
                nodeSize--;

			for (int i = 0; i < state.path.Count-1; i++)
			{
				drawLine(state.path[i], state.path[i + 1]);
			}

            for (int i = 0; i < problem.citiesCount; i++)
            {
                drawNode(i);
                if (state.notVisited.Contains(i))
                    fillNode(i, Color.Red);
                else
                    fillNode(i, Color.Black);
            }
            fillNode(state.currentPosition, Color.Green);
            screen.Refresh();
        }
示例#2
0
        public override void getSuccessors(List<StateCostPair> result)
        {
            result.Clear();
            TSPProblem p = (TSPProblem)this.p;
            foreach (var item in notVisited)
            {
                TSPState succ = (TSPState)this.clone();
                succ.notVisited.Remove(item);
                succ.currentPosition = item;
				succ.path.Add(item);
                result.Add(new StateCostPair(succ, p.getDistance(this.currentPosition, succ.currentPosition)));
            }
        }
示例#3
0
        public TSPState(TSPProblem p)
        {
            this.notVisited = new HashSet<int>();
			this.path = new List<int>();
            this.p = p;
        }