diff --git a/include/mp/flat/constr_base.h b/include/mp/flat/constr_base.h index a5e73cfb2..b440abba1 100644 --- a/include/mp/flat/constr_base.h +++ b/include/mp/flat/constr_base.h @@ -10,6 +10,7 @@ #include "mp/format.h" #include "mp/error.h" +#include "mp/common.h" #include "mp/flat/context.h" #include "mp/arrayref.h" @@ -346,6 +347,11 @@ class ConditionalConstraint : } }; +/// Write a readable variable definition +template +void WriteVar(Writer& pr, const char* name, + double lb, double ub, var::Type ty); + /// Write a CondCon template inline void WriteJSON(JW jw, diff --git a/include/mp/flat/converter.h b/include/mp/flat/converter.h index acd82da5b..f1914c07d 100644 --- a/include/mp/flat/converter.h +++ b/include/mp/flat/converter.h @@ -503,8 +503,8 @@ class FlatConverter : MPD( CloseGraphExporter() ); if (value_presolver_.GetExport()) assert( value_presolver_.AllEntriesExported() ); -// if (GetEnv().verbose_mode()) - GetEnv().PrintWarnings(); +// Printing always. if (GetEnv().verbose_mode()) + GetEnv().PrintWarnings(); } /// Check linear constraints. diff --git a/include/mp/flat/converter_model.h b/include/mp/flat/converter_model.h index 6afdd0908..2d1a12b78 100644 --- a/include/mp/flat/converter_model.h +++ b/include/mp/flat/converter_model.h @@ -88,8 +88,13 @@ class FlatModel MiniJSONWriter jw(wrt); int i_actual = i+i_start; jw["VAR_index"] = i_actual; - if (var_names_storage_.size() > i) + if (var_names_storage_.size() > i_actual) { + int i = i_actual; jw["name"] = var_names_[i]; + fmt::MemoryWriter pr; + WriteVar(pr, var_names_[i], lbs[i], ubs[i], types[i]); + jw["printed"] = pr.c_str(); + } jw["bounds"] << (lbs[i] < -DBL_MAX ? -DBL_MAX : lbs[i]) << (ubs[i] > DBL_MAX ? DBL_MAX : ubs[i]); diff --git a/include/mp/problem.h b/include/mp/problem.h index 0ee36ee37..ed8d3060f 100644 --- a/include/mp/problem.h +++ b/include/mp/problem.h @@ -478,43 +478,43 @@ class BasicProblem : public ExprFactory, public SuffixManager { /// Normal variable name const std::string& var_name(int i) { assert(0<=i && i& names, + int n, const char* stub, + int n2=std::numeric_limits::max(), + const char* stub2=nullptr); + +public: /** Returns the variable names (if present). * After normal variables follow defined variables. */ diff --git a/src/problem.cc b/src/problem.cc index f10d59aac..1ca59c64e 100644 --- a/src/problem.cc +++ b/src/problem.cc @@ -112,7 +112,43 @@ void BasicProblem::SetInfo(const NLProblemInfo &info) { nonlinear_exprs_.reserve(num_common_exprs); } -/// Instantiate +template +const std::string& BasicProblem::item_name( + int i, std::vector& names, + int n, const char* stub, int n2, const char* stub2) { + assert(0<=i && i=0 && n2; template void ReadNLFile(fmt::CStringRef filename, Problem &p, int flags); diff --git a/src/std_constr.cc b/src/std_constr.cc index faa51fe1f..ed8f8364a 100644 --- a/src/std_constr.cc +++ b/src/std_constr.cc @@ -1,8 +1,10 @@ #include +#include #include #include "mp/format.h" #include "mp/util-json-write.hpp" +#include "mp/common.h" #include "mp/flat/expr_quadratic.h" #include "mp/flat/model_info.hpp" @@ -70,6 +72,31 @@ void QuadTerms::sort_terms() { } } +template +void WriteVar(Writer& pr, const char* name, + double lb, double ub, var::Type ty) { + assert(*name); + pr << "var " << name; + if (!lb && 1.0==ub && var::INTEGER==ty) + pr << " binary"; + else if (lb==ub) + pr << " = " << lb; + else { + if (lb >= -DBL_MAX) + pr << " >=" << lb; + if (ub <= DBL_MAX) + pr << " <=" << ub; + if (var::INTEGER == ty) + pr << " integer"; + } + pr << ';'; +} + +// Generate +template +void WriteVar(fmt::MemoryWriter& pr, const char* name, + double lb, double ub, var::Type ty); + template <> void WriteJSON(JSONW jw, const QuadTerms& qt) { jw["coefs"] = qt.coefs(); diff --git a/test/end2end/cases/categorized/fast/suf_common/modellist.json b/test/end2end/cases/categorized/fast/suf_common/modellist.json index e09e788e1..c5332ae56 100644 --- a/test/end2end/cases/categorized/fast/suf_common/modellist.json +++ b/test/end2end/cases/categorized/fast/suf_common/modellist.json @@ -31,6 +31,14 @@ "solve_result_num": 0 } }, + { + "name": "mipbound_01 objno=0 writegraph", + "tags": [ "linear", "return_mipgap"], + "options": { "ANYSOLVER_options": "objno=0 writegraph=mipb_01.jsonl" }, + "values": { + "solve_result_num": 0 + } + }, { "name" : "dietu_stt sensitivity=1", "objective" : 74.273820,