00001
00002
00003
00004
00005
00006
00007
00008
00009
00014 #ifndef BonNWayObject_H
00015 #define BonNWayObject_H
00016 #include "OsiBranchingObject.hpp"
00017 #include "CbcConsequence.hpp"
00018 #include <list>
00019
00020 namespace Bonmin {
00021 class n_way_consequences {
00022 public:
00023 std::vector<int> indices;
00024
00025 n_way_consequences(): indices(){
00026 }
00027
00028 n_way_consequences(const n_way_consequences& rhs):
00029 indices(rhs.indices){
00030 }
00031
00032 n_way_consequences& operator=(const n_way_consequences& rhs){
00033 if(this != &rhs){
00034 indices = rhs.indices;
00035 }
00036 return *this;
00037 }
00038
00039 n_way_consequences * clone() const{
00040 return new n_way_consequences(*this);
00041 }
00042
00043 void applyToSolver(OsiSolverInterface * solver, int state) const{
00044 if(state < 0) return;
00045 int num_one = 0;
00046 for(size_t i = 0 ; i < indices.size() ; i++){
00047 if(solver->getColLower()[indices[i]] > 0.9) num_one++;
00048 solver->setColUpper(indices[i],solver->getColLower()[indices[i]]);
00049 }
00050 assert(num_one == 0);
00051 }
00052
00053 };
00054
00055 class BonNWayObject : public OsiObject {
00056
00057 public:
00058
00059
00060 BonNWayObject ();
00061
00064 BonNWayObject (int numberMembers,
00065 const int * which, int identifier);
00066
00067
00068 BonNWayObject ( const BonNWayObject &);
00069
00071 virtual OsiObject * clone() const;
00072
00074 BonNWayObject & operator=( const BonNWayObject& rhs);
00075
00077 virtual ~BonNWayObject ();
00078
00080 void setConsequence(int iMember, const n_way_consequences & consequence);
00081
00083 void applyConsequence(OsiSolverInterface * solver,
00084 int iSequence, int state) const;
00085
00087 virtual double infeasibility(const OsiBranchingInformation * info,
00088 int &preferredWay) const;
00089
00091 virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
00092
00094 virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
00095
00097 inline size_t numberMembers() const {
00098 return members_.size();
00099 }
00100
00102 inline const int * members() const {
00103 return members_.data();
00104 }
00105
00106 void set_bounds(std::vector<double> & bounds) const{
00107 bounds_ = bounds;
00108 }
00109
00110 void make_quick(){quicky_ = true;}
00111
00112 void set_only_frac_branches(int depth){
00113 only_frac_branch_ = depth;
00114 }
00115 private:
00117
00119 std::vector<int> members_;
00121 n_way_consequences ** consequence_;
00122
00124 mutable std::vector<double> bounds_;
00125
00127 bool quicky_;
00129 int only_frac_branch_;
00130 };
00134 class BonNWayBranchingObject : public OsiBranchingObject {
00135
00136 public:
00137
00138
00139 BonNWayBranchingObject ();
00140
00145 BonNWayBranchingObject (OsiSolverInterface * solver, const BonNWayObject * nway,
00146 const std::vector<int>& order, const std::list<int>& skipped);
00147
00148
00149 BonNWayBranchingObject ( const BonNWayBranchingObject &);
00150
00151
00152 BonNWayBranchingObject & operator=( const BonNWayBranchingObject& rhs);
00153
00155 virtual OsiBranchingObject * clone() const;
00156
00157
00158 virtual ~BonNWayBranchingObject ();
00159
00160 using OsiBranchingObject::branch ;
00162 virtual double branch(OsiSolverInterface * solver);
00163
00165 virtual double branch(OsiSolverInterface * solver, int state);
00166
00169 virtual int numberBranches() const {
00170 return static_cast<int>(order_.size()) + (!skipped_.empty());
00171 }
00173 virtual bool twoWay() const {
00174 return false;
00175 }
00176
00177 inline int var_branched_on(){
00178 if(branchIndex_ > 0)
00179 return object_->members()[order_[branchIndex_ - 1]];
00180 return -1;
00181 }
00182
00183 inline int seq_branched_on(){
00184 if(branchIndex_ > 0)
00185 return order_[branchIndex_ - 1];
00186 return -1;
00187 }
00188
00189 inline int state_branched_on(){
00190 return branchIndex_ - 1;
00191 }
00192 private:
00194 const BonNWayObject * object_;
00196 std::vector<int> order_;
00198 std::list<int> skipped_;
00199 };
00200
00201 }
00202
00203 #endif