-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithmLAHC.cpp
More file actions
51 lines (41 loc) · 839 Bytes
/
algorithmLAHC.cpp
File metadata and controls
51 lines (41 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "algorithmLAHC.h"
void AlgorithmLAHC(int pL, int wL, int closest, int prob){
if(closest)
InitClosestArray(closest);
int n = 0, w = 0;
lastCosts = new double[pL];
for(int i = 0; i<pL; i++){
lastCosts[i] = cost;
}
int restarted = 1;
double et, bt = omp_get_wtime();
while(1){
if(RandomSCHC(lastCosts[n%pL],closest,prob)){
if(BestScore - EPS > cost){
CopyBestPath();
#ifndef DEBUG
o(BestScore);
#endif
restarted = 1;
w = 0;
}
}
else w++;
lastCosts[n%pL] = cost;
if(w > wL){
for(int i = 0; i<pL; i++){
lastCosts[i] = lastCosts[i] + restarted*(rand()%(int)sqrt(cost));
}
CopyRevBestPath();
restarted++;
w = 0;
et = omp_get_wtime();
if(et - bt > MAX_RUNNING_TIME)
break;
if(restarted > 10)
break;
}
n++;
}
delete lastCosts;
}