vrpRouting  0.3
order.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: order.cpp
4 
5 Copyright (c) 2015 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 #include "problem/order.h"
29 
30 namespace vrprouting {
31 namespace problem {
32 
46  return m_compatibleI * I;
47 }
48 
63  return m_compatibleJ * J;
64 }
65 
76 std::ostream&
77 operator<< (std::ostream &log, const Order &order) {
78  log << "\n\nOrder "
79  << static_cast<Identifier>(order) << ": \n"
80  << "\tPickup: " << order.pickup() << "\n"
81  << "\tDropoff: " << order.delivery() << "\n";
82  log << "\nThere are | {I}| = "
83  << order.m_compatibleI.size()
84  << " -> order(" << order.idx()
85  << ") -> | {J}| = " << order.m_compatibleJ.size()
86  << "\n\n {";
87  for (const auto o : order.m_compatibleI) {
88  log << o << ", ";
89  }
90  log << "} -> " << order.idx() << " -> {";
91  for (const auto o : order.m_compatibleJ) {
92  log << o << ", ";
93  }
94  log << "}";
95 
96  return log;
97 }
98 
108 bool
109 Order::is_valid(Speed speed) const {
110  return
111  pickup().is_pickup()
112  && delivery().is_delivery()
113  /* IS P -> D */
114  && delivery().is_compatible_IJ(pickup(), speed);
115 }
116 
129 void
131  if (J.idx() == idx()) return;
132  if (J.isCompatibleIJ(*this, speed)) {
133  m_compatibleJ += J.idx();
134  }
135  if (this->isCompatibleIJ(J, speed)) {
136  m_compatibleI += J.idx();
137  }
138 }
139 
160 bool
161 Order::isCompatibleIJ(const Order &I, Speed speed) const {
162  /* this is true in all cases */
163  auto all_cases(
164  pickup().is_compatible_IJ(I.pickup(), speed)
165  && delivery().is_compatible_IJ(I.pickup(), speed));
166 
167  /* case other(P) other(D) this(P) this(D) */
168  auto case1(pickup().is_compatible_IJ(I.delivery(), speed)
169  && delivery().is_compatible_IJ(I.delivery(), speed));
170 
171  /* case other(P) this(P) other(D) this(D) */
172  auto case2(I.delivery().is_compatible_IJ(pickup(), speed)
173  && delivery().is_compatible_IJ(I.delivery(), speed));
174 
175  /* case other(P) this(P) this(D) other(D) */
176  auto case3(I.delivery().is_compatible_IJ(pickup(), speed)
177  && I.delivery().is_compatible_IJ(delivery(), speed));
178 
179  return all_cases && (case1 || case2 || case3);
180 }
181 
182 } // namespace problem
183 } // namespace vrprouting
184 
vrprouting::problem::Order::subsetI
Identifiers< size_t > subsetI(const Identifiers< size_t > &I) const
Get a subset of the orders that can be placed before this order.
Definition: order.cpp:45
vrprouting::problem::Tw_node::is_delivery
bool is_delivery() const
Is the node a valid order's delivery node.
Definition: tw_node.cpp:210
vrprouting::problem::Order::isCompatibleIJ
bool isCompatibleIJ(const Order &I, Speed speed=1.0) const
Can order I be placed before this order?
Definition: order.cpp:161
vrprouting::problem::operator<<
std::ostream & operator<<(std::ostream &log, const Order &order)
Prints:
Definition: order.cpp:77
Speed
double Speed
Definition: typedefs.h:76
Identifiers::size
size_t size() const
Definition: identifiers.hpp:77
vrprouting::Identifier::idx
size_t idx() const
get the internal index
Definition: identifier.cpp:37
vrprouting::problem::Tw_node::is_pickup
bool is_pickup() const
Is the node a valid order's pickup node.
Definition: tw_node.cpp:199
vrprouting::problem::Tw_node::is_compatible_IJ
bool is_compatible_IJ(const Tw_node &I, Speed=1.0) const
is possible to arrive to this after visiting other?
Definition: tw_node.cpp:94
vrprouting::problem::Order::pickup
const Vehicle_node & pickup() const
The pickup node identifier.
Definition: order.h:65
vrprouting::problem::Order::is_valid
bool is_valid(Speed speed=1.0) const
is the order valid?
Definition: order.cpp:109
vrprouting::problem::Order::set_compatibles
void set_compatibles(const Order &, Speed speed=1.0)
set compatability of this orther with the other order
Definition: order.cpp:130
order.h
vrprouting::Identifier
Class that stores the information about identifiers.
Definition: identifier.h:65
vrprouting::problem::Order
Definition: order.h:40
vrprouting::problem::Order::m_compatibleI
Identifiers< size_t > m_compatibleI
Storage for the orders that can be placed before this order.
Definition: order.h:110
vrprouting::problem::Order::delivery
const Vehicle_node & delivery() const
The delivery node identifier.
Definition: order.h:68
vrprouting::problem::Order::subsetJ
Identifiers< size_t > subsetJ(const Identifiers< size_t > &J) const
Get a subset of the orders that can be placed after this order.
Definition: order.cpp:62
vrprouting::problem::Order::m_compatibleJ
Identifiers< size_t > m_compatibleJ
Storage for the orders that can be placed after this order.
Definition: order.h:98
Identifiers< size_t >
vrprouting
Definition: base_matrix.cpp:46