qiskit_addon_opt_mapper.applications.VehicleRouting¶
- class VehicleRouting(graph, num_vehicles=2, depot=0)[source]¶
Bases:
GraphOptimizationApplicationOptimization application for the “vehicle routing problem” [1] based on a
NetworkXgraph.References
[1]: “Vehicle routing problem”, https://en.wikipedia.org/wiki/Vehicle_routing_problem
Init method.
- Parameters:
Methods
__init__(graph[, num_vehicles, depot])Init method.
create_random_instance(n[, low, high, seed, ...])Create a random instance of the vehicle routing problem.
draw([result, pos])Draw a graph with the result.
interpret(result)Interpret a result as a list of the routes for each vehicle.
sample_most_likely(state_vector)Compute the most likely binary string from state vector.
Represent as an optimization problem.
Attributes
Getter of depot.
Getter of the graph.
Getter of num_vehicles.
Getter of the graph in Networkx format.
- static create_random_instance(n, low=0, high=100, seed=None, num_vehicle=2, depot=0)[source]¶
Create a random instance of the vehicle routing problem.
- Parameters:
n (int) – the number of nodes.
low (int) – The minimum value for the coordinate of a node.
high (int) – The maximum value for the coordinate of a node.
seed (int | None) – the seed for the random coordinates.
num_vehicle (int) – The number of the vehicles
depot (int) – The index of the depot node where all the vehicle depart
- Returns:
A VehicleRouting instance created from the input information
- Return type:
- property depot: int¶
Getter of depot.
- Returns:
The node index of the depot where all the vehicles depart
- draw(result=None, pos=None)[source]¶
Draw a graph with the result.
When the result is None, draw an original graph without colors.
- property nx_graph: Graph¶
Getter of the graph in Networkx format.
- Returns:
A graph for a problem
- static sample_most_likely(state_vector)[source]¶
Compute the most likely binary string from state vector.
- Parameters:
state_vector (QuasiDistribution | Statevector | ndarray | dict) – state vector or counts or quasi-probabilities.
- Returns:
binary string as numpy.ndarray of ints.
- Raises:
ValueError – if state_vector is not QuasiDistribution, Statevector, np.ndarray, or dict.
- Return type: