Skip to content

Commit

Permalink
fix: get correct itmp values for variables in FixVarsHeur
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafa712 committed Mar 26, 2024
1 parent 311df57 commit bf62096
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/base/FixVarsHeur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ void FixVarsHeur::solve(NodePtr, RelaxationPtr, SolutionPoolPtr s_pool)
<< me_ << "Iteration Number : " << iter << std::endl;
#endif
restart = false;
unfixedVars.clear();
for(VariableConstIterator vit = p_->varsBegin(); vit != p_->varsEnd();
++vit) {
unfixedVars.insert({*vit, (*vit)->getItmp()});
}

consNumVar_.clear();
for(ConstraintConstIterator cit = p_->consBegin(); cit != p_->consEnd();
++cit) {
Expand All @@ -82,13 +76,25 @@ void FixVarsHeur::solve(NodePtr, RelaxationPtr, SolutionPoolPtr s_pool)
if(numvars == 1) {
// Just a bound constraint, should not be considered for convering.
consNumVar_.insert({*cit, 0});
if(iter == 1) {
updateItmp_(*cit);
}
} else {
consNumVar_.insert({*cit, numvars});
}
} else {
consNumVar_.insert({*cit, 0});
if(iter == 1) {
updateItmp_(*cit);
}
}
}
unfixedVars.clear();
for(VariableConstIterator vit = p_->varsBegin(); vit != p_->varsEnd();
++vit) {
unfixedVars.insert({*vit, (*vit)->getItmp()});
}

while(unfixedVars.size() > 0) {
FixVars_(unfixedVars);
if(presolve_(s_pool, unfixedVars)) {
Expand Down Expand Up @@ -278,6 +284,23 @@ void FixVarsHeur::updateMap_(ConstraintPtr c,
}
}

void FixVarsHeur::updateItmp_(ConstraintPtr c)
{
FunctionPtr f = c->getFunction();
VariablePtr v;

for(VarSetConstIterator vit = f->varsBegin(); vit != f->varsEnd(); ++vit) {
v = *vit;
if(v->getType() == Binary || v->getType() == ImplBin) {
v->setItmp(v->getItmp() - mbin_);
} else if(v->getFunType() != Linear && v->getFunType() != Constant) {
v->setItmp(v->getItmp() - mnl_);
} else {
v->setItmp(v->getItmp() - 1);
}
}
}

bool FixVarsHeur::isFeasible_(const double* x)
{
ConstraintPtr c;
Expand Down
3 changes: 3 additions & 0 deletions src/base/FixVarsHeur.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class FixVarsHeur : public Heuristic
// Unfix fixed variables.
void unfixVars_();

// update itmp of each variable in the constraint if it is covered right from start
void updateItmp_(ConstraintPtr c);

// update Map of each variable in the constraint once it is covered
void updateMap_(ConstraintPtr c, std::map<VariablePtr, UInt>& unfixedVars);
};
Expand Down

0 comments on commit bf62096

Please sign in to comment.