PGROUTING  2.5
initial_solution.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: initial_solution.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 #include "vrp/initial_solution.h"
28 #include <deque>
29 #include <algorithm>
30 #include <set>
31 #include "cpp_common/pgr_assert.h"
32 #include "vrp/solution.h"
33 #include "vrp/pgr_pickDeliver.h"
34 
35 namespace pgrouting {
36 namespace vrp {
37 
38 void
40  /* this checks there is no order duplicated */
42  pgassert((assigned * unassigned).empty());
43 }
44 
45 
47  int kind,
48  size_t number_of_orders) :
49  Solution(),
50  all_orders(number_of_orders),
51  unassigned(number_of_orders),
52  assigned() {
53  invariant();
54  pgassert(kind >= 0 && kind < 7);
55 
56  switch (kind) {
57  case 0:
59  break;
60  case 1:
61  case 2:
62  case 3:
63  case 4:
64  case 5:
65  case 6:
66  do_while_foo(kind);
67  break;
68  default: pgassert(false);
69  }
70 
71  invariant();
72 }
73 
74 
75 
76 void
78  invariant();
79  pgassert(kind > 0 && kind < 7);
80 
81  msg.log << "\nInitial_solution::do_while_foo\n";
82  Identifiers<size_t> notused;
83 #if 0
84  bool out_of_trucks(true);
85 #endif
86 
87  while (!unassigned.empty()) {
88  msg.log << unassigned.size() << " unassigned: " << unassigned << "\n";
89  msg.log << assigned.size() << " assigned:" << assigned << "\n";
90  auto current = unassigned.size();
91 #if 0
92  auto truck = out_of_trucks?
94  trucks.get_truck();
95 #else
96  auto truck = trucks.get_truck(unassigned.front());
97 #endif
98  msg.log << "got truck:" << truck.tau() << "\n";
99  /*
100  * kind 1 to 7 work with the same code structure
101  */
102  truck.do_while_feasable(kind, unassigned, assigned);
103  msg.log << unassigned.size() << " unassigned: " << unassigned << "\n";
104  msg.log << assigned.size() << " assigned:" << assigned << "\n";
105  msg.log << "current" << current << " unassigned: " << unassigned.size();
106  pgassertwm(current > unassigned.size(), msg.get_log().c_str());
107 
108 #if 0
109  if (truck.orders_in_vehicle().empty()) {
110  out_of_trucks = notused.has(truck.idx());
111  if (out_of_trucks) {
112  for (auto t : notused) {
114  }
115  }
116  notused += truck.idx();
117  continue;
118  }
119 #endif
120  fleet.push_back(truck);
121  invariant();
122  }
123 
124  pgassertwm(true, msg.get_log().c_str());
126  invariant();
127 }
128 
129 
130 
131 
132 void
134  invariant();
135  msg.log << "\nInitial_solution::one_truck_all_orders\n";
136  auto truck = trucks.get_truck();
137  while (!unassigned.empty()) {
138  auto order(truck.orders()[*unassigned.begin()]);
139 
140  truck.insert(order);
141 
144 
145  invariant();
146  }
147  fleet.push_back(truck);
148  invariant();
149 }
150 
151 
152 
153 
154 } // namespace vrp
155 } // namespace pgrouting
bool has(const T other) const
true ids() has element
Definition: identifiers.hpp:97
bool is_feasable() const
Definition: solution.cpp:56
void pop_front()
Definition: identifiers.hpp:82
#define pgassertwm(expr, msg)
Adds a message to the assertion.
Definition: pgr_assert.h:104
const_iterator begin() const
Definition: identifiers.hpp:80
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:102
Vehicle_pickDeliver get_truck()
Definition: fleet.cpp:59
std::string get_log() const
get_log
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49
Identifiers< size_t > assigned
Identifiers< size_t > all_orders
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:81
Identifiers< size_t > unassigned
void release_truck(size_t id)
Definition: fleet.cpp:73
void insert(const Order &order)
Inserts an order.
size_t size() const
Definition: identifiers.hpp:77
Book keeping class for swapping orders between vehicles.
Definition: basic_edge.cpp:28
Assertions Handling.
static Pgr_messages msg
Definition: pd_problem.h:48
T front() const
Definition: identifiers.hpp:79
bool empty() const
Definition: identifiers.hpp:78