1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
|
// * -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Gleb Belov <gleb.belov@monash.edu>
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <minizinc/exception.hh>
#include <minizinc/solvers/MIP/MIP_scip_wrap.hh>
#include <minizinc/utils.hh>
#include <array>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
using namespace std;
/// Load SCIP DLL with the given path
ScipPlugin::ScipPlugin(const std::string& dll) : _inner(dll) { load(); }
/// Load SCIP DLL with default search paths on Windows
ScipPlugin::ScipPlugin()
: _inner(
#ifdef _WIN32
{
"libscip",
"scip",
"C:\\Program Files\\SCIPOptSuite 9.2.4\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.2.3\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.2.2\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.2.1\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.2.0\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.1.4\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.1.3\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.1.2\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.1.1\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.1.0\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.0.4\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.0.3\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.0.2\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.0.1\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 9.0.0\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 8.1.0\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 8.0.4\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 8.0.3\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 8.0.2\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 8.0.1\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 8.0.0\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 7.0.3\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 7.0.2\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 7.0.1\\bin\\libscip.dll",
"C:\\Program Files\\SCIPOptSuite 7.0.0\\bin\\libscip.dll",
"C:\\Program Files (x86)\\SCIPOptSuite 7.0.1\\bin\\scip.dll",
"C:\\Program Files (x86)\\SCIPOptSuite 7.0.0\\bin\\scip.dll",
}
#else
std::vector<std::string>({
"libscip",
"/home/linuxbrew/.linuxbrew/lib/libscip.so",
"/opt/homebrew/lib/libscip.dylib",
})
#endif
) {
load();
}
void ScipPlugin::load() {
load_symbol_dynamic(_inner, SCIPmajorVersion);
load_symbol_dynamic(_inner, SCIPminorVersion);
load_symbol_dynamic(_inner, SCIPtechVersion);
load_symbol_dynamic(_inner, SCIPsubversion);
load_symbol_dynamic(_inner, SCIPprintError);
load_symbol_dynamic(_inner, SCIPcreate);
load_symbol_dynamic(_inner, SCIPincludeDefaultPlugins);
load_symbol_dynamic(_inner, SCIPcreateProbBasic);
load_symbol_dynamic(_inner, SCIPfree);
load_symbol_dynamic(_inner, SCIPcreateVarBasic);
load_symbol_dynamic(_inner, SCIPaddVar);
load_symbol_dynamic(_inner, SCIPreleaseVar);
load_symbol_dynamic(_inner, SCIPinfinity);
load_symbol_dynamic(_inner, SCIPcreateConsBasicLinear);
load_symbol_dynamic(_inner, SCIPcreateConsBasicQuadratic);
load_symbol_dynamic(_inner, SCIPaddCons);
load_symbol_dynamic(_inner, SCIPreleaseCons);
load_symbol_dynamic(_inner, SCIPchgVarLbGlobal);
load_symbol_dynamic(_inner, SCIPchgVarUbGlobal);
load_symbol_dynamic(_inner, SCIPgetNegatedVar);
load_symbol_dynamic(_inner, SCIPcreateConsBasicIndicator);
load_symbol_dynamic(_inner, SCIPcreateConsBasicBounddisjunction);
load_symbol_dynamic(_inner, SCIPcreateConsBasicCumulative);
load_symbol_dynamic(_inner, SCIPcreateConsBasicOrbisack);
load_symbol_dynamic(_inner, SCIPcreateConsBasicOrbitope);
load_symbol_dynamic(_inner, SCIPgetNSolsFound);
load_symbol_dynamic(_inner, SCIPgetNSols);
load_symbol_dynamic(_inner, SCIPsetIntParam);
load_symbol_dynamic(_inner, SCIPsetRealParam);
load_symbol_dynamic(_inner, SCIPwriteOrigProblem);
load_symbol_dynamic(_inner, SCIPsetMessagehdlrQuiet);
load_symbol_dynamic(_inner, SCIPmessagehdlrCreate);
load_symbol_dynamic(_inner, SCIPsetMessagehdlr);
load_symbol_dynamic(_inner, SCIPreadParams);
load_symbol_dynamic(_inner, SCIPwriteParams);
load_symbol_dynamic(_inner, SCIPsolve);
load_symbol_dynamic(_inner, SCIPgetStatus);
load_symbol_dynamic(_inner, SCIPgetPrimalbound);
load_symbol_dynamic(_inner, SCIPgetDualbound);
load_symbol_dynamic(_inner, SCIPgetSolVals);
load_symbol_dynamic(_inner, SCIPgetBestSol);
load_symbol_dynamic(_inner, SCIPgetNTotalNodes);
load_symbol_dynamic(_inner, SCIPgetNNodes);
load_symbol_dynamic(_inner, SCIPgetNNodesLeft);
load_symbol_dynamic(_inner, SCIPfreeTransform);
load_symbol_dynamic(_inner, SCIPsetObjsense);
load_symbol_dynamic(_inner, SCIPeventhdlrGetName);
load_symbol_dynamic(_inner, SCIPcatchEvent);
load_symbol_dynamic(_inner, SCIPdropEvent);
load_symbol_dynamic(_inner, SCIPeventGetType);
load_symbol_dynamic(_inner, SCIPgetSolOrigObj);
load_symbol_dynamic(_inner, SCIPincludeEventhdlrBasic);
load_symbol_dynamic(_inner, SCIPsetEventhdlrInit);
load_symbol_dynamic(_inner, SCIPsetEventhdlrExit);
load_symbol_dynamic(_inner, SCIPmessagePrintErrorHeader);
load_symbol_dynamic(_inner, SCIPmessagePrintError);
load_symbol_dynamic(_inner, SCIPgetNVars);
load_symbol_dynamic(_inner, SCIPgetNConss);
load_symbol_dynamic(_inner, SCIPgetParams);
load_symbol_dynamic(_inner, SCIPgetNParams);
load_symbol_dynamic(_inner, SCIPparamGetName);
load_symbol_dynamic(_inner, SCIPparamGetType);
load_symbol_dynamic(_inner, SCIPparamGetDesc);
load_symbol_dynamic(_inner, SCIPparamGetBoolDefault);
load_symbol_dynamic(_inner, SCIPparamGetCharAllowedValues);
load_symbol_dynamic(_inner, SCIPparamGetCharDefault);
load_symbol_dynamic(_inner, SCIPparamGetIntDefault);
load_symbol_dynamic(_inner, SCIPparamGetIntMin);
load_symbol_dynamic(_inner, SCIPparamGetIntMax);
load_symbol_dynamic(_inner, SCIPparamGetLongintDefault);
load_symbol_dynamic(_inner, SCIPparamGetLongintMin);
load_symbol_dynamic(_inner, SCIPparamGetLongintMax);
load_symbol_dynamic(_inner, SCIPparamGetRealDefault);
load_symbol_dynamic(_inner, SCIPparamGetRealMin);
load_symbol_dynamic(_inner, SCIPparamGetRealMax);
load_symbol_dynamic(_inner, SCIPparamGetStringDefault);
load_symbol_dynamic(_inner, SCIPgetParam);
load_symbol_dynamic(_inner, SCIPchgBoolParam);
load_symbol_dynamic(_inner, SCIPchgIntParam);
load_symbol_dynamic(_inner, SCIPchgLongintParam);
load_symbol_dynamic(_inner, SCIPchgRealParam);
load_symbol_dynamic(_inner, SCIPchgCharParam);
load_symbol_dynamic(_inner, SCIPchgStringParam);
}
#define SCIP_PLUGIN_CALL_R(plugin, x) \
{ \
SCIP_RETCODE _ret = (x); \
if (_ret != SCIP_OKAY) { \
(plugin)->SCIPmessagePrintErrorHeader(__FILE__, __LINE__); \
(plugin)->SCIPmessagePrintError("Error <%d> in function call\n", _ret); \
return _ret; \
} \
}
string MIPScipWrapper::getDescription(FactoryOptions& factoryOpt,
MiniZinc::SolverInstanceBase::Options* opt) {
ostringstream oss;
oss << "MIP wrapper for SCIP " << getVersion(factoryOpt, opt)
<< ". Compiled";
return oss.str();
}
string MIPScipWrapper::getVersion(FactoryOptions& factoryOpt,
MiniZinc::SolverInstanceBase::Options* opt) {
try {
auto* p = factoryOpt.scipDll.empty() ? new ScipPlugin() : new ScipPlugin(factoryOpt.scipDll);
ostringstream oss;
oss << p->SCIPmajorVersion() << '.' << p->SCIPminorVersion() << '.' << p->SCIPtechVersion()
<< '.' << p->SCIPsubversion();
delete p;
return oss.str();
} catch (MiniZinc::PluginError&) {
return "<unknown version>";
}
}
vector<string> MIPScipWrapper::getRequiredFlags(FactoryOptions& factoryOpt) {
try {
ScipPlugin p;
return {};
} catch (MiniZinc::PluginError&) {
return {"--scip-dll"};
}
}
vector<string> MIPScipWrapper::getFactoryFlags() { return {"--scip-dll"}; };
string MIPScipWrapper::getId() { return "scip"; }
string MIPScipWrapper::getName() { return "SCIP"; }
vector<string> MIPScipWrapper::getTags() { return {"mip", "float", "api"}; }
vector<string> MIPScipWrapper::getStdFlags() { return {"-i", "-p", "-s"}; }
void MIPScipWrapper::Options::printHelp(ostream& os) {
os << "SCIP MIP wrapper options:"
<< std::endl
// -s print statistics
// << " --readParam <file> read SCIP parameters from file
// << "--writeParam <file> write SCIP parameters to file
// << "--tuneParam instruct SCIP to tune parameters instead of solving
<< "--writeModel <file> write model to <file> (.lp, .mps, ...?)" << std::endl
<< "-i print intermediate solutions for optimization problems" << std::endl
<< "-p <N>, --parallel <N>\n use N threads, default: 1"
<< std::endl
// << "--nomippresolve disable MIP presolving NOT IMPL" << std::endl
<< "--solver-time-limit <N> stop search after N milliseconds" << std::endl
<< "--workmem <N> maximal amount of RAM used, MB" << std::endl
<< "--readParam <file> read SCIP parameters from file" << std::endl
<< "--writeParam <file> write SCIP parameters to file"
<< std::endl
// << "--tuneParam instruct SCIP to tune parameters instead of solving NOT IMPL"
<< "--absGap <n> absolute gap |primal-dual| to stop" << std::endl
<< "--relGap <n> relative gap |primal-dual|/<solver-dep> to stop. Default 1e-8, set "
"<0 "
"to use backend's default"
<< std::endl
<< "--intTol <n> integrality tolerance for a variable. Default 1e-8"
<< std::endl
// << "--objDiff <n> objective function discretization. Default 1.0" << std::endl
<< "--scip-dll <file> load the SCIP library from the given file (absolute path or file "
"basename), default 'scip'"
<< std::endl
<< std::endl;
}
static inline bool beginswith(const string& s, const string& t) {
return s.compare(0, t.length(), t) == 0;
}
bool MIPScipWrapper::FactoryOptions::processOption(int& i, std::vector<std::string>& argv,
const std::string& workingDir) {
MiniZinc::CLOParser cop(i, argv);
return cop.get("--scip-dll", &scipDll);
}
bool MIPScipWrapper::Options::processOption(int& i, vector<string>& argv,
const std::string& workingDir) {
MiniZinc::CLOParser cop(i, argv);
std::string buffer;
if (cop.get("-i")) {
flagIntermediate = true;
} else if (string(argv[i]) == "-f" ||
string(argv[i]) == "--free-search") { // NOLINT: Allow repeated empty if
// std::cerr << " Flag -f: ignoring fixed strategy anyway." << std::endl;
} else if (cop.get("--writeModel", &buffer)) {
sExportModel = MiniZinc::FileUtils::file_path(buffer, workingDir);
} else if (cop.get("-p --parallel", &nThreads)) { // NOLINT: Allow repeated empty if
} else if (cop.get("--solver-time-limit", &nTimeout)) { // NOLINT: Allow repeated empty if
} else if (cop.get("--workmem", &nWorkMemLimit)) { // NOLINT: Allow repeated empty if
} else if (cop.get("--readParam", &buffer)) {
sReadParams = MiniZinc::FileUtils::file_path(buffer, workingDir);
} else if (cop.get("--writeParam", &buffer)) {
sWriteParams = MiniZinc::FileUtils::file_path(buffer, workingDir);
} else if (cop.get("--absGap", &absGap)) { // NOLINT: Allow repeated empty if
} else if (cop.get("--relGap", &relGap)) { // NOLINT: Allow repeated empty if
} else if (cop.get("--intTol", &intTol)) { // NOLINT: Allow repeated empty if
// } else if ( cop.get( "--objDiff", &objDiff ) ) {
} else {
return false;
}
return true;
}
// NOLINTNEXTLINE(readability-identifier-naming)
void MIPScipWrapper::SCIP_PLUGIN_CALL(SCIP_RETCODE retcode, const string& msg, bool fTerm) {
/* evaluate return code of the SCIP process */
if (retcode != SCIP_OKAY) {
/* write error back trace */
_plugin->SCIPprintError(retcode);
string msgAll = (" MIPScipWrapper runtime error, see output: " + msg);
cerr << msgAll << endl;
if (fTerm) {
cerr << "TERMINATING." << endl;
throw runtime_error(msgAll);
}
}
}
SCIP_RETCODE MIPScipWrapper::openSCIP() {
if (_factoryOptions.scipDll.empty()) {
_plugin = new ScipPlugin();
} else {
_plugin = new ScipPlugin(_factoryOptions.scipDll);
}
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPcreate(&_scip));
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPincludeDefaultPlugins(_scip));
/* create empty problem */
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPcreateProbBasic(_scip, "mzn_scip"));
return SCIP_OKAY;
}
SCIP_RETCODE MIPScipWrapper::closeSCIP() {
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPfree(&_scip));
delete _plugin;
/// and at last:
// MIPWrapper::cleanup();
return SCIP_OKAY;
}
std::vector<MiniZinc::SolverConfig::ExtraFlag> MIPScipWrapper::getExtraFlags(
FactoryOptions& factoryOpt) {
try {
MIPScipWrapper msw(factoryOpt, nullptr);
auto* params = msw._plugin->SCIPgetParams(msw._scip);
int num_params = msw._plugin->SCIPgetNParams(msw._scip);
std::vector<MiniZinc::SolverConfig::ExtraFlag> res;
res.reserve(num_params);
for (int i = 0; i < num_params; i++) {
auto* param = params[i];
std::string name = std::string(msw._plugin->SCIPparamGetName(param));
if (name == "lp/threads" || name == "limits/time" || name == "limits/memory" ||
name == "limits/absgap" || name == "limits/gap" || name == "numerics/feastol") {
// Handled by stdFlags
continue;
}
// Replace / in param name with _ (can't use - as some names have - in them already)
auto type = msw._plugin->SCIPparamGetType(param);
std::string desc(msw._plugin->SCIPparamGetDesc(param));
MiniZinc::SolverConfig::ExtraFlag::FlagType param_type;
std::vector<std::string> param_range;
std::string param_default;
switch (type) {
case SCIP_ParamType::SCIP_PARAMTYPE_BOOL:
param_type = MiniZinc::SolverConfig::ExtraFlag::FlagType::T_BOOL;
param_range = {"true", "false"};
param_default = msw._plugin->SCIPparamGetBoolDefault(param) != 0 ? "true" : "false";
break;
case SCIP_ParamType::SCIP_PARAMTYPE_CHAR: {
param_type = MiniZinc::SolverConfig::ExtraFlag::FlagType::T_STRING;
param_default = msw._plugin->SCIPparamGetCharDefault(param);
auto* allowed_values = msw._plugin->SCIPparamGetCharAllowedValues(param);
if (allowed_values != nullptr) {
for (int i = 0; i < strlen(allowed_values); i++) {
param_range.emplace_back(1, allowed_values[i]);
}
}
break;
}
case SCIP_ParamType::SCIP_PARAMTYPE_INT:
param_type = MiniZinc::SolverConfig::ExtraFlag::FlagType::T_INT;
param_range.push_back(std::to_string(msw._plugin->SCIPparamGetIntMin(param)));
param_range.push_back(std::to_string(msw._plugin->SCIPparamGetIntMax(param)));
param_default = std::to_string(msw._plugin->SCIPparamGetIntDefault(param));
break;
case SCIP_ParamType::SCIP_PARAMTYPE_LONGINT:
param_type = MiniZinc::SolverConfig::ExtraFlag::FlagType::T_INT;
param_range.push_back(std::to_string(msw._plugin->SCIPparamGetLongintMin(param)));
param_range.push_back(std::to_string(msw._plugin->SCIPparamGetLongintMax(param)));
param_default = std::to_string(msw._plugin->SCIPparamGetLongintDefault(param));
break;
case SCIP_ParamType::SCIP_PARAMTYPE_REAL:
param_type = MiniZinc::SolverConfig::ExtraFlag::FlagType::T_FLOAT;
param_range.push_back(std::to_string(msw._plugin->SCIPparamGetRealMin(param)));
param_range.push_back(std::to_string(msw._plugin->SCIPparamGetRealMax(param)));
param_default = std::to_string(msw._plugin->SCIPparamGetRealDefault(param));
break;
case SCIP_ParamType::SCIP_PARAMTYPE_STRING:
param_type = MiniZinc::SolverConfig::ExtraFlag::FlagType::T_STRING;
param_default = msw._plugin->SCIPparamGetStringDefault(param);
break;
default:
break;
}
res.emplace_back("--scip-" + name, desc, param_type, param_range, param_default);
}
return res;
} catch (MiniZinc::PluginError&) {
return {};
}
return {};
}
SCIP_RETCODE MIPScipWrapper::doAddVarsSCIP(size_t n, double* obj, double* lb, double* ub,
MIPWrapper::VarType* vt, string* names) {
/// Convert var types:
// vector<char> ctype(n);
// vector<char*> pcNames(n);
for (size_t j = 0; j < n; ++j) {
// pcNames[i] = (char*)names[i].c_str();
SCIP_VARTYPE ctype;
switch (vt[j]) {
case REAL:
ctype = SCIP_VARTYPE_CONTINUOUS;
break;
case INT:
ctype = SCIP_VARTYPE_INTEGER;
break;
case BINARY:
ctype = SCIP_VARTYPE_BINARY;
break;
default:
throw runtime_error(" MIPWrapper: unknown variable type");
}
_scipVars.resize(_scipVars.size() + 1);
if (fPhase1Over) {
assert(_scipVars.size() == colObj.size());
}
SCIP_PLUGIN_CALL_R(
_plugin, _plugin->SCIPcreateVarBasic(_scip, &_scipVars.back(), names[j].c_str(), lb[j],
ub[j], obj[j], ctype));
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPaddVar(_scip, _scipVars.back()));
}
// retcode = SCIP_newcols (env, lp, n, obj, lb, ub, ctype.data(), pcNames.data());
// wrap_assert( !retcode, "Failed to declare variables." );
return SCIP_OKAY;
}
SCIP_RETCODE MIPScipWrapper::delSCIPVars() {
for (auto& v : _scipVars) {
_plugin->SCIPreleaseVar(_scip, &v);
}
return SCIP_OKAY;
}
SCIP_RETCODE MIPScipWrapper::addRowSCIP(int nnz, int* rmatind, double* rmatval,
MIPWrapper::LinConType sense, double rhs, int mask,
const string& rowName) {
/// Convert var types:
double lh = -getInfBound();
double rh = getInfBound();
switch (sense) {
case LQ:
rh = rhs;
break;
case EQ:
lh = rh = rhs;
break;
case GQ:
lh = rhs;
break;
default:
throw runtime_error(" MIPWrapper: unknown constraint type");
}
const int ccnt = 0;
const int rcnt = 1;
const int rmatbeg[] = {0};
char* pRName = (char*)rowName.c_str();
// ignoring mask for now. TODO
SCIP_CONS* cons;
vector<SCIP_VAR*> ab(nnz);
for (int j = 0; j < nnz; ++j) {
ab[j] = _scipVars[rmatind[j]];
}
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPcreateConsBasicLinear(_scip, &cons, rowName.c_str(), nnz,
ab.data(), rmatval, lh, rh));
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPaddCons(_scip, cons));
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPreleaseCons(_scip, &cons));
return SCIP_OKAY;
// retcode = SCIP_addrows (env, lp, ccnt, rcnt, nnz, &rhs,
// &ssense, rmatbeg, rmatind, rmatval,
// nullptr, &pRName);
// wrap_assert( !retcode, "Failed to add constraint." );
}
void MIPScipWrapper::setVarBounds(int iVar, double lb, double ub) {
SCIP_PLUGIN_CALL(lb <= ub ? SCIP_OKAY : SCIP_ERROR, "scip interface: setVarBounds: lb>ub");
setVarLB(iVar, lb);
setVarUB(iVar, ub);
}
void MIPScipWrapper::setVarLB(int iVar, double lb) {
auto res = _plugin->SCIPchgVarLbGlobal(_scip, _scipVars[iVar], lb);
SCIP_PLUGIN_CALL(res, "scip interface: failed to set var lb.");
}
void MIPScipWrapper::setVarUB(int iVar, double ub) {
auto res = _plugin->SCIPchgVarUbGlobal(_scip, _scipVars[iVar], ub);
SCIP_PLUGIN_CALL(res, "scip interface: failed to set var ub.");
}
void MIPScipWrapper::addIndicatorConstraint(int iBVar, int bVal, int nnz, int* rmatind,
double* rmatval, MIPWrapper::LinConType sense,
double rhs, const string& rowName) {
MZN_ASSERT_HARD_MSG(0 <= bVal && 1 >= bVal, "SCIP: addIndicatorConstraint: bVal not 0/1");
//// Make sure in order to notice the indices of lazy constr: also here? TODO
// ++ nRows;
SCIP_CONS* cons;
vector<SCIP_VAR*> ab(nnz);
SCIP_VAR*
indicator_var; // SCIP 6.0.1 requires that the implication is active for indicator_x == 1
for (int j = 0; j < nnz; ++j) {
ab[j] = _scipVars[rmatind[j]];
}
indicator_var = _scipVars[iBVar];
if (0 == bVal) {
SCIP_PLUGIN_CALL(_plugin->SCIPgetNegatedVar(_scip, indicator_var, &indicator_var));
}
if (LQ == sense || EQ == sense) {
SCIP_PLUGIN_CALL(_plugin->SCIPcreateConsBasicIndicator(
_scip, &cons, rowName.c_str(), indicator_var, nnz, ab.data(), rmatval, rhs));
SCIP_PLUGIN_CALL(_plugin->SCIPaddCons(_scip, cons));
SCIP_PLUGIN_CALL(_plugin->SCIPreleaseCons(_scip, &cons));
}
if (GQ == sense || EQ == sense) {
std::vector<double> rmatvalNEG(nnz);
for (int i = nnz; (i--) != 0;) {
rmatvalNEG[i] = -rmatval[i];
}
SCIP_PLUGIN_CALL(_plugin->SCIPcreateConsBasicIndicator(
_scip, &cons, rowName.c_str(), indicator_var, nnz, ab.data(), rmatvalNEG.data(), -rhs));
SCIP_PLUGIN_CALL(_plugin->SCIPaddCons(_scip, cons));
SCIP_PLUGIN_CALL(_plugin->SCIPreleaseCons(_scip, &cons));
}
}
void MIPScipWrapper::addBoundsDisj(int n, double* fUB, double* bnd, int* vars, int nF, double* fUBF,
double* bndF, int* varsF, const string& rowName) {
SCIP_CONS* cons;
std::vector<SCIP_VAR*> v(n + nF);
std::vector<SCIP_BOUNDTYPE> bt(n + nF);
std::vector<SCIP_Real> bs(n + nF);
for (int j = 0; j < n; ++j) {
v[j] = _scipVars[vars[j]];
bt[j] = (fUB[j] != 0.0) ? SCIP_BOUNDTYPE_UPPER : SCIP_BOUNDTYPE_LOWER;
bs[j] = bnd[j];
}
for (int j = 0; j < nF; ++j) {
v[n + j] = _scipVars[varsF[j]];
bt[n + j] = (fUBF[j] != 0.0) ? SCIP_BOUNDTYPE_UPPER : SCIP_BOUNDTYPE_LOWER;
bs[n + j] = bndF[j];
}
SCIP_PLUGIN_CALL(_plugin->SCIPcreateConsBasicBounddisjunction(
_scip, &cons, rowName.c_str(), static_cast<int>(v.size()), v.data(), bt.data(), bs.data()));
SCIP_PLUGIN_CALL(_plugin->SCIPaddCons(_scip, cons));
SCIP_PLUGIN_CALL(_plugin->SCIPreleaseCons(_scip, &cons));
}
void MIPScipWrapper::addCumulative(int nnz, int* rmatind, double* d, double* r, double b,
const string& rowName) {
SCIP_CONS* cons;
vector<SCIP_VAR*> ab(nnz);
vector<int> nd(nnz);
vector<int> nr(nnz);
for (int j = 0; j < nnz; ++j) {
ab[j] = _scipVars[rmatind[j]];
nd[j] = (int)round(d[j]);
nr[j] = (int)round(r[j]);
}
SCIP_PLUGIN_CALL(_plugin->SCIPcreateConsBasicCumulative(
_scip, &cons, rowName.c_str(), nnz, ab.data(), nd.data(), nr.data(), (int)round(b)));
SCIP_PLUGIN_CALL(_plugin->SCIPaddCons(_scip, cons));
SCIP_PLUGIN_CALL(_plugin->SCIPreleaseCons(_scip, &cons));
}
/// Lex-lesseq binary, currently SCIP only
/// TODO check all variables are binary, SCIP 7.0.2 does not
void MIPScipWrapper::addLexLesseq(int nnz, int* rmatind1, int* rmatind2, bool isModelCons,
const std::string& rowName) {
SCIP_CONS* cons;
vector<SCIP_VAR*> vars1(nnz);
vector<SCIP_VAR*> vars2(nnz);
for (int j = 0; j < nnz; ++j) {
vars1[j] = _scipVars[rmatind1[j]];
vars2[j] = _scipVars[rmatind2[j]];
}
SCIP_PLUGIN_CALL(_plugin->SCIPcreateConsBasicOrbisack(
_scip, &cons, rowName.c_str(), vars2.data(), vars1.data(), // it's actually lex_greatereq
nnz, FALSE, FALSE, (SCIP_Bool)isModelCons));
SCIP_PLUGIN_CALL(_plugin->SCIPaddCons(_scip, cons));
SCIP_PLUGIN_CALL(_plugin->SCIPreleaseCons(_scip, &cons));
}
/// Lex-chain-lesseq binary, currently SCIP only
void MIPScipWrapper::addLexChainLesseq(int m, int n, int* rmatind, int nOrbitopeType,
bool resolveprop, bool isModelCons,
const std::string& rowName) {
SCIP_CONS* cons;
vector<vector<SCIP_VAR*> > vars(m, vector<SCIP_VAR*>(size_t(n)));
vector<SCIP_VAR**> vars_data(m);
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
vars[i][j] = _scipVars[rmatind[i * n + (n - j - 1)]]; // it's actually lex_chain_greatereq
}
vars_data[i] = vars[i].data();
}
SCIP_PLUGIN_CALL(_plugin->SCIPcreateConsBasicOrbitope(
_scip, &cons, rowName.c_str(), vars_data.data(), (SCIP_ORBITOPETYPE)nOrbitopeType, m, n,
(SCIP_Bool)resolveprop, (SCIP_Bool)isModelCons));
SCIP_PLUGIN_CALL(_plugin->SCIPaddCons(_scip, cons));
SCIP_PLUGIN_CALL(_plugin->SCIPreleaseCons(_scip, &cons));
}
void MIPScipWrapper::addTimes(int x, int y, int z, const string& rowName) {
/// As x*y - z == 0
double zCoef = -1.0;
double xyCoef = 1.0;
SCIP_CONS* cons;
std::array<SCIP_VAR*, 3> zxy = {_scipVars[z], _scipVars[x], _scipVars[y]};
SCIP_PLUGIN_CALL(_plugin->SCIPcreateConsBasicQuadratic(_scip, &cons, rowName.c_str(), 1,
zxy.data(), &zCoef, 1, &zxy[1], &zxy[2],
&xyCoef, 0.0, 0.0));
SCIP_PLUGIN_CALL(_plugin->SCIPaddCons(_scip, cons));
SCIP_PLUGIN_CALL(_plugin->SCIPreleaseCons(_scip, &cons));
}
/// SolutionCallback ------------------------------------------------------------------------
/// From event_bestsol.c:
#define EVENTHDLR_NAME "bestsol"
#define EVENTHDLR_DESC "event handler for best solutions found"
namespace {
// Dirty way of accessing SCIP functions inside C callbacks
ScipPlugin* _cb_plugin;
MIPWrapper::CBUserInfo* cbuiPtr = nullptr;
SCIP_VAR** _scipVarsPtr = nullptr;
} // namespace
/** initialization method of event handler (called after problem was transformed) */
static SCIP_DECL_EVENTINIT(eventInitBestsol) { /*lint --e{715}*/
assert(scip != nullptr);
assert(eventhdlr != nullptr);
assert(strcmp(_cb_plugin->SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
/* notify SCIP that your event handler wants to react on the event type best solution found */
SCIP_PLUGIN_CALL_R(_cb_plugin, _cb_plugin->SCIPcatchEvent(scip, SCIP_EVENTTYPE_BESTSOLFOUND,
eventhdlr, nullptr, nullptr));
return SCIP_OKAY;
}
/** deinitialization method of event handler (called before transformed problem is freed) */
static SCIP_DECL_EVENTEXIT(eventExitBestsol) { /*lint --e{715}*/
assert(scip != nullptr);
assert(eventhdlr != nullptr);
assert(strcmp(_cb_plugin->SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
/* notify SCIP that your event handler wants to drop the event type best solution found */
SCIP_PLUGIN_CALL_R(_cb_plugin, _cb_plugin->SCIPdropEvent(scip, SCIP_EVENTTYPE_BESTSOLFOUND,
eventhdlr, nullptr, -1));
return SCIP_OKAY;
}
/** execution method of event handler */
static SCIP_DECL_EVENTEXEC(eventExecBestsol) { /*lint --e{715}*/
SCIP_SOL* bestsol;
SCIP_Real objVal;
int newincumbent = 0;
assert(eventhdlr != nullptr);
assert(strcmp(_cb_plugin->SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0);
assert(event != nullptr);
assert(scip != nullptr);
assert(_cb_plugin->SCIPeventGetType(event) == SCIP_EVENTTYPE_BESTSOLFOUND);
SCIPdebugMessage("exec method of event handler for best solution found\n");
bestsol = _cb_plugin->SCIPgetBestSol(scip);
assert(bestsol != nullptr);
objVal = _cb_plugin->SCIPgetSolOrigObj(scip, bestsol);
if (cbuiPtr == nullptr) {
return SCIP_OKAY;
}
if (fabs(cbuiPtr->pOutput->objVal - objVal) > 1e-12 * (1.0 + fabs(objVal))) {
newincumbent = 1;
cbuiPtr->pOutput->objVal = objVal;
cbuiPtr->pOutput->status = MIPWrapper::SAT;
cbuiPtr->pOutput->statusName = "feasible from a callback";
}
if (newincumbent != 0 && _scipVarsPtr != nullptr) {
assert(cbuiPtr->pOutput->x);
SCIP_PLUGIN_CALL_R(
_cb_plugin, _cb_plugin->SCIPgetSolVals(scip, bestsol, cbuiPtr->pOutput->nCols, _scipVarsPtr,
(double*)cbuiPtr->pOutput->x));
// wrap_assert(!retcode, "Failed to get variable values.");
cbuiPtr->pOutput->nNodes = static_cast<int>(_cb_plugin->SCIPgetNNodes(scip));
cbuiPtr->pOutput->nOpenNodes = _cb_plugin->SCIPgetNNodesLeft(scip);
cbuiPtr->pOutput->bestBound = _cb_plugin->SCIPgetDualbound(scip);
cbuiPtr->pOutput->dWallTime = std::chrono::duration<double>(std::chrono::steady_clock::now() -
cbuiPtr->pOutput->dWallTime0)
.count();
cbuiPtr->pOutput->dCPUTime =
double(std::clock() - cbuiPtr->pOutput->cCPUTime0) / CLOCKS_PER_SEC;
/// Call the user function:
if (cbuiPtr->solcbfn != nullptr) {
(*cbuiPtr->solcbfn)(*cbuiPtr->pOutput, cbuiPtr->psi);
}
}
return SCIP_OKAY;
}
/** includes event handler for best solution found */
SCIP_RETCODE MIPScipWrapper::includeEventHdlrBestsol() {
SCIP_EVENTHDLRDATA* eventhdlrdata;
SCIP_EVENTHDLR* eventhdlr;
eventhdlrdata = nullptr;
eventhdlr = nullptr;
_cb_plugin = _plugin; // So that callbacks can access plugin functions
/* create event handler for events on watched variables */
SCIP_PLUGIN_CALL_R(
_plugin, _plugin->SCIPincludeEventhdlrBasic(_scip, &eventhdlr, EVENTHDLR_NAME, EVENTHDLR_DESC,
eventExecBestsol, eventhdlrdata));
assert(eventhdlr != nullptr);
/// Not for sub-SCIPs
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPsetEventhdlrInit(_scip, eventhdlr, eventInitBestsol));
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPsetEventhdlrExit(_scip, eventhdlr, eventExitBestsol));
return SCIP_OKAY;
}
MIPScipWrapper::Status MIPScipWrapper::convertStatus(SCIP_STATUS scipStatus) {
Status s = Status::UNKNOWN;
/* Converting the status. */
switch (scipStatus) {
case SCIP_STATUS_OPTIMAL:
s = Status::OPT;
output.statusName = "Optimal";
assert(_plugin->SCIPgetNSolsFound(_scip));
break;
case SCIP_STATUS_INFEASIBLE:
s = Status::UNSAT;
output.statusName = "Infeasible";
break;
// case SCIP_MIP_OPTIMAL_INFEAS:
case SCIP_STATUS_INFORUNBD:
s = Status::UNSATorUNBND;
output.statusName = "Infeasible or unbounded";
break;
// case SCIP_MIP_SOL_LIM:
// s = Status::SAT;
// wrap_assert(SCIP_getsolnpoolnumsolns(env, lp), "Feasibility reported but pool
// empty?", false); break;
case SCIP_STATUS_UNBOUNDED:
s = Status::UNBND;
output.statusName = "Unbounded";
break;
// case SCIP_STATUSMIP_ABORT_INFEAS:
// case SCIP_MIP_FAIL_INFEAS:
// s = Status::ERROR;
// break;
default:
// case SCIP_MIP_OPTIMAL_TOL:
// case SCIP_MIP_ABORT_RELAXATION_UNBOUNDED:
if (_plugin->SCIPgetNSols(_scip) != 0) {
s = Status::SAT;
output.statusName = "Feasible";
} else {
s = Status::UNKNOWN;
output.statusName = "Unknown";
}
}
return s;
}
SCIP_DECL_MESSAGEWARNING(printMsg) { cerr << msg << flush; }
SCIP_RETCODE MIPScipWrapper::solveSCIP() { // Move into ancestor?
/////////////// Last-minute solver options //////////////////
if (_options->nThreads > 0)
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPsetIntParam(_scip, "lp/threads", _options->nThreads));
if (_options->nTimeout > 0)
SCIP_PLUGIN_CALL_R(_plugin,
_plugin->SCIPsetRealParam(_scip, "limits/time",
static_cast<double>(_options->nTimeout) / 1000.0));
if (_options->nWorkMemLimit > 0)
SCIP_PLUGIN_CALL_R(_plugin,
_plugin->SCIPsetRealParam(_scip, "limits/memory", _options->nWorkMemLimit));
if (_options->absGap >= 0.0)
SCIP_PLUGIN_CALL_R(_plugin,
_plugin->SCIPsetRealParam(_scip, "limits/absgap", _options->absGap));
if (_options->relGap >= 0.0)
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPsetRealParam(_scip, "limits/gap", _options->relGap));
if (_options->intTol >= 0.0)
SCIP_PLUGIN_CALL_R(_plugin,
_plugin->SCIPsetRealParam(_scip, "numerics/feastol", _options->intTol));
// retcode = SCIP_setintparam (env, SCIP_PARAM_ClockType, 1); // CPU time
// wrap_assert(!retcode, " SCIP Warning: Failure to measure CPU time.", false);
if (!_options->sExportModel.empty()) {
// std::cerr <<" Exporting LP model to " << sExportModel << " ..." << std::endl;
SCIP_PLUGIN_CALL_R(
_plugin, _plugin->SCIPwriteOrigProblem(_scip, _options->sExportModel.c_str(), nullptr, 0));
}
/* Turn on output to the screen - after model export */
if (!fVerbose) {
// SCIP_PLUGIN_CALL(SCIPsetMessagehdlr(_scip, nullptr)); No LP export then
_plugin->SCIPsetMessagehdlrQuiet(_scip, TRUE);
} else {
SCIP_MESSAGEHDLR* pHndl = nullptr;
SCIP_PLUGIN_CALL_R(
_plugin, _plugin->SCIPmessagehdlrCreate(&pHndl, FALSE, nullptr, FALSE, printMsg, printMsg,
printMsg, nullptr, nullptr));
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPsetMessagehdlr(_scip, pHndl));
}
// assert(_scipVars.size() == colObj.size());
int cur_numcols =
static_cast<int>(_scipVars.size()); // No, we create negated indicators: getNCols();
assert(cur_numcols == colObj.size());
assert(cur_numcols == _scipVars.size());
/// Solution callback
output.nCols = static_cast<int>(colObj.size());
_x.resize(output.nCols);
output.x = _x.data();
if (_options->flagIntermediate && cbui.solcbfn != nullptr && cbuiPtr == nullptr) {
/* include event handler for best solution found */
SCIP_PLUGIN_CALL_R(_plugin, includeEventHdlrBestsol());
cbuiPtr = &cbui; // not thread-safe... TODO
_scipVarsPtr = _scipVars.data();
// retcode = SCIP_setinfocallbackfunc (env, solcallback, &cbui);
// wrap_assert(!retcode, "Failed to set solution callback", false);
}
// Process extra flags options
for (auto& it : _options->extraParams) {
auto name = it.first.substr(7);
std::replace(name.begin(), name.end(), '_', '/');
auto* param = _plugin->SCIPgetParam(_scip, name.c_str());
if (param == nullptr) {
continue;
}
auto type = _plugin->SCIPparamGetType(param);
switch (type) {
case SCIP_ParamType::SCIP_PARAMTYPE_BOOL:
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPchgBoolParam(_scip, param, it.second == "true"));
break;
case SCIP_ParamType::SCIP_PARAMTYPE_CHAR:
if (!it.second.empty()) {
SCIP_PLUGIN_CALL_R(_plugin,
_plugin->SCIPchgCharParam(_scip, param, it.second.c_str()[0]));
}
break;
case SCIP_ParamType::SCIP_PARAMTYPE_INT:
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPchgIntParam(_scip, param, stoi(it.second)));
break;
case SCIP_ParamType::SCIP_PARAMTYPE_LONGINT:
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPchgLongintParam(_scip, param, stoll(it.second)));
break;
case SCIP_ParamType::SCIP_PARAMTYPE_REAL:
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPchgRealParam(_scip, param, stod(it.second)));
break;
case SCIP_ParamType::SCIP_PARAMTYPE_STRING:
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPchgStringParam(_scip, param, it.second.c_str()));
break;
default:
break;
}
}
if (!_options->sReadParams.empty()) {
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPreadParams(_scip, _options->sReadParams.c_str()));
}
if (!_options->sWriteParams.empty()) {
SCIP_PLUGIN_CALL_R(_plugin,
_plugin->SCIPwriteParams(_scip, _options->sReadParams.c_str(), TRUE, FALSE));
}
cbui.pOutput->dWallTime0 = output.dWallTime0 = std::chrono::steady_clock::now();
output.dCPUTime = static_cast<double>(clock());
/* Optimize the problem and obtain solution. */
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPsolve(_scip));
// wrap_assert( !retcode, "Failed to optimize MIP." );
output.dWallTime =
std::chrono::duration<double>(std::chrono::steady_clock::now() - output.dWallTime0).count();
output.dCPUTime = (static_cast<double>(clock()) - output.dCPUTime) / CLOCKS_PER_SEC;
cbuiPtr = nullptr; /// cleanup
_scipVarsPtr = nullptr;
SCIP_STATUS solstat = _plugin->SCIPgetStatus(_scip);
output.status = convertStatus(solstat);
// output.statusName = SCIP_getstatstring (env, solstat, scip_status_buffer);
/// Continuing to fill the output object:
output.objVal = _plugin->SCIPgetPrimalbound(_scip);
output.bestBound = _plugin->SCIPgetDualbound(_scip);
// wrap_assert(!retcode, "Failed to get the best bound.", false);
if (Status::OPT == output.status || Status::SAT == output.status) {
// wrap_assert( !retcode, "No MIP objective value available." );
_x.resize(cur_numcols);
output.x = _x.data();
SCIP_PLUGIN_CALL_R(_plugin,
_plugin->SCIPgetSolVals(_scip, _plugin->SCIPgetBestSol(_scip), cur_numcols,
_scipVars.data(), (double*)output.x));
if (cbui.solcbfn != nullptr && (!_options->flagIntermediate || !cbui.printed)) {
cbui.solcbfn(output, cbui.psi);
}
}
output.nNodes = static_cast<int>(_plugin->SCIPgetNTotalNodes(_scip));
output.nOpenNodes = _plugin->SCIPgetNNodesLeft(_scip); // SCIP_getnodeleftcnt (env, lp);
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPfreeTransform(_scip));
return SCIP_OKAY;
}
SCIP_RETCODE MIPScipWrapper::setObjSenseSCIP(int s) {
SCIP_PLUGIN_CALL_R(_plugin, _plugin->SCIPsetObjsense(
_scip, s > 0 ? SCIP_OBJSENSE_MAXIMIZE : SCIP_OBJSENSE_MINIMIZE));
return SCIP_OKAY;
}
|