| 1 |
// Copyright (C) 2006, 2008 International Business Machines |
| 2 |
// Corporation and others. All Rights Reserved. |
| 3 |
#ifndef BonNWayChoose_H |
| 4 |
#define BonNWayChoose_H |
| 5 |
|
| 6 |
#include "OsiChooseVariable.hpp" |
| 7 |
#include "BonBabSetupBase.hpp" |
| 8 |
#include "BonNWayObject.hpp" |
| 9 |
|
| 10 |
#define OLD_USEFULLNESS |
| 11 |
|
| 12 |
namespace Bonmin |
| 13 |
{ |
| 14 |
|
| 15 |
/** This class chooses a variable to branch on |
| 16 |
|
| 17 |
This is the base class for the branching rules in Bonmin (inherits |
| 18 |
from OsiChooseVariable). This class implements a simple strong branching algorithm where the changes in the objective |
| 19 |
value induced by branching on a specific object are estimated with the pure virtual function fill_changes. |
| 20 |
*/ |
| 21 |
|
| 22 |
class BonNWayChoose : public OsiChooseVariable |
| 23 |
{ |
| 24 |
protected: |
| 25 |
|
| 26 |
public: |
| 27 |
|
| 28 |
/// Constructor from solver (so we can set up arrays etc) |
| 29 |
BonNWayChoose (BabSetupBase& b, const OsiSolverInterface* solver); |
| 30 |
|
| 31 |
/// Copy constructor |
| 32 |
BonNWayChoose (const BonNWayChoose &); |
| 33 |
|
| 34 |
/// Assignment operator |
| 35 |
BonNWayChoose & operator= (const BonNWayChoose& rhs); |
| 36 |
|
| 37 |
/// Clone |
| 38 |
virtual OsiChooseVariable * clone() const; |
| 39 |
|
| 40 |
/// Destructor |
| 41 |
virtual ~BonNWayChoose (); |
| 42 |
|
| 43 |
/** Helper function for setupList and chooseVariable, compute usefullness of an nway object */ |
| 44 |
double compute_usefulness(int objectIndex, const OsiBranchingInformation * info) const; |
| 45 |
|
| 46 |
double compute_usefulness(const OsiBranchingInformation * info, |
| 47 |
size_t n, const int * vars, const std::vector<double> &bounds, const std::vector<double> &unit_changes) const; |
| 48 |
/** Sets up strong list and clears all if initialize is true. |
| 49 |
Returns number of infeasibilities. */ |
| 50 |
virtual int setupList ( OsiBranchingInformation *info, bool initialize); |
| 51 |
|
| 52 |
/** Choose a variable |
| 53 |
Returns - |
| 54 |
-1 Node is infeasible |
| 55 |
0 Normal termination - we have a candidate |
| 56 |
1 All looks satisfied - no candidate |
| 57 |
2 We can change the bound on a variable - but we also have a strong branching candidate |
| 58 |
3 We can change the bound on a variable - but we have a non-strong branching candidate |
| 59 |
4 We can change the bound on a variable - no other candidates |
| 60 |
We can pick up branch from bestObjectIndex() and bestWhichWay() |
| 61 |
We can pick up a forced branch (can change bound) from firstForcedObjectIndex() and firstForcedWhichWay() |
| 62 |
If we have a solution then we can pick up from goodObjectiveValue() and goodSolution() |
| 63 |
If fixVariables is true then 2,3,4 are all really same as problem changed |
| 64 |
*/ |
| 65 |
virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables); |
| 66 |
|
| 67 |
/** This is a utility function which does strong branching on |
| 68 |
a list of objects and stores the results in OsiHotInfo.objects. |
| 69 |
On entry the object sequence is stored in the OsiHotInfo object |
| 70 |
and maybe more. |
| 71 |
It returns - |
| 72 |
-1 - one branch was infeasible both ways |
| 73 |
0 - all inspected - nothing can be fixed |
| 74 |
1 - all inspected - some can be fixed (returnCriterion==0) |
| 75 |
2 - may be returning early - one can be fixed (last one done) (returnCriterion==1) |
| 76 |
3 - returning because max time |
| 77 |
|
| 78 |
*/ |
| 79 |
virtual int doStrongBranching( OsiSolverInterface * solver, |
| 80 |
OsiBranchingInformation *info, |
| 81 |
int iObject, double * saveLow, double * saveUp, double &score); |
| 82 |
|
| 83 |
|
| 84 |
/** Register class options.*/ |
| 85 |
static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions); |
| 86 |
|
| 87 |
private: |
| 88 |
/** Default Constructor, forbiden for some reason.*/ |
| 89 |
BonNWayChoose (); |
| 90 |
|
| 91 |
/** depth of strong-branching.*/ |
| 92 |
int br_depth_; |
| 93 |
/** Do we fix?*.*/ |
| 94 |
Ipopt::Index do_fixings_; |
| 95 |
/** Cutoff multiplier for infeasibles*/ |
| 96 |
double cutoff_multiplier_; |
| 97 |
/** Trust value for the pseudo costs.*/ |
| 98 |
double pseudocost_trust_value_; |
| 99 |
/** Global time limit for algorithm. */ |
| 100 |
double time_limit_; |
| 101 |
|
| 102 |
/** Starting time of algorithm.*/ |
| 103 |
double start_time_; |
| 104 |
|
| 105 |
/// Start of nway objects in array |
| 106 |
int start_nway_; |
| 107 |
|
| 108 |
/// log level |
| 109 |
int log_; |
| 110 |
typedef std::vector< std::vector<double> > full_mat; |
| 111 |
|
| 112 |
full_mat bounds_; |
| 113 |
|
| 114 |
full_mat unit_changes_; |
| 115 |
|
| 116 |
std::vector < std::vector<int> > num_ps_costs_; |
| 117 |
|
| 118 |
std::vector<int> num_eval_; |
| 119 |
|
| 120 |
int geo_means_; |
| 121 |
}; |
| 122 |
|
| 123 |
} |
| 124 |
#endif |