Skip to content

Commit cfd5372

Browse files
committed
Add debugsol changes
1 parent 54ba458 commit cfd5372

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

highs/mip/HighsDebugSol.cpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,45 @@ void HighsDebugSol::activate() {
3535
if (file) {
3636
std::string varname;
3737
double varval;
38+
std::string line;
39+
bool incolsection;
3840
std::map<std::string, int> nametoidx;
3941

40-
for (HighsInt i = 0; i != mipsolver->model_->num_col_; ++i)
41-
nametoidx["c" + std::to_string(i)] = i;
42+
for (HighsInt i = 0; i != mipsolver->orig_model_->num_col_; ++i)
43+
nametoidx[mipsolver->orig_model_->col_names_[i]] = i;
4244

43-
debugSolution.resize(mipsolver->model_->num_col_, 0.0);
44-
while (!file.eof()) {
45-
file >> varname;
45+
debugOrigSolution.resize(mipsolver->orig_model_->num_col_, 0.0);
46+
while (std::getline(file, line)) {
47+
// Check for start and stop markers
48+
if (line.find("# Columns") != std::string::npos) {
49+
incolsection = true;
50+
continue;
51+
}
52+
if (line.find("# Rows") != std::string::npos) {
53+
break;
54+
}
55+
if (!incolsection)
56+
continue;
57+
58+
std::istringstream linestream(line);
59+
linestream >> varname;
4660
auto it = nametoidx.find(varname);
4761
if (it != nametoidx.end()) {
48-
file >> varval;
62+
linestream >> varval;
63+
debugOrigSolution[it->second] = varval;
4964
highsLogDev(mipsolver->options_mip_->log_options, HighsLogType::kInfo,
5065
"%s = %g\n", varname.c_str(), varval);
51-
debugSolution[it->second] = varval;
66+
debugOrigSolution[it->second] = varval;
5267
}
53-
54-
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
5568
}
69+
debugSolution = debugOrigSolution;
5670

5771
HighsCDouble debugsolobj = 0.0;
58-
for (HighsInt i = 0; i != mipsolver->model_->num_col_; ++i)
59-
debugsolobj += mipsolver->model_->col_cost_[i] * debugSolution[i];
72+
for (HighsInt i = 0; i != mipsolver->orig_model_->num_col_; ++i)
73+
debugsolobj +=
74+
mipsolver->orig_model_->col_cost_[i] * debugOrigSolution[i];
6075

61-
debugSolObjective = double(debugsolobj);
76+
debugSolObjective = double(debugsolobj + mipsolver->orig_model_->offset_);
6277
debugSolActive = true;
6378
printf("debug sol active\n");
6479
registerDomain(mipsolver->mipdata_->domain);

highs/mip/HighsDebugSol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class HighsLp;
2929
struct HighsDebugSol {
3030
const HighsMipSolver* mipsolver;
3131
double debugSolObjective;
32+
std::vector<double> debugOrigSolution;
3233
std::vector<double> debugSolution;
3334
bool debugSolActive;
3435
std::unordered_map<const HighsDomain*, std::multiset<HighsDomainChange>>

highs/mip/HighsMipSolver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ void HighsMipSolver::run() {
8787
analysis_.mipTimerStart(kMipClockInit);
8888
mipdata_->init();
8989
analysis_.mipTimerStop(kMipClockInit);
90+
#ifdef HIGHS_DEBUGSOL
91+
mipdata_->debugSolution.activate();
92+
#endif
9093
analysis_.mipTimerStart(kMipClockRunPresolve);
9194
mipdata_->runPresolve(options_mip_->presolve_reduction_limit);
9295
analysis_.mipTimerStop(kMipClockRunPresolve);

highs/mip/HighsMipSolverData.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,6 @@ void HighsMipSolverData::init() {
694694
}
695695

696696
void HighsMipSolverData::runPresolve(const HighsInt presolve_reduction_limit) {
697-
#ifdef HIGHS_DEBUGSOL
698-
bool debugSolActive = false;
699-
std::swap(debugSolution.debugSolActive, debugSolActive);
700-
#endif
701697

702698
mipsolver.timer_.start(mipsolver.timer_.presolve_clock);
703699
presolve::HPresolve presolve;
@@ -709,13 +705,6 @@ void HighsMipSolverData::runPresolve(const HighsInt presolve_reduction_limit) {
709705
presolve_status = presolve.getPresolveStatus();
710706
}
711707
mipsolver.timer_.stop(mipsolver.timer_.presolve_clock);
712-
713-
#ifdef HIGHS_DEBUGSOL
714-
debugSolution.debugSolActive = debugSolActive;
715-
if (debugSolution.debugSolActive) debugSolution.registerDomain(domain);
716-
assert(!debugSolution.debugSolActive ||
717-
checkSolution(debugSolution.debugSolution));
718-
#endif
719708
}
720709

721710
void HighsMipSolverData::runSetup() {
@@ -1022,10 +1011,18 @@ void HighsMipSolverData::runSetup() {
10221011
heuristics.setupIntCols();
10231012

10241013
#ifdef HIGHS_DEBUGSOL
1025-
if (numRestarts == 0) {
1026-
debugSolution.activate();
1027-
assert(!debugSolution.debugSolActive ||
1028-
checkSolution(debugSolution.debugSolution));
1014+
if (debugSolution.debugSolActive) {
1015+
debugSolution.debugSolution.clear();
1016+
debugSolution.debugSolution = postSolveStack.getReducedPrimalSolution(
1017+
debugSolution.debugOrigSolution);
1018+
// Do we even need to recalculate the objective?
1019+
debugSolution.debugSolObjective = 0;
1020+
for (HighsInt i = 0; i != mipsolver.model_->num_col_; ++i) {
1021+
debugSolution.debugSolObjective +=
1022+
mipsolver.colCost(i) * debugSolution.debugSolution[i];
1023+
}
1024+
debugSolution.registerDomain(domain);
1025+
assert(checkSolution(debugSolution.debugSolution));
10291026
}
10301027
#endif
10311028

@@ -1218,6 +1215,10 @@ void HighsMipSolverData::performRestart() {
12181215
presolvedModel = lp.getLp();
12191216
presolvedModel.offset_ = offset;
12201217
presolvedModel.integrality_ = std::move(integrality);
1218+
#ifdef HIGHS_DEBUGSOL
1219+
bool debugSolActive = false;
1220+
std::swap(debugSolution.debugSolActive, debugSolActive);
1221+
#endif
12211222

12221223
const HighsBasis& basis = firstrootbasis;
12231224
if (basis.valid) {
@@ -1321,6 +1322,9 @@ void HighsMipSolverData::performRestart() {
13211322
}
13221323
// Bounds are currently in the original space since presolve will have
13231324
// changed offset_
1325+
#ifdef HIGHS_DEBUGSOL
1326+
debugSolution.debugSolActive = debugSolActive;
1327+
#endif
13241328
runSetup();
13251329

13261330
postSolveStack.removeCutsFromModel(numCuts);

0 commit comments

Comments
 (0)