00001
00002
00003 #ifndef CglTwomir_H
00004 #define CglTwomir_H
00005 #include <string>
00006
00007 #include "CglCutGenerator.hpp"
00008 #include "CoinFactorization.hpp"
00009
00010 typedef struct
00011 {
00012
00013 int nz;
00014 int max_nz;
00015 double *coeff;
00016 int *index;
00017 double rhs;
00018 char sense;
00019
00020 } DGG_constraint_t;
00021
00022 typedef struct{
00023 int n;
00024 DGG_constraint_t **c;
00025 int *ctype;
00026 double *alpha;
00027 } DGG_list_t;
00028
00029
00030 typedef struct{
00031 int q_min;
00032 int q_max;
00033 int t_min;
00034 int t_max;
00035 int a_max;
00036 int max_elements;
00037 } cutParams;
00038
00039 typedef struct
00040 {
00041 double gomory_threshold;
00042 int ncol,
00043 nrow,
00044 ninteger;
00045
00046 int nbasic_col,
00047 nbasic_row;
00048
00049
00050 int *info;
00051 double *lb;
00052 double *ub;
00053 double *x;
00054 double *rc;
00055 double *opt_x;
00056
00057 cutParams cparams;
00058 } DGG_data_t;
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #define DGG_isBasic(data,idx) ((data->info[idx])&1)
00069 #define DGG_isInteger(data,idx) ((data->info[idx] >> 1)&1)
00070 #define DGG_isStructural(data,idx) ((data->info[idx] >> 2)&1)
00071 #define DGG_isEqualityConstraint(data,idx) ((data->info[idx] >> 3)&1)
00072 #define DGG_isNonBasicAtUB(data,idx) ((data->info[idx] >> 4)&1)
00073 #define DGG_isNonBasicAtLB(data,idx) ((data->info[idx] >> 5)&1)
00074 #define DGG_isConstraintBoundedAbove(data,idx) ((data->info[idx] >> 6)&1)
00075 #define DGG_isConstraintBoundedBelow(data,idx) ((data->info[idx] >> 7)&1)
00076
00077 #define DGG_setIsBasic(data,idx) ((data->info[idx]) |= 1)
00078 #define DGG_setIsInteger(data,idx) ((data->info[idx]) |= (1<<1))
00079 #define DGG_setIsStructural(data,idx) ((data->info[idx]) |= (1<<2))
00080 #define DGG_setEqualityConstraint(data,idx) ((data->info[idx]) |= (1<<3))
00081 #define DGG_setIsNonBasicAtUB(data,idx) ((data->info[idx]) |= (1<<4))
00082 #define DGG_setIsNonBasicAtLB(data,idx) ((data->info[idx]) |= (1<<5))
00083 #define DGG_setIsConstraintBoundedAbove(data,idx) ((data->info[idx]) |= (1<<6))
00084 #define DGG_setIsConstraintBoundedBelow(data,idx) ((data->info[idx]) |= (1<<7))
00085
00086 class CoinWarmStartBasis;
00088 class CglTwomir : public CglCutGenerator {
00089
00090 friend void CglTwomirUnitTest(const OsiSolverInterface * siP,
00091 const std::string mpdDir );
00092
00093
00094 public:
00095
00097 mutable std::string probname_;
00098
00104 virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs,
00105 const CglTreeInfo info = CglTreeInfo()) const;
00107 virtual bool needsOptimalBasis() const;
00108
00111
00112 void setMirScale (int tmin, int tmax) {t_min_ = tmin; t_max_ = tmax;}
00113 void setTwomirScale (int qmin, int qmax) {q_min_ = qmin; q_max_ = qmax;}
00114 void setAMax (int a) {a_max_ = a;}
00115 void setMaxElements (int n) {max_elements_ = n;}
00116 void setMaxElementsRoot (int n) {max_elements_root_ = n;}
00117 void setCutTypes (bool mir, bool twomir, bool tab, bool form)
00118 { do_mir_ = mir; do_2mir_ = twomir; do_tab_ = tab; do_form_ = form;}
00119 void setFormulationRows (int n) {form_nrows_ = n;}
00120
00122 int getTmin() const {return t_min_;}
00123 int getTmax() const {return t_max_;}
00124 int getQmin() const {return q_min_;}
00125 int getQmax() const {return q_max_;}
00126 int getAmax() const {return a_max_;}
00127 int getMaxElements() const {return max_elements_;}
00128 int getMaxElementsRoot() const {return max_elements_root_;}
00129 int getIfMir() const { return do_mir_;}
00130 int getIfTwomir() const { return do_2mir_;}
00131 int getIfTableau() const { return do_tab_;}
00132 int getIfFormulation() const { return do_form_;}
00134
00139
00140 void setAway(double value);
00142 double getAway() const;
00144 void setAwayAtRoot(double value);
00146 double getAwayAtRoot() const;
00148
00151
00152 CglTwomir ();
00153
00155 CglTwomir (const CglTwomir &);
00156
00158 virtual CglCutGenerator * clone() const;
00159
00161 CglTwomir & operator=(const CglTwomir& rhs);
00162
00164 virtual ~CglTwomir ();
00166 virtual std::string generateCpp( FILE * fp);
00168
00169 private:
00170
00173
00174 double away_;
00176 double awayAtRoot_;
00177 bool do_mir_;
00178 bool do_2mir_;
00179 bool do_tab_;
00180 bool do_form_;
00181
00182 int t_min_;
00183 int t_max_;
00184 int q_min_;
00185 int q_max_;
00186 int a_max_;
00187 int max_elements_;
00188 int max_elements_root_;
00189 int form_nrows_;
00191 };
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 #define DGG_DEBUG_DGG 1
00208 #define DGG_TRACE_ERRORS 0
00209 #define DGG_DISPLAY 0
00210 #define DGG_AUTO_CHECK_CUT_OFF_OPTIMAL 1
00211
00212
00213
00214 #define DGG_DEFAULT_METHOD 2
00215 #define DGG_DEFAULT_TMIN 1
00216 #define DGG_DEFAULT_TMAX 1
00217 #define DGG_DEFAULT_TAUMIN 2
00218 #define DGG_DEFAULT_TAUMAX 6
00219 #define DGG_DEFAULT_MAX_CUTS 500
00220 #define DGG_DEFAULT_IMPROVEMENT_THRESH 0.001
00221 #define DGG_DEFAULT_NBELOW_THRESH INT_MAX
00222 #define DGG_DEFAULT_NROOT_ROUNDS 2
00223 #define DGG_DEFAULT_NEGATIVE_SCALED_TWOSTEPS 0
00224 #define DGG_DEFAULT_ALPHA_RULE 0
00225 #define DGG_DEFAULT_CUT_INC 250
00226 #define DGG_DEFAULT_CUT_FORM 0
00227 #define DGG_DEFAULT_NICEFY 0
00228 #define DGG_DEFAULT_ONLY_DELAYED 0
00229 #define DGG_DEFAULT_DELAYED_FREQ 9999999
00230 #define DGG_DEFAULT_LPROWS_FREQ 9999999
00231 #define DGG_DEFAULT_WHICH_FORMULATION_CUTS 2
00232
00233
00234
00235 #define DGG_OSI 0
00236 #define DGG_CPX 1
00237 #define DGG_QSO 2
00238
00239
00240 #define DGG_SOLVER DGG_OSI
00241
00242
00243 #define DGG_DEBUG_SOLVER 0
00244
00245
00246 #define DGG_SOLVER_SCREEN_FLAG 0
00247
00248
00249
00250
00251 #define DGG_TMIR_CUT 1
00252 #define DGG_2STEP_CUT 2
00253
00254
00255 #define DGG_ALPHA_MIN_SUM 0
00256 #define DGG_ALPHA_RANDOM_01 1
00257 #define DGG_ALPHA_RANDOM_COEFF 2
00258 #define DGG_ALPHA_ALL 3
00259 #define DGG_ALPHA_MAX_STEEP 5
00260
00261
00262
00263
00264 #define DGG_MIN_STEEPNESS 1.0e-4
00265 #define DGG_MAX_L2NORM 1.0e7
00266
00267
00268 #define DGG_NORM_CRITERIA 1
00269
00270
00271 #define UB_MAX DBL_MAX
00272 #define LB_MIN DBL_MIN
00273
00274
00275
00276
00277 #define DGG_GOMORY_THRESH 0.005
00278
00279 #define DGG_RHS_THRESH 0.005
00280
00281
00282
00283
00284
00285 #define DGG_BOUND_THRESH 1.0e-6
00286
00287
00288
00289 #define DGG_EQUALITY_THRESH 1.0e-5
00290
00291
00292
00293 #define DGG_SHIFT_THRESH 1.0e-6
00294
00295
00296
00297
00298 #define DGG_INTEGRALITY_THRESH 1.0e-10
00299
00300
00301
00302 #define CBC_CHECK_CUT
00303 #ifndef CBC_CHECK_CUT
00304 #define DGG_MIN_TABLEAU_COEFFICIENT 1.0e-8
00305 #else
00306 #define DGG_MIN_TABLEAU_COEFFICIENT 1.0e-12
00307 #endif
00308
00309
00310
00311 #define DGG_MIN_RHO 1.0e-7
00312 #define DGG_MIN_ALPHA 1.0e-7
00313
00314
00315 #define DGG_NULL_SLACK 1.0e-5
00316
00317
00318 #define DGG_NICEFY_MIN_ABSVALUE 1.0e-13
00319 #define DGG_NICEFY_MIN_FIX 1.0e-7
00320 #define DGG_NICEFY_MAX_PADDING 1.0e-6
00321 #define DGG_NICEFY_MAX_RATIO 1.0e9
00322
00323
00324
00325 #if DGG_TRACE_ERRORS > 0
00326
00327 #define __DGG_PRINT_LOC__(F) fprintf(((F==0)?stdout:F), " in %s (%s:%d)\n", __func__, __FILE__, __LINE__)
00328
00329 #define DGG_THROW(A,REST...) {\
00330 fprintf(stdout, ##REST); \
00331 __DGG_PRINT_LOC__(stdout); \
00332 return (A);}
00333
00334 #define DGG_IF_EXIT(A,B,REST...) {\
00335 if(A) {\
00336 fprintf(stdout, ##REST); \
00337 __DGG_PRINT_LOC__(stdout); \
00338 exit(B);}}
00339
00340 #define DGG_CHECKRVAL(A,B) {\
00341 if(A) {\
00342 __DGG_PRINT_LOC__(stdout); \
00343 return B; } }
00344
00345 #define DGG_CHECKRVAL1(A,B) {\
00346 if(A) {\
00347 __DGG_PRINT_LOC__(stdout); \
00348 rval = B; goto CLEANUP; } }
00349
00350 #define DGG_WARNING(A, REST...) {\
00351 if(A) {\
00352 fprintf(stdout, ##REST); \
00353 __DGG_PRINT_LOC__(stdout); \
00354 }}
00355
00356 #define DGG_TEST(A,B,REST...) {\
00357 if(A) DGG_THROW(B,##REST) }
00358
00359 #define DGG_TEST2(A,B,C,REST) {DGG_TEST(A,B,C,REST) }
00360 #define DGG_TEST3(A,B,C,D,REST) {DGG_TEST(A,B,C,D,REST) }
00361
00362 #else
00363
00364 #define DGG_IF_EXIT(A,B,REST) {if(A) {fprintf(stdout, REST);exit(B);}}
00365
00366 #define DGG_THROW(A,B) return(A)
00367
00368 #define DGG_CHECKRVAL(A,B) { if(A) return(B); }
00369 #define DGG_CHECKRVAL1(A,B){ if(A) { rval = B; goto CLEANUP; } }
00370
00371 #define DGG_TEST(A,B,REST) { if(A) return(B);}
00372 #define DGG_TEST2(A,B,REST,C) { DGG_TEST(A,B,REST) }
00373 #define DGG_TEST3(A,B,REST,C,D) { DGG_TEST(A,B,REST) }
00374
00375 #endif
00376
00377
00378
00379 #define DGG_MIN(a,b) ( (a<b)?a:b )
00380 #define DGG_MAX(a,b) ( (a>b)?a:b )
00381 #define KREM(vht,alpha,tau) (DGG_MIN( ceil(vht / alpha), tau ) - 1)
00382 #define LMIN(vht, d, bht) (DGG_MIN( floor(d*bht/bht), d))
00383 #define ABOV(v) (v - floor(v))
00384 #define QINT(vht,bht,tau) ( (int)floor( (vht*(tau-1))/bht ) )
00385 #define V2I(bht,tau,i) ( ((i+1)*bht / tau) )
00386
00387 int DGG_is_even(double vht, double bht, int tau, int q);
00388 double frac_part(double value);
00389 int DGG_is_a_multiple_of_b(double a, double b);
00390
00391
00392
00393 int DGG_freeData( DGG_data_t *data );
00394
00395
00396 DGG_constraint_t* DGG_newConstraint(int max_arrays);
00397 void DGG_freeConstraint(DGG_constraint_t *c);
00398 DGG_constraint_t *DGG_copyConstraint(DGG_constraint_t *c);
00399 void DGG_scaleConstraint(DGG_constraint_t *c, int t);
00400
00401
00402 void DGG_list_init (DGG_list_t *l);
00403 int DGG_list_addcut (DGG_list_t *l, DGG_constraint_t *cut, int ctype, double alpha);
00404 void DGG_list_delcut (DGG_list_t *l, int i);
00405 void DGG_list_free(DGG_list_t *l);
00406
00407
00408 DGG_data_t *DGG_getData(const void *solver_ptr);
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422 int DGG_transformConstraint( DGG_data_t *data,
00423 double **x_out,
00424 double **rc_out,
00425 char **isint_out,
00426 DGG_constraint_t *constraint );
00427
00428
00429
00430
00431
00432
00433 int DGG_unTransformConstraint( DGG_data_t *data,
00434 DGG_constraint_t *constraint );
00435
00436
00437
00438
00439 int DGG_substituteSlacks( const void *solver_ptr,
00440 DGG_data_t *data,
00441 DGG_constraint_t *cut );
00442
00443 int DGG_nicefyConstraint( const void *solver_ptr,
00444 DGG_data_t *data,
00445 DGG_constraint_t *cut);
00446
00447
00448 int DGG_getFormulaConstraint( int row_idx,
00449 const void *solver_ptr,
00450 DGG_data_t *data,
00451 DGG_constraint_t* row );
00452
00453 int DGG_getTableauConstraint( int index,
00454 const void *solver_ptr,
00455 DGG_data_t *data,
00456 DGG_constraint_t* tabrow,
00457 const int * colIsBasic,
00458 const int * rowIsBasic,
00459 CoinFactorization & factorization,
00460 int mode );
00461
00462 DGG_constraint_t* DGG_getSlackExpression(const void *solver_ptr, DGG_data_t* data, int row_index);
00463
00464 int DGG_generateTabRowCuts( DGG_list_t *list,
00465 DGG_data_t *data,
00466 const void *solver_ptr );
00467
00468 int DGG_generateFormulationCuts( DGG_list_t *list,
00469 DGG_data_t *data,
00470 const void *solver_ptr,
00471 int nrows);
00472
00473
00474 int DGG_generateFormulationCutsFromBase( DGG_constraint_t *base,
00475 double slack,
00476 DGG_list_t *list,
00477 DGG_data_t *data,
00478 const void *solver_ptr );
00479
00480 int DGG_generateCutsFromBase( DGG_constraint_t *base,
00481 DGG_list_t *list,
00482 DGG_data_t *data,
00483 const void *solver_ptr );
00484
00485 int DGG_buildMir( char *isint,
00486 DGG_constraint_t *base,
00487 DGG_constraint_t **cut_out );
00488
00489 int DGG_build2step( double alpha,
00490 char *isint,
00491 DGG_constraint_t *base,
00492 DGG_constraint_t **cut_out );
00493
00494 int DGG_addMirToList ( DGG_constraint_t *base,
00495 char *isint,
00496 double *x,
00497 DGG_list_t *list,
00498 DGG_data_t *data,
00499 DGG_constraint_t *orig_base );
00500
00501 int DGG_add2stepToList ( DGG_constraint_t *base,
00502 char *isint,
00503 double *x,
00504 double *rc,
00505 DGG_list_t *list,
00506 DGG_data_t *data,
00507 DGG_constraint_t *orig_base );
00508
00509
00510
00511 double DGG_cutLHS(DGG_constraint_t *c, double *x);
00512 int DGG_isCutDesirable(DGG_constraint_t *c, DGG_data_t *d);
00513
00514
00515
00516 int DGG_isConstraintViolated(DGG_data_t *d, DGG_constraint_t *c);
00517
00518 int DGG_isBaseTrivial(DGG_data_t *d, DGG_constraint_t* c);
00519 int DGG_is2stepValid(double alpha, double bht);
00520
00521 int DGG_cutsOffPoint(double *x, DGG_constraint_t *cut);
00522
00523
00529 void CglTwomirUnitTest(const OsiSolverInterface * siP,
00530 const std::string mpdDir);
00531
00532
00533 #endif
00534
00535