Skip to content

Commit db3eff2

Browse files
committed
Consider that bounds of free variables may have changed
1 parent ed2de02 commit db3eff2

5 files changed

Lines changed: 34 additions & 9 deletions

File tree

highs/ipm/hipo/ipm/Iterate.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void NewtonDir::add(const NewtonDir& d) {
2828
vectorAdd(zu, d.zu);
2929
}
3030

31-
Iterate::Iterate(const Model& model_input, Regularisation& r)
31+
Iterate::Iterate(Model& model_input, Regularisation& r)
3232
: model{model_input}, delta(model.m(), model.n()), regul{r} {
3333
clearIter();
3434
clearRes();
@@ -608,6 +608,7 @@ void Iterate::saveBest(double feas_tol, double opt_tol, Int iter) {
608608
best_zu = zu;
609609
best_violation = violation;
610610
best_iter = iter;
611+
model.saveBounds();
611612
}
612613
}
613614

@@ -620,6 +621,7 @@ bool Iterate::resetBest(Int iter) {
620621
y = best_y;
621622
zl = best_zl;
622623
zu = best_zu;
624+
model.resetBounds();
623625

624626
computeMu();
625627
residual1234();

highs/ipm/hipo/ipm/Iterate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct Residuals {
3030
};
3131

3232
struct Iterate {
33-
const Model& model;
33+
Model& model;
3434
IpmData data;
3535
std::vector<double> x, xl, xu, y, zl, zu;
3636
Residuals res;
@@ -57,7 +57,7 @@ struct Iterate {
5757
// ===================================================================================
5858
// Functions to construct, clear and check for nan or inf
5959
// ===================================================================================
60-
Iterate(const Model& model_input, Regularisation& r);
60+
Iterate(Model& model_input, Regularisation& r);
6161

6262
// clear existing data
6363
void clearIter();

highs/ipm/hipo/ipm/Model.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,21 +424,40 @@ void Model::adjustFreeVars(std::vector<double>& x, std::vector<double>& xl,
424424
// getting close to lower bound
425425
const double new_lower = x[i] / kFreeVarsCloseRatio;
426426
logger.printDetailed(
427-
"Free var %5d is at %8.1e with lb %8.1e, lb changed to %8.1e\n", i, x[i],
428-
lower_[i], new_lower);
427+
"Free var %5d is at %8.1e with lb %8.1e, lb changed to %8.1e\n", i,
428+
x[i], lower_[i], new_lower);
429429
lower_[i] = new_lower;
430430
xl[i] = x[i] - lower_[i];
431431
}
432432
if (x[i] > upper_[i] * kFreeVarsCloseRatio) {
433433
// getting close to upper bound
434434
const double new_upper = x[i] / kFreeVarsCloseRatio;
435435
logger.printDetailed(
436-
"Free var %5d is at %8.1e with ub %8.1e, ub changed to %8.1e\n", i, x[i],
437-
upper_[i], new_upper);
436+
"Free var %5d is at %8.1e with ub %8.1e, ub changed to %8.1e\n", i,
437+
x[i], upper_[i], new_upper);
438438
upper_[i] = new_upper;
439439
xu[i] = upper_[i] - x[i];
440440
}
441441
}
442442
}
443443

444+
void Model::saveBounds() {
445+
best_lower_.resize(free_variables_.size());
446+
best_upper_.resize(free_variables_.size());
447+
Int next = 0;
448+
for (Int i : free_variables_) {
449+
best_lower_[next] = lower_[i];
450+
best_upper_[next] = upper_[i];
451+
++next;
452+
}
453+
}
454+
void Model::resetBounds() {
455+
Int next = 0;
456+
for (Int i : free_variables_) {
457+
lower_[i] = best_lower_[next];
458+
upper_[i] = best_upper_[next];
459+
++next;
460+
}
461+
}
462+
444463
} // namespace hipo

highs/ipm/hipo/ipm/Model.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class Model {
6767

6868
std::vector<Int> free_variables_;
6969

70+
std::vector<double> best_lower_, best_upper_;
71+
7072
void preprocess();
7173
Int checkData() const;
7274
void computeNorms();
@@ -95,6 +97,9 @@ class Model {
9597
void adjustFreeVars(std::vector<double>& x, std::vector<double>& xl,
9698
std::vector<double>& xu, const Logger& logger);
9799

100+
void saveBounds();
101+
void resetBounds();
102+
98103
// Check if variable has finite lower/upper bound
99104
bool hasLb(Int j) const { return std::isfinite(lower_[j]); }
100105
bool hasUb(Int j) const { return std::isfinite(upper_[j]); }

highs/ipm/hipo/ipm/Solver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ bool Solver::initialise() {
167167
(LS_->nz() < kUplookNzPerColUpper * kkt_->n() &&
168168
LS_->flops() < kUplookSpopsRatioUpper * LS_->spops());
169169

170-
switch_to_uplooking = true;
171-
172170
if (switch_to_uplooking) {
173171
LS_.reset(new UpLookingSolver(*kkt_, info_, it_->data, regul_, model_));
174172
LS_->setup();
@@ -368,6 +366,7 @@ bool Solver::solveNewtonSystem(NewtonDir& delta) {
368366
}
369367
LS_->clear();
370368
it_->data.back().factorisation_used = LS_->type();
369+
it_->bad_iter_ = 0;
371370
logger_.printInfo("Switching to FactorHighs because of bad direction\n");
372371
resetToBestIter(iter_ - 1);
373372

0 commit comments

Comments
 (0)