source: trunk/Couenne/src/disjunctive/CouenneDisjCuts.hpp @ 945

Last change on this file since 945 was 945, checked in by stefan, 8 years ago

generateCuts in Cgl >= 0.58 will not be const anymore

  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* $Id: CouenneDisjCuts.hpp 945 2013-04-06 20:25:21Z stefan $
2 *
3 * Name:    CouenneDisjCuts.hpp
4 * Author:  Pietro Belotti
5 * Purpose: a generator of disjunctive cuts for MINLP problems
6 *
7 * (C) Carnegie-Mellon University, 2008.
8 * This file is licensed under the Eclipse Public License (EPL)
9 */
10
11#ifndef COUENNE_DISJUNCTIVE_CUTS_HPP
12#define COUENNE_DISJUNCTIVE_CUTS_HPP
13
14#include "BonRegisteredOptions.hpp"
15
16#include "OsiSolverInterface.hpp"
17#include "CglConfig.h"
18#include "CglCutGenerator.hpp"
19#include "BonOsiTMINLPInterface.hpp"
20#include "BonBabSetupBase.hpp"
21#include "BonBabInfos.hpp"
22#include "OsiChooseVariable.hpp"
23#include "CouenneTypes.hpp"
24#include "CouenneJournalist.hpp"
25
26namespace Couenne {
27
28class CouenneCutGenerator;
29
30enum {COUENNE_INFEASIBLE, COUENNE_TIGHTENED, COUENNE_FEASIBLE};
31
32/// Cut Generator for linear convexifications
33
34class CouenneDisjCuts: public CglCutGenerator {
35
36 protected:
37
38  /// pointer to symbolic repr. of constraint, variables, and bounds
39  CouenneCutGenerator *couenneCG_;
40
41  /// number of cuts generated at the first call
42  mutable int nrootcuts_;
43
44  /// total number of cuts generated
45  mutable int ntotalcuts_;
46
47  /// separation time (includes generation of problem)
48  mutable double septime_;
49
50  /// Record obj value at final point of CouenneConv.
51  mutable double objValue_;
52
53  /// nonlinear solver interface as used within Bonmin (used at first
54  /// Couenne pass of each b&b node)
55  Bonmin::OsiTMINLPInterface *minlp_;
56
57  /// Branching scheme (if strong, we can use SB candidates)
58  OsiChooseVariable *branchingMethod_;
59
60  /// Is branchMethod_ referred to a strong branching scheme?
61  bool isBranchingStrong_;
62
63  /// SmartPointer to the Journalist
64  JnlstPtr jnlst_;
65
66  /// Number of disjunction to consider at each separation
67  mutable int numDisjunctions_;
68
69  /// Initial percentage of objects to use for generating cuts, in [0,1]
70  double initDisjPercentage_;
71
72  /// Initial number of objects to use for generating cuts
73  int initDisjNumber_;
74
75  /// Depth of the BB tree where start decreasing number of objects
76  int depthLevelling_;
77
78  /// Depth of the BB tree where stop separation
79  int depthStopSeparate_;
80
81  /// only include active rows in CGLP
82  bool activeRows_;
83
84  /// only include active columns in CGLP
85  bool activeCols_;
86
87  /// add previous disj cut to current CGLP?
88  bool addPreviousCut_;
89
90  /// maximum CPU time
91  double cpuTime_;
92
93 public:
94
95  /// constructor
96  CouenneDisjCuts (Bonmin::OsiTMINLPInterface *minlp = NULL,
97                   Bonmin::BabSetupBase *base = NULL,
98                   CouenneCutGenerator *cg = NULL,
99                   OsiChooseVariable *bcv = NULL,
100                   bool is_strong = false,
101                   JnlstPtr journalist = NULL,
102                   const Ipopt::SmartPtr<Ipopt::OptionsList> options = NULL);
103
104  /// copy constructor
105  CouenneDisjCuts (const CouenneDisjCuts &);
106
107  /// destructor
108  ~CouenneDisjCuts ();
109
110  /// clone method (necessary for the abstract CglCutGenerator class)
111  CouenneDisjCuts *clone () const
112  {return new CouenneDisjCuts (*this);}
113
114  /// return pointer to symbolic problem
115  inline CouenneCutGenerator *couenneCG () const
116  {return couenneCG_;}
117
118  /// the main CglCutGenerator
119  void generateCuts (const OsiSolverInterface &, 
120                     OsiCuts &, 
121                     const CglTreeInfo = CglTreeInfo ())
122#if CGL_VERSION_MAJOR == 0 && CGL_VERSION_MINOR <= 57
123  const
124#endif
125  ;
126
127  /// Add list of options to be read from file
128  static void registerOptions (Ipopt::SmartPtr <Bonmin::RegisteredOptions> roptions);
129
130  /// Provide Journalist
131  inline ConstJnlstPtr Jnlst() const 
132  {return ConstPtr (jnlst_);}
133
134  /// get all disjunctions
135  int getDisjunctions (std::vector <std::pair <OsiCuts *, OsiCuts *> > &disjunctions, 
136                       OsiSolverInterface &si, 
137                       OsiCuts &cs, 
138                       const CglTreeInfo &info) const;
139
140  /// separate couenne cuts on both sides of single disjunction
141  int separateWithDisjunction (OsiCuts *cuts,
142                               OsiSolverInterface &si, 
143                               OsiCuts &cs, 
144                               const CglTreeInfo &info) const;
145
146  /// generate one disjunctive cut from one CGLP
147  int generateDisjCuts (std::vector <std::pair <OsiCuts *, OsiCuts *> > &disjs, 
148                       OsiSolverInterface &si, 
149                       OsiCuts &cs, 
150                        const CglTreeInfo &info) const;
151
152  /// check if (column!) cuts compatible with solver interface
153  int checkDisjSide (OsiSolverInterface &si, OsiCuts *cuts) const;
154
155  /// compute smallest box containing both left and right boxes.
156  int getBoxUnion (OsiSolverInterface &si, 
157                   OsiCuts *left, OsiCuts *right, 
158                   CoinPackedVector &lower, CoinPackedVector &upper) const;
159
160protected:
161
162  /// create single osicolcut disjunction
163  OsiCuts *getSingleDisjunction (OsiSolverInterface &si) const;
164
165  /// utility to merge vectors into one
166  void mergeBoxes (int dir,                        // direction (negative for "<", positive for ">")
167                   CoinPackedVector &left,         // input
168                   CoinPackedVector &right,        // input
169                   CoinPackedVector merged) const; // output 
170
171  /// our own applyColCuts
172  void applyColCuts (OsiSolverInterface &si,
173                     OsiCuts *cuts) const;
174
175  /// our own applyColCut, single cut
176  void applyColCuts (OsiSolverInterface &si, 
177                     OsiColCut *cut) const;
178
179  // construct reduced, standard form matrix M from coefficient matrix of si
180  void OsiSI2MatrVec (CoinPackedMatrix &M,
181                      CoinPackedVector &r,
182                      OsiSolverInterface &si) const;
183
184  /// add CGLP columns to solver interface; return number of columns
185  /// added (for later removal)
186  int OsiCuts2MatrVec (OsiSolverInterface *cglp,
187                       OsiCuts *cuts,
188                       int displRow,
189                       int displRhs) const;
190};
191
192
193/// invert all contents
194inline void CoinInvN (register const double *orig, 
195                      register int n, 
196                      register double *inverted) {
197
198  while (n--) *inverted++ = - *orig++;
199}
200
201
202/// a CoinCopyN with a += on each element
203inline void CoinCopyDisp (register const int *src, 
204                          register int num, 
205                          register int *dst, 
206                          register int displacement) {
207  while (num--)
208    *dst++ = *src++ + displacement;
209}
210
211}
212
213#endif
Note: See TracBrowser for help on using the repository browser.