PGROUTING  3.2
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 (Initials_code kind, size_t)
 
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
 
void invariant () const
 
bool is_feasable () const
 
bool operator< (const Solution &s_rhs) const
 
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
 

Private Member Functions

void do_while_foo (int kind)
 
void one_truck_all_orders ()
 

Private Attributes

Identifiers< size_t > m_all_orders
 
Identifiers< size_t > m_assigned
 
Identifiers< size_t > m_unassigned
 

Static Private Attributes

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

Detailed Description

Definition at line 46 of file initial_solution.h.

Constructor & Destructor Documentation

◆ Initial_solution()

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

Definition at line 46 of file initial_solution.cpp.

48  :
49  Solution(),
50  m_all_orders(number_of_orders),
51  m_unassigned(number_of_orders),
52  m_assigned() {
53  invariant();
54  pgassert(kind >= 0 && kind <= OneDepot);
55 
56  switch (kind) {
57  case OneTruck:
59  break;
60  case OnePerTruck:
61  case FrontTruck:
62  case BackTruck:
63  case BestInsert:
64  case BestBack:
65  case BestFront:
66  case OneDepot:
67  do_while_foo(kind);
68  break;
69  default: pgassert(false);
70  }
71 
72  invariant();
73 }

References pgrouting::vrp::BackTruck, pgrouting::vrp::BestBack, pgrouting::vrp::BestFront, pgrouting::vrp::BestInsert, do_while_foo(), pgrouting::vrp::FrontTruck, invariant(), one_truck_all_orders(), pgrouting::vrp::OneDepot, pgrouting::vrp::OnePerTruck, pgrouting::vrp::OneTruck, and pgassert.

Member Function Documentation

◆ cost()

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

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 pgrouting::vrp::Solution::fleet.

Referenced by pgrouting::vrp::Solution::cost_str(), and pgrouting::vrp::Solution::operator<().

◆ cost_str()

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

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 pgrouting::vrp::Solution::cost().

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

◆ cvTot()

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

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 pgrouting::vrp::Solution::fleet.

◆ do_while_foo()

void pgrouting::vrp::Initial_solution::do_while_foo ( int  kind)
private

Definition at line 78 of file initial_solution.cpp.

78  {
79  invariant();
80  pgassert(kind > 0 && kind <= OneDepot);
81 
82 #if 0
83  msg().log << "\nInitial_solution::do_while_foo\n";
84 #endif
85  Identifiers<size_t> notused;
86 
87  while (!m_unassigned.empty()) {
88 #if 0
89  msg().log << m_unassigned.size() << " m_unassigned: " << m_unassigned << "\n";
90  msg().log << m_assigned.size() << " m_assigned:" << m_assigned << "\n";
91 #endif
92  auto current = m_unassigned.size();
93  auto truck = trucks.get_truck(m_unassigned.front());
94 #if 0
95  msg().log << "got truck:" << truck.tau() << "\n";
96 #endif
97  /*
98  * kind 1 to 7 work with the same code structure
99  */
100  truck.do_while_feasable((Initials_code)kind, m_unassigned, m_assigned);
101 #if 0
102  msg().log << m_unassigned.size() << " m_unassigned: " << m_unassigned << "\n";
103  msg().log << m_assigned.size() << " m_assigned:" << m_assigned << "\n";
104  msg().log << "current" << current << " m_unassigned: " << m_unassigned.size();
105 #endif
106  pgassertwm(current > m_unassigned.size(), msg().get_log().c_str());
107 
108  fleet.push_back(truck);
109  invariant();
110  }
111 
112  pgassertwm(true, msg().get_log().c_str());
114  invariant();
115 }

References Identifiers< T >::empty(), pgrouting::vrp::Solution::fleet, Identifiers< T >::front(), pgrouting::vrp::Fleet::get_truck(), invariant(), pgrouting::vrp::Solution::is_feasable(), pgrouting::Pgr_messages::log, m_assigned, m_unassigned, pgrouting::vrp::Solution::msg(), pgrouting::vrp::OneDepot, pgassert, pgassertwm, Identifiers< T >::size(), and pgrouting::vrp::Solution::trucks.

Referenced by Initial_solution().

◆ duration()

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

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 pgrouting::vrp::Solution::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
inherited

◆ get_postgres_result()

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

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 pgrouting::vrp::Solution::fleet.

◆ invariant()

void pgrouting::vrp::Initial_solution::invariant ( ) const

Definition at line 39 of file initial_solution.cpp.

39  {
40  /* this checks there is no order duplicated */
42  pgassert((m_assigned * m_unassigned).empty());
43 }

References m_all_orders, m_assigned, m_unassigned, and pgassert.

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

◆ is_feasable()

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

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 pgrouting::vrp::Solution::fleet.

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

◆ msg()

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

◆ one_truck_all_orders()

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

Definition at line 121 of file initial_solution.cpp.

121  {
122  invariant();
123  msg().log << "\nInitial_solution::one_truck_all_orders\n";
124  auto truck = trucks.get_truck();
125  while (!m_unassigned.empty()) {
126  auto order(truck.orders()[*m_unassigned.begin()]);
127 
128  truck.insert(order);
129 
132 
133  invariant();
134  }
135  fleet.push_back(truck);
136  invariant();
137 }

References Identifiers< T >::begin(), Identifiers< T >::empty(), pgrouting::vrp::Solution::fleet, Identifiers< T >::front(), pgrouting::vrp::Fleet::get_truck(), invariant(), pgrouting::Pgr_messages::log, m_assigned, m_unassigned, pgrouting::vrp::Solution::msg(), Identifiers< T >::pop_front(), and pgrouting::vrp::Solution::trucks.

Referenced by Initial_solution().

◆ operator<()

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

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 pgrouting::vrp::Solution::cost().

◆ tau()

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

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

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 pgrouting::vrp::Solution::fleet.

◆ total_travel_time()

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

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 pgrouting::vrp::Solution::fleet.

◆ twvTot()

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

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 pgrouting::vrp::Solution::fleet.

◆ wait_time()

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

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 pgrouting::vrp::Solution::fleet.

Member Data Documentation

◆ EPSILON

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

Definition at line 48 of file solution.h.

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

◆ fleet

◆ m_all_orders

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

Definition at line 63 of file initial_solution.h.

Referenced by invariant().

◆ m_assigned

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

Definition at line 65 of file initial_solution.h.

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

◆ m_unassigned

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

Definition at line 64 of file initial_solution.h.

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

◆ problem

Pgr_pickDeliver * pgrouting::vrp::Solution::problem
staticprivateinherited

this solution belongs to this problem

Definition at line 114 of file solution.h.

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

◆ trucks

Fleet pgrouting::vrp::Solution::trucks
protectedinherited

The documentation for this class was generated from the following files:
pgrouting::vrp::Initial_solution::invariant
void invariant() const
Definition: initial_solution.cpp:39
pgrouting::vrp::Initial_solution::do_while_foo
void do_while_foo(int kind)
Definition: initial_solution.cpp:78
pgrouting::vrp::BestInsert
@ BestInsert
Insetion at the back of the truck.
Definition: initials_code.h:41
pgrouting::vrp::OnePerTruck
@ OnePerTruck
All orders in one truck.
Definition: initials_code.h:38
pgrouting::vrp::Solution::is_feasable
bool is_feasable() const
Definition: solution.cpp:67
pgrouting::vrp::OneTruck
@ OneTruck
Definition: initials_code.h:37
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
Identifiers::pop_front
void pop_front()
Definition: identifiers.hpp:83
pgrouting::vrp::Solution::fleet
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49
pgassertwm
#define pgassertwm(expr, msg)
Adds a message to the assertion.
Definition: pgr_assert.h:117
pgrouting::vrp::Initial_solution::m_unassigned
Identifiers< size_t > m_unassigned
Definition: initial_solution.h:64
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::Initial_solution::m_assigned
Identifiers< size_t > m_assigned
Definition: initial_solution.h:65
pgrouting::vrp::BackTruck
@ BackTruck
Insetion at the front of the truck.
Definition: initials_code.h:40
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
Identifiers::size
size_t size() const
Definition: identifiers.hpp:78
pgrouting::vrp::OneDepot
@ OneDepot
Push front order that allows more orders to be inserted at the front.
Definition: initials_code.h:44
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
Identifiers::begin
const_iterator begin() const
Definition: identifiers.hpp:81
Identifiers::empty
bool empty() const
Definition: identifiers.hpp:79
pgrouting::vrp::Initial_solution::m_all_orders
Identifiers< size_t > m_all_orders
Definition: initial_solution.h:63
pgrouting::vrp::Solution::Solution
Solution()
Definition: solution.cpp:241
pgrouting::vrp::BestBack
@ BestBack
Best place to insert Order.
Definition: initials_code.h:42
pgrouting::vrp::Pgr_pickDeliver::get_kind
Initials_code get_kind() const
Definition: pgr_pickDeliver.h:84
Identifiers::front
T front() const
Definition: identifiers.hpp:80
pgrouting::vrp::Fleet::get_truck
Vehicle_pickDeliver get_truck()
Definition: fleet.cpp:67
pgrouting::vrp::FrontTruck
@ FrontTruck
One Order per truck.
Definition: initials_code.h:39
pgrouting::vrp::BestFront
@ BestFront
Push back order that allows more orders to be inserted at the back.
Definition: initials_code.h:43
pgrouting::vrp::Initials_code
Initials_code
Different kinds to insert an order into the vehicle.
Definition: initials_code.h:36
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
Identifiers< size_t >
pgrouting::vrp::Initial_solution::one_truck_all_orders
void one_truck_all_orders()
Definition: initial_solution.cpp:121