PGROUTING  3.2
pgrouting::vrp::Fleet Class Reference

#include "fleet.h"

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)
 
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 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 ()
 

Private Member Functions

void add_vehicle (Vehicle_t, double factor, const Vehicle_node &, const Vehicle_node &)
 
bool build_fleet (std::vector< Vehicle_t > vehicles, double factor)
 build the fleet More...
 

Static Private Member Functions

static Pgr_messagesmsg ()
 the problem message More...
 

Private Attributes

std::vector< Vehicle_pickDeliverm_trucks
 
Identifiers< size_t > m_un_used
 
Identifiers< size_t > m_used
 

Static Private Attributes

static Pgr_pickDeliverproblem
 The problem. More...
 

Friends

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

Detailed Description

Definition at line 47 of file fleet.h.

Member Typedef Documentation

◆ iterator

Definition at line 51 of file fleet.h.

Constructor & Destructor Documentation

◆ Fleet() [1/3]

pgrouting::vrp::Fleet::Fleet ( )
default

◆ Fleet() [2/3]

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

Definition at line 56 of file fleet.cpp.

57  :
58  m_used(),
59  m_un_used() {
60  build_fleet(vehicles, factor);
61  Identifiers<size_t> unused(m_trucks.size());
62  m_un_used = unused;
63  }

References build_fleet(), m_trucks, and m_un_used.

◆ Fleet() [3/3]

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

Definition at line 50 of file fleet.cpp.

50  :
51  m_trucks(fleet.m_trucks),
52  m_used(fleet.m_used),
53  m_un_used(fleet.m_un_used)
54  {}

Member Function Documentation

◆ add_vehicle()

void pgrouting::vrp::Fleet::add_vehicle ( Vehicle_t  vehicle,
double  factor,
const Vehicle_node starting_site,
const Vehicle_node ending_site 
)
private

Definition at line 122 of file fleet.cpp.

126  {
127  pgassert(starting_site.is_start() && ending_site.is_end());
128  pgassert(starting_site.opens() <= starting_site.closes());
129  pgassert(ending_site.opens() <= ending_site.closes());
130 
131 
132  for (int i = 0; i < vehicle.cant_v; ++i) {
133  m_trucks.push_back(Vehicle_pickDeliver(
134  m_trucks.size(),
135  vehicle.id,
136  starting_site,
137  ending_site,
138  vehicle.capacity,
139  vehicle.speed,
140  factor));
141 #if 0
142  msg().log << "inserting vehicle: " << m_trucks.back().tau() << "\n";
143 #endif
144  pgassert((m_trucks.back().idx() + 1) == m_trucks.size());
145  pgassert(m_trucks.back().is_ok());
146  }
147 }

References 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, msg(), pgrouting::vrp::Tw_node::opens(), pgassert, and Vehicle_t::speed.

Referenced by build_fleet().

◆ begin()

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

Definition at line 80 of file fleet.h.

80 {return m_trucks.begin();}

References m_trucks.

◆ build_fleet()

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 160 of file fleet.cpp.

162  {
163  /*
164  * creating a phoney truck with max capacity and max window
165  * with the start & end points of the first vehicle given
166  */
167  vehicles.push_back({
168  /*
169  * id, capacity
170  */
171  -1,
172  std::numeric_limits<double>::infinity(),
173 
174  vehicles[0].speed,
175  vehicles[0].start_x,
176  vehicles[0].start_y,
177  vehicles[0].start_node_id,
178 
179  /*
180  * cant_v, start_open_t, start_close_t, start_service_t
181  */
182  1,
183  0,
184  std::numeric_limits<double>::infinity(),
185  0,
186 
187  vehicles[0].end_x,
188  vehicles[0].end_y,
189  vehicles[0].end_node_id,
190  /*
191  * end_open_t, end_close_t, end_service_t
192  */
193  0,
194  std::numeric_limits<double>::infinity(),
195  0});
196 
197 
198  for (auto vehicle : vehicles) {
199  if (vehicle.cant_v < 0) {
200  throw std::make_pair(std::string("Illegal number of vehicles found"), vehicle.cant_v);
201  }
202 
203  if (vehicle.capacity < 0) {
204  throw std::make_pair(std::string("Illegal value for capacity found"), vehicle.capacity);
205  }
206 
207  if (!problem->get_cost_matrix().empty()) {
208  if (!problem->get_cost_matrix().has_id(vehicle.start_node_id)) {
209  throw std::make_pair(std::string("Unable to find node on matrix"), vehicle.start_node_id);
210  }
211  if (!problem->get_cost_matrix().has_id(vehicle.end_node_id)) {
212  throw std::make_pair(std::string("Unable to find node on matrix"), vehicle.end_node_id);
213  }
214  }
215 
216  if (!(vehicle.start_open_t <= vehicle.start_close_t
217  && vehicle.end_open_t <= vehicle.end_close_t
218  && vehicle.start_open_t <= vehicle.end_close_t)) {
219  msg().error << "Illegal values found on vehicle";
220  msg().log << "On vehicle " << vehicle.id
221  << " a condition is not met, verify that:"
222  << "\nvehicle.start_open_t <= vehicle.start_close_t\t"
223  << vehicle.start_open_t << " <= " << vehicle.start_close_t
224  << "\nvehicle.end_open_t <= vehicle.end_close_t\t"
225  << vehicle.end_open_t << " <= " << vehicle.end_close_t
226  << "\nvehicle.start_open_t <= vehicle.end_close_t\t"
227  << vehicle.start_open_t << " <= " << vehicle.end_close_t;
228 
229  throw std::make_pair(msg().get_error(), msg().get_log());
230  }
231 
232  /*
233  * Matrix version
234  */
235  auto starting_site = Vehicle_node({problem->get_nodes().size(), vehicle, Tw_node::NodeType::kStart});
236  problem->add_node(starting_site);
237  auto ending_site = Vehicle_node({problem->get_nodes().size(), vehicle, Tw_node::NodeType::kEnd});
238  problem->add_node(ending_site);
239 
240  pgassert(starting_site.opens() <= starting_site.closes());
241  pgassert(ending_site.opens() <= ending_site.closes());
242  pgassert(starting_site.is_start() && ending_site.is_end());
243 
244  add_vehicle(vehicle, factor, starting_site, ending_site);
245  }
246  Identifiers<size_t> unused(m_trucks.size());
247  m_un_used = unused;
248  return true;
249 }

References pgrouting::vrp::Pgr_pickDeliver::add_node(), add_vehicle(), pgrouting::tsp::Dmatrix::empty(), pgrouting::Pgr_messages::error, pgrouting::vrp::Pgr_pickDeliver::get_cost_matrix(), pgrouting::vrp::Pgr_pickDeliver::get_nodes(), pgrouting::tsp::Dmatrix::has_id(), pgrouting::Pgr_messages::log, m_trucks, m_un_used, msg(), pgassert, problem, and size().

Referenced by Fleet().

◆ end()

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

Definition at line 81 of file fleet.h.

81 {return m_trucks.end();}

References m_trucks.

◆ get_truck() [1/2]

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

Definition at line 67 of file fleet.cpp.

67  {
68  ENTERING(msg());
69  auto idx = m_un_used.front();
70  msg().log << "Available vehicles: " << m_un_used << "\n";
71  msg().log << "NOT Available vehicles: " << m_used << "\n";
72  msg().log << "getting idx" << idx << "\n";
73  pgassertwm(idx < m_trucks.size(), msg().log.str());
74  m_used += idx;
75  if (m_un_used.size() > 1) m_un_used -= idx;
76  EXITING(msg());
77  return m_trucks[idx];
78 }

References ENTERING, EXITING, Identifiers< T >::front(), pgrouting::Pgr_messages::log, m_trucks, m_un_used, m_used, msg(), pgassertwm, and Identifiers< T >::size().

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

◆ get_truck() [2/2]

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

Definition at line 82 of file fleet.cpp.

82  {
83 #if 0
84  msg().log << "Available vehicles: " << m_un_used << "\n";
85  msg().log << "NOT Available vehicles: " << m_used << "\n";
86 #endif
87  auto idx = m_un_used.front();
88 
89  for (const auto &i : m_un_used) {
90  if (m_trucks[i].feasable_orders().has(order)) {
91  idx = i;
92  msg().log << "getting idx" << idx << "\n";
93  m_used += idx;
94  if (m_un_used.size() > 1) m_un_used -= idx;
95  return m_trucks[idx];
96  }
97  }
98 
99  /*
100  * using phoney truck
101  */
102  pgassert(false);
103  return m_trucks.back();
104 
105  for (auto truck : m_trucks) {
106  if (truck.feasable_orders().has(order)) {
107  idx = truck.idx();
108  msg().log << "idx" << idx << "size" << m_trucks.size();
109  pgassertwm(idx < m_trucks.size(), msg().get_log());
110  m_used += idx;
111  if (m_un_used.size() > 1) m_un_used -= idx;
112  break;
113  }
114  }
115  return m_trucks[idx];
116 }

References Identifiers< T >::front(), pgrouting::Pgr_messages::log, m_trucks, m_un_used, m_used, msg(), pgassert, pgassertwm, and Identifiers< T >::size().

◆ is_fleet_ok()

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

Definition at line 253 of file fleet.cpp.

253  {
254  ENTERING(msg());
255  if (!msg().get_error().empty()) return false;
256  for (auto truck : m_trucks) {
257  if (!truck.is_ok()) {
258  msg().error << "Illegal values found on vehicle";
259  msg().log << "On vehicle " << truck.id()
260  << " a condition is not met, verify that:\n"
261  << "- start_open <= start_close\n"
262  << "- end_open <= end_close\n"
263  << "- capacity > 0\n";
264  return false;
265  }
266 
267  if (!(truck.start_site().is_start()
268  && truck.end_site().is_end())) {
269  pgassertwm(false, "should never pass through here");
270  msg().error << "Illegal values found on vehicle";
271  return false;
272  }
273  if (!truck.is_feasable()) {
274  msg().error << "Truck is not feasible";
275  return false;
276  }
277  }
278  EXITING(msg());
279  return true;
280 }

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

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

◆ is_order_ok()

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 288 of file fleet.cpp.

288  {
289  for (const auto &truck : m_trucks) {
290  if (!order.is_valid(truck.speed())) continue;
291  if (truck.is_order_feasable(order)) {
292  return true;
293  }
294  }
295  return false;
296 }

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

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

◆ msg()

Pgr_messages & pgrouting::vrp::Fleet::msg ( )
staticprivate

the problem message

Returns
reference to the problem's message

Definition at line 46 of file fleet.cpp.

46  {
47  return problem->msg;
48 }

References pgrouting::vrp::Pgr_pickDeliver::msg, and problem.

Referenced by add_vehicle(), build_fleet(), get_truck(), is_fleet_ok(), and pgrouting::vrp::Pgr_pickDeliver::Pgr_pickDeliver().

◆ operator=()

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

Definition at line 299 of file fleet.cpp.

299  {
300  m_trucks = fleet.m_trucks;
301  m_used = fleet.m_used;
302  m_un_used = fleet.m_un_used;
303  return *this;
304 }

References m_trucks, m_un_used, and m_used.

◆ operator[]()

Vehicle_pickDeliver & pgrouting::vrp::Fleet::operator[] ( size_t  i)

Definition at line 307 of file fleet.cpp.

307  {
308  pgassert(i < m_trucks.size());
309  return m_trucks[i];
310 }

References m_trucks, and pgassert.

◆ set_compatibles()

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

Definition at line 313 of file fleet.cpp.

313  {
314  for (auto &truck : m_trucks) {
315  truck.set_compatibles(orders);
316  }
317 }

References m_trucks.

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

◆ size()

size_t pgrouting::vrp::Fleet::size ( ) const
inline

Definition at line 78 of file fleet.h.

78 {return m_trucks.size();}

References m_trucks.

Referenced by build_fleet().

Friends And Related Function Documentation

◆ operator<<

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

Definition at line 324 of file fleet.cpp.

324  {
325  log << "fleet\n";
326  for (const auto &v : f.m_trucks) {
327  log << v;
328  }
329  log << "end fleet\n";
330 
331  return log;
332 }

◆ PD_problem

friend class PD_problem
friend

Definition at line 48 of file fleet.h.

Member Data Documentation

◆ m_trucks

std::vector<Vehicle_pickDeliver> pgrouting::vrp::Fleet::m_trucks
private

◆ m_un_used

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

Definition at line 90 of file fleet.h.

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

◆ m_used

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

Definition at line 89 of file fleet.h.

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

◆ problem

Pgr_pickDeliver * pgrouting::vrp::Fleet::problem
staticprivate

The problem.

Definition at line 110 of file fleet.h.

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


The documentation for this class was generated from the following files:
pgrouting::vrp::Fleet::m_used
Identifiers< size_t > m_used
Definition: fleet.h:89
Vehicle_t::capacity
double capacity
Definition: vehicle_t.h:42
pgrouting::vrp::Fleet::problem
static Pgr_pickDeliver * problem
The problem.
Definition: fleet.h:110
EXITING
#define EXITING(x)
Definition: pgr_messages.h:94
pgrouting::vrp::Fleet::m_un_used
Identifiers< size_t > m_un_used
Definition: fleet.h:90
pgrouting::vrp::Fleet::add_vehicle
void add_vehicle(Vehicle_t, double factor, const Vehicle_node &, const Vehicle_node &)
Definition: fleet.cpp:122
ENTERING
#define ENTERING(x)
Definition: pgr_messages.h:93
pgrouting::vrp::Pgr_pickDeliver::get_nodes
std::vector< Vehicle_node > get_nodes() const
Definition: pgr_pickDeliver.h:88
pgassertwm
#define pgassertwm(expr, msg)
Adds a message to the assertion.
Definition: pgr_assert.h:117
pgrouting::Pgr_messages::error
std::ostringstream error
Stores the error information.
Definition: pgr_messages.h:85
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::Fleet::msg
static Pgr_messages & msg()
the problem message
Definition: fleet.cpp:46
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgrouting::tsp::Dmatrix::has_id
bool has_id(int64_t id) const
original id -> true
Definition: Dmatrix.cpp:79
Identifiers::size
size_t size() const
Definition: identifiers.hpp:78
pgrouting::vrp::Pgr_pickDeliver::get_cost_matrix
pgrouting::tsp::Dmatrix get_cost_matrix() const
Definition: pgr_pickDeliver.h:92
Vehicle_t::cant_v
int64_t cant_v
Definition: vehicle_t.h:49
pgrouting::vrp::Fleet::m_trucks
std::vector< Vehicle_pickDeliver > m_trucks
Definition: fleet.h:88
Vehicle_t::speed
double speed
Definition: vehicle_t.h:43
Identifiers::front
T front() const
Definition: identifiers.hpp:80
pgrouting::vrp::Fleet::size
size_t size() const
Definition: fleet.h:78
pgrouting::tsp::Dmatrix::empty
bool empty() const
Definition: Dmatrix.h:118
Vehicle_t::id
int64_t id
Definition: vehicle_t.h:41
pgrouting::vrp::Pgr_pickDeliver::add_node
void add_node(const Vehicle_node &node)
Definition: pgr_pickDeliver.cpp:128
pgrouting::vrp::Fleet::build_fleet
bool build_fleet(std::vector< Vehicle_t > vehicles, double factor)
build the fleet
Definition: fleet.cpp:160
Identifiers< size_t >