PGROUTING  3.2
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
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((m_assigned * m_unassigned).empty());
43 }
44 
45 
47  Initials_code kind,
48  size_t number_of_orders) :
49  Solution(),
50  m_all_orders(number_of_orders),
51  m_unassigned(number_of_orders),
52  m_assigned() {
53  invariant();
54  pgassert(kind >= 0 && kind <= OneDepot);
55 
56  switch (kind) {
57  case OneTruck:
59  break;
60  case OnePerTruck:
61  case FrontTruck:
62  case BackTruck:
63  case BestInsert:
64  case BestBack:
65  case BestFront:
66  case OneDepot:
67  do_while_foo(kind);
68  break;
69  default: pgassert(false);
70  }
71 
72  invariant();
73 }
74 
75 
76 
77 void
79  invariant();
80  pgassert(kind > 0 && kind <= OneDepot);
81 
82 #if 0
83  msg().log << "\nInitial_solution::do_while_foo\n";
84 #endif
85  Identifiers<size_t> notused;
86 
87  while (!m_unassigned.empty()) {
88 #if 0
89  msg().log << m_unassigned.size() << " m_unassigned: " << m_unassigned << "\n";
90  msg().log << m_assigned.size() << " m_assigned:" << m_assigned << "\n";
91 #endif
92  auto current = m_unassigned.size();
93  auto truck = trucks.get_truck(m_unassigned.front());
94 #if 0
95  msg().log << "got truck:" << truck.tau() << "\n";
96 #endif
97  /*
98  * kind 1 to 7 work with the same code structure
99  */
100  truck.do_while_feasable((Initials_code)kind, m_unassigned, m_assigned);
101 #if 0
102  msg().log << m_unassigned.size() << " m_unassigned: " << m_unassigned << "\n";
103  msg().log << m_assigned.size() << " m_assigned:" << m_assigned << "\n";
104  msg().log << "current" << current << " m_unassigned: " << m_unassigned.size();
105 #endif
106  pgassertwm(current > m_unassigned.size(), msg().get_log().c_str());
107 
108  fleet.push_back(truck);
109  invariant();
110  }
111 
112  pgassertwm(true, msg().get_log().c_str());
114  invariant();
115 }
116 
117 
118 
119 
120 void
122  invariant();
123  msg().log << "\nInitial_solution::one_truck_all_orders\n";
124  auto truck = trucks.get_truck();
125  while (!m_unassigned.empty()) {
126  auto order(truck.orders()[*m_unassigned.begin()]);
127 
128  truck.insert(order);
129 
132 
133  invariant();
134  }
135  fleet.push_back(truck);
136  invariant();
137 }
138 
139 
140 
141 
142 } // namespace vrp
143 } // namespace pgrouting
pgr_pickDeliver.h
pgrouting::vrp::Solution
Definition: solution.h:44
initial_solution.h
pgrouting::vrp::Initial_solution::invariant
void invariant() const
Definition: initial_solution.cpp:39
pgrouting::vrp::Initial_solution::do_while_foo
void do_while_foo(int kind)
Definition: initial_solution.cpp:78
pgrouting::vrp::BestInsert
@ BestInsert
Insetion at the back of the truck.
Definition: initials_code.h:41
pgrouting::vrp::OnePerTruck
@ OnePerTruck
All orders in one truck.
Definition: initials_code.h:38
pgrouting::vrp::Solution::is_feasable
bool is_feasable() const
Definition: solution.cpp:67
pgrouting::vrp::OneTruck
@ OneTruck
Definition: initials_code.h:37
pgrouting::vrp::Solution::trucks
Fleet trucks
Definition: solution.h:52
Identifiers::pop_front
void pop_front()
Definition: identifiers.hpp:83
pgrouting::vrp::Solution::fleet
std::deque< Vehicle_pickDeliver > fleet
Definition: solution.h:49
pgassertwm
#define pgassertwm(expr, msg)
Adds a message to the assertion.
Definition: pgr_assert.h:117
pgrouting::vrp::Initial_solution::m_unassigned
Identifiers< size_t > m_unassigned
Definition: initial_solution.h:64
pgrouting::Pgr_messages::log
std::ostringstream log
Stores the hint information.
Definition: pgr_messages.h:81
pgrouting::vrp::Initial_solution::m_assigned
Identifiers< size_t > m_assigned
Definition: initial_solution.h:65
pgrouting::vrp::BackTruck
@ BackTruck
Insetion at the front of the truck.
Definition: initials_code.h:40
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
Identifiers::size
size_t size() const
Definition: identifiers.hpp:78
pgrouting::vrp::OneDepot
@ OneDepot
Push front order that allows more orders to be inserted at the front.
Definition: initials_code.h:44
Identifiers::begin
const_iterator begin() const
Definition: identifiers.hpp:81
Identifiers::empty
bool empty() const
Definition: identifiers.hpp:79
pgrouting::vrp::Initial_solution::m_all_orders
Identifiers< size_t > m_all_orders
Definition: initial_solution.h:63
pgr_assert.h
An assert functionality that uses C++ throw().
pgrouting::vrp::Initial_solution::Initial_solution
Initial_solution(Initials_code kind, size_t)
Definition: initial_solution.cpp:46
pgrouting::vrp::BestBack
@ BestBack
Best place to insert Order.
Definition: initials_code.h:42
Identifiers::front
T front() const
Definition: identifiers.hpp:80
pgrouting::vrp::Fleet::get_truck
Vehicle_pickDeliver get_truck()
Definition: fleet.cpp:67
solution.h
pgrouting::vrp::FrontTruck
@ FrontTruck
One Order per truck.
Definition: initials_code.h:39
pgrouting::vrp::BestFront
@ BestFront
Push back order that allows more orders to be inserted at the back.
Definition: initials_code.h:43
pgrouting::vrp::Initials_code
Initials_code
Different kinds to insert an order into the vehicle.
Definition: initials_code.h:36
pgrouting
Book keeping class for swapping orders between vehicles.
Definition: pgr_alphaShape.cpp:56
pgrouting::vrp::Solution::msg
static Pgr_messages & msg()
The problem's message.
Definition: solution.cpp:60
Identifiers< size_t >
pgrouting::vrp::Initial_solution::one_truck_all_orders
void one_truck_all_orders()
Definition: initial_solution.cpp:121