csnlp.Solution#
- class csnlp.Solution(*args, **kwargs)[source]#
Bases:
Protocol[SymType]Class containing information on the solution of a solver’s run for an instance of
csnlp.Nlp.Notes
This class is merely a protocol, and as such it just defines the interface of how a solution should look like, plus some minor implementations.
Methods
cmp_key(sol)Gets the comparison keys to compare a solution with another.
from_casadi_solution(sol_with_stats, nlp)Creates a new solution from a CasADi solution,
value(expr[, eval])Computes the value of the expression substituting the values of this solution in the expression.
Attributes
Gets the IPOPT barrier parameter at the optimal solution
Optimal values of the dual variables.
Symbolical dual variables.
Optimal value of the objective function.
Gets whether the solver status indicates infeasibility.
Optimal values of the equality and inequality dual variables in a vector.
Symbolical the equality and inequality dual variables in a vector.
Optimal values of the lower- and upper-bounds dual variables in a vector.
Symbolical lower- and upper-bounds dual variables in a vector.
Values of the parameters for which this solver's solution was generated.
Symbolical parameters in a vector.
The solver plugin used to generate this solution.
Statistics of the solver for this solution's run.
Gets the status of the solver at this solution.
Gets whether the solver's run was successful.
Gets the unified status of the solver at this solution.
Optimal values of the primal variables.
Symbolical primal variables.
Optimal values of the primal variables in a vector.
Optimal values of the primal and dual variables, as well as the parameters for which the solution was found, in a vector.
Symbolical primal and dual variables and parameters in a vector.
Symbolical primal variables in a vector.
- static cmp_key(sol)[source]#
Gets the comparison keys to compare a solution with another. This solution is strictly better if
it is feasible and the other is not, or
- both are feasible or infeasible, and the current is successful and the other
is not, or
- both are successful or not, and the current has a lower optimal value than the
other.
To be used as
keyargument in, e.g.,minorsorted.- Returns:
- tuple of (bool, bool, float)
A tuple with (is_infeasible, is_unsuccessful, f).
- static from_casadi_solution(sol_with_stats, nlp)[source]#
Creates a new solution from a CasADi solution,
- Parameters:
- sol_with_statsdict of (str, cs.DM) and one entry with stats, i.e., Any
The solution dictionary from the CasADi solver, which contains the optimal values of the primal and dual variables, as well as the parameters, and the solver’s statistics.
- nlpNlp[SymType]
The NLP instance for which the solution was computed.
- Returns:
- Solution[SymType]
The solution corresponding to the CasADi solution.
- Return type:
- property infeasible: bool | None#
Gets whether the solver status indicates infeasibility. If
False, it does not imply feasibility as the solver or its CasADi interface may have not detect it.For different solvers, the infeasibility status is stored in different ways. Here is a list of what I gathered so far. The solvers are grouped based on the type of problem they solve. An (F) next to the solver’s name indicates that the the solver will crash the program if
"error_on_fail": Trueand the solver fails. Thestatusandunified_return_statuscan both be found in the solver’s stats, or in this solution object.NLPs
fatrop: unclear; better to return
Nonefor nowipopt:
status == "Infeasible_Problem_Detected"qrsqp (F):
status == "Search_Direction_Becomes_Too_Small"(dubious)sqpmethod (F):
status == "Search_Direction_Becomes_Too_Small"(dubious)
QPs
ipqp (F): no clear way to detect infeasibility; return
Nonefor nowosqp (F):
unified_return_status == "SOLVER_RET_INFEASIBLE"or"infeasible" in statusproxqp (F):
status == "PROXQP_PRIMAL_INFEASIBLE"orstatus == "PROXQP_DUAL_INFEASIBLE"qpoases (F):
"infeasib" in statusqrqp (F):
status == "Failed to calculate search direction"
LPs
clp (F):
status == "primal infeasible"orstatus == "dual infeasible"
Mixed-Iteger Problems (MIPs)
bonmin (F):
status == "INFEASIBLE"cbc (F):
"not feasible" in statusgurobi (F):
status == "INFEASIBLE"orstatus == "INF_OR_UNBD"knitro:
"INFEAS" in status
- property lam_g_and_h: DM#
Optimal values of the equality and inequality dual variables in a vector.
- property lam_g_and_h_sym: DM#
Symbolical the equality and inequality dual variables in a vector.
- property lam_lbx_and_ubx: DM#
Optimal values of the lower- and upper-bounds dual variables in a vector.
- property lam_lbx_and_ubx_sym: DM#
Symbolical lower- and upper-bounds dual variables in a vector.
- property p: DM#
Values of the parameters for which this solver’s solution was generated.
- property p_sym: DM#
Symbolical parameters in a vector.
- value(expr, eval=True)[source]#
Computes the value of the expression substituting the values of this solution in the expression.
- Parameters:
- exprcasadi.SX, MX or an array of these
The symbolic expression to be evaluated at the solution’s values.
- evalbool, optional
Evaluates numerically the new expression. By default,
True. Seecsnlp.solutions.subsevalffor more details.
- Returns:
- casadi.SX or MX or DM
The expression evaluated with the solution’s values.
- Raises:
- RuntimeError
Raises if
eval=Truebut there are symbolic variables that are still free. This can occur when there are symbols that are outside the solution’s variables, and thus have not been substituted by a numerical value.
- Return type:
Union[TypeVar(SymType,SX,MX),DM]
- property x: DM#
Optimal values of the primal variables in a vector.
- property x_and_lam_and_p: DM#
Optimal values of the primal and dual variables, as well as the parameters for which the solution was found, in a vector.
- property x_and_lam_and_p_sym: SymType#
Symbolical primal and dual variables and parameters in a vector.
- property x_sym: SymType#
Symbolical primal variables in a vector.