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 // Edwin 11/10/2009-- carved out of CbcBranchActual
7 
8 #ifndef CbcFollowOn_H
9 #define CbcFollowOn_H
10 
11 #include "CbcBranchBase.hpp"
12 #include "OsiRowCut.hpp"
13 #include "CoinHelperFunctions.hpp"
14 #include "CoinPackedMatrix.hpp"
15 
16 /** Define a follow on class.
17     The idea of this is that in air-crew scheduling problems crew may fly in on flight A
18     and out on flight B or on some other flight.  A useful branch is one which on one side
19     fixes all which go out on flight B to 0, while the other branch fixes all those that do NOT
20     go out on flight B to 0.
21 
22     This branching rule should be in addition to normal rules and have a high priority.
23 */
24 
25 class CbcFollowOn : public CbcObject {
26 
27 public:
28   // Default Constructor
29   CbcFollowOn();
30 
31   /** Useful constructor
32     */
33   CbcFollowOn(CbcModel *model);
34 
35   // Copy constructor
36   CbcFollowOn(const CbcFollowOn &);
37 
38   /// Clone
39   virtual CbcObject *clone() const;
40 
41   // Assignment operator
42   CbcFollowOn &operator=(const CbcFollowOn &rhs);
43 
44   // Destructor
45   ~CbcFollowOn();
46 
47   /// Infeasibility - large is 0.5
48   virtual double infeasibility(const OsiBranchingInformation *info,
49     int &preferredWay) const;
50 
51   using CbcObject::feasibleRegion;
52   /// This looks at solution and sets bounds to contain solution
53   virtual void feasibleRegion();
54 
55   /// Creates a branching object
56   virtual CbcBranchingObject *createCbcBranch(OsiSolverInterface *solver, const OsiBranchingInformation *info, int way);
57   /// As some computation is needed in more than one place - returns row
58   virtual int gutsOfFollowOn(int &otherRow, int &preferredWay) const;
59 
60 protected:
61   /// data
62   /// Matrix
63   CoinPackedMatrix matrix_;
64   /// Matrix by row
65   CoinPackedMatrix matrixByRow_;
66   /// Possible rhs (if 0 then not possible)
67   int *rhs_;
68 };
69 
70 /** General Branching Object class.
71     Each way fixes some variables to lower bound
72  */
73 class CbcFixingBranchingObject : public CbcBranchingObject {
74 
75 public:
76   // Default Constructor
77   CbcFixingBranchingObject();
78 
79   // Useful constructor
80   CbcFixingBranchingObject(CbcModel *model,
81     int way,
82     int numberOnDownSide, const int *down,
83     int numberOnUpSide, const int *up);
84 
85   // Copy constructor
86   CbcFixingBranchingObject(const CbcFixingBranchingObject &);
87 
88   // Assignment operator
89   CbcFixingBranchingObject &operator=(const CbcFixingBranchingObject &rhs);
90 
91   /// Clone
92   virtual CbcBranchingObject *clone() const;
93 
94   // Destructor
95   virtual ~CbcFixingBranchingObject();
96 
97   using CbcBranchingObject::branch;
98   /// Does next branch and updates state
99   virtual double branch();
100 
101 #ifdef JJF_ZERO
102   // No need to override. Default works fine.
103   /** Reset every information so that the branching object appears to point to
104         the previous child. This method does not need to modify anything in any
105         solver. */
106   virtual void previousBranch();
107 #endif
108 
109   using CbcBranchingObject::print;
110   /** \brief Print something about branch - only if log level high
111     */
112   virtual void print();
113 
114   /** Return the type (an integer identifier) of \c this */
type() const115   virtual CbcBranchObjType type() const
116   {
117     return FollowOnBranchObj;
118   }
119 
120   /** Compare the original object of \c this with the original object of \c
121         brObj. Assumes that there is an ordering of the original objects.
122         This method should be invoked only if \c this and brObj are of the same
123         type.
124         Return negative/0/positive depending on whether \c this is
125         smaller/same/larger than the argument.
126     */
127   virtual int compareOriginalObject(const CbcBranchingObject *brObj) const;
128 
129   /** Compare the \c this with \c brObj. \c this and \c brObj must be os the
130         same type and must have the same original object, but they may have
131         different feasible regions.
132         Return the appropriate CbcRangeCompare value (first argument being the
133         sub/superset if that's the case). In case of overlap (and if \c
134         replaceIfOverlap is true) replace the current branching object with one
135         whose feasible region is the overlap.
136      */
137   virtual CbcRangeCompare compareBranchingObject(const CbcBranchingObject *brObj, const bool replaceIfOverlap = false);
138 
139 private:
140   /// data
141   /// Number on down list
142   int numberDown_;
143   /// Number on up list
144   int numberUp_;
145   /// downList - variables to fix to lb on down branch
146   int *downList_;
147   /// upList - variables to fix to lb on up branch
148   int *upList_;
149 };
150 
151 /** Define an idiotic idea class.
152     The idea of this is that we take some integer variables away from integer and
153     sum them with some randomness to get signed sum close to 0.5.  We then can
154     branch to exclude that gap.
155 
156     This branching rule should be in addition to normal rules and have a high priority.
157 */
158 
159 class CbcIdiotBranch : public CbcObject {
160 
161 public:
162   // Default Constructor
163   CbcIdiotBranch();
164 
165   /** Useful constructor
166     */
167   CbcIdiotBranch(CbcModel *model);
168 
169   // Copy constructor
170   CbcIdiotBranch(const CbcIdiotBranch &);
171 
172   /// Clone
173   virtual CbcObject *clone() const;
174 
175   // Assignment operator
176   CbcIdiotBranch &operator=(const CbcIdiotBranch &rhs);
177 
178   // Destructor
179   ~CbcIdiotBranch();
180 
181   /// Infeasibility - large is 0.5
182   virtual double infeasibility(const OsiBranchingInformation *info,
183     int &preferredWay) const;
184 
185   using CbcObject::feasibleRegion;
186   /// This looks at solution and sets bounds to contain solution
187   virtual void feasibleRegion();
188 
189   /// Creates a branching object
190   virtual CbcBranchingObject *createCbcBranch(OsiSolverInterface *solver, const OsiBranchingInformation *info, int way);
191   /// Initialize for branching
192   virtual void initializeForBranching(CbcModel *);
193 
194 protected:
195   /// Build "cut"
196   OsiRowCut buildCut(const OsiBranchingInformation *info, int type, int &preferredWay) const;
197   /// data
198   /// Thread specific random number generator
199   mutable CoinThreadRandom randomNumberGenerator_;
200   /// Saved version of thread specific random number generator
201   mutable CoinThreadRandom savedRandomNumberGenerator_;
202 };
203 
204 #endif
205 
206 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
207 */
208