QuadraticProgram.substitute_variables¶
- QuadraticProgram.substitute_variables(constants=None, variables=None)[source]¶
Substitutes variables with constants or other variables.
- Parameters:
constants (
Optional
[Dict
[Union
[int
,str
],float
]]) – replace variable by constant e.g.,{'x': 2}
meansx
is substituted with 2variables (
Optional
[Dict
[Union
[str
,int
],Tuple
[Union
[str
,int
],float
]]]) – replace variables by weighted other variable need to copy everything using name reference to make sure that indices are matched correctly. The lower and upper bounds are updated accordingly. e.g.,{'x': ('y', 2)}
meansx
is substituted withy * 2
- Return type:
- Returns:
An optimization problem by substituting variables with constants or other variables. If the substitution is valid,
QuadraticProgram.status
is stillQuadraticProgram.Status.VALID
. Otherwise, it getsQuadraticProgram.Status.INFEASIBLE
.- Raises:
QiskitOptimizationError – if the substitution is invalid as follows. - Same variable is substituted multiple times. - Coefficient of variable substitution is zero.