- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/svn-release/Blis-0.93.10/Bcps/examples/Blis/BlisModel.h

Go to the documentation of this file.

    00001 /*===========================================================================*
    00002  * This file is part of the Bcps Linear Solver (BLIS).                       *
    00003  *                                                                           *
    00004  * BLIS is distributed under the Eclipse Public License as part of the       *
    00005  * COIN-OR repository (http://www.coin-or.org).                              *
    00006  *                                                                           *
    00007  * Authors:                                                                  *
    00008  *                                                                           *
    00009  *          Yan Xu, Lehigh University                                        *
    00010  *          Ted Ralphs, Lehigh University                                    *
    00011  *                                                                           *
    00012  * Conceptual Design:                                                        *
    00013  *                                                                           *
    00014  *          Yan Xu, Lehigh University                                        *
    00015  *          Ted Ralphs, Lehigh University                                    *
    00016  *          Laszlo Ladanyi, IBM T.J. Watson Research Center                  *
    00017  *          Matthew Saltzman, Clemson University                             *
    00018  *                                                                           *
    00019  *                                                                           *
    00020  * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs.       *
    00021  * All Rights Reserved.                                                      *
    00022  *===========================================================================*/
    00023
    00024 //#############################################################################
    00025
    00026 #ifndef BlisModel_h_
    00027 #define BlisModel_h_
    00028
    00029 //#############################################################################
    00030
    00031 #include "CoinMpsIO.hpp"
    00032 #include "CoinPackedMatrix.hpp"
    00033 #include "CoinMessageHandler.hpp"
    00034 #include "OsiSolverInterface.hpp"
    00035 #include "OsiCuts.hpp"
    00036 #include "CglCutGenerator.hpp"
    00037
    00038 #include "AlpsKnowledgeBroker.h"
    00039 #include "AlpsParams.h"
    00040
    00041 #include "BcpsModel.h"
    00042
    00043 #include "BcpsBranchStrategy.h"
    00044 #include "BcpsObject.h"
    00045 #include "BcpsObjectPool.h"
    00046
    00047 #include "Blis.h"
    00048 #include "BlisConGenerator.h"
    00049 #include "BlisHeuristic.h"
    00050 #include "BlisParams.h"
    00051
    00052 #include "AlpsTreeNode.h"
    00053
    00054 //#############################################################################
    00055
    00056 class BlisConstraint;
    00057
    00058 //#############################################################################
    00059
    00060 class BlisModel : public BcpsModel {
    00061
    00062  private:
    00063
    00064     //------------------------------------------------------
    00065     // LP SOLVER.
    00066     //------------------------------------------------------
    00067
    00069     OsiSolverInterface *lpSolver_;
    00070
    00071     //------------------------------------------------------
    00072     // PROBLEM DATA. Populate when readInstance() or decodeToSelf().
    00073     //------------------------------------------------------
    00074
    00076     CoinPackedMatrix *colMatrix_;
    00077
    00080     double *origVarLB_;
    00081     double *origVarUB_;
    00082     double *origConLB_;
    00083     double *origConUB_;
    00085
    00089     int numCols_;
    00090     int numRows_;
    00091     int numElems_;
    00093
    00096     double objSense_;
    00097     double *objCoef_;
    00099
    00102     int numIntVars_;
    00103     int *intVars_;
    00104     char *colType_;
    00106
    00107     //------------------------------------------------------
    00108     // SOLUTION.
    00109     //------------------------------------------------------
    00110
    00111     int numSolutions_;
    00112     int numHeurSolutions_;
    00113
    00115     //double *savedLpSolution_;
    00116
    00118     double incObjValue_;
    00119
    00121     double *incumbent_;
    00122
    00124     double cutoff_;
    00125
    00127     double cutoffInc_;
    00128
    00129     //------------------------------------------------------
    00130     // SEARCHING.
    00131     //------------------------------------------------------
    00132
    00135     double *startVarLB_;
    00136     double *startVarUB_;
    00137     double *startConLB_;
    00138     double *startConUB_;
    00140
    00142     BcpsBranchStrategy * branchStrategy_;
    00143
    00144     // Hotstart strategy 0 = off,
    00145     // 1 = branch if incorrect,
    00146     // 2 = branch even if correct, ....
    00147     int hotstartStrategy_;
    00148
    00150     int numObjects_;
    00151
    00153     BcpsObject **objects_;
    00154
    00156     int * priority_;
    00157
    00159     AlpsTreeNode *activeNode_;
    00160
    00162     int numStrong_;
    00163
    00164     // Not used.
    00165     double nodeWeight_;
    00166
    00167     //------------------------------------------------------
    00168     // HEURISTICS.
    00169     //------------------------------------------------------
    00170
    00172     int numHeuristics_;
    00173
    00175     BlisHeuristic ** heuristics_;
    00176
    00177     //------------------------------------------------------
    00178     // CONSTRAINTS.
    00179     //------------------------------------------------------
    00180
    00182     int useCons_;
    00183
    00185     int numCutGenerators_;
    00186
    00188     int maxNumCons_;
    00189
    00191     BlisConGenerator ** generators_;
    00192
    00194     BcpsConstraintPool *constraintPool_;
    00195
    00197     BlisConstraint **oldConstraints_;
    00198
    00200     int oldConstraintsSize_;
    00201
    00203     int numOldConstraints_;
    00204
    00206     double * conRandoms_;
    00207
    00209     int denseConCutoff_;
    00210
    00211     //------------------------------------------------------
    00212     // PARAMETERS, STATISTICS, and MESSAGE
    00213     //------------------------------------------------------
    00214
    00216     BlisParams *BlisPar_;
    00217
    00219     CoinMessageHandler * handler_;
    00220
    00222     int numNodes_;
    00223
    00225     int numIterations_;
    00226
    00228     int aveIterations_;
    00229
    00230     //------------------------------------------------------
    00231     // TEMPORARY STORAGE
    00232     //------------------------------------------------------
    00233
    00236     int *tempVarLBPos_;
    00237     int *tempVarUBPos_;
    00238     int *tempConLBPos_;
    00239     int *tempConUBPos_;
    00241
    00242  public:
    00243
    00245     bool isRoot_;
    00246
    00248     double startTime_;
    00249
    00251     double timeLimit_;
    00252
    00254     double integerTol_;
    00255
    00257     double optimalRelGap_;
    00258
    00260     double optimalAbsGap_;
    00261
    00263     bool useHeuristics_;
    00264
    00266     OsiCuts newCutPool_;
    00267
    00268  public:
    00269
    00271     std::vector<AlpsTreeNode *> leafToRootPath;
    00272
    00273  public:
    00274
    00276     BlisModel() { init(); }
    00277
    00279     virtual ~BlisModel();
    00280
    00282     void gutsOfDestructor();
    00283
    00284     //------------------------------------------------------
    00285     // SETUP, LP SOLVER
    00286     //------------------------------------------------------
    00287
    00289     void init();
    00290
    00292     virtual void readInstance(const char* dataFile);
    00293
    00295     virtual void readParameters(const int argnum, const char * const *arglist);
    00296
    00298     virtual void writeParameters(std::ostream& outstream) const;
    00299
    00301     virtual AlpsTreeNode * createRoot();
    00302
    00304     virtual bool setupSelf();
    00305
    00307     virtual void setSolver(OsiSolverInterface *si) { lpSolver_ = si; }
    00308
    00310     virtual OsiSolverInterface *solver() { return lpSolver_; }
    00311
    00313     bool resolve();
    00314
    00316     void setActiveNode(AlpsTreeNode *node) { activeNode_ = node; }
    00317
    00319     void setSolEstimate(double est) { activeNode_->setSolEstimate(est); }
    00320
    00322     int getNumStrong() { return numStrong_; }
    00323
    00325     void addNumStrong(int num=1) { numStrong_ += num; }
    00326
    00327     //------------------------------------------------------
    00328     // PROBLEM DATA
    00329     //------------------------------------------------------
    00330
    00332     double* getObjCoef() const { return objCoef_; }
    00333
    00335     const double * getColLower() { return lpSolver_->getColLower(); }
    00336
    00338     const double * getColUpper() { return lpSolver_->getColUpper(); }
    00339
    00341     int getNumCols() { return lpSolver_->getNumCols(); }
    00342
    00344     int getNumRows() { return lpSolver_->getNumRows(); }
    00345
    00347     double *origVarLB() { return origVarLB_; }
    00348     double *origVarUB() { return origVarUB_; }
    00349
    00351     double *origConLB() { return origConLB_; }
    00352     double *origConUB() { return origConUB_; }
    00353
    00355     double *startVarLB() { return startVarLB_; }
    00356     double *startVarUB() { return startVarUB_; }
    00357
    00359     double *startConLB() { return startConLB_; }
    00360     double *startConUB() { return startConUB_; }
    00361
    00363     int *tempVarLBPos() { return tempVarLBPos_; }
    00364     int *tempVarUBPos() { return tempVarUBPos_; }
    00365     int *tempConLBPos() { return tempConLBPos_; }
    00366     int *tempConUBPos() { return tempConUBPos_; }
    00367
    00368     //------------------------------------------------------
    00369     // LP SOLUTION
    00370     //------------------------------------------------------
    00371
    00373     double getLpObjValue() const { return lpSolver_->getObjValue(); }
    00374
    00376     const double * getLpSolution() const { return lpSolver_->getColSolution();}
    00377
    00379     //double * savedLpSolution() { return savedLpSolution_; }
    00380
    00381     //------------------------------------------------------
    00382     // MILP SOLUTION
    00383     //------------------------------------------------------
    00384
    00386     int getNumSolutions() const { return numSolutions_; }
    00387
    00389     int getNumHeurSolutions() const { return numHeurSolutions_;}
    00390
    00392     double * incumbent() { return incumbent_; }
    00393
    00395     bool setBestSolution(BLIS_SOL_TYPE how,
    00396                          double & objectiveValue,
    00397                          const double *solution,
    00398                          bool fixVariables = false);
    00399
    00401     inline double getCutoff() const { return cutoff_;  }
    00402
    00404     inline void setCutoff(double co) {
    00405         double direction = lpSolver_->getObjSense();
    00406         lpSolver_->setDblParam(OsiDualObjectiveLimit, co * direction);
    00407         cutoff_ = co;
    00408     }
    00409
    00413     bool feasibleSolution(int & numIntegerInfs);
    00414
    00420     bool feasibleSolution(int & numIntegerInfs, int & numObjectInfs);
    00421
    00422     //------------------------------------------------------
    00423     // BRANCHING
    00424     //------------------------------------------------------
    00425
    00431     inline BcpsBranchStrategy * branchStrategy() const
    00432         { return branchStrategy_; }
    00433
    00435     inline void setBranchingMethod(BcpsBranchStrategy * method){
    00436         if (branchStrategy_) delete branchStrategy_;
    00437         branchStrategy_ = method;
    00438     }
    00439
    00441     inline void setBranchingMethod(BcpsBranchStrategy & method) {
    00442         if (branchStrategy_) delete branchStrategy_;
    00443         branchStrategy_ = &method;
    00444     }
    00446
    00451     inline int numObjects() const { return numObjects_; }
    00452
    00454     inline void setNumObjects(int num) { numObjects_ = num; }
    00455
    00457     inline BcpsObject ** objects() { return objects_;}
    00458
    00460     inline BcpsObject * objects(int which) { return objects_[which]; }
    00461
    00463     void deleteObjects();
    00464
    00467     void addObjects(int numObjects, BcpsObject ** objects);
    00469
    00471     void findIntegers(bool startAgain);
    00472
    00474     int getNumIntVars() const { return numIntVars_; }
    00475
    00477     int* getIntVars() const { return intVars_; }
    00478
    00480     bool checkInteger(double value) const {
    00481         double integerTolerance = 1.0e-5;
    00482         double nearest = floor(value + 0.5);
    00483         if (fabs(value - nearest) <= integerTolerance) {
    00484             return true;
    00485         }
    00486         else {
    00487             return false;
    00488         }
    00489     }
    00490
    00491     //------------------------------------------------------
    00492     // HEURISTICS.
    00493     //------------------------------------------------------
    00494
    00496     void addHeuristic(BlisHeuristic * heur);
    00497
    00499     BlisHeuristic * heuristics(int i) const { return heuristics_[i]; }
    00500
    00502     int numHeuristics() const { return numHeuristics_; }
    00503
    00504     //------------------------------------------------------
    00505     // CONSTRAINTS.
    00506     //------------------------------------------------------
    00507
    00509     void addCutGenerator(CglCutGenerator * generator,
    00510                          const char * name = NULL,
    00511                          int strategy = 0,
    00512                          bool normal = true,
    00513                          bool atSolution = false,
    00514                          bool whenInfeasible = false);
    00515
    00517     BlisConGenerator *cutGenerators(int i) const { return generators_[i]; }
    00518
    00520     int numCutGenerators() const { return numCutGenerators_; }
    00521
    00523     int getMaxNumCons() const { return maxNumCons_; }
    00524
    00526     void setMaxNumCons(int m) { maxNumCons_ = m; }
    00527
    00529     BcpsConstraintPool *constraintPool() { return constraintPool_; }
    00530
    00532
    00533     int getNumOldConstraints() const { return numOldConstraints_; }
    00534
    00536     void setNumOldConstraints(int num) { numOldConstraints_ = num; }
    00537
    00539     int getOldConstraintsSize() const { return oldConstraintsSize_; }
    00540
    00542     void setOldConstraintsSize(int num) { oldConstraintsSize_ = num; }
    00543
    00545     BlisConstraint **oldConstraints() { return oldConstraints_; }
    00546
    00548     void setOldConstraints(BlisConstraint **old) { oldConstraints_ = old; }
    00549
    00551     void delOldConstraints() {
    00552         delete [] oldConstraints_;
    00553         oldConstraints_ = NULL;
    00554     }
    00556
    00558     int useCons() const { return useCons_; }
    00559
    00561     void setUseCons(int u) { useCons_ = u; }
    00562
    00564     int getDenseConCutoff() const { return denseConCutoff_; }
    00565
    00567     void setDenseConCutoff(int cutoff) { denseConCutoff_ = cutoff; }
    00568
    00570     double *getConRandoms() const { return conRandoms_; }
    00571
    00572     //------------------------------------------------------
    00573     // PRIORITY AND WEITGHT.
    00574     //------------------------------------------------------
    00575
    00590     void passInPriorities(const int * priorities,
    00591                           bool ifNotSimpleIntegers,
    00592                           int defaultValue = 1000);
    00593
    00595     inline const int * priority() const { return priority_; }
    00596
    00598     inline int priority(int sequence) const {
    00599         if (priority_) return priority_[sequence];
    00600         else return 1000;
    00601     }
    00602
    00603     inline const double getNodeWeight() const { return nodeWeight_; }
    00604
    00605     inline void setNodeWeight(double nw) { nodeWeight_ = nw; }
    00607
    00608     //------------------------------------------------------
    00609     // STATISTICS.
    00610     //------------------------------------------------------
    00611
    00613     virtual void modelLog();
    00614
    00616     int getNumNodes() const { return numNodes_; }
    00617
    00619     int getNumIterations() const { return numIterations_; }
    00620
    00622     int getAveIterations() const { return aveIterations_; }
    00623
    00625     void addNumNodes(int newNodes = 1) { numNodes_ += newNodes; }
    00626
    00628     void addNumIterations(int newIter) {
    00629         numIterations_ += newIter;
    00630         aveIterations_ = numIterations_ / numNodes_;
    00631     }
    00632
    00634     inline CoinMessageHandler * messageHandler() const { return handler_; }
    00635
    00638     BlisParams * BlisPar() { return BlisPar_; }
    00640
    00642     int getHotstartStrategy() { return hotstartStrategy_; }
    00643     void setHotstartStrategy(int value) { hotstartStrategy_ = value; }
    00644
    00645     //------------------------------------------------------
    00646     // PARALLEL
    00647     //------------------------------------------------------
    00648
    00650     virtual void registerKnowledge();
    00651
    00653     virtual AlpsEncoded* encode() const;
    00654
    00656     virtual void decodeToSelf(AlpsEncoded&);
    00657 };
    00658
    00659 #endif /* End of file */