Repository navigation
Expand file tree
/
Copy pathProblemData.cpp
More file actions
65 lines (52 loc) · 1.43 KB
/
Copy pathProblemData.cpp
File metadata and controls
65 lines (52 loc) · 1.43 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
#include "ProblemData.hpp"
using namespace LcVRPContest;
using namespace std;
Coordinate::Coordinate() : x(0.0), y(0.0) {}
Coordinate::Coordinate(double xP, double yP) : x(xP), y(yP) {}
ProblemData::ProblemData()
: nodeCount_(0),
maxCapacity_(0),
depot_(1),
hasLimitDistance_(false),
maxDistance_(0.0),
numGroups_(0),
isMatrixReady_(false)
{
weightType_ = "EUC_2D";
}
double ProblemData::calculateTravelCost(int i, int j) const {
if (i < 0 || i >= nodeCount_ || j < 0 || j >= nodeCount_) {
return INVALID_DATA;
}
return distanceMatrix_[i][j];
}
void ProblemData::computeDistanceMatrix() {
if (weightType_ != "EUC_2D") return;
distanceMatrix_ = vector<vector<double>>(nodeCount_, vector<double>(nodeCount_, 0.0));
for (int i = 0; i < nodeCount_; i++) {
for (int j = i; j < nodeCount_; j++) {
if (i == j) {
distanceMatrix_[i][j] = 0.0;
}
else {
double distance = calculateCoordinatesDistance(i, j);
distanceMatrix_[i][j] = distance;
distanceMatrix_[j][i] = distance;
}
}
}
}
double ProblemData::calculateCoordinatesDistance(int i, int j) const {
double dx = coordinates_[i].x - coordinates_[j].x;
double dy = coordinates_[i].y - coordinates_[j].y;
return hypot(dx, dy);
}
void ProblemData::setNodeCount(int count) {
nodeCount_ = count;
coordinates_.resize(count);
demands_.resize(count);
}
void ProblemData::setDistanceLimit(double dist) {
maxDistance_ = dist;
hasLimitDistance_ = true;
}