From e752dfce215b2fe5093bdb58ba18fbb306c84cd4 Mon Sep 17 00:00:00 2001 From: Gleb Belov Date: Tue, 22 Aug 2023 15:51:59 +1000 Subject: [PATCH] sol:chk:mode = none/warn/fail #200 --- include/mp/flat/converter.h | 22 +++++++++++++------ .../categorized/fast/tech/modellist.json | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/include/mp/flat/converter.h b/include/mp/flat/converter.h index b1a06e07a..793bfa238 100644 --- a/include/mp/flat/converter.h +++ b/include/mp/flat/converter.h @@ -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 @@ -1029,7 +1029,7 @@ class FlatConverter : int relax_ = 0; - bool solcheckfail_ = false; + int solcheckmode_ = 1; double solfeastol_ = 1e-6; double solinttol_ = 1e-5; }; @@ -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()); @@ -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. " @@ -1191,7 +1198,8 @@ class FlatConverter : ArrayRef x, const pre::ValueMapDbl& y, ArrayRef 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 diff --git a/test/end2end/cases/categorized/fast/tech/modellist.json b/test/end2end/cases/categorized/fast/tech/modellist.json index 8d4bdad88..2f5eb4e45 100644 --- a/test/end2end/cases/categorized/fast/tech/modellist.json +++ b/test/end2end/cases/categorized/fast/tech/modellist.json @@ -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