PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pgrouting::vrp::Initial_solution Class Reference

#include "initial_solution.h"

Inheritance diagram for pgrouting::vrp::Initial_solution:
Collaboration diagram for pgrouting::vrp::Initial_solution:

Public Member Functions

 Initial_solution (int kind, size_t)
 
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_t
get_postgres_result () const
 
void invariant () const
 
bool is_feasable () const
 
bool operator< (const Solution &s_rhs) const
 
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
 

Private Member Functions

void do_while_foo (int kind)
 
void one_truck_all_orders ()
 

Private Attributes

Identifiers< size_t > all_orders
 
Identifiers< size_t > assigned
 
Identifiers< size_t > unassigned
 

Detailed Description

Definition at line 45 of file initial_solution.h.

Constructor & Destructor Documentation

pgrouting::vrp::Initial_solution::Initial_solution ( int  kind,
size_t  number_of_orders 
)

Definition at line 46 of file initial_solution.cpp.

References do_while_foo(), invariant(), one_truck_all_orders(), and pgassert.

48  :
49  Solution(),
50  all_orders(number_of_orders),
51  unassigned(number_of_orders),
52  assigned() {
53  invariant();
54  pgassert(kind >= 0 && kind < 7);
55 
56  switch (kind) {
57  case 0:
59  break;
60  case 1:
61  case 2:
62  case 3:
63  case 4:
64  case 5:
65  case 6:
66  do_while_foo(kind);
67  break;
68  default: pgassert(false);
69  }
70 
71  invariant();
72 }
Identifiers< size_t > assigned
Identifiers< size_t > all_orders
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
Identifiers< size_t > unassigned

Here is the call graph for this function:

Member Function Documentation

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

Definition at line 119 of file solution.cpp.

References pgrouting::vrp::Solution::fleet.

Referenced by pgrouting::vrp::Solution::cost_str(), pgrouting::vrp::Solution::operator<(), and pgrouting::vrp::Solution::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
inherited

Definition at line 138 of file solution.cpp.

References pgrouting::vrp::Solution::cost().

Referenced by pgrouting::vrp::Optimize::save_if_best(), and pgrouting::vrp::Solution::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
inherited

Definition at line 110 of file solution.cpp.

References pgrouting::vrp::Solution::fleet.

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
void pgrouting::vrp::Initial_solution::do_while_foo ( int  kind)
private

Definition at line 77 of file initial_solution.cpp.

References assigned, Identifiers< T >::empty(), pgrouting::vrp::Solution::fleet, Identifiers< T >::front(), pgrouting::Pgr_messages::get_log(), pgrouting::vrp::Fleet::get_truck(), Identifiers< T >::has(), invariant(), pgrouting::vrp::Solution::is_feasable(), pgrouting::Pgr_messages::log, pgrouting::vrp::PD_problem::msg, pgassert, pgassertwm, pgrouting::vrp::Fleet::release_truck(), Identifiers< T >::size(), pgrouting::vrp::Solution::trucks, and unassigned.

Referenced by Initial_solution().

77  {
78  invariant();
79  pgassert(kind > 0 && kind < 7);
80 
81  msg.log << "\nInitial_solution::do_while_foo\n";
82  Identifiers<size_t> notused;
83 #if 0
84  bool out_of_trucks(true);
85 #endif
86 
87  while (!unassigned.empty()) {
88  msg.log << unassigned.size() << " unassigned: " << unassigned << "\n";
89  msg.log << assigned.size() << " assigned:" << assigned << "\n";
90  auto current = unassigned.size();
91 #if 0
92  auto truck = out_of_trucks?
94  trucks.get_truck();
95 #else
96  auto truck = trucks.get_truck(unassigned.front());
97 #endif
98  msg.log << "got truck:" << truck.tau() << "\n";
99  /*
100  * kind 1 to 7 work with the same code structure
101  */
102  truck.do_while_feasable(kind, unassigned, assigned);
103  msg.log << unassigned.size() << " unassigned: " << unassigned << "\n";
104  msg.log << assigned.size() << " assigned:" << assigned << "\n";
105  msg.log << "current" << current << " unassigned: " << unassigned.size();
106  pgassertwm(current > unassigned.size(), msg.get_log().c_str());
107 
108 #if 0
109  if (truck.orders_in_vehicle().empty()) {
110  out_of_trucks = notused.has(truck.idx());
111  if (out_of_trucks) {
112  for (auto t : notused) {
114  }
115  }
116  notused += truck.idx();
117  continue;
118  }
119 #endif
120  fleet.push_back(truck);
121  invariant();
122  }
123 
124  pgassertwm(true, msg.get_log().c_str());
126  invariant();
127 }
bool has(const T other) const
true ids() has element
Definition: identifiers.hpp:97
bool is_feasable() const
Definition: solution.cpp:56
#define pgassertwm(expr, msg)
Adds a message to the assertion.
Definition: pgr_assert.h:104
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
Vehicle_pickDeliver get_truck()
Definition: fleet.cpp:59
std::string get_log() const
get_log
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49
Identifiers< size_t > assigned
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
Identifiers< size_t > unassigned
void release_truck(size_t id)
Definition: fleet.cpp:73
size_t size() const
Definition: identifiers.hpp:77
static Pgr_messages msg
Definition: pd_problem.h:48
T front() const
Definition: identifiers.hpp:79
bool empty() const
Definition: identifiers.hpp:78

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 65 of file solution.cpp.

References pgrouting::vrp::Solution::fleet.

Referenced by 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
inlineinherited

Definition at line 102 of file solution.h.

References pgrouting::vrp::Solution::fleet.

102 {return fleet.size();}
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49
std::vector< General_vehicle_orders_t > pgrouting::vrp::Solution::get_postgres_result ( ) const
inherited

Definition at line 39 of file solution.cpp.

References pgrouting::vrp::Solution::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
void pgrouting::vrp::Initial_solution::invariant ( ) const

Definition at line 39 of file initial_solution.cpp.

References all_orders, assigned, pgassert, and unassigned.

Referenced by do_while_foo(), Initial_solution(), and one_truck_all_orders().

39  {
40  /* this checks there is no order duplicated */
42  pgassert((assigned * unassigned).empty());
43 }
Identifiers< size_t > assigned
Identifiers< size_t > all_orders
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
Identifiers< size_t > unassigned

Here is the caller graph for this function:

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

Definition at line 56 of file solution.cpp.

References pgrouting::vrp::Solution::fleet.

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

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:

void pgrouting::vrp::Initial_solution::one_truck_all_orders ( )
private

Definition at line 133 of file initial_solution.cpp.

References assigned, Identifiers< T >::begin(), Identifiers< T >::empty(), pgrouting::vrp::Solution::fleet, Identifiers< T >::front(), pgrouting::vrp::Fleet::get_truck(), pgrouting::vrp::Vehicle_pickDeliver::insert(), invariant(), pgrouting::Pgr_messages::log, pgrouting::vrp::PD_problem::msg, Identifiers< T >::pop_front(), pgrouting::vrp::Solution::trucks, and unassigned.

Referenced by Initial_solution().

133  {
134  invariant();
135  msg.log << "\nInitial_solution::one_truck_all_orders\n";
136  auto truck = trucks.get_truck();
137  while (!unassigned.empty()) {
138  auto order(truck.orders()[*unassigned.begin()]);
139 
140  truck.insert(order);
141 
144 
145  invariant();
146  }
147  fleet.push_back(truck);
148  invariant();
149 }
void pop_front()
Definition: identifiers.hpp:82
const_iterator begin() const
Definition: identifiers.hpp:80
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
Vehicle_pickDeliver get_truck()
Definition: fleet.cpp:59
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49
Identifiers< size_t > assigned
Identifiers< size_t > unassigned
void insert(const Order &order)
Inserts an order.
static Pgr_messages msg
Definition: pd_problem.h:48
T front() const
Definition: identifiers.hpp:79
bool empty() const
Definition: identifiers.hpp:78

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 187 of file solution.cpp.

References pgrouting::vrp::Solution::cost().

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:

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

Definition at line 166 of file solution.cpp.

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

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:

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

Definition at line 153 of file solution.cpp.

References pgrouting::vrp::Solution::cost(), pgrouting::vrp::Solution::cost_str(), and pgrouting::vrp::Solution::fleet.

Referenced by pgrouting::vrp::Optimize::inter_swap(), pgrouting::vrp::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
inherited

Definition at line 101 of file solution.cpp.

References pgrouting::vrp::Solution::fleet.

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
double pgrouting::vrp::Solution::total_travel_time ( ) const
inherited

Definition at line 92 of file solution.cpp.

References pgrouting::vrp::Solution::fleet.

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
int pgrouting::vrp::Solution::twvTot ( ) const
inherited

Definition at line 74 of file solution.cpp.

References pgrouting::vrp::Solution::fleet.

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
double pgrouting::vrp::Solution::wait_time ( ) const
inherited

Definition at line 83 of file solution.cpp.

References pgrouting::vrp::Solution::fleet.

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

Member Data Documentation

Identifiers<size_t> pgrouting::vrp::Initial_solution::all_orders
private

Definition at line 63 of file initial_solution.h.

Referenced by invariant().

Identifiers<size_t> pgrouting::vrp::Initial_solution::assigned
private

Definition at line 65 of file initial_solution.h.

Referenced by do_while_foo(), invariant(), and one_truck_all_orders().

double pgrouting::vrp::Solution::EPSILON
protectedinherited

Definition at line 48 of file solution.h.

Referenced by pgrouting::vrp::Solution::operator=().

Fleet pgrouting::vrp::Solution::trucks
protectedinherited
Identifiers<size_t> pgrouting::vrp::Initial_solution::unassigned
private

Definition at line 64 of file initial_solution.h.

Referenced by do_while_foo(), invariant(), and one_truck_all_orders().


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