PGROUTING  2.6-dev
fleet.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: fleet.h
4 
5 Copyright (c) 2017 pgRouting developers
6 Mail: project@pgrouting.org
7 
8 ------
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 
24  ********************************************************************PGR-GNU*/
25 
28 #ifndef INCLUDE_VRP_FLEET_H_
29 #define INCLUDE_VRP_FLEET_H_
30 #pragma once
31 
32 #include <iosfwd>
33 #include <vector>
34 #include <memory>
35 #include <utility>
36 
38 #include "vrp/pd_problem.h"
40 
41 namespace pgrouting {
42 namespace vrp {
43 
44 class Pgr_pickDeliver;
45 class PD_Orders;
46 
47 class Fleet : public PD_problem {
48  public:
49  typedef std::vector<Vehicle_pickDeliver>::iterator iterator;
50  std::vector<Vehicle_pickDeliver> m_trucks;
51 
52 
53  public:
57  Fleet() = default;
58 
59  Fleet(const std::vector<Vehicle_t> &vehicles, double factor);
60 
61  Fleet(const Fleet &fleet);
64  /* TODO move code to .cpp */
65  Fleet& operator=(const Fleet &fleet) {
66  m_trucks = fleet.m_trucks;
67  used = fleet.used;
68  un_used = fleet.un_used;
69  return *this;
70  }
71 
72  void set_compatibles(const PD_Orders &orders);
73 
74  bool is_fleet_ok() const;
75  bool is_order_ok(const Order &order) const;
76 
78  void release_truck(size_t id);
79  Vehicle_pickDeliver get_truck(size_t order);
80  Vehicle_pickDeliver get_truck(const Order order);
81 
85  size_t size() const {return m_trucks.size();}
87  iterator begin() {return m_trucks.begin();}
88  iterator end() {return m_trucks.end();}
89 
92  friend std::ostream& operator << (std::ostream &log, const Fleet &v);
93 
94  private:
97 
102  bool build_fleet(
103  std::vector<Vehicle_t> vehicles,
104  double factor);
105 
106  void add_vehicle(
107  Vehicle_t,
108  double factor,
109  std::unique_ptr<Base_node>,
110  const Vehicle_node&,
111  std::unique_ptr<Base_node>,
112  const Vehicle_node&);
113 
114  template <typename T> std::unique_ptr<Base_node> create_b_start(
115  const Vehicle_t &vehicle,
116  size_t node_id) {
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  }
124 
125  template <typename T> std::unique_ptr<Base_node> create_b_end(
126  const Vehicle_t &vehicle,
127  size_t node_id) {
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  }
135 };
136 
137 
138 } // namespace vrp
139 } // namespace pgrouting
140 
141 #endif // INCLUDE_VRP_FLEET_H_
std::unique_ptr< Base_node > create_b_start(const Vehicle_t &vehicle, size_t node_id)
Definition: fleet.h:114
iterator end()
Definition: fleet.h:88
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
Vehicle_pickDeliver get_truck()
Definition: fleet.cpp:59
Extend Tw_node to evaluate the vehicle at node level.
Definition: vehicle_node.h:48
std::vector< Vehicle_pickDeliver >::iterator iterator
Definition: fleet.h:49
double start_y
Definition: vehicle_t.h:66
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
double end_x
Definition: vehicle_t.h:75
friend std::ostream & operator<<(std::ostream &log, const Fleet &v)
Definition: fleet.cpp:379
double end_y
Definition: vehicle_t.h:76
int64_t end_node_id
Definition: vehicle_t.h:77
double start_x
Definition: vehicle_t.h:65
void release_truck(size_t id)
Definition: fleet.cpp:73
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 truc...
Definition: fleet.cpp:351
bool is_fleet_ok() const
Definition: fleet.cpp:316
Fleet & operator=(const Fleet &fleet)
Definition: fleet.h:65
Vehicle_pickDeliver & operator[](size_t i)
Definition: fleet.cpp:362
int64_t start_node_id
Definition: vehicle_t.h:67
Book keeping class for swapping orders between vehicles.
Definition: basic_edge.cpp:28
Identifiers< size_t > used
Definition: fleet.h:95
Identifiers< size_t > un_used
Definition: fleet.h:96
size_t size() const
Definition: fleet.h:85
std::unique_ptr< Base_node > create_b_end(const Vehicle_t &vehicle, size_t node_id)
Definition: fleet.h:125
void set_compatibles(const PD_Orders &orders)
Definition: fleet.cpp:368
iterator begin()
Definition: fleet.h:87