PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
order.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: order.cpp
4 
5 Copyright (c) 2015 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 
26 
27 
28 #include <set>
29 #include "./../../common/src/pgr_assert.h"
30 #include "./pgr_pickDeliver.h"
31 #include "./order.h"
32 
33 namespace pgrouting {
34 namespace vrp {
35 
36 
37 std::set<size_t>
38 Order::subsetI(const std::set<size_t> &I) const {
39  std::set<size_t> intersect;
40  std::set_intersection(m_compatibleI.begin(), m_compatibleI.end(),
41  I.begin(), I.end(),
42  std::inserter(intersect, intersect.begin()));
43  return intersect;
44 }
45 
46 std::set<size_t>
47 Order::subsetJ(const std::set<size_t> &J) const {
48  std::set<size_t> intersect;
49  std::set_intersection(m_compatibleJ.begin(), m_compatibleJ.end(),
50  J.begin(), J.end(),
51  std::inserter(intersect, intersect.begin()));
52  return intersect;
53 }
54 
55 
56 Order::Order(size_t p_id,
57  const Vehicle_node &p_pickup,
58  const Vehicle_node &p_delivery,
59  const Pgr_pickDeliver *p_problem) :
60  m_id(p_id),
61  pickup_id(p_pickup.id()),
62  delivery_id(p_delivery.id()),
63  problem(p_problem) {
64  pgassert(pickup().is_pickup());
65  pgassert(delivery().is_delivery());
66  }
67 
68 std::ostream&
69 operator << (std::ostream &log, const Order &order) {
70  log << "\n\nOrder " << order.m_id << ":\n"
71  << "\tPickup: " << order.pickup() << "\n"
72  << "\tDelivery: " << order.delivery() << "\n\n";
73  if (order.delivery().is_partially_compatible_IJ(order.pickup())) {
74  log << "\tis_partially_compatible_IJ: ";
75  } else if (order.delivery().is_tight_compatible_IJ(order.pickup())) {
76  log << "\tis_tight_compatible_IJ: ";
77  } else if (order.delivery().is_waitTime_compatible_IJ(order.pickup())) {
78  log << "\tis_waitTime_compatible_IJ: ";
79  } else {
80  pgassert(false);
81  }
82  log << "\nThere are | {I}| = "
83  << order.m_compatibleI.size()
84  << " -> order(" << order.id()
85  << ") -> | {J}| = " << order.m_compatibleJ.size()
86  << "\n\n {";
87  for (const auto o : order.m_compatibleI) {
88  log << o << ", ";
89  }
90  log << "} -> " << order.id() << " -> {";
91  for (const auto o : order.m_compatibleJ) {
92  log << o << ", ";
93  }
94  log << "}";
95 
96  return log;
97 }
98 
99 
100 
101 const Vehicle_node&
103 
104 
105 const Vehicle_node&
106 Order::pickup() const {return problem->node(pickup_id);}
107 
108 
109 bool
111  return
112  pickup().is_pickup()
113  && delivery().is_delivery()
114  /* P -> D */
116 }
117 
118 
119 /*
120  * Initializing the set of nodes that can be placed
121  * inmediately after \bthis node
122  *
123  * (*this) -> J
124  *
125  */
126 
127 void
129  for (const auto J : problem->orders()) {
130  if (J.id() == id()) continue;
131  if (J.isCompatibleIJ(*this)) {
132  /*
133  * this -> {J}
134  */
135  m_compatibleJ.insert(J.id());
136  }
137  if (this->isCompatibleIJ(J)) {
138  /*
139  * {J} -> this
140  */
141  m_compatibleI.insert(J.id());
142  }
143  }
144 }
145 
146 /*
147  * True when
148  *
149  * I -> (*this)
150  *
151  */
152 
153 bool
154 Order::isCompatibleIJ(const Order &I) const {
155  /* this is true in all cases */
156  auto all_cases(
157  pickup().is_compatible_IJ(I.pickup())
158  && delivery().is_compatible_IJ(I.pickup()));
159 
160  /* case other(P) other(D) this(P) this(D) */
161  auto case1(pickup().is_compatible_IJ(I.delivery())
163 
164  /* case other(P) this(P) other(D) this(D) */
165  auto case2(I.delivery().is_compatible_IJ(pickup())
167 
168  /* case other(P) this(P) this(D) other(D) */
169  auto case3(I.delivery().is_compatible_IJ(pickup())
171 
172  return all_cases && (case1 || case2 || case3);
173 }
174 
175 
176 #if 0
177 bool
178 Order::isOrderCompatibleEnd(const Vehicle_node &node) const {
179  return false;
180 }
181 
182 bool
183 Order::isOrderCompatibleStart(const Vehicle_node &node) const {
184  return false;
185 }
186 #endif
187 
188 } // namespace vrp
189 } // namespace pgrouting
190 
bool is_valid() const
An order is valid when:
Definition: order.cpp:110
size_t pickup_id
Definition: order.h:85
size_t id() const
Definition: order.h:57
bool isCompatibleIJ(const Order &other) const
Definition: order.cpp:154
const Vehicle_node & pickup() const
Definition: order.cpp:106
Extend Tw_node to evaluate the vehicle at node level.
Definition: vehicle_node.h:46
bool is_tight_compatible_IJ(const Tw_node &I) const
Definition: tw_node.cpp:87
std::set< size_t > subsetI(const std::set< size_t > &I) const
Definition: order.cpp:38
PGDLLEXPORT Datum vrp(PG_FUNCTION_ARGS)
Definition: VRP.c:732
Order(size_t p_id, const Vehicle_node &p_pickup, const Vehicle_node &p_deliver, const Pgr_pickDeliver *p_problem)
Definition: order.cpp:56
bool is_compatible_IJ(const Tw_node &I) const
Definition: tw_node.cpp:65
bool is_waitTime_compatible_IJ(const Tw_node &I) const
Definition: tw_node.cpp:102
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
size_t delivery_id
Definition: order.h:86
bool is_partially_compatible_IJ(const Tw_node &I) const
Definition: tw_node.cpp:79
std::set< size_t > m_compatibleI
Definition: order.h:98
bool is_pickup() const
is_pickup
Definition: tw_node.cpp:132
bool is_delivery() const
is_delivery
Definition: tw_node.cpp:142
const Vehicle_node & node(ID id) const
const Pgr_pickDeliver * problem
Definition: order.h:102
const Vehicle_node & delivery() const
Definition: order.cpp:102
const std::vector< Order > & orders() const
std::set< size_t > m_compatibleJ
Definition: order.h:92
std::set< size_t > subsetJ(const std::set< size_t > &J) const
Definition: order.cpp:47
std::ostream & operator<<(std::ostream &log, const Node &node)
Definition: node.cpp:41