grid.Edge

class grid.Edge(node_from, node_to, distance=None, travel_time=None)[source]

Bases: object

Directed arc of the routing graph between two Node instances.

Holds attributes used to model travel distance and time between nodes.

Parameters:
  • node_from (Node) – Source node of the edge.

  • node_to (Node) – Destination node of the edge.

  • distance (float) – Travel distance along the edge.

  • travel_time (float) – Travel time along the edge.

transitions

Transitions registered on this edge via add_transition().

Type:

list of Transition

constraints

Constraints registered on this edge via add_constraint().

Type:

list of Constraint

Examples

>>> import grid
>>> model = grid.RoutingModel()
>>> a = model.add_node(id=0, depot=True)
>>> b = model.add_node(id=1, demand=3)
>>> edge = model.add_edge(node_from=a, node_to=b, distance=4)
>>> edge.distance
4
__init__(node_from, node_to, distance=None, travel_time=None)[source]
Parameters:

Methods

__init__(node_from, node_to[, distance, ...])

add_constraint(constraint)

Register a boolean precondition required to traverse this edge.

add_transition(var, expression)

Register a variable update applied when the edge is traversed.

add_constraint(constraint)[source]

Register a boolean precondition required to traverse this edge.

Parameters:

constraint (Expr) – Boolean expression that must evaluate to true for the edge to be traversed.

Examples

>>> import grid
>>> model = grid.RoutingModel()
>>> a = model.add_node(id=0, depot=True)
>>> b = model.add_node(id=1, demand=3)
>>> edge = model.add_edge(node_from=a, node_to=b, distance=4)
>>> vehicle = model.add_vehicle_type(id=0, count=1, capacity=10)
>>> battery = vehicle.add_float_var(initial_value=100.0, preference="high")
>>> edge.add_constraint(battery - 4 >= 0)
>>> len(edge.constraints)
1
add_transition(var, expression)[source]

Register a variable update applied when the edge is traversed.

Parameters:
  • var (Var) – The decision variable to update.

  • expression (Expr or int or float or bool) – Expression assigned to var. Python literals are automatically wrapped into a Const.

Examples

>>> import grid
>>> model = grid.RoutingModel()
>>> a = model.add_node(id=0, depot=True)
>>> b = model.add_node(id=1, demand=3)
>>> edge = model.add_edge(node_from=a, node_to=b, distance=4)
>>> vehicle = model.add_vehicle_type(id=0, count=1, capacity=10)
>>> battery = vehicle.add_float_var(initial_value=100.0, preference="high")
>>> edge.add_transition(var=battery, expression=battery - 4)
>>> len(edge.transitions)
1