PGROUTING  2.6-dev
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
 
size_t fleet_size () 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)
 
void sort_by_id ()
 
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 Attributes

static Pgr_messages msg
 

Protected Attributes

double EPSILON
 
std::deque< Vehicle_pickDeliverfleet
 
Fleet trucks
 

Static Protected Attributes

static Pgr_pickDeliverproblem
 

Friends

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

Detailed Description

Definition at line 45 of file solution.h.

Constructor & Destructor Documentation

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

Definition at line 234 of file solution.cpp.

References ENTERING, EXITING, pgrouting::Pgr_messages::log, pgrouting::vrp::PD_problem::msg, and trucks.

234  :
235  EPSILON(0.0001),
236  trucks(problem->trucks()) {
237  ENTERING();
238  for (const auto &t : trucks) {
239  msg.log << t.tau() << "\n";
240  }
241  EXITING();
242 }
static Pgr_pickDeliver * problem
Definition: pd_problem.h:51
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
#define EXITING()
Definition: pgr_messages.h:119
#define ENTERING()
Definition: pgr_messages.h:118
static Pgr_messages msg
Definition: pd_problem.h:48
pgrouting::vrp::Solution::Solution ( const Solution sol)
inline

Definition at line 71 of file solution.h.

71  :
72  PD_problem(),
73  EPSILON(0.0001),
74  fleet(sol.fleet),
75  trucks(sol.trucks)
76  {};
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49

Member Function Documentation

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

Definition at line 119 of file solution.cpp.

References fleet.

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

119  {
120  double total_duration(0);
121  double total_wait_time(0);
122  int total_twv(0);
123  int total_cv(0);
124  for (const auto v : fleet) {
125  total_duration += v.duration();
126  total_wait_time += v.total_wait_time();
127  total_twv += v.twvTot();
128  total_cv += v.cvTot();
129  }
130  return std::make_tuple(
131  total_twv, total_cv, fleet.size(),
132  total_wait_time, total_duration);
133 }
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49

Here is the caller graph for this function:

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

Definition at line 138 of file solution.cpp.

References cost().

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

138  {
139  Vehicle::Cost s_cost(cost());
140  std::ostringstream log;
141 
142  log << "(twv, cv, fleet, wait, duration) = ("
143  << std::get<0>(s_cost) << ", "
144  << std::get<1>(s_cost) << ", "
145  << std::get<2>(s_cost) << ", "
146  << std::get<3>(s_cost) << ", "
147  << std::get<4>(s_cost) << ")";
148 
149  return log.str();
150 }
Vehicle::Cost cost() const
Definition: solution.cpp:119
std::tuple< int, int, size_t, double, double > Cost
Definition: vehicle.h:86

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 110 of file solution.cpp.

References fleet.

Referenced by operator=().

110  {
111  int total(0);
112  for (const auto v : fleet) {
113  total += v.cvTot();
114  }
115  return total;
116 }
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49

Here is the caller graph for this function:

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

Definition at line 65 of file solution.cpp.

References fleet.

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

65  {
66  double total(0);
67  for (const auto v : fleet) {
68  total += v.duration();
69  }
70  return total;
71 }
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49

Here is the caller graph for this function:

size_t pgrouting::vrp::Solution::fleet_size ( ) const
inline

Definition at line 102 of file solution.h.

References cost().

102 {return fleet.size();}
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49

Here is the call graph for this function:

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

Definition at line 39 of file solution.cpp.

References fleet.

39  {
40  std::vector<General_vehicle_orders_t> result;
41  /* postgres numbering starts with 1 */
42  int i(1);
43  for (const auto truck : fleet) {
44  std::vector<General_vehicle_orders_t> data =
45  truck.get_postgres_result(i);
46  result.insert(result.end(), data.begin(), data.end());
47 
48  ++i;
49  }
50  return result;
51 }
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49
bool pgrouting::vrp::Solution::is_feasable ( ) const

Definition at line 56 of file solution.cpp.

References fleet.

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

56  {
57  for (const auto v : fleet) {
58  if (v.is_feasable()) continue;
59  return false;
60  }
61  return true;
62 }
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49

Here is the caller graph for this function:

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

Definition at line 187 of file solution.cpp.

References cost().

Referenced by operator=().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 79 of file solution.h.

References cost_str(), cvTot(), duration(), fleet, is_feasable(), operator<(), operator<<, sort_by_id(), tau(), total_service_time(), total_travel_time(), trucks, twvTot(), and wait_time().

79  {
80  EPSILON = 0.0001,
81  fleet = sol.fleet;
82  trucks = sol.trucks;
83  return *this;
84  };
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49

Here is the call graph for this function:

void pgrouting::vrp::Solution::sort_by_id ( )

Definition at line 166 of file solution.cpp.

References fleet, and pgrouting::Identifier::idx().

Referenced by operator=().

166  {
167  std::sort(fleet.begin(), fleet.end(), []
168  (const Vehicle_pickDeliver &lhs, const Vehicle_pickDeliver &rhs)
169  -> bool {
170  return lhs.idx() < rhs.idx();
171  });
172 }
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 153 of file solution.cpp.

References cost(), cost_str(), and fleet.

Referenced by pgrouting::vrp::Optimize::delete_empty_truck(), pgrouting::vrp::Optimize::inter_swap(), pgrouting::vrp::operator<<(), operator=(), pgrouting::vrp::Optimize::Optimize(), pgrouting::vrp::Pgr_pickDeliver::optimize(), and pgrouting::vrp::Optimize::save_if_best().

153  {
154  Vehicle::Cost s_cost(cost());
155  std::ostringstream log;
156 
157  log << "\n" << title << ": " << std::endl;
158  for (const auto v : fleet) {
159  log << "\n" << v.tau();
160  }
161  log << "\n" << cost_str() << "\n";
162  return log.str();
163 }
Vehicle::Cost cost() const
Definition: solution.cpp:119
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49
std::string cost_str() const
Definition: solution.cpp:138
std::tuple< int, int, size_t, double, double > Cost
Definition: vehicle.h:86

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 101 of file solution.cpp.

References fleet.

Referenced by operator=().

101  {
102  double total(0);
103  for (const auto v : fleet) {
104  total += v.total_service_time();
105  }
106  return total;
107 }
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49

Here is the caller graph for this function:

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

Definition at line 92 of file solution.cpp.

References fleet.

Referenced by operator=().

92  {
93  double total(0);
94  for (const auto v : fleet) {
95  total += v.total_travel_time();
96  }
97  return total;
98 }
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49

Here is the caller graph for this function:

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

Definition at line 74 of file solution.cpp.

References fleet.

Referenced by operator=().

74  {
75  int total(0);
76  for (const auto v : fleet) {
77  total += v.twvTot();
78  }
79  return total;
80 }
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49

Here is the caller graph for this function:

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

Definition at line 83 of file solution.cpp.

References fleet.

Referenced by operator=().

83  {
84  double total(0);
85  for (const auto v : fleet) {
86  total += v.total_wait_time();
87  }
88  return total;
89 }
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49

Here is the caller graph for this function:

Friends And Related Function Documentation

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

Definition at line 175 of file solution.cpp.

Referenced by operator=().

175  {
176  for (const auto vehicle : solution.fleet) {
177  log << vehicle;
178  }
179 
180  log << "\n SOLUTION:\n\n "
181  << solution.tau();
182 
183  return log;
184 }
friend class Optimize
friend

Definition at line 46 of file solution.h.

Member Data Documentation

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

Definition at line 48 of file solution.h.

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

The documentation for this class was generated from the following files: