source: stable/0.2/Couenne/src/convex/genColCuts.cpp @ 159

Last change on this file since 159 was 159, checked in by pbelotti, 11 years ago

created new stable branch 0.2 from trunk (rev. 157)

File size: 3.1 KB
Line 
1/* $Id: genColCuts.cpp 141 2009-06-03 04:19:19Z pbelotti $ */
2/*
3 * Name:    genColCuts.cpp
4 * Author:  Pietro Belotti
5 * Purpose: generate Column Cuts for improved bounds
6 *
7 * (C) Carnegie-Mellon University, 2006-07.
8 * This file is licensed under the Common Public License (CPL)
9 */
10
11#include "CglCutGenerator.hpp"
12#include "CouenneCutGenerator.hpp"
13#include "CouenneProblem.hpp"
14
15//#define DEBUG
16
17/// generate OsiColCuts for improved (implied and propagated) bounds
18void CouenneCutGenerator::genColCuts (const OsiSolverInterface &si,
19                                      OsiCuts &cs,
20                                      int nchanged,
21                                      int *changed) const {
22
23#ifdef DEBUG
24  int nrc = cs.sizeRowCuts ();// Must go
25#endif
26
27  int  ncols  = problem_ -> nVars (),
28      *indLow = new int [ncols], // indices for OsiColCut
29      *indUpp = new int [ncols], //
30       nLow, nUpp = nLow = 0;
31    //ind_obj = problem_ -> Obj (0) -> Body () -> Index ();
32
33  // values fo OsiColCut
34  CouNumber *bndLow = new CouNumber [ncols],
35            *bndUpp = new CouNumber [ncols];
36
37  const CouNumber
38    *oldLow = si.getColLower (), // old bounds
39    *oldUpp = si.getColUpper (),
40    *newLow = problem_ -> Lb (), // changed bounds
41    *newUpp = problem_ -> Ub ();
42
43#ifdef DEBUG
44  for (int i=0; i < problem_ -> nVars (); i++)
45    if ((newLow [i] > oldLow [i] + COUENNE_EPS) ||
46        (newUpp [i] < oldUpp [i] - COUENNE_EPS))
47      printf ("x%-3d. [%-10g , %10g] ---> [%-10g , %10g]\n",
48      i, oldLow [i], oldUpp [i], newLow [i], newUpp [i]);*/
49#endif
50
51  // check all changed bounds
52  for (int i = 0; i < nchanged; i++) {
53
54    int index = changed [i];
55
56    // fails with spectra2 with (abt=2,obbt=0) for variable x70
57    //assert (problem_ -> Var (index) -> Multiplicity () > 0);
58
59    if (//(index == ind_obj) ||
60        (problem_ -> Var (index) -> Multiplicity () <= 0))
61      continue;
62
63    if (newLow [index] > newUpp [index])
64      problem_ -> Lb (index) = problem_ -> Ub (index);
65
66    CouNumber bd;
67
68    if ((((bd = newLow [index]) > oldLow [index] + COUENNE_EPS) || firstcall_) // better lb?
69        && (bd > -COUENNE_INFINITY / 10)) {                                    // finite?
70
71      //printf ("chging low %d %g -> %g\n", index, oldLow [index], newLow [index]);
72      if (problem_ -> Var (index) -> isInteger ()) 
73        bd = ceil (bd);
74      indLow [nLow]   = index;
75      bndLow [nLow++] = bd;
76    }
77
78    if ((((bd = newUpp [index]) < oldUpp [index] - COUENNE_EPS) || firstcall_) // better ub?
79        && (bd < COUENNE_INFINITY / 10)) {                                     // finite?
80
81      //printf ("chging upp %d %g -> %g\n", index, oldUpp [index], newUpp [index]);
82      if (problem_ -> Var (index) -> isInteger ()) 
83        bd = floor (bd);
84      indUpp [nUpp]   = index;
85      bndUpp [nUpp++] = bd;
86    }
87  }
88
89  // create Column Cut
90
91  if (nUpp || nLow) {
92
93    OsiColCut *cut = new OsiColCut;
94
95    if (cut) {
96      cut -> setLbs (nLow, indLow, bndLow);
97      cut -> setUbs (nUpp, indUpp, bndUpp);
98
99      cs.insert (cut);
100      delete cut;
101    }
102  }
103
104#ifdef DEBUG
105  printf ("column cuts\n");
106  for (int jj = nrc; jj < cs.sizeRowCuts (); jj++) cs.rowCutPtr (jj) -> print ();
107#endif
108
109  delete [] bndLow; delete [] indLow;
110  delete [] bndUpp; delete [] indUpp;
111}
Note: See TracBrowser for help on using the repository browser.