|
@@ -38,11 +38,166 @@ unsigned tabuStopTime = 60;
|
38
|
38
|
// Domyslna liczba watkow tabu search
|
39
|
39
|
unsigned tabuThreadsNumber = 2;
|
40
|
40
|
|
|
41
|
+void parseTSPLIB_FULL_MATRIX(const char *filename)
|
|
42
|
+{
|
|
43
|
+ // Jan Potocki 2017
|
|
44
|
+ string fileInput;
|
|
45
|
+ ifstream salesmanDataFile;
|
|
46
|
+
|
|
47
|
+ salesmanDataFile.open(filename);
|
|
48
|
+ if(salesmanDataFile.is_open())
|
|
49
|
+ {
|
|
50
|
+ do
|
|
51
|
+ salesmanDataFile >> fileInput;
|
|
52
|
+ while(fileInput != "DIMENSION:");
|
|
53
|
+
|
|
54
|
+ salesmanDataFile >> fileInput;
|
|
55
|
+ int vertex = stoi(fileInput);
|
|
56
|
+
|
|
57
|
+ do
|
|
58
|
+ salesmanDataFile >> fileInput;
|
|
59
|
+ while(fileInput != "EDGE_WEIGHT_FORMAT:");
|
|
60
|
+
|
|
61
|
+ salesmanDataFile >> fileInput;
|
|
62
|
+ if(fileInput == "FULL_MATRIX")
|
|
63
|
+ {
|
|
64
|
+ if(graph != NULL)
|
|
65
|
+ delete graph;
|
|
66
|
+
|
|
67
|
+ if(useListGraph)
|
|
68
|
+ graph = new ListGraph(vertex);
|
|
69
|
+ else
|
|
70
|
+ graph = new ArrayGraph(vertex);
|
|
71
|
+
|
|
72
|
+ do
|
|
73
|
+ salesmanDataFile >> fileInput;
|
|
74
|
+ while(fileInput != "EDGE_WEIGHT_SECTION");
|
|
75
|
+
|
|
76
|
+ for(int i = 0; i < vertex; i++)
|
|
77
|
+ {
|
|
78
|
+ for(int j = 0; j < vertex; j++)
|
|
79
|
+ {
|
|
80
|
+ salesmanDataFile >> fileInput;
|
|
81
|
+ int weight = stoi(fileInput);
|
|
82
|
+
|
|
83
|
+ if(i != j)
|
|
84
|
+ graph->addEdge(i, j, weight);
|
|
85
|
+ }
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ cout << "Liczba wczytanych wierzcholkow: " << vertex << endl;
|
|
89
|
+ cout << endl;
|
|
90
|
+ }
|
|
91
|
+ else
|
|
92
|
+ {
|
|
93
|
+ cout << "+++ MELON MELON MELON +++ Nieobslugiwany format " << fileInput << " +++" << endl;
|
|
94
|
+ cout << endl;
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+ salesmanDataFile.close();
|
|
98
|
+ }
|
|
99
|
+ else
|
|
100
|
+ {
|
|
101
|
+ cout << "+++ MELON MELON MELON +++ Brak pliku " << filename << " +++" << endl;
|
|
102
|
+ cout << endl;
|
|
103
|
+ }
|
|
104
|
+}
|
|
105
|
+
|
|
106
|
+void parseTSPLIB_EUC_2D(const char *filename)
|
|
107
|
+{
|
|
108
|
+ // Jan Potocki 2017
|
|
109
|
+ string fileInput;
|
|
110
|
+ vector<float> xCoord, yCoord;
|
|
111
|
+ ifstream salesmanDataFile;
|
|
112
|
+
|
|
113
|
+ salesmanDataFile.open(filename);
|
|
114
|
+ if(salesmanDataFile.is_open())
|
|
115
|
+ {
|
|
116
|
+ do
|
|
117
|
+ salesmanDataFile >> fileInput;
|
|
118
|
+ while(fileInput != "DIMENSION:");
|
|
119
|
+
|
|
120
|
+ salesmanDataFile >> fileInput;
|
|
121
|
+ int vertex = stoi(fileInput);
|
|
122
|
+
|
|
123
|
+ do
|
|
124
|
+ salesmanDataFile >> fileInput;
|
|
125
|
+ while(fileInput != "EDGE_WEIGHT_TYPE:");
|
|
126
|
+
|
|
127
|
+ salesmanDataFile >> fileInput;
|
|
128
|
+ if(fileInput == "EUC_2D")
|
|
129
|
+ {
|
|
130
|
+ if(*graph != NULL)
|
|
131
|
+ delete graph;
|
|
132
|
+
|
|
133
|
+ if(useListGraph)
|
|
134
|
+ graph = new ListGraph(vertex);
|
|
135
|
+ else
|
|
136
|
+ graph = new ArrayGraph(vertex);
|
|
137
|
+
|
|
138
|
+ do
|
|
139
|
+ salesmanDataFile >> fileInput;
|
|
140
|
+ while(fileInput != "NODE_COORD_SECTION");
|
|
141
|
+
|
|
142
|
+ for(int i = 0; i < vertex; i++)
|
|
143
|
+ {
|
|
144
|
+ salesmanDataFile >> fileInput;
|
|
145
|
+
|
|
146
|
+ salesmanDataFile >> fileInput;
|
|
147
|
+ xCoord.push_back(stof(fileInput));
|
|
148
|
+
|
|
149
|
+ salesmanDataFile >> fileInput;
|
|
150
|
+ yCoord.push_back(stof(fileInput));
|
|
151
|
+ }
|
|
152
|
+
|
|
153
|
+ // To daloby sie zrobic optymalniej (macierz symetryczna), ale nie chce mi sie ...
|
|
154
|
+ // ..wole zoptymalizować czas programowania ;-)
|
|
155
|
+ for(int i = 0; i < vertex; i++)
|
|
156
|
+ {
|
|
157
|
+ for(int j = 0; j < vertex; j++)
|
|
158
|
+ {
|
|
159
|
+ if(i != j)
|
|
160
|
+ {
|
|
161
|
+ float xDiff = xCoord.at(i) - xCoord.at(j);
|
|
162
|
+ float yDiff = yCoord.at(i) - yCoord.at(j);
|
|
163
|
+ int weight = nearbyint(sqrt(xDiff * xDiff + yDiff * yDiff));
|
|
164
|
+
|
|
165
|
+ graph->addEdge(i, j, weight);
|
|
166
|
+ }
|
|
167
|
+ }
|
|
168
|
+ }
|
|
169
|
+
|
|
170
|
+ cout << "Liczba wczytanych wierzcholkow: " << vertex << endl;
|
|
171
|
+ cout << endl;
|
|
172
|
+ }
|
|
173
|
+ else
|
|
174
|
+ {
|
|
175
|
+ cout << "+++ MELON MELON MELON +++ Nieobslugiwany format " << fileInput << " +++" << endl;
|
|
176
|
+ cout << endl;
|
|
177
|
+ }
|
|
178
|
+
|
|
179
|
+ salesmanDataFile.close();
|
|
180
|
+ }
|
|
181
|
+ else
|
|
182
|
+ {
|
|
183
|
+ cout << "+++ MELON MELON MELON +++ Brak pliku " << filename << " +++" << endl;
|
|
184
|
+ cout << endl;
|
|
185
|
+ }
|
|
186
|
+}
|
|
187
|
+
|
|
188
|
+void banner()
|
|
189
|
+{
|
|
190
|
+ cout << "PEA Projekt 2 Plus v2.0ALPHA" << endl;
|
|
191
|
+ cout << "Jan Potocki 2017-2019" << endl;
|
|
192
|
+ cout << "(beerware)" << endl;
|
|
193
|
+}
|
|
194
|
+
|
41
|
195
|
int main(int argc, char *argv[])
|
42
|
196
|
{
|
43
|
197
|
Stopwatch clock; // czasomierz
|
44
|
198
|
Graph *graph = NULL; // <- tu bedziemy zapisywac adresy przez caly program
|
45
|
199
|
|
|
200
|
+ // Parsowanie parametrow z linii komend
|
46
|
201
|
if(argc > 1)
|
47
|
202
|
{
|
48
|
203
|
for(int i = 1; i < argc; i++)
|
|
@@ -61,12 +216,41 @@ int main(int argc, char *argv[])
|
61
|
216
|
else
|
62
|
217
|
cout << "+++ MELON MELON MELON +++ Nieprawidlowa liczba watkow +++" << endl << endl;
|
63
|
218
|
}
|
|
219
|
+ else if(strcmp(argv[i], "-fmatrix") == 0)
|
|
220
|
+ {
|
|
221
|
+ i++;
|
|
222
|
+ parseTSPLIB_FULL_MATRIX(argv[i], graph);
|
|
223
|
+ }
|
|
224
|
+ else if(strcmp(argv[i], "-feuc2d") == 0)
|
|
225
|
+ {
|
|
226
|
+ i++;
|
|
227
|
+ parseTSPLIB_EUC_2D(argv[i], graph);
|
|
228
|
+ }
|
|
229
|
+ else if(strcmp(argv[i], "-h") == 0)
|
|
230
|
+ {
|
|
231
|
+ banner();
|
|
232
|
+ cout << endl << "Parametry:" << endl;
|
|
233
|
+ cout << "-feuc2d [plik]" << "\t\t" << "wczytanie danych z pliku w formacie TSPLIB EUC_2D" << endl;
|
|
234
|
+ cout << endl;
|
|
235
|
+ cout << "-fmatrix [plik]" << "\t\t" << "wczytanie danych z pliku w formacie TSPLIB FULL_MATRIX" << endl;
|
|
236
|
+ cout << endl;
|
|
237
|
+ cout << "-l" << "\t\t\t" << "uzycie reprezentacji grafu w pamieci w postaci listy" << endl;
|
|
238
|
+ cout << "\t\t\t" << "sasiedztwa (domyslnie macierz sasiedztwa)" << endl;
|
|
239
|
+ cout << endl;
|
|
240
|
+ cout << "-t [liczba]" << "\t\t" << "liczba watkow roboczych dla algorytmu tabu search" << endl;
|
|
241
|
+ cout << endl;
|
|
242
|
+ cout << "-h" << "\t\t\t" << "wyswietlenie pomocy (opisu parametrow)" << endl;
|
|
243
|
+ return 0;
|
|
244
|
+ }
|
|
245
|
+ else
|
|
246
|
+ {
|
|
247
|
+ cout << "Nieprawidlowy parametr, uzyj -h aby uzyskac pomoc" << endl;
|
|
248
|
+ return 0;
|
|
249
|
+ }
|
64
|
250
|
}
|
65
|
251
|
}
|
66
|
252
|
|
67
|
|
- cout << "PEA Projekt 2 Plus v2.0ALPHA" << endl;
|
68
|
|
- cout << "Jan Potocki 2017-2019" << endl;
|
69
|
|
- cout << "(beerware)" << endl;
|
|
253
|
+ banner();
|
70
|
254
|
if(useListGraph)
|
71
|
255
|
cout << "Uzycie listowej reprezentacji grafu" << endl;
|
72
|
256
|
else
|
|
@@ -407,155 +591,24 @@ int main(int argc, char *argv[])
|
407
|
591
|
break;
|
408
|
592
|
case 8:
|
409
|
593
|
{
|
410
|
|
- // Jan Potocki 2017
|
411
|
|
- string filename, fileInput;
|
412
|
|
- ifstream salesmanDataFile;
|
|
594
|
+ // Jan Potocki 2019
|
|
595
|
+ string filename;
|
413
|
596
|
|
414
|
597
|
cout << "Podaj nazwe pliku: ";
|
415
|
598
|
cin >> filename;
|
416
|
599
|
|
417
|
|
- salesmanDataFile.open(filename.c_str());
|
418
|
|
- if(salesmanDataFile.is_open())
|
419
|
|
- {
|
420
|
|
- do
|
421
|
|
- salesmanDataFile >> fileInput;
|
422
|
|
- while(fileInput != "DIMENSION:");
|
423
|
|
-
|
424
|
|
- salesmanDataFile >> fileInput;
|
425
|
|
- int vertex = stoi(fileInput);
|
426
|
|
-
|
427
|
|
- do
|
428
|
|
- salesmanDataFile >> fileInput;
|
429
|
|
- while(fileInput != "EDGE_WEIGHT_FORMAT:");
|
430
|
|
-
|
431
|
|
- salesmanDataFile >> fileInput;
|
432
|
|
- if(fileInput == "FULL_MATRIX")
|
433
|
|
- {
|
434
|
|
- if(graph != NULL)
|
435
|
|
- delete graph;
|
436
|
|
-
|
437
|
|
- if(useListGraph)
|
438
|
|
- graph = new ListGraph(vertex);
|
439
|
|
- else
|
440
|
|
- graph = new ArrayGraph(vertex);
|
441
|
|
-
|
442
|
|
- do
|
443
|
|
- salesmanDataFile >> fileInput;
|
444
|
|
- while(fileInput != "EDGE_WEIGHT_SECTION");
|
445
|
|
-
|
446
|
|
- for(int i = 0; i < vertex; i++)
|
447
|
|
- {
|
448
|
|
- for(int j = 0; j < vertex; j++)
|
449
|
|
- {
|
450
|
|
- salesmanDataFile >> fileInput;
|
451
|
|
- int weight = stoi(fileInput);
|
452
|
|
-
|
453
|
|
- if(i != j)
|
454
|
|
- graph->addEdge(i, j, weight);
|
455
|
|
- }
|
456
|
|
- }
|
457
|
|
-
|
458
|
|
- cout << "Wczytano - liczba wierzcholkow: " << vertex << endl;
|
459
|
|
- cout << endl;
|
460
|
|
- }
|
461
|
|
- else
|
462
|
|
- {
|
463
|
|
- cout << "+++ MELON MELON MELON +++ Nieobslugiwany format " << fileInput << " +++" << endl;
|
464
|
|
- cout << endl;
|
465
|
|
- }
|
466
|
|
-
|
467
|
|
- salesmanDataFile.close();
|
468
|
|
- }
|
469
|
|
- else
|
470
|
|
- {
|
471
|
|
- cout << "+++ MELON MELON MELON +++ Brak pliku " << filename << " +++" << endl;
|
472
|
|
- cout << endl;
|
473
|
|
- }
|
|
600
|
+ parseTSPLIB_FULL_MATRIX(filename.c_str(), graph);
|
474
|
601
|
}
|
475
|
602
|
break;
|
476
|
603
|
case 9:
|
477
|
604
|
{
|
478
|
|
- // Jan Potocki 2017
|
479
|
|
- string filename, fileInput;
|
480
|
|
- vector<float> xCoord, yCoord;
|
481
|
|
- ifstream salesmanDataFile;
|
|
605
|
+ // Jan Potocki 2019
|
|
606
|
+ string filename;
|
482
|
607
|
|
483
|
608
|
cout << "Podaj nazwe pliku: ";
|
484
|
609
|
cin >> filename;
|
485
|
610
|
|
486
|
|
- salesmanDataFile.open(filename.c_str());
|
487
|
|
- if(salesmanDataFile.is_open())
|
488
|
|
- {
|
489
|
|
- do
|
490
|
|
- salesmanDataFile >> fileInput;
|
491
|
|
- while(fileInput != "DIMENSION:");
|
492
|
|
-
|
493
|
|
- salesmanDataFile >> fileInput;
|
494
|
|
- int vertex = stoi(fileInput);
|
495
|
|
-
|
496
|
|
- do
|
497
|
|
- salesmanDataFile >> fileInput;
|
498
|
|
- while(fileInput != "EDGE_WEIGHT_TYPE:");
|
499
|
|
-
|
500
|
|
- salesmanDataFile >> fileInput;
|
501
|
|
- if(fileInput == "EUC_2D")
|
502
|
|
- {
|
503
|
|
- if(graph != NULL)
|
504
|
|
- delete graph;
|
505
|
|
-
|
506
|
|
- if(useListGraph)
|
507
|
|
- graph = new ListGraph(vertex);
|
508
|
|
- else
|
509
|
|
- graph = new ArrayGraph(vertex);
|
510
|
|
-
|
511
|
|
- do
|
512
|
|
- salesmanDataFile >> fileInput;
|
513
|
|
- while(fileInput != "NODE_COORD_SECTION");
|
514
|
|
-
|
515
|
|
- for(int i = 0; i < vertex; i++)
|
516
|
|
- {
|
517
|
|
- salesmanDataFile >> fileInput;
|
518
|
|
-
|
519
|
|
- salesmanDataFile >> fileInput;
|
520
|
|
- xCoord.push_back(stof(fileInput));
|
521
|
|
-
|
522
|
|
- salesmanDataFile >> fileInput;
|
523
|
|
- yCoord.push_back(stof(fileInput));
|
524
|
|
- }
|
525
|
|
-
|
526
|
|
- // To daloby sie zrobic optymalniej (macierz symetryczna), ale nie chce mi sie ...
|
527
|
|
- // ..wole zoptymalizować czas programowania ;-)
|
528
|
|
- for(int i = 0; i < vertex; i++)
|
529
|
|
- {
|
530
|
|
- for(int j = 0; j < vertex; j++)
|
531
|
|
- {
|
532
|
|
- if(i != j)
|
533
|
|
- {
|
534
|
|
- float xDiff = xCoord.at(i) - xCoord.at(j);
|
535
|
|
- float yDiff = yCoord.at(i) - yCoord.at(j);
|
536
|
|
- int weight = nearbyint(sqrt(xDiff * xDiff + yDiff * yDiff));
|
537
|
|
-
|
538
|
|
- graph->addEdge(i, j, weight);
|
539
|
|
- }
|
540
|
|
- }
|
541
|
|
- }
|
542
|
|
-
|
543
|
|
- cout << "Wczytano - liczba wierzcholkow: " << vertex << endl;
|
544
|
|
- cout << endl;
|
545
|
|
- }
|
546
|
|
- else
|
547
|
|
- {
|
548
|
|
- cout << "+++ MELON MELON MELON +++ Nieobslugiwany format " << fileInput << " +++" << endl;
|
549
|
|
- cout << endl;
|
550
|
|
- }
|
551
|
|
-
|
552
|
|
- salesmanDataFile.close();
|
553
|
|
- }
|
554
|
|
- else
|
555
|
|
- {
|
556
|
|
- cout << "+++ MELON MELON MELON +++ Brak pliku " << filename << " +++" << endl;
|
557
|
|
- cout << endl;
|
558
|
|
- }
|
|
611
|
+ parseTSPLIB_EUC_2D(filename.c_str(), graph);
|
559
|
612
|
}
|
560
|
613
|
break;
|
561
|
614
|
case 0:
|