15 #include "CoinTypes.hpp"
16 #include "OsiSolverInterface.hpp"
17 #include "OsiSolverBranch.hpp"
19 #include "CoinSort.hpp"
20 #include "CoinError.hpp"
38 const int * which,
int identifier):
40 members_(numberMembers),
45 memcpy(
members_.data(), which, numberMembers*
sizeof(
int));
53 : OsiObject(rhs), members_(rhs.members_), quicky_(rhs.quicky_), only_frac_branch_(rhs.only_frac_branch_)
59 for (
size_t i = 0; i <
members_.size(); i++) {
82 OsiObject::operator=(rhs);
87 for (
size_t i = 0; i <
members_.size(); i++)
94 for (
size_t i = 0; i <
members_.size(); i++) {
109 for (
size_t i = 0; i <
members_.size(); i++)
120 for (
size_t i = 0; i <
members_.size(); i++)
130 assert (state == -9999 || state == 9999);
139 int &preferredWay)
const
141 int numberUnsatis = 0;
143 const double * solution = info->solution_;
144 const double * lower = info->lower_;
145 const double * upper = info->upper_;
146 double largestValue = 0.0;
148 double integerTolerance = info->integerTolerance_;
150 for (j = 0; j <
members_.size(); j++) {
152 double value = solution[iColumn];
153 value = CoinMax(value, lower[iColumn]);
154 value = CoinMin(value, upper[iColumn]);
155 double distance = CoinMin(value - lower[iColumn], upper[iColumn] - value);
156 if (distance > integerTolerance) {
158 largestValue = CoinMax(distance, largestValue);
172 const OsiBranchingInformation *
info)
const
175 const double * solution = info->solution_;
176 const double * lower = info->lower_;
177 const double * upper = info->upper_;
178 double integerTolerance = info->integerTolerance_;
180 for (j = 0; j <
members_.size(); j++) {
182 double value = solution[iColumn];
183 value = CoinMax(value, lower[iColumn]);
184 value = CoinMin(value, upper[iColumn]);
185 if (value >= upper[iColumn] - integerTolerance) {
186 r_val += value - upper[iColumn];
187 solver->setColLower(iColumn, upper[iColumn]);
189 assert (value <= lower[iColumn] + integerTolerance);
190 r_val += value - lower[iColumn];
191 solver->setColUpper(iColumn, lower[iColumn]);
201 const double * solution = info->solution_;
202 const double * lower = info->lower_;
203 const double * upper = info->upper_;
204 double integerTolerance = info->integerTolerance_;
205 double cutoff = info->cutoff_;
206 std::vector<int> list;
208 std::vector<double> sort;
212 std::list<int> skipped;
216 double value = solution[iColumn];
217 value = CoinMax(value, lower[iColumn]);
218 value = CoinMin(value, upper[iColumn]);
219 if (upper[iColumn] > lower[iColumn]) {
228 skipped.push_back(static_cast<int>(
j));
232 double distance = upper[iColumn] - value;
233 list.push_back(static_cast<int>(
j));
234 sort.push_back(distance);
239 const int& iColumn =
members_[skipped.front()];
240 double value = solution[iColumn];
241 value = CoinMax(value, lower[iColumn]);
242 value = CoinMin(value, upper[iColumn]);
243 double distance = upper[iColumn] - value;
244 list.push_back(skipped.front());
245 sort.push_back(distance);
251 CoinSort_2(sort.data(), sort.data() + sort.size(), list.data());
253 OsiBranchingObject * branch;
263 : OsiBranchingObject(), object_(NULL),
271 const std::vector<int>& order,
const std::list<int> &skipped)
272 : OsiBranchingObject(solver, 0.5), order_(order), skipped_(skipped)
274 numberBranches_ =
static_cast<int>(
order_.size()) + (!skipped.empty());
280 OsiBranchingObject(rhs), object_(rhs.object_),
281 order_(rhs.order_), skipped_(rhs.skipped_)
291 OsiBranchingObject::operator=(rhs);
313 int which = branchIndex_;
315 if(!
skipped_.empty() && branchIndex_ ==
static_cast<int>(
order_.size())){
318 return branch(solver, which);
324 const double * lower = solver->getColLower();
325 const double * upper = solver->getColUpper();
327 for (
size_t j = 0;
j <
order_.size();
j++) {
328 const int& iSequence =
order_[
j];
329 const int& iColumn = members[iSequence];
331 solver->setColUpper(iColumn, lower[iColumn]);
332 assert (lower[iColumn] > -1.0e20);
334 solver->setColLower(iColumn, upper[iColumn]);
336 printf(
"Up Fix %d to %g\n", iColumn, upper[iColumn]);
338 assert (upper[iColumn] < 1.0e20);
345 assert(upper[members[*
k]] > lower[members[*
k]] + 0.5);
346 solver->setColUpper(members[*
k], lower[members[*k]]);
virtual ~BonNWayBranchingObject()
std::vector< int > members_
data
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint * info
virtual OsiObject * clone() const
Clone.
virtual ~BonNWayObject()
Destructor.
virtual OsiBranchingObject * createBranch(OsiSolverInterface *solver, const OsiBranchingInformation *info, int way) const
Creates a branching object.
const BonNWayObject * object_
Points back to object.
BonNWayObject & operator=(const BonNWayObject &rhs)
Assignment operator.
int only_frac_branch_
Only branch on fractional variables (last branch puts all of them to 0)
bool quicky_
Quicky only branch up on variables with non zero value.
void applyConsequence(OsiSolverInterface *solver, int iSequence, int state) const
Applies a consequence for a single member.
BonNWayBranchingObject & operator=(const BonNWayBranchingObject &rhs)
void setConsequence(int iMember, const n_way_consequences &consequence)
Set up a consequence for a single member.
n_way_consequences ** consequence_
Consequences (normally NULL)
virtual double branch(OsiSolverInterface *solver)
Does next branch and updates state.
const int * members() const
Members (indices in range 0 ... numberColumns-1)
virtual double feasibleRegion(OsiSolverInterface *solver, const OsiBranchingInformation *info) const
This looks at solution and sets bounds to contain solution.
N way branching Object class.
void applyToSolver(OsiSolverInterface *solver, int state) const
std::list< int > skipped_
Is only branching on a subset of variables (has to do a last branch with all variables in order set t...
std::vector< double > bounds_
Bounds on the members.
n_way_consequences * clone() const
double distance(const double *p1, const double *p2, int size, double k=2.)
compute Euclidean distance between two points (most likely LP solutions) l_2 norm by default...
std::vector< int > order_
order of branching
virtual double infeasibility(const OsiBranchingInformation *info, int &preferredWay) const
Infeasibility - large is 0.5 (and 0.5 will give this)
virtual OsiBranchingObject * clone() const
Clone.