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

#include "fleet.h"

Inheritance diagram for pgrouting::vrp::Fleet:
Collaboration diagram for pgrouting::vrp::Fleet:

Public Types

typedef std::vector
< Vehicle_pickDeliver >
::iterator 
iterator
 

Public Member Functions

Vehicle_pickDeliver get_truck ()
 
Vehicle_pickDeliver get_truck (size_t order)
 
Vehicle_pickDeliver get_truck (const Order order)
 
bool is_fleet_ok () const
 
bool is_order_ok (const Order &order) const
 Given an order, Cycle trhugh all the trucks to verify if the order can be served by at least one truck. More...
 
Fleetoperator= (const Fleet &fleet)
 
void release_truck (size_t id)
 
void set_compatibles (const PD_Orders &orders)
 
constructor
 Fleet ()=default
 
 Fleet (const std::vector< Vehicle_t > &vehicles, double factor)
 
 Fleet (const Fleet &fleet)
 
vector like functions
size_t size () const
 
Vehicle_pickDeliveroperator[] (size_t i)
 
iterator begin ()
 
iterator end ()
 

Public Attributes

std::vector< Vehicle_pickDeliverm_trucks
 

Static Public Attributes

static Pgr_messages msg
 

Static Protected Attributes

static Pgr_pickDeliverproblem
 

Private Member Functions

void add_vehicle (Vehicle_t, double factor, std::unique_ptr< Base_node >, const Vehicle_node &, std::unique_ptr< Base_node >, const Vehicle_node &)
 
bool build_fleet (std::vector< Vehicle_t > vehicles, double factor)
 build the fleet More...
 
template<typename T >
std::unique_ptr< Base_nodecreate_b_end (const Vehicle_t &vehicle, size_t node_id)
 
template<typename T >
std::unique_ptr< Base_nodecreate_b_start (const Vehicle_t &vehicle, size_t node_id)
 

Private Attributes

Identifiers< size_t > un_used
 
Identifiers< size_t > used
 

Friends

std::ostream & operator<< (std::ostream &log, const Fleet &v)
 

Detailed Description

Definition at line 47 of file fleet.h.

Member Typedef Documentation

Definition at line 49 of file fleet.h.

Constructor & Destructor Documentation

pgrouting::vrp::Fleet::Fleet ( )
default
pgrouting::vrp::Fleet::Fleet ( const std::vector< Vehicle_t > &  vehicles,
double  factor 
)

Definition at line 47 of file fleet.cpp.

References build_fleet(), m_trucks, and un_used.

48  :
49  PD_problem(),
50  used(),
51  un_used() {
52  build_fleet(vehicles, factor);
53  Identifiers<size_t> unused(m_trucks.size());
54  un_used = unused;
55  }
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
bool build_fleet(std::vector< Vehicle_t > vehicles, double factor)
build the fleet
Definition: fleet.cpp:175
Identifiers< size_t > used
Definition: fleet.h:95
Identifiers< size_t > un_used
Definition: fleet.h:96

Here is the call graph for this function:

pgrouting::vrp::Fleet::Fleet ( const Fleet fleet)

Definition at line 40 of file fleet.cpp.

40  :
41  PD_problem(),
42  m_trucks(fleet.m_trucks),
43  used(fleet.used),
44  un_used(fleet.un_used)
45  {}
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
Identifiers< size_t > used
Definition: fleet.h:95
Identifiers< size_t > un_used
Definition: fleet.h:96

Member Function Documentation

void pgrouting::vrp::Fleet::add_vehicle ( Vehicle_t  vehicle,
double  factor,
std::unique_ptr< Base_node b_start,
const Vehicle_node starting_site,
std::unique_ptr< Base_node b_end,
const Vehicle_node ending_site 
)
private

Definition at line 133 of file fleet.cpp.

References pgrouting::vrp::Pgr_pickDeliver::add_base_node(), pgrouting::vrp::Pgr_pickDeliver::add_node(), Vehicle_t::cant_v, Vehicle_t::capacity, pgrouting::vrp::Tw_node::closes(), Vehicle_t::id, pgrouting::vrp::Tw_node::is_end(), pgrouting::vrp::Tw_node::is_start(), pgrouting::Pgr_messages::log, m_trucks, pgrouting::vrp::PD_problem::msg, pgrouting::vrp::Tw_node::opens(), pgassert, pgrouting::vrp::PD_problem::problem, and Vehicle_t::speed.

Referenced by build_fleet().

139  {
140  pgassert(starting_site.is_start() && ending_site.is_end());
141  pgassert(starting_site.opens() <= starting_site.closes());
142  pgassert(ending_site.opens() <= ending_site.closes());
143 
144  problem->add_base_node(std::move(b_start));
145  problem->add_base_node(std::move(b_end));
146  problem->add_node(starting_site);
147  problem->add_node(ending_site);
148 
149  for (int i = 0; i < vehicle.cant_v; ++i) {
150  m_trucks.push_back(Vehicle_pickDeliver(
151  m_trucks.size(),
152  vehicle.id,
153  starting_site,
154  ending_site,
155  vehicle.capacity,
156  vehicle.speed,
157  factor));
158  msg.log << "inserting vehicle: " << m_trucks.back().tau() << "\n";
159  pgassert((m_trucks.back().idx() + 1) == m_trucks.size());
160  pgassert(m_trucks.back().is_ok());
161  }
162 }
void add_base_node(std::unique_ptr< Base_node > node_ptr)
double capacity
Definition: vehicle_t.h:62
void add_node(const Vehicle_node &node)
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
static Pgr_pickDeliver * problem
Definition: pd_problem.h:51
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
int64_t cant_v
Definition: vehicle_t.h:69
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
double speed
Definition: vehicle_t.h:63
static Pgr_messages msg
Definition: pd_problem.h:48
int64_t id
Definition: vehicle_t.h:61

Here is the call graph for this function:

Here is the caller graph for this function:

iterator pgrouting::vrp::Fleet::begin ( )
inline

Definition at line 87 of file fleet.h.

References m_trucks.

87 {return m_trucks.begin();}
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
bool pgrouting::vrp::Fleet::build_fleet ( std::vector< Vehicle_t vehicles,
double  factor 
)
private

build the fleet

builds a fleet from a vector of Vehicle_t

Parameters
[in]vehiclesof type Vehicle_t
  • creates a phoney truck with unlimited capacity and unlimited closing times
  • checks that the number of vehicles is a legal value
  • creates the requested vehicles
Parameters
[in]vehiclesthe list of vehicles
[in]factorthe multiplier to speed up or slow down

Definition at line 175 of file fleet.cpp.

References add_vehicle(), pgrouting::Pgr_messages::clear(), pgrouting::tsp::Dmatrix::empty(), pgrouting::Pgr_messages::error, pgrouting::Pgr_messages::get_error(), pgrouting::Pgr_messages::log, pgrouting::vrp::Pgr_pickDeliver::m_cost_matrix, m_trucks, pgrouting::vrp::PD_problem::msg, pgrouting::vrp::Pgr_pickDeliver::node_id(), pgassert, pgassertwm, pgrouting::vrp::PD_problem::problem, and un_used.

Referenced by Fleet().

177  {
178  /*
179  * creating a phoney truck with max capacity and max window
180  * with the start & end points of the first vehicle given
181  */
182  vehicles.push_back({
183  /*
184  * id, capacity
185  */
186  -1,
187  std::numeric_limits<double>::infinity(),
188 
189  vehicles[0].speed,
190  vehicles[0].start_x,
191  vehicles[0].start_y,
192  vehicles[0].start_node_id,
193 
194  /*
195  * cant_v, start_open_t, start_close_t, start_service_t
196  */
197  1,
198  0,
199  std::numeric_limits<double>::infinity(),
200  0,
201 
202  vehicles[0].end_x,
203  vehicles[0].end_y,
204  vehicles[0].end_node_id,
205  /*
206  * end_open_t, end_close_t, end_service_t
207  */
208  0,
209  std::numeric_limits<double>::infinity(),
210  0});
211 
212 
213  for (auto vehicle : vehicles) {
214  if (vehicle.cant_v < 0) {
215  msg.error << "Illegal number of vehicles found vehicle";
216  msg.log << vehicle.cant_v << "< 0 on vehicle " << vehicle.id;
217  return false;
218  }
219 
220  if (problem->m_cost_matrix.empty()) {
221  /*
222  * Euclidean version
223  */
224  auto b_start = create_b_start<Node>(vehicle, problem->node_id());
225  auto starting_site = Vehicle_node(
226  {problem->node_id()++, vehicle, Tw_node::NodeType::kStart});
227 
228  auto b_end = create_b_end<Node>(vehicle, problem->node_id());
229  auto ending_site = Vehicle_node(
230  {problem->node_id()++, vehicle, Tw_node::NodeType::kEnd});
231 
232  if (!(starting_site.is_start() && ending_site.is_end()
233  && starting_site.opens() <= starting_site.closes()
234  && ending_site.opens() <= ending_site.closes())) {
235  msg.clear();
236  msg.error << "Illegal values found on vehicle";
237  msg.log << "On vehicle " << vehicle.id << " a condition is not met, verify that:\n"
238  << "- start_open <= start_close\n"
239  << "- end_open <= end_close\n"
240  << "- capacity > 0\n";
241  pgassert(!msg.get_error().empty());
242  return false;
243  }
244 
245  pgassert(starting_site.opens() <= starting_site.closes());
246  pgassert(ending_site.opens() <= ending_site.closes());
247  pgassertwm(starting_site.is_start() && ending_site.is_end(), msg.get_error().c_str());
248  add_vehicle(vehicle, factor,
249  std::move(b_start), starting_site,
250  std::move(b_end), ending_site);
251  } else {
252  /*
253  * Matrix version
254  */
255  auto b_start = create_b_start<Dnode>(vehicle, problem->node_id());
256  auto starting_site = Vehicle_node(
257  {problem->node_id()++, vehicle, Tw_node::NodeType::kStart});
258 
259  auto b_end = create_b_end<Dnode>(vehicle, problem->node_id());
260  auto ending_site = Vehicle_node(
261  {problem->node_id()++, vehicle, Tw_node::NodeType::kEnd});
262 
263  if (!(starting_site.is_start() && ending_site.is_end()
264  && starting_site.opens() <= starting_site.closes()
265  && ending_site.opens() <= ending_site.closes())) {
266  msg.clear();
267  msg.error << "Illegal values found on vehicle";
268  msg.log << "On vehicle " << vehicle.id << " a condition is not met, verify that:\n"
269  << "- start_open <= start_close\n"
270  << "- end_open <= end_close\n"
271  << "- capacity > 0\n";
272  pgassert(!msg.get_error().empty());
273  return false;
274  }
275 
276  pgassert(starting_site.opens() <= starting_site.closes());
277  pgassert(ending_site.opens() <= ending_site.closes());
278  pgassert(starting_site.is_start() && ending_site.is_end());
279  add_vehicle(vehicle, factor,
280  std::move(b_start), starting_site,
281  std::move(b_end), ending_site);
282  }
283  }
284  Identifiers<size_t> unused(m_trucks.size());
285  un_used = unused;
286  return true;
287 }
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
static Pgr_pickDeliver * problem
Definition: pd_problem.h:51
#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
void add_vehicle(Vehicle_t, double factor, std::unique_ptr< Base_node >, const Vehicle_node &, std::unique_ptr< Base_node >, const Vehicle_node &)
Definition: fleet.cpp:133
std::string get_error() const
get_error
std::ostringstream error
Stores the error information.
Definition: pgr_messages.h:106
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
pgrouting::tsp::Dmatrix m_cost_matrix
double empty() const
Definition: Dmatrix.h:116
static Pgr_messages msg
Definition: pd_problem.h:48
Identifiers< size_t > un_used
Definition: fleet.h:96

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T >
std::unique_ptr<Base_node> pgrouting::vrp::Fleet::create_b_end ( const Vehicle_t vehicle,
size_t  node_id 
)
inlineprivate

Definition at line 125 of file fleet.h.

References Vehicle_t::end_node_id, Vehicle_t::end_x, and Vehicle_t::end_y.

127  {
128  std::unique_ptr<Base_node> b_end(new T(
129  node_id,
130  vehicle.end_node_id,
131  vehicle.end_x,
132  vehicle.end_y));
133  return std::move(b_end);
134  }
double end_x
Definition: vehicle_t.h:75
double end_y
Definition: vehicle_t.h:76
int64_t end_node_id
Definition: vehicle_t.h:77
template<typename T >
std::unique_ptr<Base_node> pgrouting::vrp::Fleet::create_b_start ( const Vehicle_t vehicle,
size_t  node_id 
)
inlineprivate

Definition at line 114 of file fleet.h.

References Vehicle_t::start_node_id, Vehicle_t::start_x, and Vehicle_t::start_y.

116  {
117  std::unique_ptr<Base_node> b_start(new T(
118  node_id,
119  vehicle.start_node_id,
120  vehicle.start_x,
121  vehicle.start_y));
122  return std::move(b_start);
123  }
double start_y
Definition: vehicle_t.h:66
double start_x
Definition: vehicle_t.h:65
int64_t start_node_id
Definition: vehicle_t.h:67
iterator pgrouting::vrp::Fleet::end ( )
inline

Definition at line 88 of file fleet.h.

References m_trucks.

88 {return m_trucks.end();}
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
Vehicle_pickDeliver pgrouting::vrp::Fleet::get_truck ( )

Definition at line 59 of file fleet.cpp.

References ENTERING, EXITING, Identifiers< T >::front(), pgrouting::Pgr_messages::log, m_trucks, pgrouting::vrp::PD_problem::msg, pgassertwm, Identifiers< T >::size(), un_used, and used.

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

59  {
60  ENTERING();
61  auto idx = un_used.front();
62  msg.log << "Available vehicles: " << un_used << "\n";
63  msg.log << "NOT Available vehicles: " << used << "\n";
64  msg.log << "getting idx" << idx << "\n";
65  pgassertwm(idx < m_trucks.size(), msg.log.str());
66  used += idx;
67  if (un_used.size() > 1) un_used -= idx;
68  EXITING();
69  return m_trucks[idx];
70 }
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
#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
#define EXITING()
Definition: pgr_messages.h:119
#define ENTERING()
Definition: pgr_messages.h:118
size_t size() const
Definition: identifiers.hpp:77
static Pgr_messages msg
Definition: pd_problem.h:48
Identifiers< size_t > used
Definition: fleet.h:95
T front() const
Definition: identifiers.hpp:79
Identifiers< size_t > un_used
Definition: fleet.h:96

Here is the call graph for this function:

Here is the caller graph for this function:

Vehicle_pickDeliver pgrouting::vrp::Fleet::get_truck ( size_t  order)

Definition at line 79 of file fleet.cpp.

References Identifiers< T >::front(), pgrouting::Pgr_messages::get_log(), pgrouting::Pgr_messages::log, m_trucks, pgrouting::vrp::PD_problem::msg, pgassert, pgassertwm, un_used, and used.

79  {
80  msg.log << "Available vehicles: " << un_used << "\n";
81  msg.log << "NOT Available vehicles: " << used << "\n";
82  auto idx = un_used.front();
83 
84  for (const auto i : un_used) {
85  if (m_trucks[i].feasable_orders().has(order)) {
86  idx = i;
87  msg.log << "getting idx" << idx << "\n";
88  used += idx;
89  if (un_used.size() > 1) un_used -= idx;
90  return m_trucks[idx];
91  }
92  }
93 
94  /*
95  * using phoney truck
96  */
97  pgassert(false);
98  return m_trucks.back();
99 
100  for (auto truck : m_trucks) {
101  if (truck.feasable_orders().has(order)) {
102  idx = truck.idx();
103  msg.log << "idx" << idx << "size" << m_trucks.size();
104  pgassertwm(idx < m_trucks.size(), msg.get_log());
105  used += idx;
106  if (un_used.size() > 1) un_used -= idx;
107  break;
108  }
109  }
110  return m_trucks[idx];
111 }
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
#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
std::string get_log() const
get_log
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
static Pgr_messages msg
Definition: pd_problem.h:48
Identifiers< size_t > used
Definition: fleet.h:95
T front() const
Definition: identifiers.hpp:79
Identifiers< size_t > un_used
Definition: fleet.h:96

Here is the call graph for this function:

Vehicle_pickDeliver pgrouting::vrp::Fleet::get_truck ( const Order  order)

Definition at line 115 of file fleet.cpp.

References pgrouting::Pgr_messages::get_log(), pgrouting::Identifier::idx(), pgrouting::Pgr_messages::log, m_trucks, pgrouting::vrp::PD_problem::msg, pgassertwm, Identifiers< T >::size(), un_used, and used.

115  {
116  auto id = m_trucks.front().idx();
117  for (auto truck : m_trucks) {
118  if (truck.feasable_orders().has(order.idx())) {
119  id = truck.idx();
120  msg.log << "id" << id
121  << "size" << m_trucks.size();
122  pgassertwm(id < m_trucks.size(), msg.get_log());
123  used += id;
124  if (un_used.size() > 1) un_used -= id;
125  break;
126  }
127  }
128  return m_trucks[id];
129 }
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
#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
std::string get_log() const
get_log
size_t size() const
Definition: identifiers.hpp:77
static Pgr_messages msg
Definition: pd_problem.h:48
Identifiers< size_t > used
Definition: fleet.h:95
Identifiers< size_t > un_used
Definition: fleet.h:96

Here is the call graph for this function:

bool pgrouting::vrp::Fleet::is_fleet_ok ( ) const

Definition at line 291 of file fleet.cpp.

References ENTERING, pgrouting::Pgr_messages::error, EXITING, pgrouting::Pgr_messages::get_error(), pgrouting::Pgr_messages::log, m_trucks, pgrouting::vrp::PD_problem::msg, and pgassertwm.

Referenced by pgrouting::vrp::Pgr_pickDeliver::Pgr_pickDeliver().

291  {
292  ENTERING();
293  if (!msg.get_error().empty()) return false;
294  for (auto truck : m_trucks) {
295  if (!truck.is_ok()) {
296  msg.error << "Illegal values found on vehicle";
297  msg.log << "On vehicle " << truck.id() << " a condition is not met, verify that:\n"
298  << "- start_open <= start_close\n"
299  << "- end_open <= end_close\n"
300  << "- capacity > 0\n";
301  return false;
302  }
303 
304  if (!(truck.start_site().is_start()
305  && truck.end_site().is_end())) {
306  pgassertwm(false, "should never pass through here");
307  msg.error << "Illegal values found on vehicle";
308  return false;
309  }
310  if (!truck.is_feasable()) {
311  msg.error << "Truck is not feasible";
312  return false;
313  }
314  }
315  EXITING();
316  return true;
317 }
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
#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
std::string get_error() const
get_error
#define EXITING()
Definition: pgr_messages.h:119
std::ostringstream error
Stores the error information.
Definition: pgr_messages.h:106
#define ENTERING()
Definition: pgr_messages.h:118
static Pgr_messages msg
Definition: pd_problem.h:48

Here is the call graph for this function:

Here is the caller graph for this function:

bool pgrouting::vrp::Fleet::is_order_ok ( const Order order) const

Given an order, Cycle trhugh all the trucks to verify if the order can be served by at least one truck.

Definition at line 325 of file fleet.cpp.

References pgrouting::vrp::Order::is_valid(), and m_trucks.

325  {
326  for (const auto truck : m_trucks) {
327  if (!order.is_valid(truck.speed())) continue;
328  if (truck.is_order_feasable(order)) {
329  return true;
330  }
331  }
332  return false;
333 }
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50

Here is the call graph for this function:

Fleet& pgrouting::vrp::Fleet::operator= ( const Fleet fleet)
inline

Definition at line 65 of file fleet.h.

References m_trucks, un_used, and used.

65  {
66  m_trucks = fleet.m_trucks;
67  used = fleet.used;
68  un_used = fleet.un_used;
69  return *this;
70  }
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
Identifiers< size_t > used
Definition: fleet.h:95
Identifiers< size_t > un_used
Definition: fleet.h:96
Vehicle_pickDeliver & pgrouting::vrp::Fleet::operator[] ( size_t  i)

Definition at line 336 of file fleet.cpp.

References m_trucks, and pgassert.

336  {
337  pgassert(i < m_trucks.size());
338  return m_trucks[i];
339 }
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
void pgrouting::vrp::Fleet::release_truck ( size_t  id)

Definition at line 73 of file fleet.cpp.

References un_used, and used.

Referenced by pgrouting::vrp::Initial_solution::do_while_foo().

73  {
74  used -= id;
75  un_used += id;
76 }
Identifiers< size_t > used
Definition: fleet.h:95
Identifiers< size_t > un_used
Definition: fleet.h:96

Here is the caller graph for this function:

void pgrouting::vrp::Fleet::set_compatibles ( const PD_Orders orders)

Definition at line 342 of file fleet.cpp.

References m_trucks.

342  {
343  for (auto &truck : m_trucks) {
344  truck.set_compatibles(orders);
345  }
346 }
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50
size_t pgrouting::vrp::Fleet::size ( ) const
inline

Definition at line 85 of file fleet.h.

References m_trucks.

85 {return m_trucks.size();}
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:50

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  log,
const Fleet v 
)
friend

Definition at line 353 of file fleet.cpp.

353  {
354  log << "fleet\n";
355  for (const auto v : f.m_trucks) {
356  log << v;
357  }
358  log << "end fleet\n";
359 
360  return log;
361 }

Member Data Documentation

Identifiers<size_t> pgrouting::vrp::Fleet::un_used
private

Definition at line 96 of file fleet.h.

Referenced by build_fleet(), Fleet(), get_truck(), operator=(), and release_truck().

Identifiers<size_t> pgrouting::vrp::Fleet::used
private

Definition at line 95 of file fleet.h.

Referenced by get_truck(), operator=(), and release_truck().


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