PGROUTING  2.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
book_keeping.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2  *
3  * FILE: book_keeping.h
4  *
5  * Copyright (c) 2017 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 
28 #ifndef INCLUDE_VRP_BOOK_KEEPING_H_
29 #define INCLUDE_VRP_BOOK_KEEPING_H_
30 #pragma once
31 
32 #include <queue>
33 #include <vector>
34 #include <iostream>
40 namespace pgrouting {
41 namespace vrp {
42 
43 class Swap_bk;
44 class Swap_info {
45  friend class Swap_bk;
46 
47  public:
48  Swap_info() = default;
49  Swap_info(const Swap_info &) = default;
50  Swap_info(const Vehicle_pickDeliver &from,
51  const Vehicle_pickDeliver &to,
52  size_t from_o,
53  size_t to_o,
54  double delta);
55 #if 0
56  from_truck(from),
57  to_truck(to),
58  from_order(from_o),
59  to_order(to_o),
60  estimated_delta(delta)
61  { }
62 #endif
63  friend std::ostream& operator << (std::ostream& log, const Swap_info &d);
64 #if 0
65  {
66  log
67  << "\n" << d.from_truck.tau() << " --> "
68  << d.from_order
69  << "("
70  << d.from_truck.orders()[d.from_order].pickup().original_id()
71  << ")"
72  << "\n" << d.to_truck.tau() << " --> "
73  << d.to_order
74  << "("
75  << d.to_truck.orders()[d.to_order].pickup().original_id()
76  << ")"
77  << "\n" << "delta = " << d.estimated_delta;
78  return log;
79  }
80 #endif
81 
82  public:
85  size_t from_order;
86  size_t to_order;
88 };
89 
90 
91 class Swap_bk {
92  private:
93  class Compare {
94  public:
95  bool operator() (const Swap_info &lhs, const Swap_info rhs) {
96  return lhs.estimated_delta > rhs.estimated_delta;
97  }
98  };
99 
100  public:
101  typedef std::priority_queue<
102  Swap_info,
103  std::vector<Swap_info>,
105 
106 
108  friend std::ostream& operator<< (std::ostream &log, const Swap_bk &data);
109 #if 0
110  {
111  auto q = data.m_swaps;
112  while (!q.empty()) {
113  log << q.top() << " ";
114  q.pop();
115  }
116  log << '\n';
117  return log;
118  }
119 #endif
120 
121  public:
122  Swap_bk() = default;
123  Swap_bk(const Swap_bk &bk) = default;
125  void push(const Swap_info& data) {m_swaps.push(data);}
126  Swap_info top() {return m_swaps.top();}
127  void pop() {return m_swaps.pop();}
128  bool empty() {return m_swaps.empty();}
129 };
130 
131 } // namespace vrp
132 } // namespace pgrouting
133 
134 #endif // INCLUDE_VRP_BOOK_KEEPING_H_
friend std::ostream & operator<<(std::ostream &log, const Swap_bk &data)
friend std::ostream & operator<<(std::ostream &log, const Swap_info &d)
std::priority_queue< Swap_info, std::vector< Swap_info >, Compare > Swaps_queue
Definition: book_keeping.h:104
Swaps_queue & possible_swaps()
Definition: book_keeping.h:124
Vehicle_pickDeliver from_truck
Definition: book_keeping.h:83
bool operator()(const Swap_info &lhs, const Swap_info rhs)
Definition: book_keeping.h:95
Vehicle_pickDeliver to_truck
Definition: book_keeping.h:84
void push(const Swap_info &data)
Definition: book_keeping.h:125