-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsolution.cpp
More file actions
75 lines (64 loc) · 1.7 KB
/
solution.cpp
File metadata and controls
75 lines (64 loc) · 1.7 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
67
68
69
70
71
72
73
74
75
#include <iostream>
#include "solution.h"
void Solution::Copy(Solution& solution_copy) const
{
for (int i=0; i < kMaxVehicleSize; i++)
solution_copy.vehicles_[i] = vehicles_[i];
solution_copy.current_vehicle_id_ = current_vehicle_id_;
solution_copy.customer_size_ = customer_size_;
solution_copy.vehicle_size_ = vehicle_size_;
}
Vehicle *Solution::CurrentVehicle()
{
return &vehicles_[current_vehicle_id_];
}
void Solution::ChangeVehicle()
{
++current_vehicle_id_;
}
bool Solution::IsFeasible() const
{
for (unsigned int i=1; i <= customer_size_; i++)
{
for (unsigned int j=0; j <= current_vehicle_id_; j++)
{
if (vehicles_[j].IsVisit(i))
break;
if (j == current_vehicle_id_)
return false;
}
}
return true;
}
bool Solution::IsFinish() const
{
/* 用意されている車両を使いきった */
/*
if (current_vehicle_id_ >= vehicle_size_)
return true;
*/
/* 全ての顧客を訪問したかの確認 */
/*
return IsFeasible();
*/
return IsFeasible() || (current_vehicle_id_ >= vehicle_size_);
}
bool Solution::IsVisit(int customer_id) const
{
for (unsigned int i=0; i <= current_vehicle_id_; i++)
if (vehicles_[i].IsVisit(customer_id))
return true;
return false;
}
unsigned int Solution::ComputeTotalCost(const BaseVrp& vrp) const
{
int total_cost = 0;
for (unsigned int i=0; i <= current_vehicle_id_; i++)
total_cost += vehicles_[i].ComputeCost(vrp);
return total_cost;
}
void Solution::Print() const
{
for (unsigned int i=0; i <= current_vehicle_id_; i++)
vehicles_[i].Print();
}