-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgvns.cpp
58 lines (47 loc) · 1.4 KB
/
gvns.cpp
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
52
53
54
55
56
57
58
#include "gvns.h"
//------------------------------------------------------------------------------
GVNS::GVNS(TSPTW *tsp, int max)
{
this->tsp = tsp;
this->max = max;
}
//------------------------------------------------------------------------------
GVNS::~GVNS()
{
}
//------------------------------------------------------------------------------
TSPTWSolution *GVNS::optimize()
{
TSPTWCons *cons = new TSPTWCons(tsp);
LocalSearch *ls = new LocalVND();
int levelmax = 8;//8//(this->tsp->numNodes/40)+5;
int itermax = 30;//30//(this->tsp->numNodes/20)+10;
TSPTWSolution *best = cons->process();
int bestfo = best->getPathDistance();
int iter = 0;
while (iter < this->max)
{
iter++;
TSPTWSolution *s = cons->process();
VNS *ils = new VNS(s, ls, levelmax, itermax);
TSPTWSolution *saux = ils->optimize();
delete ils;
delete s;
int sauxfo = saux->getPathDistance();
if (sauxfo < bestfo)
{
delete best;
best = saux;
bestfo = sauxfo;
}
else
{
delete saux;
}
}
delete cons;
delete ls;
return best;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------