mqt.problemsolver.qubo_tools.pathfinder.cost_functions¶
Includes all cost functions supported by the pathfinding QuboGenerator.
Module Contents¶
- GetVariableFunction¶
- SetCallback¶
- class EncodingType[source]¶
Bases:
enum.EnumThe encoding types supported for the QUBO generation.
- ONE_HOT = 1¶
- DOMAIN_WALL = 2¶
- BINARY = 3¶
- class A[source]¶
Bases:
sympy.FunctionCustom sympy function for the adjacency matrix.
A(v, w) represents the weight of edge (v, w).
- class X[source]¶
Bases:
sympy.FunctionCustom sympy function for the encoding variables.
x(p, v, i) represents a single binary variable. Its meaning depends on the encoding type.
- class Decompose[source]¶
Bases:
sympy.FunctionCustom sympy function for the decomposition of an integer into its binary digits.
Example
Decompose(5, 1) represents digit 1 of the binary string 101, i.e., 1.
- doit(**_hints: Any) sympy.Expr[source]¶
Evaluate objects that are not evaluated by default like limits, integrals, sums and products. All objects of this kind will be evaluated recursively, unless some species were excluded via ‘hints’ or unless the ‘deep’ hint was set to ‘False’.
>>> from sympy import Integral >>> from sympy.abc import x
>>> 2*Integral(x, x) 2*Integral(x, x)
>>> (2*Integral(x, x)).doit() x**2
>>> (2*Integral(x, x)).doit(deep=False) 2*Integral(x, x)
- class ExpandingSum[source]¶
Bases:
sympy.SumRepresents a sum that is always expanded into a sum of its elements when calling doit().
- args: tuple[sympy.Expr, tuple[sympy.Symbol, sympy.Expr, sympy.Expr]]¶
Returns a tuple of arguments of ‘self’.
Examples¶
>>> from sympy import cot >>> from sympy.abc import x, y
>>> cot(x).args (x,)
>>> cot(x).args[0] x
>>> (x*y).args (x, y)
>>> (x*y).args[1] y
Notes¶
Never use self._args, always use self.args. Only use _args in __new__ when creating a new function. Do not override .args() from Basic (so that it is easy to change the interface in the future if needed).
- doit(**_hints: Any) sympy.Expr[source]¶
Evaluate objects that are not evaluated by default like limits, integrals, sums and products. All objects of this kind will be evaluated recursively, unless some species were excluded via ‘hints’ or unless the ‘deep’ hint was set to ‘False’.
>>> from sympy import Integral >>> from sympy.abc import x
>>> 2*Integral(x, x) 2*Integral(x, x)
>>> (2*Integral(x, x)).doit() x**2
>>> (2*Integral(x, x)).doit(deep=False) 2*Integral(x, x)
- class SumSet(expr: sympy.Expr, element_expr: sympy.Expr, latex: _StringForSumSet)[source]¶
Bases:
sympy.ExprA class that can be used to represent a sum over a set.
This is just a symbolic representation for the display of the equation. In the background, it stores the actual expanded sum that is used for calculations.
- expr: sympy.Expr¶
- element_expr: sympy.Expr¶
- latex: _StringForSumSet¶
- class FormulaHelpers[source]¶
Provides static methods for the more efficient construction of sympy formulas.
- static sum_from_to(expression: sympy.Expr, var: str, from_number: sympy.Expr | float, to_number: sympy.Expr | float) sympy.Expr[source]¶
Generates a sum of the form Sum(expression, (var, from_number, to_number).
- static prod_from_to(expression: sympy.Expr, var: str, from_number: sympy.Expr | float, to_number: sympy.Expr | float) sympy.Expr[source]¶
Generates a product of the form Product(expression, (var, from_number, to_number).
- Parameters:
expression – The term inside the sum.
var – The iteration variable of the sum as a string.
from_number – The lower bound of the sum.
to_number – The upper bound of the sum.
- Returns:
The sympy sum term.
- static sum_set(expression: sympy.Expr, variables: list[str], latex: str, callback: SetCallback) sympy.Expr[source]¶
Generates a sum of the form sum_{[variables] in [callback]} [expression].
- Parameters:
expression – The term inside the sum.
variables – A list of iteration variables of the sum as strings.
latex – The LaTex representation of the set expression.
callback – A callback returning the set over which the sum should iterate.
- Returns:
The sympy sum term.
- static adjacency(v: int | str | sympy.Expr, w: int | str | sympy.Expr) sympy.Expr[source]¶
Returns an access to the adjacency matrix with indices v and w.
v and w may be of type int, str, or sympy expressions.
- static variable(name: str) sympy.Symbol[source]¶
Returns a variable with the given name.
- Parameters:
name (str) – The name of the variable.
- Returns:
The generated variable.
- Return type:
sp.Symbol
- static get_encoding_variable_one_hot(path: str | int | sympy.Expr, vertex: str | int | sympy.Expr, position: str | int | sympy.Expr, _num_vertices: int = 0) sympy.Expr[source]¶
Returns an access to the binary variable x_{path, vertex, position} that represents the statement “Vertex vertex is located at position position in path path” for One-Hot encoding.
All indices can be integers, strings, or sympy expressions. The _num_vertices parameter is only included for compatibility.
- Parameters:
path (Any) – The path index.
vertex (Any) – The vertex index.
position (Any) – The position index.
_num_vertices (int, optional) – The number of vertices in the graph. Defaults to 0.
- Returns:
An expression representing the statement “Vertex vertex is located at position position in path path” for One-Hot encoding.
- Return type:
sp.Expr
- static get_encoding_variable_domain_wall(path: str | int | sympy.Expr, vertex: str | int | sympy.Expr, position: str | int | sympy.Expr, _num_vertices: int = 0) sympy.Expr[source]¶
Returns an expression representing the statement “Vertex vertex is located at position position in path path” for Domain-Wall encoding.
All indices can be integers, strings, or sympy expressions. The _num_vertices parameter is only included for compatibility.
- Parameters:
path (Any) – The path index.
vertex (Any) – The vertex index.
position (Any) – The position index.
_num_vertices (int, optional) – The number of vertices in the graph. Defaults to 0.
- Returns:
An expression representing the statement “Vertex vertex is located at position position in path path” for Domain-Wall encoding.
- Return type:
sp.Function
- static get_encoding_variable_binary(path: str | int | sympy.Expr, vertex: str | int | sympy.Expr, position: str | int | sympy.Expr, num_vertices: int = 0) sympy.Expr[source]¶
Returns an expression representing the statement “Vertex vertex is located at position position in path path” for Binary encoding.
All indices can be integers, strings, or sympy expressions. The _num_vertices parameter is only included for compatibility.
- Parameters:
path (Any) – The path index.
vertex (Any) – The vertex index.
position (Any) – The position index.
num_vertices (int, optional) – The number of vertices in the graph. Defaults to 0.
- Returns:
An expression representing the statement “Vertex vertex is located at position position in path path” for Binary encoding.
- Return type:
sp.Function
- static get_for_each_path(expression: sympy.Expr, paths: list[int]) sympy.Expr[source]¶
Returns a sum iterating over the given expression for each path in paths.
- static get_for_each_position(expression: sympy.Expr, path_size: int) sympy.Expr[source]¶
Returns a sum iterating over the given expression for each possible index in the path.
- Parameters:
expression (sp.Expr) – The expression to sum up.
path_size (int) – The maximum length of a path.
- Returns:
A sum of the expression for each position.
- Return type:
sp.Expr
- class CostFunction[source]¶
Bases:
abc.ABCAn abstract base class for cost functions.
Represents a cost function that can be translated into a QUBO expression.
- get_formula(graph: Graph, settings: PathFindingQuboGeneratorSettings) sympy.Expr[source]¶
Translates the cost function into a QUBO expression.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- abstractmethod get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- get_formula_one_hot(graph: Graph, settings: PathFindingQuboGeneratorSettings) sympy.Expr[source]¶
Computes the QUBO expression for the cost function for One-Hot encoding.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- get_formula_domain_wall(graph: Graph, settings: PathFindingQuboGeneratorSettings) sympy.Expr[source]¶
Computes the QUBO expression for the cost function for Domain-Wall encoding.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- get_formula_binary(graph: Graph, settings: PathFindingQuboGeneratorSettings) sympy.Expr[source]¶
Computes the QUBO expression for the cost function for Binary encoding.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class CompositeCostFunction(*parts: tuple[CostFunction, int])[source]¶
Bases:
CostFunctionA composite cost function that is the sum of multiple cost functions.
- summands¶
A list of tuples of cost functions and their weights.
- Type:
list[tuple[CostFunction, int]]
- summands: list[tuple[CostFunction, int]]¶
- __str__() str[source]¶
Returns a string representation of the cost function.
- Returns:
A string representation of the cost function.
- Return type:
- get_formula(graph: Graph, settings: PathFindingQuboGeneratorSettings) sympy.Expr[source]¶
Translates the cost function into a QUBO expression.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class PathPositionIs(position: int, vertex_ids: list[int], path: int)[source]¶
Bases:
CostFunctionA cost function that penalises paths that do not contain a given vertex at a given position.
- vertex_ids¶
The list of vertices, one of which must be located at the given position.
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class PathStartsAt(vertex_ids: list[int], path: int)[source]¶
Bases:
PathPositionIsA cost function that penalises paths that do not start at a given vertex.
- class PathEndsAt(vertex_ids: list[int], path: int)[source]¶
Bases:
CostFunctionA cost function that penalises paths that do not end at a given vertex.
- vertex_ids¶
The list of vertices, one of which must be located at the end of the path.
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class PathContainsVertices(min_occurrences: int, max_occurrences: int, vertex_ids: list[int], path_ids: list[int])[source]¶
Bases:
CostFunctionA cost function that penalises paths that do not contain a given set of vertices.
- class PathContainsVerticesExactlyOnce(vertex_ids: list[int], path_ids: list[int])[source]¶
Bases:
PathContainsVerticesA cost function that penalises paths that do not contain a given set of vertices exactly once.
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class PathContainsVerticesAtLeastOnce(vertex_ids: list[int], path_ids: list[int])[source]¶
Bases:
PathContainsVerticesA cost function that penalises paths that do not contain a given set of vertices at least once.
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class PathContainsVerticesAtMostOnce(vertex_ids: list[int], path_ids: list[int])[source]¶
Bases:
PathContainsVerticesA cost function that penalises paths that do not contain a given set of vertices at most once.
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class PathContainsEdges(min_occurrences: int, max_occurrences: int, edges: list[tuple[int, int]], path_ids: list[int])[source]¶
Bases:
CostFunctionA cost function that penalises paths that do not contain a given set of edges.
- class PathContainsEdgesExactlyOnce(edges: list[tuple[int, int]], path_ids: list[int])[source]¶
Bases:
PathContainsEdgesA cost function that penalises paths that do not contain a given set of edges exactly once.
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class PathContainsEdgesAtLeastOnce(edges: list[tuple[int, int]], path_ids: list[int])[source]¶
Bases:
PathContainsEdgesA cost function that penalises paths that do not contain a given set of edges at least once.
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class PathContainsEdgesAtMostOnce(edges: list[tuple[int, int]], path_ids: list[int])[source]¶
Bases:
PathContainsEdgesA cost function that penalises paths that do not contain a given set of edges at most once.
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class PathBound(path_ids: list[int])[source]¶
Bases:
CostFunctionAn abstract cost function for penalties limited to an individual path.
- class PrecedenceConstraint(pre: int, post: int, path_ids: list[int])[source]¶
Bases:
PathBoundA cost function that penalises paths that do not satisfy a given precedence constraint.
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class PathComparison(path_one: int, path_two: int)[source]¶
Bases:
CostFunctionAn abstract cost function for penalties that compare two paths.
path_two (int): The second path.
Bases:
PathComparisonA cost function that penalises paths that share vertices.
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
Bases:
PathComparisonA cost function that penalises paths that share edges.
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class PathIsValid(path_ids: list[int])[source]¶
Bases:
PathBoundA cost function that penalises paths that are not valid for a given encoding.
- A path may be invalid if
it contains an edge that is not in the graph,
- it has an assignment incompatible with the encoding:
for One-Hot encoding, multiple vertices are assigned to a single position
for Domain-Wall encoding, a position bit string is of the form 1…10…1…0
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- get_formula_one_hot(graph: Graph, settings: PathFindingQuboGeneratorSettings) sympy.Expr[source]¶
Computes the QUBO expression for the cost function for One-Hot encoding.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- get_formula_domain_wall(graph: Graph, settings: PathFindingQuboGeneratorSettings) sympy.Expr[source]¶
Computes the QUBO expression for the cost function for Domain-Wall encoding.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- get_formula_binary(graph: Graph, settings: PathFindingQuboGeneratorSettings) sympy.Expr[source]¶
Computes the QUBO expression for the cost function for Binary encoding.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class MinimizePathLength(path_ids: list[int])[source]¶
Bases:
PathBoundA cost function that penalises paths based on their length.
A bigger total weight causes a bigger penalty.
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- class MaximizePathLength(path_ids: list[int])[source]¶
Bases:
PathBoundA cost function that penalises paths based on their length.
A lower total weight causes a bigger penalty.
- get_formula_general(graph: Graph, settings: PathFindingQuboGeneratorSettings, get_variable_function: GetVariableFunction) sympy.Expr[source]¶
Returns the QUBO expression for the cost function in the general case.
In the general case, the cost function may access the blackbox function get_variable_function(p, v, i) that returns 1 if vertex v is located at position i in path p and 0 otherwise.
- Parameters:
graph (Graph) – The graph on which the cost function should be applied.
settings (PathFindingQuboGeneratorSettings) – The settings of the QUBO generator.
get_variable_function (GetVariableFunction) – The blackbox function for accessing the encoding variables.
- Returns:
An expression representing the cost function as a QUBO function.
- Return type:
sp.Expr
- merge(cost_functions: list[CostFunction], optimisation_goals: list[CostFunction]) CompositeCostFunction[source]¶
Merges a list of cost functions and a list of optimisation criteria into a single cost function.
- Parameters:
cost_functions (list[CostFunction]) – The list of cost functions.
optimisation_goals (list[CostFunction]) – The optimisation criteria.
- Returns:
The resulting cost function.
- Return type: