00001 /* $Id: genRowCuts.cpp 217 2009-07-08 17:02:07Z pbelotti $ 00002 * 00003 * Name: genRowCuts.cpp 00004 * Author: Pietro Belotti 00005 * Purpose: generate Row Cuts for current convexification 00006 * 00007 * (C) Carnegie-Mellon University, 2006-09. 00008 * This file is licensed under the Common Public License (CPL) 00009 */ 00010 00011 #include "CglCutGenerator.hpp" 00012 #include "CouenneCutGenerator.hpp" 00013 #include "CouenneProblem.hpp" 00014 00015 00017 void CouenneCutGenerator::genRowCuts (const OsiSolverInterface &si, 00018 OsiCuts &cs, 00019 int nchanged, 00020 int *changed, 00021 t_chg_bounds *chg) const { 00022 00023 // TODO: make nchanged and changed useful 00024 // TODO: pass have_NLP to all 00025 00026 // For each auxiliary variable, create convexification cut (or set 00027 // of cuts) and add it to cs 00028 00029 // do NOT project current point into new bounding box! it prevents 00030 // convexification cuts that are violated by current point 00031 00032 /*for (int i=0, j = problem_ -> nVars (); j--; i++) { 00033 00034 CouNumber &x = problem_ -> X (i), 00035 lb = problem_ -> Lb (i), 00036 ub = problem_ -> Ub (i); 00037 00038 if (x < lb) x = lb; 00039 else if (x > ub) x = ub; 00040 }*/ 00041 00042 if (firstcall_) 00043 for (int i=0, j = problem_ -> nVars (); j--; i++) { 00044 00045 if (CoinCpuTime () > problem_ -> getMaxCpuTime ()) 00046 break; 00047 00048 exprVar *var = problem_ -> Var (i); 00049 00050 if ((var -> Multiplicity () > 0) && 00051 (var -> Type () == AUX)) { 00052 00053 var -> generateCuts (/*si,*/ cs, this, chg); 00054 } 00055 } 00056 else { // chg_bds contains the indices of the variables whose bounds 00057 // have changed (a -1 follows the last element) 00058 00059 /* 00060 printf ("# # # # pass = %d, have_NLP = %d. nchanged = %d: {", info.pass, have_NLP, nchanged); 00061 00062 if (changed) 00063 for (int i=0; (i<nchanged) && (changed [i] >= 0); i++) 00064 printf ("%d ", changed [i]); 00065 00066 printf ("}\n"); 00067 */ 00068 00069 for (int i = 0, j = problem_ -> nVars (); j--; i++) { 00070 00071 // TODO: check if list contains all and only aux's to cut 00072 00073 /*expression * image = problem_ -> Aux (i) -> Image (); 00074 00075 if ((image -> dependsOn (changed, nchanged)) && 00076 (image -> Linearity () > LINEAR)) { 00077 printf (" "); 00078 problem_ -> Aux (i) -> print (); 00079 printf (" : = "); 00080 image -> print (); 00081 printf ("\n"); 00082 } 00083 */ 00084 // cut only if: 00085 00086 /*if ( (image -> Linearity () > LINEAR) // 1) expression is non linear 00087 && (image -> dependsOn (changed, nchanged) // 2) it depends on changed variables 00088 || have_NLP 00089 || info.pass > 0)) { 00090 */ 00091 00092 exprVar *var = problem_ -> Var (problem_ -> evalOrder (i)); 00093 00094 if ((var -> Type () == AUX) && 00095 (var -> Multiplicity () > 0) && 00096 (var -> Image () -> Linearity () > LINEAR)) { 00097 00098 if (CoinCpuTime () > problem_ -> getMaxCpuTime ()) 00099 break; 00100 00101 var -> generateCuts (/*si,*/ cs, this, chg); 00102 } 00103 } 00104 } 00105 }