-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtsptwsolution.cpp
More file actions
66 lines (66 loc) · 1.98 KB
/
tsptwsolution.cpp
File metadata and controls
66 lines (66 loc) · 1.98 KB
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
59
60
61
62
63
64
65
66
#include "tsptwsolution.h"
//------------------------------------------------------------------------------
TSPTWSolution::TSPTWSolution(TSPTW *tspAux)
{
this->tsp = tspAux;
this->solution = new int[this->tsp->numNodes];
}
//------------------------------------------------------------------------------
TSPTWSolution::~TSPTWSolution()
{
delete[] this->solution;
}
//------------------------------------------------------------------------------
TSPTWSolution *TSPTWSolution::clone()
{
TSPTWSolution *s = new TSPTWSolution(this->tsp);
int numNodes = this->tsp->numNodes;
for (int i = 0; i < numNodes; i++)
{
s->solution[i] = this->solution[i];
}
return s;
}
//------------------------------------------------------------------------------
int TSPTWSolution::getPathDistance()
{
int numNodes = this->tsp->numNodes;
int sum = this->tsp->matrix[this->solution[numNodes-1]][this->solution[0]];
for (int i = 0; i < numNodes-1; i++)
{
sum = sum + this->tsp->matrix[this->solution[i]][this->solution[i+1]];
}
return sum;
}
//------------------------------------------------------------------------------
int TSPTWSolution::penalty()
{
int sum = 0;
int psum = 0;
int ni = 0;
int next = 0;
int d = 0;
int numNodes = this->tsp->numNodes;
for (int i = 0; i < numNodes-1; i++)
{
ni = this->solution[i];
next = this->solution[i+1];
d = this->tsp->matrix[ni][next];
sum = max(this->tsp->readytime[ni], sum) + d;
psum += max(0, sum - this->tsp->duedate[next]);
}
return psum;
}
//------------------------------------------------------------------------------
void TSPTWSolution::print()
{
int numNodes = this->tsp->numNodes;
cout << endl;
for (int i = 0; i < numNodes; i++)
{
cout << solution[i] << " - ";
}
cout << endl;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------