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

Last change on this file since 490 was 490, checked in by pbelotti, 10 years ago

cut repeated (EPL)...

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