Skip to main contentIBM Quantum Documentation
This page is from an old version of Qiskit SDK and does not exist in the latest version. We recommend you migrate to the latest version. See the release notes for more information.
Important

IBM Quantum Platform is moving and this version will be sunset on July 1. To get started on the new platform, read the migration guide.

qiskit.optimization.applications.ising.vehicle_routing

Converts vehicle routing instances into a list of Paulis, and provides some related routines (extracting a solution, checking its objective function value).

Functions

get_operator(instance, n, K)Converts an instance of a vehicle routing problem into a list of Paulis.
get_vehiclerouting_cost(instance, n, K, x_sol)Computes the cost of a solution to an instance of a vehicle routing problem.
get_vehiclerouting_matrices(instance, n, K)Constructs auxiliary matrices from a vehicle routing instance,
get_vehiclerouting_solution(instance, n, K, …)Tries to obtain a feasible solution (in vector form) of an instance

get_operator

get_operator(instance, n, K)

GitHub

Converts an instance of a vehicle routing problem into a list of Paulis.

Parameters

  • instance (numpy.ndarray) – a customers-to-customers distance matrix.
  • n (integer) – the number of customers.
  • K (integer) – the number of vehicles available.

Returns

operator for the Hamiltonian.

Return type

WeightedPauliOperator

get_vehiclerouting_cost

get_vehiclerouting_cost(instance, n, K, x_sol)

GitHub

Computes the cost of a solution to an instance of a vehicle routing problem.

Parameters

  • instance (numpy.ndarray) – a customers-to-customers distance matrix.
  • n (integer) – the number of customers.
  • K (integer) – the number of vehicles available.
  • x_sol (numpy.ndarray) – a solution, i.e., a path, in its binary representation.

Returns

objective function value.

Return type

float

get_vehiclerouting_matrices

get_vehiclerouting_matrices(instance, n, K)

GitHub

Constructs auxiliary matrices from a vehicle routing instance,

which represent the encoding into a binary quadratic program. This is used in the construction of the qubit ops and computation of the solution cost.

Parameters

  • instance (numpy.ndarray) – a customers-to-customers distance matrix.
  • n (integer) – the number of customers.
  • K (integer) – the number of vehicles available.

Returns

a matrix defining the interactions between variables. a matrix defining the contribution from the individual variables. the constant offset.

Return type

tuple(numpy.ndarray, numpy.ndarray, float)

get_vehiclerouting_solution

get_vehiclerouting_solution(instance, n, K, result)

GitHub

Tries to obtain a feasible solution (in vector form) of an instance

of vehicle routing from the results dictionary.

Parameters

  • instance (numpy.ndarray) – a customers-to-customers distance matrix.
  • n (integer) – the number of customers.
  • K (integer) – the number of vehicles available.
  • result (dictionary) – a dictionary obtained by QAOA.run or VQE.run containing key ‘eigvecs’.

Returns

a solution, i.e., a path, in its binary representation.

Return type

numpy.ndarray

#TODO: support statevector simulation, results should be a statevector or counts format, not

a result from algorithm run

Was this page helpful?
Report a bug or request content on GitHub.