PGROUTING  3.2
pgrouting::vrp::Solution Class Reference

#include "solution.h"

Inheritance diagram for pgrouting::vrp::Solution:
Collaboration diagram for pgrouting::vrp::Solution:

Public Member Functions

 Solution ()
 
 Solution (const Solution &sol)
 
Vehicle::Cost cost () const
 
std::string cost_str () const
 
int cvTot () const
 
double duration () const
 
Initials_code get_kind () const
 
std::vector< General_vehicle_orders_tget_postgres_result () const
 
bool is_feasable () const
 
bool operator< (const Solution &s_rhs) const
 
Solutionoperator= (const Solution &sol)
 
std::string tau (const std::string &title="Tau") const
 
double total_service_time () const
 
double total_travel_time () const
 
int twvTot () const
 
double wait_time () const
 

Static Public Member Functions

static Pgr_messagesmsg ()
 The problem's message. More...
 

Protected Attributes

double EPSILON
 
std::deque< Vehicle_pickDeliverfleet
 
Fleet trucks
 

Static Private Attributes

static Pgr_pickDeliverproblem
 this solution belongs to this problem More...
 

Friends

std::ostream & operator<< (std::ostream &log, const Solution &solution)
 
class Optimize
 
class PD_problem
 

Detailed Description

Definition at line 44 of file solution.h.

Constructor & Destructor Documentation

◆ Solution() [1/2]

pgrouting::vrp::Solution::Solution ( )

Definition at line 241 of file solution.cpp.

241  :
242  EPSILON(0.0001),
243  trucks(problem->trucks()) {
244  ENTERING(msg());
245  for (const auto &t : trucks) {
246  msg().log << t.tau() << "\n";
247  }
248  EXITING(msg());
249 }

References ENTERING, EXITING, pgrouting::Pgr_messages::log, msg(), and trucks.

◆ Solution() [2/2]

pgrouting::vrp::Solution::Solution ( const Solution sol)
inline

Definition at line 67 of file solution.h.

67  :
68  EPSILON(0.0001),
69  fleet(sol.fleet),
70  trucks(sol.trucks)
71  {};

Member Function Documentation

◆ cost()

Vehicle::Cost pgrouting::vrp::Solution::cost ( ) const

Definition at line 130 of file solution.cpp.

130  {
131  double total_duration(0);
132  double total_wait_time(0);
133  int total_twv(0);
134  int total_cv(0);
135  for (const auto &v : fleet) {
136  total_duration += v.duration();
137  total_wait_time += v.total_wait_time();
138  total_twv += v.twvTot();
139  total_cv += v.cvTot();
140  }
141  return std::make_tuple(
142  total_twv, total_cv, fleet.size(),
143  total_wait_time, total_duration);
144 }

References fleet.

Referenced by cost_str(), and operator<().

◆ cost_str()

std::string pgrouting::vrp::Solution::cost_str ( ) const

Definition at line 149 of file solution.cpp.

149  {
150  Vehicle::Cost s_cost(cost());
151  std::ostringstream log;
152 
153  log << "(twv, cv, fleet, wait, duration) = ("
154  << std::get<0>(s_cost) << ", "
155  << std::get<1>(s_cost) << ", "
156  << std::get<2>(s_cost) << ", "
157  << std::get<3>(s_cost) << ", "
158  << std::get<4>(s_cost) << ")";
159 
160  return log.str();
161 }

References cost().

Referenced by pgrouting::vrp::Optimize::save_if_best(), and tau().

◆ cvTot()

int pgrouting::vrp::Solution::cvTot ( ) const

Definition at line 121 of file solution.cpp.

121  {
122  int total(0);
123  for (const auto &v : fleet) {
124  total += v.cvTot();
125  }
126  return total;
127 }

References fleet.

◆ duration()

double pgrouting::vrp::Solution::duration ( ) const

Definition at line 76 of file solution.cpp.

76  {
77  double total(0);
78  for (const auto &v : fleet) {
79  total += v.duration();
80  }
81  return total;
82 }

References fleet.

Referenced by pgrouting::vrp::Optimize::move_reduce_cost(), pgrouting::vrp::Optimize::save_if_best(), and pgrouting::vrp::Optimize::swap_worse().

◆ get_kind()

Initials_code pgrouting::vrp::Solution::get_kind ( ) const

◆ get_postgres_result()

std::vector< General_vehicle_orders_t > pgrouting::vrp::Solution::get_postgres_result ( ) const

Definition at line 42 of file solution.cpp.

42  {
43  std::vector<General_vehicle_orders_t> result;
44  /* postgres numbering starts with 1 */
45  int i(1);
46  for (const auto& truck : fleet) {
47  std::vector<General_vehicle_orders_t> data =
48  truck.get_postgres_result(i);
49  result.insert(result.end(), data.begin(), data.end());
50 
51  ++i;
52  }
53  return result;
54 }

References fleet.

◆ is_feasable()

bool pgrouting::vrp::Solution::is_feasable ( ) const

Definition at line 67 of file solution.cpp.

67  {
68  for (const auto& v : fleet) {
69  if (v.is_feasable()) continue;
70  return false;
71  }
72  return true;
73 }

References fleet.

Referenced by pgrouting::vrp::Optimize::decrease_truck(), and pgrouting::vrp::Initial_solution::do_while_foo().

◆ msg()

Pgr_messages & pgrouting::vrp::Solution::msg ( )
static

◆ operator<()

bool pgrouting::vrp::Solution::operator< ( const Solution s_rhs) const

Definition at line 189 of file solution.cpp.

189  {
190  Vehicle::Cost lhs(cost());
191  Vehicle::Cost rhs(s_rhs.cost());
192 
193  /*
194  * capacity violations
195  */
196  if (std::get<0>(lhs) < std::get<0>(rhs))
197  return true;
198  if (std::get<0>(lhs) > std::get<0>(rhs))
199  return false;
200 
201  /*
202  * time window violations
203  */
204  if (std::get<1>(lhs) < std::get<1>(rhs))
205  return true;
206  if (std::get<1>(lhs) > std::get<1>(rhs))
207  return false;
208 
209  /*
210  * fleet size
211  */
212  if (std::get<2>(lhs) < std::get<2>(rhs))
213  return true;
214  if (std::get<2>(lhs) > std::get<2>(rhs))
215  return false;
216 
217  /*
218  * waiting time
219  */
220  if (std::get<3>(lhs) < std::get<3>(rhs))
221  return true;
222  if (std::get<3>(lhs) > std::get<3>(rhs))
223  return false;
224 
225  /*
226  * duration
227  */
228  if (std::get<4>(lhs) < std::get<4>(rhs))
229  return true;
230  if (std::get<4>(lhs) > std::get<4>(rhs))
231  return false;
232 
233  return false;
234 }

References cost().

◆ operator=()

Solution& pgrouting::vrp::Solution::operator= ( const Solution sol)
inline

Definition at line 74 of file solution.h.

74  {
75  EPSILON = 0.0001,
76  fleet = sol.fleet;
77  trucks = sol.trucks;
78  return *this;
79  };

References EPSILON, fleet, and trucks.

◆ tau()

std::string pgrouting::vrp::Solution::tau ( const std::string &  title = "Tau") const

Definition at line 164 of file solution.cpp.

164  {
165  std::ostringstream log;
166 
167  log << "\n" << title << ": " << std::endl;
168  for (const auto &v : fleet) {
169  log << "\n" << v.tau();
170  }
171  log << "\n" << cost_str() << "\n";
172  return log.str();
173 }

References cost_str(), and fleet.

Referenced by pgrouting::vrp::Optimize::inter_swap(), pgrouting::vrp::operator<<(), pgrouting::vrp::Optimize::Optimize(), and pgrouting::vrp::Optimize::save_if_best().

◆ total_service_time()

double pgrouting::vrp::Solution::total_service_time ( ) const

Definition at line 112 of file solution.cpp.

112  {
113  double total(0);
114  for (const auto &v : fleet) {
115  total += v.total_service_time();
116  }
117  return total;
118 }

References fleet.

◆ total_travel_time()

double pgrouting::vrp::Solution::total_travel_time ( ) const

Definition at line 103 of file solution.cpp.

103  {
104  double total(0);
105  for (const auto &v : fleet) {
106  total += v.total_travel_time();
107  }
108  return total;
109 }

References fleet.

◆ twvTot()

int pgrouting::vrp::Solution::twvTot ( ) const

Definition at line 85 of file solution.cpp.

85  {
86  int total(0);
87  for (const auto &v : fleet) {
88  total += v.twvTot();
89  }
90  return total;
91 }

References fleet.

◆ wait_time()

double pgrouting::vrp::Solution::wait_time ( ) const

Definition at line 94 of file solution.cpp.

94  {
95  double total(0);
96  for (const auto &v : fleet) {
97  total += v.total_wait_time();
98  }
99  return total;
100 }

References fleet.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  log,
const Solution solution 
)
friend

Definition at line 177 of file solution.cpp.

177  {
178  for (const auto &vehicle : solution.fleet) {
179  log << vehicle;
180  }
181 
182  log << "\n SOLUTION:\n\n "
183  << solution.tau();
184 
185  return log;
186 }

◆ Optimize

friend class Optimize
friend

Definition at line 45 of file solution.h.

◆ PD_problem

friend class PD_problem
friend

Definition at line 46 of file solution.h.

Member Data Documentation

◆ EPSILON

double pgrouting::vrp::Solution::EPSILON
protected

Definition at line 48 of file solution.h.

Referenced by operator=().

◆ fleet

◆ problem

Pgr_pickDeliver * pgrouting::vrp::Solution::problem
staticprivate

this solution belongs to this problem

Definition at line 114 of file solution.h.

Referenced by get_kind(), msg(), and pgrouting::vrp::PD_problem::PD_problem().

◆ trucks

Fleet pgrouting::vrp::Solution::trucks
protected

The documentation for this class was generated from the following files:
EXITING
#define EXITING(x)
Definition: pgr_messages.h:94
pgrouting::vrp::Solution::problem
static Pgr_pickDeliver * problem
this solution belongs to this problem
Definition: solution.h:114
pgrouting::vrp::Solution::trucks
Fleet trucks
Definition: solution.h:52
ENTERING
#define ENTERING(x)
Definition: pgr_messages.h:93
pgrouting::vrp::Solution::fleet
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49
pgrouting::vrp::Solution::EPSILON
double EPSILON
Definition: solution.h:48
pgrouting::Pgr_messages::log
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:81
pgrouting::vrp::Pgr_pickDeliver::msg
Pgr_messages msg
message controller for all classes
Definition: pgr_pickDeliver.h:99
pgrouting::vrp::Solution::cost
Vehicle::Cost cost() const
Definition: solution.cpp:130
pgrouting::vrp::Solution::cost_str
std::string cost_str() const
Definition: solution.cpp:149
pgrouting::vrp::Pgr_pickDeliver::get_kind
Initials_code get_kind() const
Definition: pgr_pickDeliver.h:84
pgrouting::vrp::Pgr_pickDeliver::trucks
Fleet trucks() const
Definition: pgr_pickDeliver.h:96
pgrouting::vrp::Vehicle::Cost
std::tuple< int, int, size_t, double, double > Cost
Definition: vehicle.h:90
pgrouting::vrp::Solution::msg
static Pgr_messages & msg()
The problem's message.
Definition: solution.cpp:60