corneto.backend package#
Module contents#
- class corneto.backend.Backend(default_solver=None, sparse_class=<class 'scipy.sparse._csr.csr_array'>)#
Bases:
ABC
- static get_symbols(expressions)#
- abstract Variable(name=None, shape=None, lb=None, ub=None, vartype=VarType.CONTINUOUS)#
Create a variable for optimization.
This method defines an optimization variable with optional bounds, type, and additional graph-related properties.
- Parameters:
name (Optional[str]) – The name of the variable. Defaults to None.
shape (Optional[Tuple[int, ...]]) – The shape of the variable as a tuple. Defaults to None.
lb (Optional[Union[float, np.ndarray]]) – The lower bound of the variable. Can be a scalar or an array. Defaults to None.
ub (Optional[Union[float, np.ndarray]]) – The upper bound of the variable. Can be a scalar or an array. Defaults to None.
vartype (VarType) – The type of the variable (e.g., continuous, integer). Defaults to VarType.CONTINUOUS.
- Returns:
The created variable symbol, to be used in further expressions or constraints.
- Return type:
CSymbol
- abstract Parameter(name=None, shape=None, value=None)#
- Problem(constraints=None, objectives=None, expressions=None, weights=None, direction=Direction.MIN)#
- solve(p, solver=None, max_seconds=None, warm_start=False, verbosity=0, **options)#
- Flow(g, lb=0, ub=10, n_flows=1, values=False, shared_bounds=False, varname='_flow', create_nonzero_indicators=False, alias_flow='flow', alias_flow_ipos='positive_flow', alias_flow_ineg='negative_flow', alias_nonzero_flow='with_flow', indicator_tolerance=0.0001)#
- Return type:
ProblemDef
- Parameters:
- AcyclicFlow(g, lb=0, ub=10, values=False, max_parents=None, vertex_lb_dist=None, varname='_flow', alias_flow='flow', alias_flow_ipos='positive_flow', alias_flow_ineg='negative_flow', alias_nonzero_flow='with_flow', indicator_tolerance=0.0001)#
- Return type:
ProblemDef
- Parameters:
- Indicator(V, indexes=None, suffix='_i', name=None)#
- NonZeroIndicator(V, indexes=None, suffix_pos='_ipos', suffix_neg='_ineg', tolerance=0.001)#
- Indicators(V, tolerance=0.001, positive=True, negative=True, suffix_pos='_ipos', suffix_neg='_ineg')#
- Return type:
ProblemDef
- Parameters:
V (CSymbol)
- Xor(x, y, varname='_xor')#
- Parameters:
x (CExpression)
y (CExpression)
- class corneto.backend.VarType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#
-
- INTEGER = 'integer'#
- CONTINUOUS = 'continuous'#
- BINARY = 'binary'#
- class corneto.backend.CvxpyBackend(default_solver=None, sparse_class=<class 'scipy.sparse._csr.csr_array'>)#
Bases:
Backend
- Variable(name=None, shape=None, lb=None, ub=None, vartype=VarType.CONTINUOUS)#
Create a variable for optimization.
This method defines an optimization variable with optional bounds, type, and additional graph-related properties.
- Parameters:
name (Optional[str]) – The name of the variable. Defaults to None.
shape (Optional[Tuple[int, ...]]) – The shape of the variable as a tuple. Defaults to None.
lb (Optional[Union[float, np.ndarray]]) – The lower bound of the variable. Can be a scalar or an array. Defaults to None.
ub (Optional[Union[float, np.ndarray]]) – The upper bound of the variable. Can be a scalar or an array. Defaults to None.
vartype (VarType) – The type of the variable (e.g., continuous, integer). Defaults to VarType.CONTINUOUS.
- Returns:
The created variable symbol, to be used in further expressions or constraints.
- Return type:
CSymbol
- Parameter(name=None, shape=None, value=None)#
- class corneto.backend.PicosBackend(default_solver=None)#
Bases:
Backend
- Parameters:
default_solver (str | None)
- Variable(name=None, shape=None, lb=None, ub=None, vartype=VarType.CONTINUOUS, variable=True)#
Create a variable for optimization.
This method defines an optimization variable with optional bounds, type, and additional graph-related properties.
- Parameters:
name (Optional[str]) – The name of the variable. Defaults to None.
shape (Optional[Tuple[int, ...]]) – The shape of the variable as a tuple. Defaults to None.
lb (Optional[Union[float, np.ndarray]]) – The lower bound of the variable. Can be a scalar or an array. Defaults to None.
ub (Optional[Union[float, np.ndarray]]) – The upper bound of the variable. Can be a scalar or an array. Defaults to None.
vartype (VarType) – The type of the variable (e.g., continuous, integer). Defaults to VarType.CONTINUOUS.
variable (bool)
- Returns:
The created variable symbol, to be used in further expressions or constraints.
- Return type:
CSymbol