1 | // Copyright (C) 2006, International Business Machines |
---|
2 | // Corporation and others. All Rights Reserved. |
---|
3 | #ifndef CoinChooseVariable_H |
---|
4 | #define CoinChooseVariable_H |
---|
5 | |
---|
6 | #include <string> |
---|
7 | #include <vector> |
---|
8 | |
---|
9 | #include "CoinWarmStartBasis.hpp" |
---|
10 | #include "OsiBranchingObject.hpp" |
---|
11 | |
---|
12 | class OsiSolverInterface; |
---|
13 | |
---|
14 | /** This class chooses a variable to branch on |
---|
15 | |
---|
16 | The base class just chooses the variable and direction without strong branching but it |
---|
17 | has information which would normally be used by strong branching e.g. to re-enter |
---|
18 | having fixed a variable but using same candidates for strong branching. |
---|
19 | |
---|
20 | The flow is : |
---|
21 | a) initialize the process. This clears all information.and sets state_ to 0 |
---|
22 | b) if we are at state 0 then decide on strong branching list and set state to 1 |
---|
23 | c) if state is 1 then do strong branching on list. If list is empty then just |
---|
24 | choose aone candidate and return without strong branching. If not empty then |
---|
25 | go through list and return best. However we may find that the node is infeasible |
---|
26 | or that we can fix a variable. If so we return and it is up to user to call |
---|
27 | again (after fixing a variable). |
---|
28 | d) when finished we clear the state |
---|
29 | */ |
---|
30 | |
---|
31 | class CoinChooseVariable { |
---|
32 | |
---|
33 | public: |
---|
34 | |
---|
35 | /// Default Constructor |
---|
36 | CoinChooseVariable (); |
---|
37 | |
---|
38 | /// Constructor from solver (so we can set up arrays etc) |
---|
39 | CoinChooseVariable (const OsiSolverInterface * solver); |
---|
40 | |
---|
41 | /// Copy constructor |
---|
42 | CoinChooseVariable (const CoinChooseVariable &); |
---|
43 | |
---|
44 | /// Assignment operator |
---|
45 | CoinChooseVariable & operator= (const CoinChooseVariable& rhs); |
---|
46 | |
---|
47 | /// Clone |
---|
48 | virtual CoinChooseVariable * clone() const; |
---|
49 | |
---|
50 | /// Destructor |
---|
51 | virtual ~CoinChooseVariable (); |
---|
52 | |
---|
53 | /// Initialize |
---|
54 | void initialize ( OsiBranchingInformation *info=NULL); |
---|
55 | /** Choose a variable |
---|
56 | Returns - |
---|
57 | -1 Node is infeasible |
---|
58 | 0 Normal termination - we have a candidate |
---|
59 | 1 All looks satisfied - no candidate |
---|
60 | 2 We can change the bound on a variable - but we also have a strong branching candidate |
---|
61 | 3 We can change the bound on a variable - but we have a non-strong branching candidate |
---|
62 | 4 We can change the bound on a variable - no other candidates |
---|
63 | We can pick up branch from whichObject() and whichWay() |
---|
64 | We can pick up a forced branch (can change bound) from whichForcedObject() and whichForcedWay() |
---|
65 | If we have a solution then we can pick up from goodObjectiveValue() and goodSolution() |
---|
66 | */ |
---|
67 | int chooseVariable( OsiBranchingInformation *info=NULL); |
---|
68 | /// Finish - deletes any solution etc |
---|
69 | void finalize(); |
---|
70 | /// Objective value for feasible solution |
---|
71 | inline double goodObjectiveValue() const |
---|
72 | { return goodObjectiveValue_;}; |
---|
73 | /// Good solution - deleted by finalize |
---|
74 | inline const double * goodSolution() const |
---|
75 | { return goodSolution_;}; |
---|
76 | /// Get the number of objects unsatisfied at this node. |
---|
77 | inline int numberUnsatisfied() const |
---|
78 | {return numberUnsatisfied_;}; |
---|
79 | /// Number of objects to choose for strong branching |
---|
80 | inline int numberStrong() const |
---|
81 | { return numberStrong_;}; |
---|
82 | /// Set number of objects to choose for strong branching |
---|
83 | inline void setNumberStrong(int value) |
---|
84 | { numberStrong_ = value;}; |
---|
85 | /// Number left on strong list |
---|
86 | inline int numberOnList() const |
---|
87 | { return numberOnList_;}; |
---|
88 | /// Trust results from strong branching for changing bounds |
---|
89 | inline bool trustStrongForBound() const |
---|
90 | { return trustStrongForBound_;}; |
---|
91 | /// Set trust results from strong branching for changing bounds |
---|
92 | inline void setTrustStrongForBound(bool yesNo) |
---|
93 | { trustStrongForBound_ = yesNo;}; |
---|
94 | /// Trust results from strong branching for valid solution |
---|
95 | inline bool trustStrongForSolution() const |
---|
96 | { return trustStrongForSolution_;}; |
---|
97 | /// Set trust results from strong branching for valid solution |
---|
98 | inline void setTrustStrongForSolution(bool yesNo) |
---|
99 | { trustStrongForSolution_ = yesNo;}; |
---|
100 | /// Set solver |
---|
101 | inline void setSolver (OsiSolverInterface * solver) |
---|
102 | { solver_ = solver;}; |
---|
103 | |
---|
104 | |
---|
105 | protected: |
---|
106 | // Data |
---|
107 | /// Objective value for feasible solution |
---|
108 | double goodObjectiveValue_; |
---|
109 | /// Good solution - deleted by finalize |
---|
110 | double * goodSolution_; |
---|
111 | /// List of candidates |
---|
112 | int * list_; |
---|
113 | /// Useful array (for sorting etc) |
---|
114 | double * useful_; |
---|
115 | /// Pointer to solver |
---|
116 | const OsiSolverInterface * solver_; |
---|
117 | /// State 0 - no list, 1 a list |
---|
118 | int state_; |
---|
119 | /* Status - |
---|
120 | -1 Node is infeasible |
---|
121 | 0 Normal termination - we have a candidate |
---|
122 | 1 All looks satisfied - no candidate |
---|
123 | 2 We can change the bound on a variable - but we also have a strong branching candidate |
---|
124 | 3 We can change the bound on a variable - but we have a non-strong branching candidate |
---|
125 | 4 We can change the bound on a variable - no other candidates |
---|
126 | */ |
---|
127 | /// The number of objects unsatisfied at this node. |
---|
128 | int numberUnsatisfied_; |
---|
129 | /// Number of objects to choose for strong branching |
---|
130 | int numberStrong_; |
---|
131 | /// Number left on strong list |
---|
132 | int numberOnList_; |
---|
133 | /// List of unsatisfied objects - first numberOnList_ for strong branching |
---|
134 | /// Trust results from strong branching for changing bounds |
---|
135 | bool trustStrongForBound_; |
---|
136 | /// Trust results from strong branching for valid solution |
---|
137 | bool trustStrongForSolution_; |
---|
138 | }; |
---|
139 | |
---|
140 | |
---|
141 | #endif |
---|