vrpRouting  0.3
solution.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 FILE: solution.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 #ifndef INCLUDE_PROBLEM_SOLUTION_H_
29 #define INCLUDE_PROBLEM_SOLUTION_H_
30 #pragma once
31 
32 #include <deque>
33 #include <vector>
34 #include <string>
35 #include <ostream>
36 #include <numeric>
37 #include <algorithm>
38 #include <tuple>
39 #include <iomanip>
40 
42 #include "problem/fleet.h"
43 #include "c_types/short_vehicle.h"
44 
45 typedef struct Solution_rt Solution_rt;
46 
47 namespace vrprouting {
48 namespace problem {
49 
50 class Solution {
51  public:
53  Solution() = delete;
54 
56  template <typename P>
57  explicit Solution(P* p_problem) :
58  m_orders(p_problem->orders()),
59  m_trucks(p_problem->vehicles()),
60  m_msg(p_problem->msg) { }
61 
62 
64  Solution(const Solution &sol) = default;
65 
67  Solution& operator = (const Solution& sol) = default;
68 
70  std::vector<Short_vehicle> get_stops() const;
71 
73  std::vector<Solution_rt> get_postgres_result() const;
74 
76  friend std::ostream& operator<< (std::ostream &log, const Solution &solution) {
77  for (const auto& vehicle : solution.m_fleet) log << vehicle;
78  log << "\n SOLUTION:\n\n " << solution.tau();
79  return log;
80  }
81 
83  std::string tau(const std::string &title = "Tau") const;
84 
86  bool is_feasible() const;
87 
89  TInterval duration() const;
90 
92  TInterval wait_time() const;
93 
96 
99 
101  int twvTot() const;
102 
104  int cvTot() const;
105 
107  const std::deque<Vehicle_pickDeliver>& fleet() const {return m_fleet;}
108 
110  double objective() const {return static_cast<double>(total_travel_time());}
111 
113  std::tuple<int, int, size_t, TInterval, TInterval, TInterval> cost() const;
114 
115  std::string cost_str() const;
116 
117  bool operator<(const Solution&) const;
118 
119  Pgr_messages& msg() {return m_msg;}
120  const Orders& orders() const {return m_orders;}
121  Fleet& vehicles() {return m_trucks;}
122 
123  protected:
125  std::deque<Vehicle_pickDeliver> m_fleet;
126 
131 };
132 
133 } // namespace problem
134 } // namespace vrprouting
135 
136 #endif // INCLUDE_PROBLEM_SOLUTION_H_
vrprouting::problem::Solution
Definition: solution.h:50
vrprouting::problem::Solution::orders
const Orders & orders() const
Definition: solution.h:120
vrprouting::problem::Solution::total_service_time
TInterval total_service_time() const
Total service time of the solution.
Definition: solution.cpp:174
vrprouting::problem::Solution::objective
double objective() const
Get the value of the objective function.
Definition: solution.h:110
vrprouting::problem::Fleet
Definition: fleet.h:52
vrprouting::problem::Solution::m_fleet
std::deque< Vehicle_pickDeliver > m_fleet
The current solution.
Definition: solution.h:125
vrprouting::problem::Solution::cvTot
int cvTot() const
Total number of capacity constraint violations of the solution.
Definition: solution.cpp:196
vrprouting::problem::Solution::operator<
bool operator<(const Solution &) const
Definition: solution.cpp:267
vrprouting::problem::Solution::total_travel_time
TInterval total_travel_time() const
Total travel time of the solution.
Definition: solution.cpp:162
vrprouting::problem::Solution::vehicles
Fleet & vehicles()
Definition: solution.h:121
vrprouting::problem::Solution::twvTot
int twvTot() const
Total number of time windows constraint violations of the solution.
Definition: solution.cpp:185
vrprouting::problem::Orders
Definition: orders.h:48
vrprouting::problem::Solution::Solution
Solution()=delete
constructor
vrprouting::problem::Solution::wait_time
TInterval wait_time() const
Total waiting time of the solution.
Definition: solution.cpp:151
vrprouting::problem::Solution::duration
TInterval duration() const
Total duration of the solution.
Definition: solution.cpp:140
vrprouting::problem::Solution::get_postgres_result
std::vector< Solution_rt > get_postgres_result() const
get solution like postgres needs it
Definition: solution.cpp:61
vrprouting::problem::Solution::operator=
Solution & operator=(const Solution &sol)=default
copy assignment
Solution_rt
Solution schedule when twv & cw are hard restrictions.
Definition: solution_rt.h:56
vrprouting::problem::Solution::fleet
const std::deque< Vehicle_pickDeliver > & fleet() const
Get the current fleet solution.
Definition: solution.h:107
vrprouting::problem::Solution::msg
Pgr_messages & msg()
Definition: solution.h:119
vrprouting::problem::Solution::tau
std::string tau(const std::string &title="Tau") const
writing the solution in compact form into a string
Definition: solution.cpp:116
vrprouting::problem::Solution::m_msg
Pgr_messages m_msg
Definition: solution.h:130
vehicle_pickDeliver.h
short_vehicle.h
vrprouting::problem::Solution::cost
std::tuple< int, int, size_t, TInterval, TInterval, TInterval > cost() const
Get all statistics in one cycle.
Definition: solution.cpp:218
vrprouting::problem::Solution::is_feasible
bool is_feasible() const
is the solution feasible?
Definition: solution.cpp:129
vrprouting::Pgr_messages
Messages Handling.
Definition: pgr_messages.h:52
vrprouting::problem::Solution::operator<<
friend std::ostream & operator<<(std::ostream &log, const Solution &solution)
printing function
Definition: solution.h:76
TInterval
int64_t TInterval
Definition: typedefs.h:72
vrprouting::problem::Solution::Solution
Solution(P *p_problem)
constructor
Definition: solution.h:57
vrprouting::problem::Solution::m_trucks
Fleet m_trucks
Definition: solution.h:129
vrprouting::problem::Solution::m_orders
Orders m_orders
the problem info
Definition: solution.h:128
vrprouting::problem::Solution::get_stops
std::vector< Short_vehicle > get_stops() const
get solution like postgres needs it
Definition: solution.cpp:49
vrprouting
Definition: base_matrix.cpp:46
vrprouting::problem::Solution::cost_str
std::string cost_str() const
Definition: solution.cpp:246
fleet.h