Skip to content

Commit

Permalink
sol:chk:mode = none/warn/fail #200
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Aug 22, 2023
1 parent a53f9e4 commit e752dfc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
22 changes: 15 additions & 7 deletions include/mp/flat/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ class FlatConverter :
// a summary in the final solve message.
// For now, do this via warnings?
if (chk.HasAnyViols()) {
if (options_.solcheckfail_)
if (2 == options_.solcheckmode_)
MP_RAISE_WITH_CODE(520, // numeric error
chk.GetReport());
else
Expand Down Expand Up @@ -1029,7 +1029,7 @@ class FlatConverter :

int relax_ = 0;

bool solcheckfail_ = false;
int solcheckmode_ = 1;
double solfeastol_ = 1e-6;
double solinttol_ = 1e-5;
};
Expand All @@ -1054,6 +1054,14 @@ class FlatConverter :


private:
const mp::OptionValueInfo values_solchk_[3] = {
{ "0", "No solution check (e.g., with feasrelax.)", 0},
{ "1",
"Warn if tolerances or logical constraints "
"violated (default.)", 1},
{ "2", "Fail on violations.", 2}
};

void InitOwnOptions() {
/// Should be called after adding all constraint keepers
FlatModel::ConsiderAcceptanceOptions(*this, GetModelAPI(), GetEnv());
Expand Down Expand Up @@ -1105,10 +1113,9 @@ class FlatConverter :
GetEnv().AddOption("alg:relax relax",
"0*/1: Whether to relax integrality of variables.",
options_.relax_, 0, 1);
GetEnv().AddOption("sol:chk:fail solcheckfail checkfail chk:fail",
"Fail if solution violates tolerances "
"(normally only warning).",
options_.solcheckfail_, false, true);
GetEnv().AddStoredOption("sol:chk:mode solcheck checkmode chk:mode",
"Solution checking mode:\n" "\n.. value-table::\n",
options_.solcheckmode_, values_solchk_);
GetEnv().AddOption("sol:chk:feastol sol:chk:eps sol:eps chk:eps",
"Solution checking tolerance for objective values, variable "
"and constraint bounds. Default 1e-6. "
Expand Down Expand Up @@ -1191,7 +1198,8 @@ class FlatConverter :
ArrayRef<double> x,
const pre::ValueMapDbl& y,
ArrayRef<double> obj) -> bool {
return this->CheckSolution(x, y, obj);
return !this->options_.solcheckmode_ // not desired
|| this->CheckSolution(x, y, obj);
}
};
pre::CopyLink copy_link_ { GetValuePresolver() }; // the copy links
Expand Down
4 changes: 2 additions & 2 deletions test/end2end/cases/categorized/fast/tech/modellist.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
"objective": 88.2
},
{
"name" : "Check sol:chk:fail",
"name" : "Check sol:chk:mode",
"tags" : ["linear", "feasrelax"],
"files" : ["infeas_int_01.mod"],
"options": {
"ANYSOLVER_options":
"sol:chk:fail sol:chk:feastol=1e-7 sol:chk:inttol=1e-4 feasrelax=1"
"sol:chk:mode=2 sol:chk:feastol=1e-7 sol:chk:inttol=1e-4 feasrelax=1"
},
"values": {
"solve_result_num": 520
Expand Down

0 comments on commit e752dfc

Please sign in to comment.