PGROUTING  3.2
pgrouting::vrp::Tw_node Class Reference

Extends the Node class to create a Node with time window attributes. More...

#include "tw_node.h"

Inheritance diagram for pgrouting::vrp::Tw_node:
Collaboration diagram for pgrouting::vrp::Tw_node:

Public Types

enum  NodeType {
  kStart = 0, kPickup, kDelivery, kDump,
  kLoad, kEnd
}
 

Public Member Functions

 Tw_node ()=default
 
 Tw_node (const Tw_node &)=default
 
 Tw_node (size_t id, PickDeliveryOrders_t data, NodeType type)
 
 Tw_node (size_t id, Vehicle_t data, NodeType type)
 
double distance (const Dnode &other) const
 
int64_t id () const
 
size_t idx () const
 
void reset_id (int64_t)
 

Static Protected Member Functions

static Pgr_messagesmsg ()
 

Static Protected Attributes

static Pgr_pickDeliverproblem
 The problem. More...
 

Private Attributes

double m_closes
 closing time of the node More...
 
double m_demand
 The demand for the Node. More...
 
int64_t m_id
 
size_t m_idx
 
double m_opens
 opening time of the node More...
 
int64_t m_order
 order to which it belongs More...
 
double m_service_time
 
NodeType m_type
 The demand for the Node. More...
 
friend PD_problem
 

Friends

std::ostream & operator<< (std::ostream &log, const Tw_node &node)
 Print the contents of a Twnode object. More...
 

Detailed Description

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 type and streetid.

Definition at line 57 of file tw_node.h.

Member Enumeration Documentation

◆ NodeType

Enumerator
kStart 

starting site

kPickup 

pickup site

kDelivery 

delivery site

kDump 

dump site, empties truck

kLoad 

load site, fills the truck

kEnd 

ending site

Definition at line 59 of file tw_node.h.

59  {
60  kStart = 0,
61  kPickup,
62  kDelivery,
63  kDump,
64  kLoad,
65  kEnd
66  } NodeType;

Constructor & Destructor Documentation

◆ Tw_node() [1/4]

pgrouting::vrp::Tw_node::Tw_node ( )
default

◆ Tw_node() [2/4]

pgrouting::vrp::Tw_node::Tw_node ( const Tw_node )
default

◆ Tw_node() [3/4]

pgrouting::vrp::Tw_node::Tw_node ( size_t  id,
PickDeliveryOrders_t  data,
NodeType  type 
)

◆ Tw_node() [4/4]

pgrouting::vrp::Tw_node::Tw_node ( size_t  id,
Vehicle_t  data,
NodeType  type 
)

Definition at line 171 of file tw_node.cpp.

174  :
175  Dnode(id, data.start_node_id),
176  m_opens(data.start_open_t),
177  m_closes(data.start_close_t),
179  m_demand(0),
180  m_type(type) {
181  if (m_type == kEnd) {
182  reset_id(data.end_node_id);
183  m_opens = data.end_open_t;
184  m_closes = data.end_close_t;
186  }
187  }

References Vehicle_t::end_close_t, Vehicle_t::end_node_id, Vehicle_t::end_open_t, Vehicle_t::end_service_t, kEnd, m_closes, m_opens, m_service_time, m_type, and pgrouting::Identifier::reset_id().

Member Function Documentation

◆ arrival_j_opens_i()

double pgrouting::vrp::Tw_node::arrival_j_opens_i ( const Tw_node I,
double  speed 
) const

@ {

The actual arrival time at This node, given that: this node is visited directly after other node and that the actual arrival time at other node was opens(other)

Definition at line 50 of file tw_node.cpp.

50  {
51  if (m_type == kStart) return (std::numeric_limits<double>::max)();
52  return I.opens() + I.service_time() + I.travel_time_to(*this, speed);
53 }

References kStart, m_type, opens(), service_time(), and travel_time_to().

Referenced by is_compatible_IJ().

◆ closes()

double pgrouting::vrp::Tw_node::closes ( ) const
inline

◆ demand() [1/2]

double pgrouting::vrp::Tw_node::demand ( ) const
inline

Returns the demand associated with this node.

Definition at line 82 of file tw_node.h.

82 {return m_demand;}

References m_demand.

Referenced by pgrouting::vrp::Vehicle_node::evaluate(), is_delivery(), is_dump(), is_end(), is_pickup(), and is_start().

◆ demand() [2/2]

void pgrouting::vrp::Tw_node::demand ( double  value)
inline

Definition at line 83 of file tw_node.h.

83 {m_demand = value;}

References m_demand.

◆ distance()

double pgrouting::vrp::Dnode::distance ( const Dnode other) const
inherited

◆ id()

◆ idx()

◆ is_compatible_IJ()

bool pgrouting::vrp::Tw_node::is_compatible_IJ ( const Tw_node I,
double  speed 
) const

Definition at line 60 of file tw_node.cpp.

60  {
61  /*
62  * I /-> kStart
63  */
64  if (m_type == kStart) return false;
65  /*
66  * kEnd /-> (*this)
67  */
68  if (I.m_type == kEnd) return false;
69 
70  return !is_late_arrival(arrival_j_opens_i(I, speed));
71 }

References arrival_j_opens_i(), is_late_arrival(), kEnd, kStart, and m_type.

Referenced by pgrouting::vrp::Vehicle::getPosHighLimit(), pgrouting::vrp::Order::is_valid(), and pgrouting::vrp::Order::isCompatibleIJ().

◆ is_delivery()

bool pgrouting::vrp::Tw_node::is_delivery ( ) const

is_delivery

To be a delivery node:

  • type is kDelivery
  • demand < 0

Definition at line 106 of file tw_node.cpp.

106  {
107  return m_type == kDelivery
108  && (opens() < closes())
109  && (service_time() >= 0)
110  && (demand() < 0);
111 }

References closes(), demand(), kDelivery, m_type, opens(), and service_time().

Referenced by pgrouting::vrp::Order::is_valid().

◆ is_dump()

bool pgrouting::vrp::Tw_node::is_dump ( ) const

is_dump

To be a dump node:

  • type is kDump
  • demand <= 0

Definition at line 115 of file tw_node.cpp.

115  {
116  return m_type == kDump
117  && (opens() < closes())
118  && (service_time() >= 0)
119  && (demand() <= 0);
120 }

References closes(), demand(), kDump, m_type, opens(), and service_time().

Referenced by pgrouting::vrp::Vehicle_node::evaluate().

◆ is_early_arrival()

bool pgrouting::vrp::Tw_node::is_early_arrival ( double  arrival_time) const
inline

True when arrivalTime is before it opens.

Definition at line 179 of file tw_node.h.

179  {
180  return arrival_time < m_opens;
181  }

References m_opens.

Referenced by pgrouting::vrp::Vehicle_node::evaluate().

◆ is_end()

bool pgrouting::vrp::Tw_node::is_end ( ) const

is_end

To be a End node:

  • type is kEnd
  • demand == 0

Definition at line 126 of file tw_node.cpp.

126  {
127  return m_type == kEnd
128  && (opens() < closes())
129  && (service_time() >= 0)
130  && (demand() == 0);
131 }

References closes(), demand(), kEnd, m_type, opens(), and service_time().

Referenced by pgrouting::vrp::Fleet::add_vehicle(), and pgrouting::vrp::Vehicle_node::has_cv().

◆ is_late_arrival()

bool pgrouting::vrp::Tw_node::is_late_arrival ( double  arrival_time) const
inline

True when arrivalTime is after it closes.

Definition at line 184 of file tw_node.h.

184  {
185  return arrival_time > m_closes;
186  }

References m_closes.

Referenced by pgrouting::vrp::Vehicle_node::has_twv(), and is_compatible_IJ().

◆ is_pickup()

bool pgrouting::vrp::Tw_node::is_pickup ( ) const

is_pickup

To be a pickup node:

  • type is kPickup
  • demand > 0

Definition at line 97 of file tw_node.cpp.

97  {
98  return m_type == kPickup
99  && (opens() < closes())
100  && (service_time() >= 0)
101  && (demand() > 0);
102 }

References closes(), demand(), kPickup, m_type, opens(), and service_time().

Referenced by pgrouting::vrp::Order::is_valid().

◆ is_start()

bool pgrouting::vrp::Tw_node::is_start ( ) const

@ {

is_start

To be a start node:

  • type is kStart
  • demand == 0

Definition at line 88 of file tw_node.cpp.

88  {
89  return
90  m_type == kStart
91  && (opens() < closes())
92  && (service_time() >= 0)
93  && (demand() == 0);
94 }

References closes(), demand(), kStart, m_type, opens(), and service_time().

Referenced by pgrouting::vrp::Fleet::add_vehicle(), pgrouting::vrp::Vehicle_node::evaluate(), and pgrouting::vrp::Vehicle_node::has_cv().

◆ msg()

static Pgr_messages& pgrouting::vrp::Dnode::msg ( )
staticprotectedinherited

◆ opens()

double pgrouting::vrp::Tw_node::opens ( ) const
inline

◆ operator==()

bool pgrouting::vrp::Tw_node::operator== ( const Tw_node rhs) const

Definition at line 135 of file tw_node.cpp.

135  {
136  if (&other == this) return true;
137  return m_order == other.m_order
138  && m_opens == other.m_opens
139  && m_closes == other.m_closes
140  && m_service_time == other.m_service_time
141  && m_demand == other.m_demand
142  && m_type == other.m_type
143  && id() == other.id()
144  && idx() == other.idx();
145 }

References pgrouting::Identifier::id(), pgrouting::Identifier::idx(), m_closes, m_demand, m_opens, m_order, m_service_time, and m_type.

◆ order()

int64_t pgrouting::vrp::Tw_node::order ( ) const
inline

@ {

Returns the opening time.

Definition at line 73 of file tw_node.h.

73 {return m_order;}

References m_order.

◆ reset_id()

void pgrouting::Identifier::reset_id ( int64_t  _id)
inherited

Definition at line 47 of file identifier.cpp.

47  {
48  m_id = _id;
49 }

References pgrouting::Identifier::m_id.

Referenced by Tw_node().

◆ service_time()

double pgrouting::vrp::Tw_node::service_time ( ) const
inline

Returns the service time for this node.

Definition at line 86 of file tw_node.h.

86 {return m_service_time;}

References m_service_time.

Referenced by arrival_j_opens_i(), pgrouting::vrp::Vehicle_node::evaluate(), is_delivery(), is_dump(), is_end(), is_pickup(), is_start(), and pgrouting::vrp::operator<<().

◆ travel_time_to()

double pgrouting::vrp::Tw_node::travel_time_to ( const Tw_node other,
double  speed 
) const

time = distance / speed.

Definition at line 40 of file tw_node.cpp.

40  {
41  pgassert(speed != 0);
42  return distance(to) / speed;
43 }

References pgrouting::vrp::Dnode::distance(), and pgassert.

Referenced by arrival_j_opens_i(), and pgrouting::vrp::operator<<().

◆ type()

NodeType pgrouting::vrp::Tw_node::type ( ) const
inline

Returns the type of this node.

Definition at line 89 of file tw_node.h.

89 {return m_type;}

References m_type.

Referenced by type_str().

◆ type_str()

std::string pgrouting::vrp::Tw_node::type_str ( ) const

Definition at line 75 of file tw_node.cpp.

75  {
76  switch (type()) {
77  case kStart: return "START"; break;
78  case kEnd: return "END"; break;
79  case kDump: return "DUMP"; break;
80  case kLoad: return "LOAD"; break;
81  case kPickup: return "PICKUP"; break;
82  case kDelivery: return "DELIVERY"; break;
83  default: return "UNKNOWN";
84  }
85 }

References kDelivery, kDump, kEnd, kLoad, kPickup, kStart, and type().

Referenced by pgrouting::vrp::operator<<().

◆ window_length()

double pgrouting::vrp::Tw_node::window_length ( ) const
inline

Returns the length of time between the opening and closing.

Definition at line 92 of file tw_node.h.

92 {return m_closes - m_opens;}

References m_closes, and m_opens.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  log,
const Tw_node node 
)
friend

Print the contents of a Twnode object.

Definition at line 191 of file tw_node.cpp.

191  {
192  log << n.id()
193  << "[opens = " << n.m_opens
194  << "\tcloses = " << n.m_closes
195  << "\tservice = " << n.m_service_time
196  << "\tdemand = " << n.m_demand
197  << "\ttype = " << n.type_str()
198  << "]"
199  << "\n";
200  return log;
201 }

Member Data Documentation

◆ m_closes

double pgrouting::vrp::Tw_node::m_closes
private

closing time of the node

Definition at line 227 of file tw_node.h.

Referenced by closes(), is_late_arrival(), pgrouting::vrp::operator<<(), operator==(), Tw_node(), and window_length().

◆ m_demand

double pgrouting::vrp::Tw_node::m_demand
private

The demand for the Node.

Definition at line 229 of file tw_node.h.

Referenced by demand(), pgrouting::vrp::operator<<(), operator==(), and Tw_node().

◆ m_id

int64_t pgrouting::Identifier::m_id
privateinherited

Definition at line 53 of file identifier.h.

Referenced by pgrouting::Identifier::id(), and pgrouting::Identifier::reset_id().

◆ m_idx

size_t pgrouting::Identifier::m_idx
privateinherited

Definition at line 52 of file identifier.h.

Referenced by pgrouting::Identifier::idx().

◆ m_opens

double pgrouting::vrp::Tw_node::m_opens
private

opening time of the node

Definition at line 226 of file tw_node.h.

Referenced by is_early_arrival(), opens(), pgrouting::vrp::operator<<(), operator==(), Tw_node(), and window_length().

◆ m_order

int64_t pgrouting::vrp::Tw_node::m_order
private

order to which it belongs

Definition at line 225 of file tw_node.h.

Referenced by operator==(), and order().

◆ m_service_time

double pgrouting::vrp::Tw_node::m_service_time
private

Definition at line 228 of file tw_node.h.

Referenced by pgrouting::vrp::operator<<(), operator==(), service_time(), and Tw_node().

◆ m_type

NodeType pgrouting::vrp::Tw_node::m_type
private

The demand for the Node.

Definition at line 230 of file tw_node.h.

Referenced by arrival_j_opens_i(), is_compatible_IJ(), is_delivery(), is_dump(), is_end(), is_pickup(), is_start(), operator==(), Tw_node(), and type().

◆ PD_problem

friend pgrouting::vrp::Dnode::PD_problem
privateinherited

Definition at line 49 of file dnode.h.

◆ problem

Pgr_pickDeliver * pgrouting::vrp::Dnode::problem
staticprotectedinherited

The problem.

Definition at line 70 of file dnode.h.

Referenced by pgrouting::vrp::Dnode::distance(), and pgrouting::vrp::PD_problem::PD_problem().


The documentation for this class was generated from the following files:
Vehicle_t::end_service_t
double end_service_t
Definition: vehicle_t.h:61
pgrouting::tsp::Dmatrix::get_index
size_t get_index(int64_t id) const
original id -> idx
Definition: Dmatrix.cpp:93
PickDeliveryOrders_t::demand
double demand
Definition: pickDeliveryOrders_t.h:47
pgrouting::vrp::Dnode::distance
double distance(const Dnode &other) const
Definition: dnode.cpp:43
Vehicle_t::start_open_t
double start_open_t
Definition: vehicle_t.h:51
pgrouting::vrp::Tw_node::kDump
@ kDump
dump site, empties truck
Definition: tw_node.h:63
pgrouting::vrp::Tw_node::m_type
NodeType m_type
The demand for the Node.
Definition: tw_node.h:230
pgrouting::vrp::Dnode::problem
static Pgr_pickDeliver * problem
The problem.
Definition: dnode.h:70
Vehicle_t::end_close_t
double end_close_t
Definition: vehicle_t.h:60
pgrouting::vrp::Tw_node::kDelivery
@ kDelivery
delivery site
Definition: tw_node.h:62
PickDeliveryOrders_t::id
int64_t id
Definition: pickDeliveryOrders_t.h:46
pgrouting::vrp::Tw_node::kStart
@ kStart
starting site
Definition: tw_node.h:60
Vehicle_t::end_open_t
double end_open_t
Definition: vehicle_t.h:59
pgrouting::vrp::Tw_node::demand
double demand() const
Returns the demand associated with this node.
Definition: tw_node.h:82
pgrouting::vrp::Tw_node::m_opens
double m_opens
opening time of the node
Definition: tw_node.h:226
Vehicle_t::start_close_t
double start_close_t
Definition: vehicle_t.h:52
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgrouting::Identifier::idx
size_t idx() const
Definition: identifier.cpp:37
pgrouting::vrp::Tw_node::arrival_j_opens_i
double arrival_j_opens_i(const Tw_node &I, double speed) const
@ {
Definition: tw_node.cpp:50
pgrouting::vrp::Pgr_pickDeliver::get_cost_matrix
pgrouting::tsp::Dmatrix get_cost_matrix() const
Definition: pgr_pickDeliver.h:92
pgrouting::vrp::Tw_node::kEnd
@ kEnd
ending site
Definition: tw_node.h:65
Vehicle_t::end_node_id
int64_t end_node_id
Definition: vehicle_t.h:57
pgrouting::Identifier::id
int64_t id() const
Definition: identifier.cpp:42
Vehicle_t::start_service_t
double start_service_t
Definition: vehicle_t.h:53
PickDeliveryOrders_t::deliver_close_t
double deliver_close_t
Definition: pickDeliveryOrders_t.h:62
pgrouting::vrp::Tw_node::closes
double closes() const
Returns the closing time.
Definition: tw_node.h:79
pgrouting::vrp::Tw_node::m_service_time
double m_service_time
Definition: tw_node.h:228
pgrouting::vrp::Tw_node::kLoad
@ kLoad
load site, fills the truck
Definition: tw_node.h:64
PickDeliveryOrders_t::deliver_service_t
double deliver_service_t
Definition: pickDeliveryOrders_t.h:63
pgrouting::vrp::Tw_node::kPickup
@ kPickup
pickup site
Definition: tw_node.h:61
PickDeliveryOrders_t::pick_open_t
double pick_open_t
Definition: pickDeliveryOrders_t.h:53
pgrouting::vrp::Tw_node::m_order
int64_t m_order
order to which it belongs
Definition: tw_node.h:225
pgrouting::vrp::Tw_node::m_closes
double m_closes
closing time of the node
Definition: tw_node.h:227
PickDeliveryOrders_t::deliver_open_t
double deliver_open_t
Definition: pickDeliveryOrders_t.h:61
pgrouting::Identifier::m_idx
size_t m_idx
Definition: identifier.h:52
pgrouting::Identifier::m_id
int64_t m_id
Definition: identifier.h:53
pgrouting::Identifier::reset_id
void reset_id(int64_t)
Definition: identifier.cpp:47
pgrouting::vrp::Tw_node::is_late_arrival
bool is_late_arrival(double arrival_time) const
True when arrivalTime is after it closes.
Definition: tw_node.h:184
pgrouting::vrp::Tw_node::opens
double opens() const
Returns the opening time.
Definition: tw_node.h:76
pgrouting::vrp::Tw_node::service_time
double service_time() const
Returns the service time for this node.
Definition: tw_node.h:86
Vehicle_t::start_node_id
int64_t start_node_id
Definition: vehicle_t.h:47
PickDeliveryOrders_t::pick_service_t
double pick_service_t
Definition: pickDeliveryOrders_t.h:55
pgrouting::tsp::Dmatrix::distance
double distance(int64_t i, int64_t j) const
Definition: Dmatrix.h:108
PickDeliveryOrders_t::pick_node_id
int64_t pick_node_id
Definition: pickDeliveryOrders_t.h:51
pgrouting::vrp::Dnode::Dnode
Dnode()=default
PickDeliveryOrders_t::deliver_node_id
int64_t deliver_node_id
Definition: pickDeliveryOrders_t.h:59
PickDeliveryOrders_t::pick_close_t
double pick_close_t
Definition: pickDeliveryOrders_t.h:54
pgrouting::vrp::Tw_node::type
NodeType type() const
Returns the type of this node.
Definition: tw_node.h:89
pgrouting::vrp::Tw_node::NodeType
NodeType
Definition: tw_node.h:59
pgrouting::vrp::Tw_node::m_demand
double m_demand
The demand for the Node.
Definition: tw_node.h:229