00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "CglCutGenerator.hpp"
00012 #include "CouenneCutGenerator.hpp"
00013 #include "CouenneProblem.hpp"
00014 #include "CouenneExprVar.hpp"
00015
00016 using namespace Couenne;
00017
00018
00019
00021 void CouenneCutGenerator::genColCuts (const OsiSolverInterface &si,
00022 OsiCuts &cs,
00023 int nchanged,
00024 int *changed) const {
00025
00026 #ifdef DEBUG
00027 int nrc = cs.sizeRowCuts ();
00028 #endif
00029
00030 int ncols = problem_ -> nVars (),
00031 *indLow = new int [ncols],
00032 *indUpp = new int [ncols],
00033 nLow, nUpp = nLow = 0;
00034
00035
00036
00037 CouNumber *bndLow = new CouNumber [ncols],
00038 *bndUpp = new CouNumber [ncols];
00039
00040 const CouNumber
00041 *oldLow = si.getColLower (),
00042 *oldUpp = si.getColUpper (),
00043 *newLow = problem_ -> Lb (),
00044 *newUpp = problem_ -> Ub ();
00045
00046 #ifdef DEBUG
00047 for (int i=0; i < problem_ -> nVars (); i++)
00048 if ((newLow [i] > oldLow [i] + COUENNE_EPS) ||
00049 (newUpp [i] < oldUpp [i] - COUENNE_EPS))
00050 printf ("x%-3d. [%-10g , %10g] ---> [%-10g , %10g]\n",
00051 i, oldLow [i], oldUpp [i], newLow [i], newUpp [i]);*/
00052 #endif
00053
00054
00055 for (int i = 0; i < nchanged; i++) {
00056
00057 int index = changed [i];
00058
00059
00060
00061
00062 if (
00063 (problem_ -> Var (index) -> Multiplicity () <= 0))
00064 continue;
00065
00066 if (newLow [index] > newUpp [index])
00067 problem_ -> Lb (index) = problem_ -> Ub (index);
00068
00069 CouNumber bd;
00070
00071 if ((((bd = newLow [index]) > oldLow [index] + COUENNE_EPS) || firstcall_)
00072 && (bd > -COUENNE_INFINITY / 10)) {
00073
00074
00075 if (problem_ -> Var (index) -> isInteger ())
00076 bd = ceil (bd - COUENNE_EPS);
00077 indLow [nLow] = index;
00078 bndLow [nLow++] = bd;
00079 }
00080
00081 if ((((bd = newUpp [index]) < oldUpp [index] - COUENNE_EPS) || firstcall_)
00082 && (bd < COUENNE_INFINITY / 10)) {
00083
00084
00085 if (problem_ -> Var (index) -> isInteger ())
00086 bd = floor (bd + COUENNE_EPS);
00087 indUpp [nUpp] = index;
00088 bndUpp [nUpp++] = bd;
00089 }
00090 }
00091
00092
00093
00094 if (nUpp || nLow) {
00095
00096 OsiColCut *cut = new OsiColCut;
00097
00098 if (cut) {
00099 cut -> setLbs (nLow, indLow, bndLow);
00100 cut -> setUbs (nUpp, indUpp, bndUpp);
00101
00102 cs.insert (cut);
00103 delete cut;
00104 }
00105 }
00106
00107 #ifdef DEBUG
00108 printf ("column cuts\n");
00109 for (int jj = nrc; jj < cs.sizeRowCuts (); jj++) cs.rowCutPtr (jj) -> print ();
00110 #endif
00111
00112 delete [] bndLow; delete [] indLow;
00113 delete [] bndUpp; delete [] indUpp;
00114 }