Browse Source

Fixed automatic measure

Jan Potocki 5 years ago
parent
commit
26438c8e3b
1 changed files with 12 additions and 20 deletions
  1. 12
    20
      pea2plus.cpp

+ 12
- 20
pea2plus.cpp View File

17
 // liczba automatycznych pomiarow
17
 // liczba automatycznych pomiarow
18
 const int measureNumber = 4;
18
 const int measureNumber = 4;
19
 // Czas zatrzymania algorytmu tabu search w kazdym z automatycznych pomiarow
19
 // Czas zatrzymania algorytmu tabu search w kazdym z automatycznych pomiarow
20
-const int measureTabuStop[4] = {1, 5, 10, 15};
20
+const int measureTabuStop[4] = {30, 60, 120, 240};
21
 // Maksymalna odleglosc miast przy automatycznym generowaniu
21
 // Maksymalna odleglosc miast przy automatycznym generowaniu
22
 const int measureSalesmanDistance = 400;
22
 const int measureSalesmanDistance = 400;
23
 
23
 
503
             break;
503
             break;
504
             case 7:
504
             case 7:
505
             {
505
             {
506
-                // PEA 2
506
+                // PEA 2 Plus
507
-                // Jan Potocki 2017
507
+                // Jan Potocki 2019
508
                 if(graph != NULL)
508
                 if(graph != NULL)
509
                 {
509
                 {
510
                     unsigned effectiveTabuLength;
510
                     unsigned effectiveTabuLength;
519
                         effectiveTabuLength = tabuLength;
519
                         effectiveTabuLength = tabuLength;
520
                     }
520
                     }
521
 
521
 
522
-                    double measureResults[measureNumber], measureResultsDiv[measureNumber];
522
+                    int measureResult = -1;
523
-                    for(int i = 0; i < measureNumber; i++)
523
+                    int measureResultDiv = -1;
524
-                    {
525
-                        measureResults[i] = 0;
526
-                        measureResultsDiv[i] = 0;
527
-                    }
528
 
524
 
529
                     cout << "Pomiary dla problemu komiwojazera, tabu search" << tabuLength << endl;
525
                     cout << "Pomiary dla problemu komiwojazera, tabu search" << tabuLength << endl;
530
 
526
 
552
                             routeLength = 0;
548
                             routeLength = 0;
553
                             for(int j = 1; j < route.size(); j++)
549
                             for(int j = 1; j < route.size(); j++)
554
                                 routeLength += graph->getWeight(route.at(j - 1), route.at(j));
550
                                 routeLength += graph->getWeight(route.at(j - 1), route.at(j));
555
-                            measureResults[i] += routeLength;
551
+
552
+                            if(measureResult = -1 || measureResult > routeLength)
553
+                                measureResult = routeLength;
556
 
554
 
557
                             // Z dywersyfikacja
555
                             // Z dywersyfikacja
558
                             cout << "Pomiar " << measureTabuStop[i] << " [s] (" << krok + 1 << " z " << measureIterations << " z dywersyfikacja)..." << endl;
556
                             cout << "Pomiar " << measureTabuStop[i] << " [s] (" << krok + 1 << " z " << measureIterations << " z dywersyfikacja)..." << endl;
562
                             routeLength = 0;
560
                             routeLength = 0;
563
                             for(int j = 1; j < route.size(); j++)
561
                             for(int j = 1; j < route.size(); j++)
564
                                 routeLength += graph->getWeight(route.at(j - 1), route.at(j));
562
                                 routeLength += graph->getWeight(route.at(j - 1), route.at(j));
565
-                            measureResultsDiv[i] += routeLength;
566
-                        }
567
-                    }
568
-
569
-                    cout << "Opracowywanie wynikow..." << endl;
570
 
563
 
571
-                    for(int i = 0; i < measureNumber; i++)
564
+                            if(measureResultDiv = -1 || measureResultDiv > routeLength)
572
-                    {
565
+                                measureResultDiv = routeLength;
573
-                        measureResults[i] = nearbyint(measureResults[i] / measureIterations);
566
+                        }
574
-                        measureResultsDiv[i] = nearbyint(measureResultsDiv[i] / measureIterations);
575
                     }
567
                     }
576
 
568
 
577
                     cout << "Zapis wynikow..." << endl;
569
                     cout << "Zapis wynikow..." << endl;
581
                     salesmanToFile << "czas - bez dywersyfikacji - z dywersyfikacja" << endl;
573
                     salesmanToFile << "czas - bez dywersyfikacji - z dywersyfikacja" << endl;
582
                     for(int i = 0; i < measureNumber; i++)
574
                     for(int i = 0; i < measureNumber; i++)
583
                     {
575
                     {
584
-                        salesmanToFile << measureTabuStop[i] << " [s]: " << (int)measureResults[i] << ' ' << (int)measureResultsDiv[i] << endl;
576
+                        salesmanToFile << measureTabuStop[i] << " [s]: " << measureResult << ' ' << measureResultsDiv << endl;
585
                     }
577
                     }
586
                     salesmanToFile.close();
578
                     salesmanToFile.close();
587
 
579
 

Loading…
Cancel
Save