Skip to content

Commit

Permalink
NL solution check #200 #237
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Aug 27, 2024
1 parent 787be6c commit 35ef588
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
5 changes: 3 additions & 2 deletions include/mp/flat/constr_2_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ class Constraints2Expr {
bool ConvertWithExpressions(
const ComplementarityConstraint<Expr>& con,
int i,
ConstraintAcceptanceLevel , ExpressionAcceptanceLevel ) { // TODO check acc for NLCompl
if (1==stage_cvt2expr_
ConstraintAcceptanceLevel , ExpressionAcceptanceLevel ) {
if (false // TODO check acc for NLCompl
&& 1==stage_cvt2expr_
&& !con.GetExpression().is_variable()) { // already a variable
ConvertComplementarityExpr(con, i);
return true;
Expand Down
2 changes: 2 additions & 0 deletions include/mp/flat/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ class FlatConverter :
/// if provided (>=0)
int AcceptanceLevelCommon() const { return options_.accAll_; }

public:
/// Option to actually use expressions if available
bool IfWantNLOutput() const { return options_.accExpr_==1; }

Expand All @@ -322,6 +323,7 @@ class FlatConverter :
ExpressionAcceptanceLevel::Recommended
== ModelAPI::ExpressionInterfaceAcceptanceLevel(); }

protected:
/// Finish exporting the reformulation graph
void CloseGraphExporter() {
value_presolver_.FinishExportingLinkEntries();
Expand Down
21 changes: 16 additions & 5 deletions include/mp/flat/sol_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class SolutionChecker {
try { // protect
std::vector<double> x_back = x;
if (MPCD( sol_check_mode() ) & (1+2+4+8+16)) {
if (MPCD( IfWantNLOutput() ))
x = RecomputeAuxVars(x, true); // Compute expressions
msgreal = DoCheckSol(x, duals, obj, {}, x_back, false);
}
if (MPCD( sol_check_mode() ) & (32+64+128+256+512)) {
Expand Down Expand Up @@ -64,8 +66,9 @@ class SolutionChecker {
// a summary in the final solve message.
// For now, do this via warnings?
if (MPCD( sol_check_fail() ))
MP_RAISE_WITH_CODE(int(sol::MP_SOLUTION_CHECK), // failure
warn);
MP_RAISE_WITH_CODE(int(sol::MP_SOLUTION_CHECK),
"Solution check failed - reporting as fatal:\n"
+ warn);
else
MPD( AddWarning(
MPD( GetEnv() ).GetSolCheckWarningKey(true),
Expand Down Expand Up @@ -108,7 +111,9 @@ class SolutionChecker {
};

/// Recompute auxiliary variables
ArrayRef<double> RecomputeAuxVars(ArrayRef<double> x) {
/// @param fExprOnly: only NL expressions
ArrayRef<double> RecomputeAuxVars(
ArrayRef<double> x, bool fExprOnly=false) {
VarInfoRecomp vir {
MPCD( sol_feas_tol() ),
true, // currently not relevant for recomputation
Expand All @@ -120,8 +125,14 @@ class SolutionChecker {
MPCD( sol_round() ), MPCD( sol_prec() )
};
vir.get_x().set_p_var_info(&vir);
for (auto i=vir.size(); i--; )
vir[i]; // touch the variable to be recomputed
if (fExprOnly) {
for (auto i=vir.size(); i--; )
if ( !MPCD( IsProperVar(i) ) )
vir[i]; // touch the variable to be recomputed
} else {
for (auto i=vir.size(); i--; )
vir[i];
}
return std::move(vir.get_x().get_x());
}

Expand Down

0 comments on commit 35ef588

Please sign in to comment.