Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

MipHandler.h

Go to the documentation of this file.
00001 /*Copyright (C) 2006/2007, Professorship (p.p.) for Land Use Economics in the Tropics and
00002 Subtropics, Institute for Agricultural Economics and Social Sciences in the Tropics
00003 and Subtropics, University of Hohenheim, Stuttgart
00004 Thomas Berger, Lutz Göhring
00005 All rights reserved
00006 */
00007 #ifndef LP_OLD
00008 #ifndef __MIP_HANDLER__
00009 #define __MIP_HANDLER__
00010 
00011 #include <string>
00012 
00013 #include "BasicEnums.h"
00014 #include "OsiSolverInterface.hpp"
00015 #include "AgentProblem.h"
00016 #include "AgentSolution.h"
00017 #include "ProblemDescription.h"
00018 
00020 
00024 struct mat // Charakteristika der LP-MatrixDouble
00025 {       public:
00026         int lpanzahl;
00027    int lpfehler;
00028    int lpkritisch;
00029         int m1;//Anzahl der Restriktionen LE
00030         int m2;//Anzahl der Restriktionen GE
00031         int m3;//Anzahl der Restriktionen E
00032 };//Tbe taken from "funktio9.h"
00033 
00034 
00036 
00043 class MipHandler {
00044 
00045 public:
00047 
00048 
00049   
00053   int getAgentID()const; 
00055   
00059   int getSubcatchmentID()const;
00061   
00065   AgentProblem* const getSpecificProblemPtr()const;
00067  
00071   AgentProblem getSpecificProblem()const;
00073   
00078   ProblemDescription* const getProblemDescriptionPtr()const;
00079 
00081  //----------------------------------------------------------------
00083 
00084 
00085   
00089   virtual void setAgentID(int agentID); 
00091   
00095   virtual void setSubcatchmentID(int subcatchmentID);
00097   virtual int setSpecificProblem(const AgentProblem& specificProblem);
00099   virtual void resetProblem();
00101   
00103 
00104 
00105   
00110   virtual int solve(AgentSolution& solution_);
00112 
00114 
00115 
00116   virtual void setSolverType(SolverType solver);
00118   
00122   virtual void setTestFlag(int test);
00124 
00128   virtual void setTolerance(double eps);
00129   
00131   
00136   virtual bool setVerbosity(int verbosity);
00138   virtual void setSafePrimalSolutionFlag(bool safePrimalSolution);
00140   
00142 
00143 
00144   virtual SolverType getSolverType()const;
00146   bool getTestFlag()const;
00148 
00152   double getTolerance()const;
00153 
00155   int getNumberOfSolvedMIPs() const;
00156 
00158   bool getSafePrimalSolutionFlag();
00160   virtual string getSolverName();
00162   
00163   //------------------------------------------------------------------------------------------------------------
00165 
00166 
00167 
00174   virtual int readMtx(char* filename);
00175   virtual int readDat(char* filename);
00177   
00181   virtual int writeMtx(char* filename)const;
00183   
00189   virtual int writeDat(char* filename)const;
00193   virtual void writeSolutionPrimal(char* filename)const;
00197   void writeSolverProblemExcel(char* filename)const;
00201   virtual void writeMps(const string filename, const string extension = "mps") const;
00205    virtual void readMps(const string infile, const string extension = "mps");
00209   virtual void templateOutput(string name);
00213   virtual void specificOutput(string name);
00217   virtual void outputSolver(string name);
00219   virtual void manipulateObjective();
00221   
00223 
00224 
00225 
00229   MipHandler();
00230   //Default copy constructor//TODO: implement if neccessary
00231   //Default asignment operator//TODO: implement if neccessary
00233   ~MipHandler();
00235  
00236 //----------------------------------------------------------------------------------------------------------------
00237 private:
00239 
00240 
00241   AgentProblem* templateProblem;
00243   AgentProblem* specificProblem;
00245   
00251   ProblemDescription* problemDescriptionObject;
00253   OsiSolverInterface* mipSolver;
00254   // Data structure where solution of MIP problem is temporarily stored
00255   
00260   AgentSolution* solution;
00262 
00264 
00265 
00266   SolverType solver;
00268   string solvername;
00270   //int numberofblocks; 
00271   // boolean flag: true if MatrixDouble is transposed
00272   int istransposed;  
00274   int test;
00276   double eps;        
00278   int agentID;
00280   int subcatchmentID;
00282    int verbosity;
00284   int nudC; 
00286   mat lpmatrix;
00288   int mp;
00290   int forcedSolutionFlag;
00292   bool savePrimalSolution;
00294   
00296 
00297 
00298   virtual int switchSolver();
00300   void setInitialParamSym();
00302 
00306   virtual int loadProblem();
00308 
00313   virtual int solve();
00315   int solveSym();
00317   int solveOsl();
00319   int warmstart1Osl();
00321   int warmstart2Osl();
00323   int coldstart1Osl();
00325   int coldstart2Osl();
00327   int coldstart3Osl();
00329   
00334   virtual void forcedSolution(const AgentProblem& problem_,AgentSolution& solution_, bool save);
00336   
00340   virtual void forcedSolution();
00342   virtual int loadSolutionSym();
00344   virtual int loadSolutionOsl();
00346   
00353   virtual void deleteEmptyRowsAndCols();//TODO:set to private as soon as stable
00355   void preForcedSolutionMessages();
00357   void postSolveTest();
00359   void printTime(char* mode);
00361   template <class ClassType> int copy(ClassType*& finalObjectPtr_, const ClassType* const originalObjectPtr_);
00365   virtual void errormessage()const;
00367 };
00368 
00369 //Allocates memory for class member finalObjectPtr_ if necessary and copies data from the object originalObjectPtr_ points to
00370 template <class ClassType> int MipHandler::copy(ClassType*& finalObjectPtr_, const ClassType* const originalObjectPtr_){
00371         if (originalObjectPtr_ != NULL){
00372                 if (finalObjectPtr_ == NULL)
00373                         try {
00374                                 finalObjectPtr_ = new ClassType(*originalObjectPtr_);
00375                         }
00376                         catch (exception& exceptionObject){
00377                                 cerr << "Exception: "<< exceptionObject.what() << endl;
00378                                 cerr << "Error in "<< typeid(*this).name()<<"::copy(): cannot allocate memory for"<< typeid(ClassType).name()  << endl;
00379                                 errormessage();
00380                                 return 0;
00381                         }
00382                 else {
00383                         delete finalObjectPtr_;
00384                         finalObjectPtr_ = NULL;
00385                         try {
00386                                 finalObjectPtr_ = new ClassType(*originalObjectPtr_);
00387                         }
00388                         catch (exception& exceptionObject){
00389                                 cerr << "Exception: "<< exceptionObject.what() << endl;
00390                                 cerr << "Error in "<< typeid(*this).name()<<"::copy(): cannot allocate memory for"<< typeid(ClassType).name() << endl;
00391                                 errormessage();
00392                                 return 0;
00393                         }
00394                 }
00395         }
00396         else if (test) cerr << "Warning in "<< typeid(*this).name() << "::copy():  "<<typeid(originalObjectPtr_).name() <<"  == NULL!" << endl;
00397         return 1;
00398 }
00399 #endif
00400 #endif /* LP_OLD*/

Generated on Thu Aug 28 12:38:45 2008 for MPMAS by  doxygen 1.3.9.1