CVRPProblem¶
- class CVRPProblem(cost_matrix, *, demands, capacity, n_vehicles, depot=0, encoding='one_hot', constraint_penalty=4.0, objective_weight=1.0, capacity_penalty=4.0, max_steps=None)[source]¶
Bases:
_RoutingProblemBaseCapacitated Vehicle Routing Problem for QAOA.
Supports two encodings:
"one_hot"— block one-hot with W-state + XY mixer."binary"— compact binary (HUBO) with Hadamard + X mixer, reducing qubit count from O(N) to O(log N) per slot.
- Parameters:
cost_matrix (
ndarray[tuple[Any,...],dtype[floating]]) – Symmetric distance/cost matrix of shape(n, n).demands (
ndarray[tuple[Any,...],dtype[floating]]) – Customer demands (length = n_nodes, depot demand = 0).capacity (
float) – Vehicle capacity.n_vehicles (
int) – Number of vehicles.depot (
int) – Index of the depot node. Defaults to 0.encoding (
Literal['one_hot','binary']) –"one_hot"or"binary". Defaults to"one_hot".constraint_penalty (
float) – Constraint penalty strength. Defaults to 4.0.objective_weight (
float) – Objective weight. Defaults to 1.0.capacity_penalty (
float) – Capacity penalty strength. Defaults to 4.0.max_steps (
int|None) – Maximum route length per vehicle ("binary"encoding only).None(default) usesn_customers. Qubit count and HUBO term count both scale withn_vehicles * max_steps; loweringmax_stepsbelow a vehicle’s actual stop count renders the instance infeasible.
Attributes Summary
Map a measurement bitstring to a domain-level solution.
Recommended initial quantum state for this problem.
Methods Summary
compute_energy(bitstring)Evaluate the objective energy for a bitstring.
is_feasible(bitstring)Check whether a bitstring represents a feasible solution.
repair_infeasible_bitstring(bitstring)Repair an infeasible bitstring into a feasible one.
Attributes Documentation
- binary_config¶
- decode_fn¶
- encoding¶
- recommended_initial_state¶
Methods Documentation
- compute_energy(bitstring)[source]¶
Evaluate the objective energy for a bitstring.
Defaults to
None(unknown).
- is_feasible(bitstring)[source]¶
Check whether a bitstring represents a feasible solution.
Defaults to
True(unconstrained).- Return type:
- repair_infeasible_bitstring(bitstring)[source]¶
Repair an infeasible bitstring into a feasible one.
- Returns:
repaired_bitstring: The feasible bitstring after repair.
decoded: Domain-level solution (e.g. tour list, routes), or
Noneif unavailable.energy: Objective value of the repaired solution, or
Noneif unknown.
- Return type:
The default implementation returns the bitstring unchanged.