BonNWayObject.hpp
Go to the documentation of this file.
1 // $Id$
2 // Copyright (C) 2002, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5 
6 // Pierre Bonami 13/10/2011 copy and modify CbcNWay to adapt to use an OsiObject for Bonmin
7 //
8 // Edwin 11/9/2009-- carved out of CbcBranchActual
9 
14 #ifndef BonNWayObject_H
15 #define BonNWayObject_H
16 #include "OsiBranchingObject.hpp"
17 #include "CbcConsequence.hpp"
18 #include <list>
19 
20 namespace Bonmin {
22 public:
23  std::vector<int> indices;
24 
26  }
27 
29  indices(rhs.indices){
30  }
31 
33  if(this != &rhs){
34  indices = rhs.indices;
35  }
36  return *this;
37  }
38 
40  return new n_way_consequences(*this);
41  }
42 
43  void applyToSolver(OsiSolverInterface * solver, int state) const{
44  if(state < 0) return;
45  int num_one = 0;
46  for(size_t i = 0 ; i < indices.size() ; i++){
47  if(solver->getColLower()[indices[i]] > 0.9) num_one++;
48  solver->setColUpper(indices[i],solver->getColLower()[indices[i]]);
49  }
50  assert(num_one == 0);
51  }
52 
53 };
54 
55 class BonNWayObject : public OsiObject {
56 
57 public:
58 
59  // Default Constructor
60  BonNWayObject ();
61 
65  const int * which, int identifier);
66 
67  // Copy constructor
68  BonNWayObject ( const BonNWayObject &);
69 
71  virtual OsiObject * clone() const;
72 
74  BonNWayObject & operator=( const BonNWayObject& rhs);
75 
77  virtual ~BonNWayObject ();
78 
80  void setConsequence(int iMember, const n_way_consequences & consequence);
81 
83  void applyConsequence(OsiSolverInterface * solver,
84  int iSequence, int state) const;
85 
87  virtual double infeasibility(const OsiBranchingInformation * info,
88  int &preferredWay) const;
89 
91  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
92 
94  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
95 
97  inline size_t numberMembers() const {
98  return members_.size();
99  }
100 
102  inline const int * members() const {
103  return members_.data();
104  }
105 
106  void set_bounds(std::vector<double> & bounds) const{
107  bounds_ = bounds;
108  }
109 
110  void make_quick(){quicky_ = true;}
111 
112  void set_only_frac_branches(int depth){
113  only_frac_branch_ = depth;
114  }
115 private:
117 
119  std::vector<int> members_;
122 
124  mutable std::vector<double> bounds_;
125 
127  bool quicky_;
130 };
134 class BonNWayBranchingObject : public OsiBranchingObject {
135 
136 public:
137 
138  // Default Constructor
140 
145  BonNWayBranchingObject (OsiSolverInterface * solver, const BonNWayObject * nway,
146  const std::vector<int>& order, const std::list<int>& skipped);
147 
148  // Copy constructor
150 
151  // Assignment operator
153 
155  virtual OsiBranchingObject * clone() const;
156 
157  // Destructor
158  virtual ~BonNWayBranchingObject ();
159 
160  using OsiBranchingObject::branch ;
162  virtual double branch(OsiSolverInterface * solver);
163 
165  virtual double branch(OsiSolverInterface * solver, int state);
166 
169  virtual int numberBranches() const {
170  return static_cast<int>(order_.size()) + (!skipped_.empty());
171  }
173  virtual bool twoWay() const {
174  return false;
175  }
176 
177  inline int var_branched_on(){
178  if(branchIndex_ > 0)
179  return object_->members()[order_[branchIndex_ - 1]];
180  return -1;
181  }
182 
183  inline int seq_branched_on(){
184  if(branchIndex_ > 0)
185  return order_[branchIndex_ - 1];
186  return -1;
187  }
188 
189  inline int state_branched_on(){
190  return branchIndex_ - 1;
191  }
192 private:
196  std::vector<int> order_;
198  std::list<int> skipped_;
199 };
200 
201 }
202 
203 #endif
void set_only_frac_branches(int depth)
virtual bool twoWay() const
Is this a two way object (-1 down, +1 up)
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 int numberBranches() const
The number of branch arms created for this branching object.
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.
n_way_consequences & operator=(const n_way_consequences &rhs)
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)
size_t numberMembers() const
Number of members.
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_consequences(const n_way_consequences &rhs)
N way branching Object class.
void set_bounds(std::vector< double > &bounds) const
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< int > indices
std::vector< double > bounds_
Bounds on the members.
n_way_consequences * clone() const
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.