Composable Attribute System#
Runtime composition of VRP features without inheritance hierarchies.
Quick Start#
Python#
import routing
from routing.constants import Attribute
routing.init()
problem = routing.Problem()
# Depot
depot = problem.add_depot(0)
depot.add_attribute(Attribute.GEONODE, x=0, y=0)
depot.add_attribute(Attribute.RENDEZVOUS, open=0, close=1000)
# Vehicles
for v in range(3):
vehicle = problem.add_vehicle(v)
vehicle.add_attribute(Attribute.STOCK, capacity=100)
# Clients
client = problem.add_client(1)
client.add_attribute(Attribute.GEONODE, x=10, y=20)
client.add_attribute(Attribute.CONSUMER, demand=15)
client.add_attribute(Attribute.RENDEZVOUS, open=50, close=200)
client.add_attribute(Attribute.SERVICE_QUERY, service_time=10)
# Solve (constraints auto-activated!)
solution = routing.solve(problem, "ga", timeout=30)
C++#
#include <routing/routing.hpp>
int main() {
routing::Problem problem;
// Depot
auto* depot = problem.addDepot(0);
depot->addAttribute<routing::attributes::GeoNode>(0.0, 0.0);
depot->addAttribute<routing::attributes::Rendezvous>(0, 1000);
// Vehicles
for (int v = 0; v < 3; ++v) {
auto* vehicle = problem.addVehicle(v);
vehicle->addAttribute<routing::attributes::Stock>(100);
}
// Clients
auto* client = problem.addClient(1);
client->addAttribute<routing::attributes::GeoNode>(10.0, 20.0);
client->addAttribute<routing::attributes::Consumer>(15);
client->addAttribute<routing::attributes::Rendezvous>(50, 200);
client->addAttribute<routing::attributes::ServiceQuery>(10);
// Solve
routing::GASolver solver(&problem);
solver.solve(30.0);
return 0;
}
Available Attributes#
Attribute |
Entity |
Description |
|---|---|---|
|
Any |
Coordinates (x, y) |
|
Client |
Demand |
|
Vehicle |
Capacity |
|
Any |
Time window (open, close) |
|
Client |
Service time |
|
Client |
Profit (TOP) |
|
Client |
Pickup demand |
|
Client |
Delivery demand |
|
Client |
Synchronization |
Problem Types#
Problem |
Attributes |
|---|---|
TSP |
|
CVRP |
|
VRPTW |
|
CVRPTW |
|
TOP |
|
PDVRP |
|
How It Works#
Add attributes to entities
Constraints auto-activate based on attributes:
GeoNode→ Routing/distanceConsumer+Stock→ Capacity constraintsRendezvous→ Time windows
Solve with any solver
Custom Attributes (C++)#
// Define attribute
struct MyAttribute : public Attribute<MyAttribute> {
double value;
explicit MyAttribute(double v) : value(v) {}
};
// Use it
client->addAttribute<MyAttribute>(42.0);
See Plugins for full custom attribute guide.