TSP矩阵为什么我的结果总是0
TSP matrix why is my result always 0?
我正在制定我的旅行销售计划(不使用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];
相关文章:
- 为什么我的程序在 O0 和 O2 的优化级别返回不同的结果
- 我的 SonarQube C++扫描成功,但结果仅标记重复项,而没有标记其他标记的位置
- 当我的 if 条件计算结果为 false 时,我的 else 块将不会执行
- 为什么我的性能基准给了我错误的结果?
- 我的输出结果是 0 英寸C++.可能是什么问题
- 我的代码厨师提交显示错误的结果
- 为什么在我的程序中输入另一个输入会给我不同的结果
- 我无法弄清楚我的代码未显示预期结果的问题
- 我想根据小数位将我的结果对齐到列中
- 删除动态数组会弄乱我的结果
- 我的循环超时并且不显示结果
- 为什么我的结果中有 0?我不知道它从哪里来
- 为什么我的代码给了我错误的结果?
- 为什么我的 Go 解决方案给出的结果与C++不同
- 如何打印返回值的结果?我是一个初学者学习C++
- 为什么我的Cooley-Tukey和蛮力(傅立叶)算法给出的结果非常不同
- 我的程序打印出与预期不同的结果
- 在我的C++链表实现中取消引用节点指针,给出意想不到的结果
- 我的C 程序在CodeBlocks中提供了正确的结果,但在Visual Basic 2005 Express Edi
- infix/postfix/prefix程序.想要使用我的printresult()函数打印结果.需要帮助获得输出