How to use TSPlib to solve traveling salesman problem (TSP) [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am actually working on TSP problem, and I need to test program, I am using the data from the TSPlib API(Symmetric traveling salesman problem) :
https://www.iwr.uni-heidelberg.de/groups/comopt/software/TSPLIB95/tsp/
So I so confused about the data file, for example, is a280.tsp represent the coordinates of cities or the distances because when I am using it like coordinate it gives me wrong values,
please, someone can help !!!

Each line is : node number + x coordinate + y coordinates
Node_id x y
The content of the a280.tsp file is the following (opened with a text editor):
NAME : a280
COMMENT : drilling problem (Ludwig)
TYPE : TSP
DIMENSION: 280
EDGE_WEIGHT_TYPE : EUC_2D
NODE_COORD_SECTION
1 288 149
2 288 129
3 270 133
4 256 141
5 256 157
6 246 157
7 236 169
8 228 169
9 228 161
10 220 169
...
280 280 133
EOF
For further details, have a look here

Related

Is this how a minheap is sorted? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
My professor claims my Minheap is incorrect on the following question:
Convert the following numbers to minheap using min heap down and draw the final minheap tree level by level and final array content.
Array given: 100 10 80 30 60 50 40 70 20 90
My answer was as follows:
10
/ \
20 40
/ \ / \
30 60 80 50
/\ /
100 70 90
Sorted Array: 10,20,40,30,60,80,50,100,70,90
Am I incorrect?
A Min-Heap is a complete binary tree in which the value in each internal node is smaller than or equal to the values in the children of that node.
Mapping the elements of a heap into an array is trivial: if a node is stored an index k, then its left child is stored at index 2k + 1 and its right child at index 2k + 2.
your answer is right you miss placed 70 and 100 that's wrong here otherwise its correct
the sorted array will be
10,20,40,30,60,50,80,70,100,90

What is wrong with this code for generating random integers in Java??? (Unexpected Outputs) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
The code below is supposed to generate random integers from 97 till 122:
for(int x = 0; x < 10; x++) {
int a = (int)(Math.random()*(26 + 97));
System.out.println(a);
}
The outputs I am getting are all over the place. They go below 97.
Here are the outputs for one of the runs:
33
113
87
73
22
25
118
29
16
21
It's a paren problem. Try this instead.
(int)(Math.random()*26) gives a number between 0 and 25 inclusive.
Add 97 to that range and you get between 97 and 122 inclusive.
int a = (int)(Math.random()*26) + 97;

Hard logic - Reversing a format [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have this code which reads from a file:
dummy = fd.readLong();
for(i = 0; i < chunks; i++) {
dummy2=fd.readLong();
chunksizes[i] = dummy2- dummy;
dummy = dummy2;
}
I now have a list of chunk sizes and I want to write them in the format above. I have an array called actualSizes which is the sizes I want to write, I have the amount of chunks. Any psuedocode that could do this? My head is going crazy yet it looks so simple
Seems that the file has a list of offsets and that you load them into an array as deltas (chunk sizes):
0 100 250 420 580 Offsets from file
└──┬──┴──┬──┴──┬──┴──┬──┘
100 150 170 160 Deltas, aka chunk sizes
You then say:
I now have a list of chunk sizes and I want to write them in the format above.
The only "format above" would be the list of offsets, so you create a list of offsets from a list of delta (chunk/actual) sizes, by starting with 0 and writing a running sum:
long offset = 0;
fd.writeLong(offset);
for (long size : actualSizes) {
offset += size;
fd.writeLong(offset);
}
120 140 130 150 actual sizes
┌──┴──┬──┴──┬──┴──┬──┴──┐
0 120 260 390 540 offsets in file (running total)

How to make a dynamic array Fibonacci series java program? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am in 8th grade. I am taking a 12th grade java course. I just started and my home work is to make a Fibonacci series dynamic array program. I don't know where to go. It is online so I can't ask a teacher or something.
How do you make a Fibonacci sequence using a dynamic array in Java?
This was an example of a dynamic array I got:
I don't see how you can make the Fibonacci series out of it! Here is the Fibonacci series example I got.
You can combine the two examples, as such:
Take the DynamicArrayOfInt class, and add the main method of the Fibonacci class.
Insert a new statement at the beginning of the main method instantiating a DynamicArrayOfInt object, as such:
DynamicArrayOfInt arr = new DynamicArrayOfInt();
Replace every instance of numbers[x] with arr.get(x), and instances of numbers[x] = y with arr.put(x, y).
Remove the leftover statements dealing with the numbers array. This will essentially make use of the DynamicArrayOfInt object. A sample output would look like this:
iplante$ java DynamicArrayOfInt
Size of dynamic array increased to: 2
Fibonacci series:
0
1
Size of dynamic array increased to: 4
1
2
Size of dynamic array increased to: 8
3
5
8
13
Size of dynamic array increased to: 16
21
34
55
89
144
233
377
610
Size of dynamic array increased to: 32
987
1597
2584
4181
iplante$

Write a Csv file to a Matrix like structure [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a csv file with this format, where in the first column I have the number of repetitions, in the second the number of days and in the third the time of execution.
Here's the representation:
1 7 131
2 7 71
3 7 114
[.....]
9 7 338
10 7 394
11 7 437
12 7 496
1 31 171
[.....]
12 31 1894
1 91 437
[.....]
10 91 4394
[.....]
I want to process this file to transform it in this way, I can use Java or Excel Macros
7 31 91 183 366
1 131 171 437 866 1906
2 71 305 867 173 3460
3 114 493 136 261 5356
4 159 596 182 356 6916
5 210 800 249 468 8762
6 223 919 378 605 11296
7 270 107 354 644 12898
8 270 123 401 746 14265
9 338 145 398 903 15487
10 394 164 439 934 16971
11 437 174 507 104 18941
12 496 189 527 110 21378
Where the first column of the Csv file remain the first column of the file, but not repeated. Then the period [7,31,...,366] must be placed as the first row.
Inside this matrix there will be placed all elements?
How can i do with Java or directly with macro inside Excel?
Thanks
What about a Map <Integer, Map <Integer, Integer>> being the first key the column and the inner key the number of days? The inner value would be the time of execution.
After being filled, you could print it doing something like:
print map.get(1).getKeys()
for (Entry entry : map.getKeys()
print entry.key()
for (Integer innerValue : map.get(entry.key())
print innerValue
The maps should be ordered for this to work...

Categories