vrpRouting  0.3
vehicle_pickDeliver.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: vehicle_pickDeliver.h
4 
5 Copyright (c) 2016 pgRouting developers
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_PROBLEM_VEHICLE_PICKDELIVER_H_
29 #define INCLUDE_PROBLEM_VEHICLE_PICKDELIVER_H_
30 #pragma once
31 
32 #include <limits>
33 #include <vector>
34 #include "c_types/typedefs.h"
35 #include "cpp_common/pgr_assert.h"
38 #include "problem/vehicle.h"
39 #include "problem/orders.h"
40 
41 namespace vrprouting {
42 namespace problem {
43 class Order;
44 class Orders;
45 
46 class Vehicle_pickDeliver : public Vehicle {
47  public:
48  using Vehicle::insert;
50  using Vehicle::erase;
51  using Vehicle::size;
52  using Vehicle::invariant;
53  using Vehicle::evaluate;
55 
56  using Vehicle::at;
57  using Vehicle::empty;
58 
64  friend std::ostream& operator<< (std::ostream &log, const Vehicle_pickDeliver &v) {
65  int i(0);
66  log << "\n\n****************** " << v.idx() << "th VEHICLE*************\n";
67  log << "id = " << v.id()
68  << "\tcapacity = " << v.capacity() << "\n";
69 
70  for (const auto &path_stop : v) {
71  log << "Path_stop" << ++i << "\n";
72  log << path_stop << "\n";
73  }
74 
75  log << v.feasible_orders() << "\n";
76  return log;
77  }
78 
79 
80  Vehicle_pickDeliver() = delete;
81  Vehicle_pickDeliver(const Vehicle_pickDeliver &) = default;
83  Idx p_idx,
84  Id p_id,
85  const Vehicle_node & p_starting_site,
86  const Vehicle_node & p_ending_site,
87  const std::vector<int64_t>& p_stops,
88  PAmount p_capacity,
89  Speed p_speed,
90  const Orders& p_orders) :
91  Vehicle(p_idx, p_id, p_starting_site, p_ending_site, p_capacity, p_speed),
92  m_cost((std::numeric_limits<double>::max)()),
95  m_orders(p_orders),
96  m_stops(p_stops) {}
97 
98 
103 
106 
108  bool has_order(const Order &order) const {return m_orders_in_vehicle.has(order.idx());}
109 
110  size_t orders_size() const {return m_orders_in_vehicle.size();}
111 
113  void push_back(const Order &order);
114 
116  void push_front(const Order &order);
117 
119  bool hillClimb(const Order &order);
120 
122  bool semiLIFO(const Order &order);
123 
125  void erase(const Order &order);
126 
127  size_t pop_back();
128  size_t pop_front();
129 
130  // TODO(pending): move code to cpp file
132  pgassert(!empty());
133  return orders()[at(1).idx()];
134  }
135 
137  double objective() const;
138 
139 
142 
144  void set_unmovable(TTimestamp execution_date);
145 
146  bool is_order_feasible(const Order &order) const;
147 
148  const Orders& orders() const {pgassert(m_orders.size() != 0); return m_orders;}
149 
150  Pgr_messages& msg() {return m_msg;}
151 
152  protected:
153  using Vehicle::begin;
154  using Vehicle::end;
155  using Vehicle::rbegin;
156  using Vehicle::rend;
157 
158  double m_cost;
159 
162 
165 
167 
169 
170  private:
175  std::vector<int64_t> m_stops;
176 };
177 
178 } // namespace problem
179 } // namespace vrprouting
180 
181 #endif // INCLUDE_PROBLEM_VEHICLE_PICKDELIVER_H_
vrprouting::problem::Vehicle_pickDeliver::Vehicle_pickDeliver
Vehicle_pickDeliver()=delete
vrprouting::problem::Vehicle_pickDeliver::set_unmovable
void set_unmovable(TTimestamp execution_date)
sets as unmovable the orders that start before the execution date
Definition: vehicle_pickDeliver.cpp:292
vrprouting::problem::Vehicle_pickDeliver::erase
void erase(const Order &order)
erases the order from the vehicle
Definition: vehicle_pickDeliver.cpp:154
vrprouting::problem::Vehicle_pickDeliver::m_orders
Orders m_orders
Definition: vehicle_pickDeliver.h:166
vrprouting::problem::Vehicle::evaluate
void evaluate()
Definition: vehicle.cpp:126
vrprouting::problem::Vehicle_pickDeliver::operator<<
friend std::ostream & operator<<(std::ostream &log, const Vehicle_pickDeliver &v)
Definition: vehicle_pickDeliver.h:64
vrprouting::problem::Vehicle::invariant
void invariant() const
Definition: vehicle.cpp:100
vrprouting::problem::Vehicle_pickDeliver::feasible_orders
Identifiers< size_t > & feasible_orders()
returns the set of feasible orders for modification
Definition: vehicle_pickDeliver.h:100
vrprouting::problem::Vehicle
Vehicle with time windows.
Definition: vehicle.h:61
pgr_messages.h
vrprouting::problem::Vehicle_pickDeliver::get_first_order
Order get_first_order() const
Definition: vehicle_pickDeliver.h:131
vrprouting::problem::Vehicle_pickDeliver::m_feasible_orders
Identifiers< size_t > m_feasible_orders
orders that fit in the truck
Definition: vehicle_pickDeliver.h:164
vrprouting::Identifier::id
int64_t id() const
get the original id
Definition: identifier.cpp:42
vrprouting::problem::Vehicle_pickDeliver::pop_back
size_t pop_back()
Definition: vehicle_pickDeliver.cpp:95
vrprouting::problem::Vehicle_pickDeliver::hillClimb
bool hillClimb(const Order &order)
Inserts an order with hill Climb approach.
Definition: vehicle_pickDeliver.cpp:444
vrprouting::problem::Vehicle_pickDeliver::m_stops
std::vector< int64_t > m_stops
order ids of an initial solution given by the user [1,2,1,3,3,2] = P1 P2 D1 P3 D3 D2
Definition: vehicle_pickDeliver.h:175
vrprouting::problem::Vehicle_pickDeliver::push_back
void push_back(const Order &order)
puts an order at the end of the truck
Definition: vehicle_pickDeliver.cpp:57
vrprouting::problem::Vehicle_pickDeliver::msg
Pgr_messages & msg()
Definition: vehicle_pickDeliver.h:150
vrprouting::problem::Vehicle::is_feasible
bool is_feasible() const
Definition: vehicle.cpp:120
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:95
vrprouting::problem::Orders
Definition: orders.h:48
Speed
double Speed
Definition: typedefs.h:76
vrprouting::problem::Vehicle_pickDeliver::objective
double objective() const
Get the value of the objective function.
Definition: vehicle_pickDeliver.cpp:321
vrprouting::problem::Vehicle_pickDeliver::feasible_orders
const Identifiers< size_t > & feasible_orders() const
returns the set of feasible orders
Definition: vehicle_pickDeliver.h:102
vrprouting::problem::Vehicle_pickDeliver::m_orders_in_vehicle
Identifiers< size_t > m_orders_in_vehicle
orders inserted in this vehicle
Definition: vehicle_pickDeliver.h:161
Identifiers::size
size_t size() const
Definition: identifiers.hpp:77
vrprouting::problem::Vehicle_pickDeliver::has_order
bool has_order(const Order &order) const
does the vehicle has the order?
Definition: vehicle_pickDeliver.h:108
vrprouting::problem::Vehicle_pickDeliver::semiLIFO
bool semiLIFO(const Order &order)
Inserts an order In semi-Lifo (almost last in first out) order.
Definition: vehicle_pickDeliver.cpp:361
Id
int64_t Id
Definition: typedefs.h:78
vrprouting::problem::Vehicle_pickDeliver::orders
const Orders & orders() const
Definition: vehicle_pickDeliver.h:148
typedefs.h
vrprouting::Identifier::idx
size_t idx() const
get the internal index
Definition: identifier.cpp:37
vrprouting::problem::Vehicle_node
Extend Tw_node to evaluate the vehicle at node level.
Definition: vehicle_node.h:49
vrprouting::problem::Vehicle_pickDeliver
Definition: vehicle_pickDeliver.h:46
vrprouting::problem::Vehicle_pickDeliver::is_order_feasible
bool is_order_feasible(const Order &order) const
Definition: vehicle_pickDeliver.cpp:334
pgr_assert.h
An assert functionality that uses C++ throw().
vrprouting::problem::Vehicle_pickDeliver::Vehicle_pickDeliver
Vehicle_pickDeliver(Idx p_idx, Id p_id, const Vehicle_node &p_starting_site, const Vehicle_node &p_ending_site, const std::vector< int64_t > &p_stops, PAmount p_capacity, Speed p_speed, const Orders &p_orders)
Definition: vehicle_pickDeliver.h:82
vrprouting::problem::Vehicle_pickDeliver::push_front
void push_front(const Order &order)
Puts an order at the end front of the truck.
Definition: vehicle_pickDeliver.cpp:84
TTimestamp
int64_t TTimestamp
Definition: typedefs.h:71
Idx
uint64_t Idx
Definition: typedefs.h:79
vrprouting::problem::Vehicle_pickDeliver::m_msg
Pgr_messages m_msg
Definition: vehicle_pickDeliver.h:168
vrprouting::problem::Vehicle::erase
void erase(size_t pos)
Definition: vehicle.cpp:172
vehicle.h
Identifiers::has
bool has(const T other) const
true ids() has element
Definition: identifiers.hpp:100
vrprouting::problem::Vehicle_pickDeliver::m_cost
double m_cost
Definition: vehicle_pickDeliver.h:158
vrprouting::Pgr_messages
Messages Handling.
Definition: pgr_messages.h:52
vrprouting::problem::Vehicle::insert_node
void insert_node(size_t pos, const Vehicle_node &node)
Definition: vehicle.cpp:158
PAmount
uint32_t PAmount
Definition: typedefs.h:75
vrprouting::problem::Vehicle_pickDeliver::orders_size
size_t orders_size() const
Definition: vehicle_pickDeliver.h:110
orders.h
vrprouting::problem::Vehicle::capacity
PAmount capacity() const
returns the capacity of the vehicle
Definition: vehicle.cpp:66
vrprouting::problem::Vehicle_pickDeliver::pop_front
size_t pop_front()
Definition: vehicle_pickDeliver.cpp:121
vrprouting::problem::Order
Definition: order.h:40
vrprouting::problem::Vehicle_pickDeliver::set_initial_solution
void set_initial_solution(const Orders &, Identifiers< size_t > &, Identifiers< size_t > &, TTimestamp, bool)
sets the initial solution given by the user
Definition: vehicle_pickDeliver.cpp:171
identifiers.hpp
Identifiers< size_t >
vrprouting::problem::Vehicle::insert
void insert(size_t pos, const Vehicle_node &node)
Definition: vehicle.cpp:202
vrprouting::problem::Vehicle_pickDeliver::orders_in_vehicle
Identifiers< size_t > orders_in_vehicle() const
returns the number of orders in the vehicle
Definition: vehicle_pickDeliver.h:105
vrprouting::problem::Vehicle::empty
bool empty() const
Definition: vehicle.cpp:112
vrprouting
Definition: base_matrix.cpp:46