quast_decisiontree.problems.classes.qubo
quast_decisiontree.problems.classes.qubo
General QUBO problem
QUBO
Bases: OptimizationProblem
class representing an instance of a general quadratic unconstrained binary optimization problem
Source code in src/quast_decisiontree/problems/classes/qubo.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
direct_encoding_modes
class-attribute
instance-attribute
direct_encoding_modes = ('QUBO',)
alias
class-attribute
instance-attribute
alias = ['QUBO']
matrix_modes
class-attribute
instance-attribute
matrix_modes = ['symmetric', 'upper_triangular', 'raw']
coeff_tol
class-attribute
instance-attribute
coeff_tol = 1e-05
qubo_matrix
property
writable
qubo_matrix
num_nodes
property
num_nodes
matrix_mode
property
writable
matrix_mode
__init__
__init__(qubo_matrix, matrix_mode='symmetric')
initializes a qubo instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qubo_matrix
|
ndarray
|
the QUBO matrix of the instance |
required |
matrix_mode
|
str
|
A str indicating the form of the matrix stored in the instance. Options are: - "symmetric" (default): symmetrize the QUBO matrix - "upper_triangular": turn it into an upper triangular matrix - "raw": allow any kind of QUBO matrix |
'symmetric'
|
Source code in src/quast_decisiontree/problems/classes/qubo.py
32 33 34 35 36 37 38 39 40 41 42 43 44 | |
create_random_instance
classmethod
create_random_instance(
size,
seed=None,
min_coeff=0,
max_coeff=10,
density=1,
negative_diag=True,
int_coeffs=False,
matrix_mode="symmetric",
)
create a random QUBO instance. Parameters: size (int) : How many variables are contained in the QUBO seed (Any) : seed passed on to the random numbers generator min_coeff (float): lower bound of the coefficients drawn randomly. Default 0. max_coeff (float): upper bound of the coefficients drawn randomly. Default 10. density (float): If between 0 and 1, sets the (mean) density of the off-diagonal components. Values larger than 1 are treated as 1, values smaller than 0 will result in a diagonal QUBO (that is, a trivial binary linear problem). Default 1. negative_diag (bool): whether the diagonal should be drawn from the interval (-max_coeff, -min_coeff). Default True. int_coeffs (bool): whether the coeffs should be integer. Default False. matrix_mode (str): a matrix mode from QUBO.matrix_modes to be passed to the constructor of the instance. Since the random numbers generated are upper triangular, there is no difference between 'raw' and 'upper_triangular' modes.
Returns:
| Type | Description |
|---|---|
|
a randomly created QUBO instance |
Source code in src/quast_decisiontree/problems/classes/qubo.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
from_dict
classmethod
from_dict(problem_dict)
constructs the QUBO from dict.
Raises:
| Type | Description |
|---|---|
InvalidProblemDictError
|
If the required 'qubo_matrix' key is missing. |
Source code in src/quast_decisiontree/problems/classes/qubo.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
__eq__
__eq__(other)
checks whether the QUBOs are equal.
Permutations of variables is not recognized as equal.
Source code in src/quast_decisiontree/problems/classes/qubo.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
to_dict
to_dict()
converts the QUBO instance to a dictionary.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary. Content: |
dict
|
"problem_class" : "QUBO" |
|
dict
|
"qubo_matrix": the QUBO matrix |
|
dict
|
"matrix_mode": the stored matrix mode |
Source code in src/quast_decisiontree/problems/classes/qubo.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
evaluate_objective
evaluate_objective(result)
Source code in src/quast_decisiontree/problems/classes/qubo.py
196 197 198 199 200 201 | |
formulate_problem
formulate_problem(mode='QUBO')
Source code in src/quast_decisiontree/problems/classes/qubo.py
203 204 205 | |