QUBO container#
The binary optimisation container used by trust-aware task allocation.
A Qubo is the problem \(\min_x\, x^T Q x + \text{offset}\) over \(x \in \{0, 1\}^n\).
quantum_mind.applications.allocation.trust_aware_allocation() builds one from each person’s trust in
the robot, and small instances are solved exactly with Qubo.brute_force(). General-purpose problem
builders (max-cut, knapsack, portfolio) and solvers are left to dedicated optimisation libraries.
Classes
Quadratic unconstrained binary optimisation problem. |
- class Qubo(Q, offset=0.0, labels=<factory>, name='QUBO')[source]#
Bases:
objectQuadratic unconstrained binary optimisation problem.
Minimise \(x^T Q x + \text{offset}\) over \(x \in \{0, 1\}^n\).
- Parameters:
Q (
array_like) –(n, n)coefficient matrix (any square matrix; seenormalised()).offset (
float, optional) – Constant energy offset.labels (
listofstr, optional) – Variable names (defaultx0, x1, ...).name (
str, optional) – Problem name.
- energy(x)[source]#
Energy of bit strings.
- Parameters:
x (
array_like) – One bit string (1-D) or one per row (2-D).- Returns:
- all_energies()[source]#
Energies of all \(2^n\) bit strings.
Index k holds the bits of k with \(x_0\) the least significant bit (Qiskit ordering).
- Returns:
- Raises:
ValueError – If n > 22.
- brute_force()[source]#
Exact minimum by enumeration (small n).
- Returns:
x (
numpy.ndarray) – Optimal bit string.energy (
float)
- to_ising()[source]#
Equivalent Ising model with spins \(s = 1 - 2x \in \{+1, -1\}\).
- Returns:
h (
numpy.ndarray) – Local fields.J (
numpy.ndarray) – Upper-triangular couplings.c (
float) – Constant, so that energy \(= h \cdot s + \sum_{i<j} J_{ij} s_i s_j + c\).