Hi, both the compiler and debugger don't show any errors except the program only runs until when I call the function
first_2_opt(n, d, f, p)
at line 69 from
https://pastebin.com/9sGMSwp1 . The original code is this one :
https://pastebin.com/Xz3vScrL . The function mentioned starts from line 288 for both code. The original one doesn't have the problem, even though I just added a few lines of code for the problematic one.
Allow me to explain why I added the lines for the problematic one. If you refer to the function in the original one, the i and j indices increases sequentially, which is {0,0},{0,1},{0,2},...,{n,n-2},{n,n-1},{n,n}. However, I want it to be random, for example, {3,2},{n-2,3},{n,5} and so on. So I thought of letting the i and j be random numbers less than n, which is shown from my for loop initialisation where
i = rand()%(n-1)
and
j = rand()%(n-1)
. And the lines that involves
count_i
and
count_j
is my attempt to make sure the same number for i and j only appear n times, since repetition of the combination of i and j would happen if they appear more than n times.
This explanation I give also serves to let everyone know what I'm trying to achieve so if those code are incorrect for the purpose I wish to achieve, I sincerely wish someone would correct me. Also, I apologise to those that already saw me posting this same code again and again (for different problem) because I didn't take up some of your suggestions such as using vectors and many more.
Here is the file I'm reading from:
Nug12
12
578
0 1 2 3 1 2 3 4 2 3 4 5
1 0 1 2 2 1 2 3 3 2 3 4
2 1 0 1 3 2 1 2 4 3 2 3
3 2 1 0 4 3 2 1 5 4 3 2
1 2 3 4 0 1 2 3 1 2 3 4
2 1 2 3 1 0 1 2 2 1 2 3
3 2 1 2 2 1 0 1 3 2 1 2
4 3 2 1 3 2 1 0 4 3 2 1
2 3 4 5 1 2 3 4 0 1 2 3
3 2 3 4 2 1 2 3 1 0 1 2
4 3 2 3 3 2 1 2 2 1 0 1
5 4 3 2 4 3 2 1 3 2 1 0
0 5 2 4 1 0 0 6 2 1 1 1
5 0 3 0 2 2 2 0 4 5 0 0
2 3 0 0 0 0 0 5 5 2 2 2
4 0 0 0 5 2 2 10 0 0 5 5
1 2 0 5 0 10 0 0 0 5 1 1
0 2 0 2 10 0 5 1 1 5 4 0
0 2 0 2 0 5 0 10 5 2 3 3
6 0 5 10 0 1 10 0 0 0 5 0
2 4 5 0 0 1 5 0 0 0 10 10
1 5 2 0 5 5 2 0 0 0 5 0
1 0 2 5 1 4 3 5 10 5 0 2
1 0 2 5 1 0 3 0 10 0 2 0
Thanks in advance, and have a nice day!