vrpRouting  0.3
orders.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: pd_orders.h
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/orders.h"
29 
30 #include <vector>
31 #include <utility>
32 
33 #include "cpp_common/pgr_assert.h"
35 
36 
37 namespace vrprouting {
38 namespace problem {
39 
45 size_t
47  const Identifiers<size_t> &within_this_set) const {
48  pgassert(!within_this_set.empty());
49  auto best_order = within_this_set.front();
50  size_t max_size = 0;
51 
52  for (const auto o : within_this_set) {
53  auto size_J = this->at(o).subsetJ(within_this_set).size();
54  if (max_size < size_J) {
55  max_size = size_J;
56  best_order = o;
57  }
58  }
59  return best_order;
60 }
61 
67 size_t
69  const Identifiers<size_t> &within_this_set) const {
70  pgassert(!within_this_set.empty());
71  auto best_order = within_this_set.front();
72  size_t max_size = 0;
73  for (const auto o : within_this_set) {
74  auto size_I = this->at(o).subsetI(within_this_set).size();
75  if (max_size < size_I) {
76  max_size = size_I;
77  best_order = o;
78  }
79  }
80  return best_order;
81 }
82 
88 size_t
90  const Identifiers<size_t> &within_this_set) const {
91  pgassert(!within_this_set.empty());
92  auto best_order = within_this_set.front();
93  size_t max_size = 0;
94 
95  for (const auto o : within_this_set) {
96  auto size_I = this->at(o).subsetI(within_this_set).size();
97  auto size_J = this->at(o).subsetJ(within_this_set).size();
98  if (max_size < (std::max)(size_I, size_J)) {
99  max_size = (std::max)(size_I, size_J);
100  best_order = o;
101  }
102  }
103  return best_order;
104 }
105 
109 bool
110 Orders::is_valid(Speed speed) const {
111  for (const auto &o : *this) {
112  if (!o.is_valid(speed)) {
113  return false;
114  }
115  pgassert(o.pickup().is_pickup());
116  pgassert(o.delivery().is_delivery());
117  /* P -> D */
118  pgassert(o.delivery().is_compatible_IJ(o.pickup(), speed));
119  }
120  return true;
121 }
122 
127 void
129  for (auto &I : *this) {
130  for (const auto& J : *this) {
131  I.set_compatibles(J, speed);
132  }
133  }
134 }
135 
136 } // namespace problem
137 } // namespace vrprouting
138 
vrprouting::problem::Orders::is_valid
bool is_valid(Speed=1.0) const
is the order valid?
Definition: orders.cpp:110
vrprouting::problem::Orders::find_best_I_J
size_t find_best_I_J(const Identifiers< size_t > &within_this_set) const
find the best order -> this -> order
Definition: orders.cpp:89
vrprouting::problem::Orders::set_compatibles
void set_compatibles(Speed=1.0)
set the compatability between all orders
Definition: orders.cpp:128
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:95
Speed
double Speed
Definition: typedefs.h:76
Identifiers::empty
bool empty() const
Definition: identifiers.hpp:78
pgr_assert.h
An assert functionality that uses C++ throw().
Identifiers::front
T front() const
Definition: identifiers.hpp:79
vrprouting::problem::Orders::find_best_J
size_t find_best_J(const Identifiers< size_t > &within_this_set) const
find the best order -> this -> order
Definition: orders.cpp:46
orders.h
vrprouting::problem::Orders::find_best_I
size_t find_best_I(const Identifiers< size_t > &within_this_set) const
find the best order -> this
Definition: orders.cpp:68
identifiers.hpp
Identifiers< size_t >
vrprouting
Definition: base_matrix.cpp:46