File: tw_node.hpp

package info (click to toggle)
pgrouting 4.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,332 kB
  • sloc: cpp: 21,315; sql: 10,419; ansic: 9,795; perl: 1,142; sh: 919; javascript: 314; xml: 182; makefile: 29
file content (235 lines) | stat: -rw-r--r-- 6,009 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*PGR-GNU*****************************************************************
File: tw_node.hpp

Copyright (c) 2016-2026 pgRouting developers
Mail: project@pgrouting.org

------

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

 ********************************************************************PGR-GNU*/

/*! @file */

#ifndef INCLUDE_VRP_TW_NODE_HPP_
#define INCLUDE_VRP_TW_NODE_HPP_
#pragma once

#include <string>
#include <cstdint>

#include "cpp_common/orders_t.hpp"
#include "cpp_common/vehicle_t.hpp"
#include "cpp_common/assert.hpp"
#include "cpp_common/identifier.hpp"

#include "vrp/pd_problem.hpp"
#include "vrp/dnode.hpp"

namespace pgrouting {
namespace vrp {


/*! @class Tw_node
 * @brief Extends the Node class to create a Node with time window attributes.
 *
 * A Time Window node is a Node with addition attributes and methods to
 * to support Time Windows and to model a more complex Node need in many
 * vehicle routing problems.
 *
 * Most application specific code will extend this class and define the specific
 * values and requirements for @c type and @c streetid.
 *
 */
class Tw_node : public Dnode {
 public:
     typedef enum {
         kStart = 0,  ///< starting site
         kPickup,  ///< pickup site
         kDelivery,  ///< delivery site
         kDump,  ///< dump site, empties truck
         kLoad,  ///< load site, fills the truck
         kEnd        ///< ending site
     } NodeType;


     /** @name accessors */
     ///@{

     /*! @brief Returns the opening time.*/
     inline int64_t order() const {return m_order;}

     /*! @brief Returns the opening time.*/
     inline double opens() const {return m_opens;}

     /*! @brief Returns the closing time. */
     inline double closes() const {return m_closes;}

     /*! @brief Returns the demand associated with this node. */
     inline double demand() const {return m_demand;}
     inline void demand(double value) {m_demand = value;}

     /*! * @brief Returns the service time for this node. */
     inline double service_time() const {return m_service_time;}

     /*! * @brief Returns the type of this node. */
     inline NodeType type() const {return m_type;}

     /*! @brief Returns the length of time between the opening and closing. */
     inline double window_length() const {return m_closes - m_opens;}

     /*! @brief time = distance / speed. */
     double travel_time_to(const Tw_node &other, double speed) const;

     ///@}

     /** @name kind of node
      *
      * A true value when;
      *
      *   - 0 < opens < closes
      *   - the type is the requested type
      *   - the demand are valid for the requested type
      */

     ///@{


     /*! @brief is_start
      *
      * To be a start node:
      *   - type is kStart
      *   - demand == 0
      *
      **/
     bool is_start() const;


     /*! @brief is_pickup
      *
      * To be a pickup node:
      *   - type is kPickup
      *   - demand > 0
      *
      **/
     bool is_pickup() const;


     /*! @brief is_delivery
      *
      * To be a delivery node:
      *   - type is kDelivery
      *   - demand < 0
      *
      **/
     bool is_delivery() const;


     /*! @brief is_dump
      *
      * To be a dump node:
      *   - type is kDump
      *   - demand <= 0
      *
      **/
     bool is_dump() const;




     /*! @brief is_end
      *
      * To be a End node:
      *   - type is kEnd
      *   - demand == 0
      *
      **/
     bool is_end() const;


     std::string type_str() const;

     /*!@}*/


     /*! * @brief Print the contents of a Twnode object. */
     friend std::ostream& operator<< (std::ostream &log, const Tw_node &node);

     /*! @name to be or not to be
      * @{
      */
     bool operator ==(const Tw_node &rhs) const;



     /*! @brief True when @b arrivalTime is before it @b opens */
     inline bool is_early_arrival(double arrival_time) const {
         return arrival_time < m_opens;
     }

     /*! @brief True when @b arrivalTime is after it @b closes */
     inline bool is_late_arrival(double arrival_time) const {
         return arrival_time > m_closes;
     }


     /** @name document functions */
     ///@{
     /*!
      * The actual arrival time at @b This node, given that:
      * @b this node is visited directly after @b other node
      *   and that the actual arrival time at @b other node was opens(other)
      **/
     double arrival_j_opens_i(const Tw_node &I, double speed) const;



     /*
      * is possible to arrive to @b this after visiting @bother
      *   - departing as early as possible from @b other it can arrives to @b this
      */
     bool is_compatible_IJ(const Tw_node &I, double speed) const;



     ///@}



     Tw_node() = default;
     Tw_node(
             size_t id,
             Orders_t data,
             NodeType type);
     Tw_node(
             size_t id,
             Vehicle_t data,
             NodeType type);


 private:
     int64_t m_order;       ///< order to which it belongs
     double m_opens;        ///< opening time of the node
     double m_closes;       ///< closing time of the node
     double m_service_time;  // /< time it takes to be served
     double m_demand;       ///< The demand for the Node
     NodeType m_type;       ///< The demand for the Node
};

}  //  namespace vrp
}  //  namespace pgrouting

#endif  // INCLUDE_VRP_TW_NODE_HPP_