Advertisement

算法设计与分析课程采用回溯法解决旅行售货员问题

阅读量:
复制代码
    #include<iostream>
    #include<bits/stdc++.h>
    using namespace std;
    const int noEdge=65535;
    class Traveling
    {
    	public:
    		void BackTrack(int i);
    		
    		int n;		//图G的顶点数 
    		int *x;		//当前的解 
    		int *bestx; // 当前的最优解 
    		int **a;    // 图G的临界矩阵 
    		int cc;     // 当前费用 
    		int bestc;  //当前最优花费的值 
    	//  int noEdge  无边标记 
     };
     
     void Traveling::BackTrack(int i)
     {
     	if(i == n)
     	{
     		if(a[x[n-1]][x[n]] !=noEdge && a[x[n]][1] !=noEdge 
    		   &&(cc+a[x[n-1]][x[n]]+a[x[n]][1]<bestc || bestc ==noEdge))
    		   {

全部评论 (0)

还没有任何评论哟~