问题描述
我有一个用于dijkstra算法的程序..工作正常但是这个应用程序有问题。
它可以找到最短的路径。
示例
--------------------------
节点数:6(0, 1,2,3,4,5)
我的程序可以找到介于0到5之间的最短路径但是它找不到4到5,2,5或者1,4 ...等..
---------------------------
有没有人可以提供帮助?
i have a program which is used for dijkstra algorithm..its working correctly but there is a problem in this application.
it can find the shortest path.
EXAMPLE
--------------------------
Node Count : 6 (0,1,2,3,4,5)
my program can find shortest path between from 0 to 5 but it cant find between 4 to 5, 2,5 or 1,4...etc..
---------------------------
is there anyone to help for tht?
for (i = 1; i < sayac; ++i)
{
EKM[i] = ebas;
ead = 0;
}
for (i = 0; i < sayac; ++i)
{
for (j = 0; j < sayac; ++j)
if (elealindi[j] == 0)
if (graph[ead, j] != -1)
if (EKM[j] > graph[ead, j] + EKM[ead])
{
EKM[j] = graph[ead, j] + EKM[ead];
System.String.Concat(ROTA[j], ROTA[ead]);
ptr = ROTA[j];
while (ptr == null)
++ptr;
ptr = Convert.ToChar('A' + ead);
Label2.Text = Label2.Text + " " + ROTA[j];
dij_saving();
}
ek = ebas;
for (j = 1; j < sayac; ++j)
if (elealindi[j] == 0)
if (EKM[j] < ek)
{
ek = EKM[j];
ead = j;
}
elealindi[ead] = 1;
}
我的尝试:
查找从一个节点到另一个节点的最短路径..
What I have tried:
Finding the shortest path from one node to another node..
推荐答案
Input Expected output Actual output
1 2 1
2 4 4
3 6 9
4 8 16
然后很明显问题出在将它加倍的位 - 它不会将自身加到自身上,或者将它乘以2,它会将它自身相乘并返回输入的平方。
所以,你可以查看代码和很明显,它在某处:
Then it's fairly obvious that the problem is with the bit which doubles it - it's not adding itself to itself, or multiplying it by 2, it's multiplying it by itself and returning the square of the input.
So with that, you can look at the code and it's obvious that it's somewhere here:
private int Double(int value)
{
return value * value;
}
一旦你知道可能出现的问题,就开始使用调试器找出原因。在你的行上设一个断点:
Once you have an idea what might be going wrong, start using the debugger to find out why. Put a breakpoint on your line:
for (i = 0; i < sayac; ++i)
和运行你的应用程序在执行代码之前,请考虑代码中的每一行应该做什么,并将其与使用Step over按钮依次执行每一行时实际执行的操作进行比较。它符合您的期望吗?如果是这样,请转到下一行。
如果没有,为什么不呢?它有何不同?
这是一项非常值得开发的技能,因为它可以帮助你在现实世界和发展中。和所有技能一样,它只能通过使用来改善!
是的,我可能会告诉你问题是什么 - 但这并不难做到,并且你将同时学到一些非常值得的东西!
and run your app. Think about what each line in the code should do before you execute it, and compare that to what it actually did when you use the "Step over" button to execute each line in turn. Did it do what you expect? If so, move on to the next line.
If not, why not? How does it differ?
This is a skill, and it's one which is well worth developing as it helps you in the real world as well as in development. And like all skills, it only improves by use!
Yes, I could probably tell you what "the problem" is - but it's not difficult to do this yourself, and you will learn something really worthwhile at the same time!
它的工作正常但是那里是这个应用程序中的一个问题。
its working correctly but there is a problem in this application.
问题意味着该应用程序无法正常工作。
您的代码剪辑我们无法使用,它使用我们不喜欢的东西我知道,我不知道你怎么告诉玩具想要的起点和终点。
我唯一可能的建议是调试器。
调试器允许你逐行跟踪执行,检查变量,你会发现它有一个点停止你做的事情。
[]
[]
Problem mean that the app don't work correctly.
Your code snipset us not usable, it use things we don't know and I don't see how you tell start and end points toy want.
My only possible advice is debugger.
The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
这篇关于Dijkstra算法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!