TSP矩阵为什么我的结果总是0

TSP matrix why is my result always 0?

本文关键字:结果 我的 为什么 TSP      更新时间:2023-10-16

我正在制定我的旅行销售计划(不使用STL)

我知道这不应该给我正确的答案。我正在努力确保我的矩阵首先被正确加载。

有人能看到这里的问题吗?无论我投入什么,我的总成本总是为0。

附带说明:如何从一行中读取多个字符。实际上,我需要从第6点开始的字符。

//method for getting the minimum cost of the given routes.
void getCost(){
for(int i = 0; i <50; i++){

for(int j = 0; j <50; j++){
    if (graph[i][j]>0)
        totalCost == totalCost + graph[i][j];

   }
}
}
   switch (line[0]) {
      case 'c':

        cCount++;
        cout << "Added City: " << line << "n";
         break;
      case 'a':
         aCount++;
         c1 = line[2];
         c2 = line[4];
         cost = line[6];
         cout << "Added Route: " << line << "n";
         graph[c1][c2] == cost;

         break;
      default:
        getCost();
        cout << totalCost;
         stop = true;
         break;
   }

以下是比较,而不是赋值;它不会改变totalCost:

totalCost == totalCost + graph[i][j];

要解决此问题,请写入

totalCost = totalCost + graph[i][j];

或者,等效但更简洁的

totalCost += graph[i][j];