QuadraticObjective¶
- class QuadraticObjective(quadratic_program, constant=0.0, linear=None, quadratic=None, sense=ObjSense.MINIMIZE)[source]¶
Bases:
QuadraticProgramElement
Representation of quadratic objective function of the form: constant + linear * x + x * quadratic * x.
Constructs a quadratic objective function.
- Parameters:
quadratic_program (Any) – The parent quadratic program.
constant (float) – The constant offset of the objective.
linear (ndarray | spmatrix | list[float] | dict[str | int, float] | None) – The coefficients of the linear part of the objective.
quadratic (ndarray | spmatrix | list[list[float]] | dict[tuple[int | str, int | str], float] | None) – The coefficients of the quadratic part of the objective.
sense (ObjSense) – The optimization sense of the objective.
Attributes
- constant¶
Returns the constant part of the objective function.
- Returns:
The constant part of the objective function.
- linear¶
Returns the linear part of the objective function.
- Returns:
The linear part of the objective function.
- quadratic¶
Returns the quadratic part of the objective function.
- Returns:
The quadratic part of the objective function.
- quadratic_program¶
Returns the parent QuadraticProgram.
- Returns:
The parent QuadraticProgram.
- sense¶
Returns the sense of the objective function.
- Returns:
The sense of the objective function.
Methods
- evaluate(x)[source]¶
Evaluate the quadratic objective for given variable values.
- Parameters:
x (ndarray | list | dict[int | str, float]) – The values of the variables to be evaluated.
- Returns:
The value of the quadratic objective given the variable values.
- Raises:
QiskitOptimizationError – if the shape of the objective function does not match with the number of variables.
- Return type:
- evaluate_gradient(x)[source]¶
Evaluate the gradient of the quadratic objective for given variable values.
- Parameters:
x (ndarray | list | dict[int | str, float]) – The values of the variables to be evaluated.
- Returns:
The value of the gradient of the quadratic objective given the variable values.
- Raises:
QiskitOptimizationError – if the shape of the objective function does not match with the number of variables.
- Return type:
ndarray