00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef BlisModel_h_
00028 #define BlisModel_h_
00029
00030
00031
00032 #include "CoinMpsIO.hpp"
00033 #include "CoinPackedMatrix.hpp"
00034 #include "CoinMessageHandler.hpp"
00035 #include "OsiSolverInterface.hpp"
00036 #include "OsiCuts.hpp"
00037 #include "CglCutGenerator.hpp"
00038
00039 #include "AlpsKnowledgeBroker.h"
00040 #include "AlpsParams.h"
00041
00042 #include "BcpsModel.h"
00043
00044 #include "BcpsBranchStrategy.h"
00045 #include "BcpsObject.h"
00046 #include "BcpsObjectPool.h"
00047
00048 #include "Blis.h"
00049 #include "BlisConGenerator.h"
00050 #include "BlisHeuristic.h"
00051 #include "BlisParams.h"
00052
00053 #include "AlpsTreeNode.h"
00054
00055
00056
00057 class BlisConstraint;
00058
00059
00060
00061 class BlisModel : public BcpsModel {
00062
00063 private:
00064
00065
00066
00067
00068
00070 OsiSolverInterface *lpSolver_;
00071
00072
00073
00074
00075
00077 CoinPackedMatrix *colMatrix_;
00078
00081 double *origVarLB_;
00082 double *origVarUB_;
00083 double *origConLB_;
00084 double *origConUB_;
00086
00090 int numCols_;
00091 int numRows_;
00092 int numElems_;
00094
00097 double objSense_;
00098 double *objCoef_;
00100
00103 int numIntVars_;
00104 int *intVars_;
00105 char *colType_;
00107
00108
00109
00110
00111
00112 int numSolutions_;
00113 int numHeurSolutions_;
00114
00116
00117
00119 double incObjValue_;
00120
00122 double *incumbent_;
00123
00125 double cutoff_;
00126
00128 double cutoffInc_;
00129
00130
00131
00132
00133
00136 double *startVarLB_;
00137 double *startVarUB_;
00138 double *startConLB_;
00139 double *startConUB_;
00141
00143 BcpsBranchStrategy * branchStrategy_;
00144
00145
00146
00147
00148 int hotstartStrategy_;
00149
00151 int numObjects_;
00152
00154 BcpsObject **objects_;
00155
00157 int * priority_;
00158
00160 AlpsTreeNode *activeNode_;
00161
00163 int numStrong_;
00164
00165
00166 double nodeWeight_;
00167
00168
00169
00170
00171
00173 int numHeuristics_;
00174
00176 BlisHeuristic ** heuristics_;
00177
00178
00179
00180
00181
00183 int useCons_;
00184
00186 int numCutGenerators_;
00187
00189 int maxNumCons_;
00190
00192 BlisConGenerator ** generators_;
00193
00195 BcpsConstraintPool *constraintPool_;
00196
00198 BlisConstraint **oldConstraints_;
00199
00201 int oldConstraintsSize_;
00202
00204 int numOldConstraints_;
00205
00207 double * conRandoms_;
00208
00210 int denseConCutoff_;
00211
00212
00213
00214
00215
00217 BlisParams *BlisPar_;
00218
00220 CoinMessageHandler * handler_;
00221
00223 int numNodes_;
00224
00226 int numIterations_;
00227
00229 int aveIterations_;
00230
00231
00232
00233
00234
00237 int *tempVarLBPos_;
00238 int *tempVarUBPos_;
00239 int *tempConLBPos_;
00240 int *tempConUBPos_;
00242
00243 public:
00244
00246 bool isRoot_;
00247
00249 double startTime_;
00250
00252 double timeLimit_;
00253
00255 double integerTol_;
00256
00258 double optimalRelGap_;
00259
00261 double optimalAbsGap_;
00262
00264 bool useHeuristics_;
00265
00267 OsiCuts newCutPool_;
00268
00269 public:
00270
00272 std::vector<AlpsTreeNode *> leafToRootPath;
00273
00274 public:
00275
00277 BlisModel() { init(); }
00278
00280 virtual ~BlisModel();
00281
00283 void gutsOfDestructor();
00284
00285
00286
00287
00288
00290 void init();
00291
00293 virtual void readInstance(const char* dataFile);
00294
00296 virtual void readParameters(const int argnum, const char * const *arglist);
00297
00299 virtual void writeParameters(std::ostream& outstream) const;
00300
00302 virtual AlpsTreeNode * createRoot();
00303
00305 virtual bool setupSelf();
00306
00308 virtual void setSolver(OsiSolverInterface *si) { lpSolver_ = si; }
00309
00311 virtual OsiSolverInterface *solver() { return lpSolver_; }
00312
00314 bool resolve();
00315
00317 void setActiveNode(AlpsTreeNode *node) { activeNode_ = node; }
00318
00320 void setSolEstimate(double est) { activeNode_->setSolEstimate(est); }
00321
00323 int getNumStrong() { return numStrong_; }
00324
00326 void addNumStrong(int num=1) { numStrong_ += num; }
00327
00328
00329
00330
00331
00333 double* getObjCoef() const { return objCoef_; }
00334
00336 const double * getColLower() { return lpSolver_->getColLower(); }
00337
00339 const double * getColUpper() { return lpSolver_->getColUpper(); }
00340
00342 int getNumCols() { return lpSolver_->getNumCols(); }
00343
00345 int getNumRows() { return lpSolver_->getNumRows(); }
00346
00348 double *origVarLB() { return origVarLB_; }
00349 double *origVarUB() { return origVarUB_; }
00350
00352 double *origConLB() { return origConLB_; }
00353 double *origConUB() { return origConUB_; }
00354
00356 double *startVarLB() { return startVarLB_; }
00357 double *startVarUB() { return startVarUB_; }
00358
00360 double *startConLB() { return startConLB_; }
00361 double *startConUB() { return startConUB_; }
00362
00364 int *tempVarLBPos() { return tempVarLBPos_; }
00365 int *tempVarUBPos() { return tempVarUBPos_; }
00366 int *tempConLBPos() { return tempConLBPos_; }
00367 int *tempConUBPos() { return tempConUBPos_; }
00368
00369
00370
00371
00372
00374 double getLpObjValue() const { return lpSolver_->getObjValue(); }
00375
00377 const double * getLpSolution() const { return lpSolver_->getColSolution();}
00378
00380
00381
00382
00383
00384
00385
00387 int getNumSolutions() const { return numSolutions_; }
00388
00390 int getNumHeurSolutions() const { return numHeurSolutions_;}
00391
00393 double * incumbent() { return incumbent_; }
00394
00396 bool setBestSolution(BLIS_SOL_TYPE how,
00397 double & objectiveValue,
00398 const double *solution,
00399 bool fixVariables = false);
00400
00402 inline double getCutoff() const { return cutoff_; }
00403
00405 inline void setCutoff(double co) {
00406 double direction = lpSolver_->getObjSense();
00407 lpSolver_->setDblParam(OsiDualObjectiveLimit, co * direction);
00408 cutoff_ = co;
00409 }
00410
00414 bool feasibleSolution(int & numIntegerInfs);
00415
00421 bool feasibleSolution(int & numIntegerInfs, int & numObjectInfs);
00422
00423
00424
00425
00426
00432 inline BcpsBranchStrategy * branchStrategy() const
00433 { return branchStrategy_; }
00434
00436 inline void setBranchingMethod(BcpsBranchStrategy * method){
00437 if (branchStrategy_) delete branchStrategy_;
00438 branchStrategy_ = method;
00439 }
00440
00442 inline void setBranchingMethod(BcpsBranchStrategy & method) {
00443 if (branchStrategy_) delete branchStrategy_;
00444 branchStrategy_ = &method;
00445 }
00447
00452 inline int numObjects() const { return numObjects_; }
00453
00455 inline void setNumObjects(int num) { numObjects_ = num; }
00456
00458 inline BcpsObject ** objects() { return objects_;}
00459
00461 inline BcpsObject * objects(int which) { return objects_[which]; }
00462
00464 void deleteObjects();
00465
00468 void addObjects(int numObjects, BcpsObject ** objects);
00470
00472 void findIntegers(bool startAgain);
00473
00475 int getNumIntVars() const { return numIntVars_; }
00476
00478 int* getIntVars() const { return intVars_; }
00479
00481 bool checkInteger(double value) const {
00482 double integerTolerance = 1.0e-5;
00483 double nearest = floor(value + 0.5);
00484 if (fabs(value - nearest) <= integerTolerance) {
00485 return true;
00486 }
00487 else {
00488 return false;
00489 }
00490 }
00491
00492
00493
00494
00495
00497 void addHeuristic(BlisHeuristic * heur);
00498
00500 BlisHeuristic * heuristics(int i) const { return heuristics_[i]; }
00501
00503 int numHeuristics() const { return numHeuristics_; }
00504
00505
00506
00507
00508
00510 void addCutGenerator(CglCutGenerator * generator,
00511 const char * name = NULL,
00512 int strategy = 0,
00513 bool normal = true,
00514 bool atSolution = false,
00515 bool whenInfeasible = false);
00516
00518 BlisConGenerator *cutGenerators(int i) const { return generators_[i]; }
00519
00521 int numCutGenerators() const { return numCutGenerators_; }
00522
00524 int getMaxNumCons() const { return maxNumCons_; }
00525
00527 void setMaxNumCons(int m) { maxNumCons_ = m; }
00528
00530 BcpsConstraintPool *constraintPool() { return constraintPool_; }
00531
00533
00534 int getNumOldConstraints() const { return numOldConstraints_; }
00535
00537 void setNumOldConstraints(int num) { numOldConstraints_ = num; }
00538
00540 int getOldConstraintsSize() const { return oldConstraintsSize_; }
00541
00543 void setOldConstraintsSize(int num) { oldConstraintsSize_ = num; }
00544
00546 BlisConstraint **oldConstraints() { return oldConstraints_; }
00547
00549 void setOldConstraints(BlisConstraint **old) { oldConstraints_ = old; }
00550
00552 void delOldConstraints() {
00553 delete [] oldConstraints_;
00554 oldConstraints_ = NULL;
00555 }
00557
00559 int useCons() const { return useCons_; }
00560
00562 void setUseCons(int u) { useCons_ = u; }
00563
00565 int getDenseConCutoff() const { return denseConCutoff_; }
00566
00568 void setDenseConCutoff(int cutoff) { denseConCutoff_ = cutoff; }
00569
00571 double *getConRandoms() const { return conRandoms_; }
00572
00573
00574
00575
00576
00591 void passInPriorities(const int * priorities,
00592 bool ifNotSimpleIntegers,
00593 int defaultValue = 1000);
00594
00596 inline const int * priority() const { return priority_; }
00597
00599 inline int priority(int sequence) const {
00600 if (priority_) return priority_[sequence];
00601 else return 1000;
00602 }
00603
00604 inline const double getNodeWeight() const { return nodeWeight_; }
00605
00606 inline void setNodeWeight(double nw) { nodeWeight_ = nw; }
00608
00609
00610
00611
00612
00614 virtual void modelLog();
00615
00617 int getNumNodes() const { return numNodes_; }
00618
00620 int getNumIterations() const { return numIterations_; }
00621
00623 int getAveIterations() const { return aveIterations_; }
00624
00626 void addNumNodes(int newNodes = 1) { numNodes_ += newNodes; }
00627
00629 void addNumIterations(int newIter) {
00630 numIterations_ += newIter;
00631 aveIterations_ = numIterations_ / numNodes_;
00632 }
00633
00635 inline CoinMessageHandler * messageHandler() const { return handler_; }
00636
00639 BlisParams * BlisPar() { return BlisPar_; }
00641
00643 int getHotstartStrategy() { return hotstartStrategy_; }
00644 void setHotstartStrategy(int value) { hotstartStrategy_ = value; }
00645
00646
00647
00648
00649
00651 virtual void registerKnowledge();
00652
00654 virtual AlpsEncoded* encode() const;
00655
00657 virtual void decodeToSelf(AlpsEncoded&);
00658 };
00659
00660 #endif