source: branches/sandbox/Cbc/src/CbcSOS.hpp @ 1357

Last change on this file since 1357 was 1357, checked in by coin, 10 years ago

run 'astyle -A4 -p' and dos2unix

File size: 7.5 KB
Line 
1// Edwin 11/9/2009-- carved out of CbcBranchActual
2#ifndef CbcSOS_H
3#define CbcSOS_H
4
5/** Define Special Ordered Sets of type 1 and 2.  These do not have to be
6    integer - so do not appear in lists of integers.
7
8    which_ points directly to columns of matrix
9*/
10
11
12class CbcSOS : public CbcObject {
13
14public:
15
16    // Default Constructor
17    CbcSOS ();
18
19    /** Useful constructor - which are indices
20        and  weights are also given.  If null then 0,1,2..
21        type is SOS type
22    */
23    CbcSOS (CbcModel * model, int numberMembers,
24            const int * which, const double * weights, int identifier,
25            int type = 1);
26
27    // Copy constructor
28    CbcSOS ( const CbcSOS &);
29
30    /// Clone
31    virtual CbcObject * clone() const;
32
33    // Assignment operator
34    CbcSOS & operator=( const CbcSOS& rhs);
35
36    // Destructor
37    virtual ~CbcSOS ();
38
39    /// Infeasibility - large is 0.5
40    virtual double infeasibility(const OsiBranchingInformation * info,
41                                 int &preferredWay) const;
42
43    using CbcObject::feasibleRegion ;
44    /// This looks at solution and sets bounds to contain solution
45    virtual void feasibleRegion();
46
47    /// Creates a branching object
48    virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) ;
49
50
51
52    /** Pass in information on branch just done and create CbcObjectUpdateData instance.
53        If object does not need data then backward pointer will be NULL.
54        Assumes can get information from solver */
55    virtual CbcObjectUpdateData createUpdateInformation(const OsiSolverInterface * solver,
56            const CbcNode * node,
57            const CbcBranchingObject * branchingObject);
58    /// Update object by CbcObjectUpdateData
59    virtual void updateInformation(const CbcObjectUpdateData & data) ;
60    using CbcObject::solverBranch ;
61    /** Create an OsiSolverBranch object
62
63        This returns NULL if branch not represented by bound changes
64    */
65    virtual OsiSolverBranch * solverBranch() const;
66    /// Redoes data when sequence numbers change
67    virtual void redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns);
68
69    /// Construct an OsiSOS object
70    OsiSOS * osiObject(const OsiSolverInterface * solver) const;
71    /// Number of members
72    inline int numberMembers() const {
73        return numberMembers_;
74    }
75
76    /// Members (indices in range 0 ... numberColumns-1)
77    inline const int * members() const {
78        return members_;
79    }
80
81    /// SOS type
82    inline int sosType() const {
83        return sosType_;
84    }
85    /// Down number times
86    inline int numberTimesDown() const {
87        return numberTimesDown_;
88    }
89    /// Up number times
90    inline int numberTimesUp() const {
91        return numberTimesUp_;
92    }
93
94    /** Array of weights */
95    inline const double * weights() const {
96        return weights_;
97    }
98
99    /// Set number of members
100    inline void setNumberMembers(int n) {
101        numberMembers_ = n;
102    }
103
104    /// Members (indices in range 0 ... numberColumns-1)
105    inline int * mutableMembers() const {
106        return members_;
107    }
108
109    /** Array of weights */
110    inline double * mutableWeights() const {
111        return weights_;
112    }
113
114    /** \brief Return true if object can take part in normal heuristics
115    */
116    virtual bool canDoHeuristics() const {
117        return (sosType_ == 1 && integerValued_);
118    }
119    /// Set whether set is integer valued or not
120    inline void setIntegerValued(bool yesNo) {
121        integerValued_ = yesNo;
122    }
123private:
124    /// data
125
126    /// Members (indices in range 0 ... numberColumns-1)
127    int * members_;
128    /// Weights
129    double * weights_;
130    /// Current pseudo-shadow price estimate down
131    mutable double shadowEstimateDown_;
132    /// Current pseudo-shadow price estimate up
133    mutable double shadowEstimateUp_;
134    /// Down pseudo ratio
135    double downDynamicPseudoRatio_;
136    /// Up pseudo ratio
137    double upDynamicPseudoRatio_;
138    /// Number of times we have gone down
139    int numberTimesDown_;
140    /// Number of times we have gone up
141    int numberTimesUp_;
142    /// Number of members
143    int numberMembers_;
144    /// SOS type
145    int sosType_;
146    /// Whether integer valued
147    bool integerValued_;
148};
149
150/** Branching object for Special ordered sets
151
152    Variable_ is the set id number (redundant, as the object also holds a
153    pointer to the set.
154 */
155class CbcSOSBranchingObject : public CbcBranchingObject {
156
157public:
158
159    // Default Constructor
160    CbcSOSBranchingObject ();
161
162    // Useful constructor
163    CbcSOSBranchingObject (CbcModel * model,  const CbcSOS * clique,
164                           int way,
165                           double separator);
166
167    // Copy constructor
168    CbcSOSBranchingObject ( const CbcSOSBranchingObject &);
169
170    // Assignment operator
171    CbcSOSBranchingObject & operator=( const CbcSOSBranchingObject& rhs);
172
173    /// Clone
174    virtual CbcBranchingObject * clone() const;
175
176    // Destructor
177    virtual ~CbcSOSBranchingObject ();
178
179    using CbcBranchingObject::branch ;
180    /// Does next branch and updates state
181    virtual double branch();
182    /** Update bounds in solver as in 'branch' and update given bounds.
183        branchState is -1 for 'down' +1 for 'up' */
184    virtual void fix(OsiSolverInterface * solver,
185                     double * lower, double * upper,
186                     int branchState) const ;
187
188    /** Reset every information so that the branching object appears to point to
189        the previous child. This method does not need to modify anything in any
190        solver. */
191    virtual void previousBranch() {
192        CbcBranchingObject::previousBranch();
193        computeNonzeroRange();
194    }
195
196    using CbcBranchingObject::print ;
197    /** \brief Print something about branch - only if log level high
198    */
199    virtual void print();
200
201    /** Return the type (an integer identifier) of \c this */
202    virtual int type() const {
203        return 104;
204    }
205
206    /** Compare the original object of \c this with the original object of \c
207        brObj. Assumes that there is an ordering of the original objects.
208        This method should be invoked only if \c this and brObj are of the same
209        type.
210        Return negative/0/positive depending on whether \c this is
211        smaller/same/larger than the argument.
212    */
213    virtual int compareOriginalObject(const CbcBranchingObject* brObj) const;
214
215    /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
216        same type and must have the same original object, but they may have
217        different feasible regions.
218        Return the appropriate CbcRangeCompare value (first argument being the
219        sub/superset if that's the case). In case of overlap (and if \c
220        replaceIfOverlap is true) replace the current branching object with one
221        whose feasible region is the overlap.
222     */
223    virtual CbcRangeCompare compareBranchingObject
224    (const CbcBranchingObject* brObj, const bool replaceIfOverlap = false);
225
226    /** Fill out the \c firstNonzero_ and \c lastNonzero_ data members */
227    void computeNonzeroRange();
228
229private:
230    /// data
231    const CbcSOS * set_;
232    /// separator
233    double separator_;
234    /** The following two members describe the range in the members_ of the
235        original object that whose upper bound is not fixed to 0. This is not
236        necessary for Cbc to function correctly, this is there for heuristics so
237        that separate branching decisions on the same object can be pooled into
238        one branching object. */
239    int firstNonzero_;
240    int lastNonzero_;
241};
242#endif
Note: See TracBrowser for help on using the repository browser.