Modelib: Fichier source de SolverAPI.h

Page principale | Liste des namespaces | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

# SolverAPI.h

Aller à la documentation de ce fichier.

    00001 /*
    00002     Copyright (c) 2005, Quentin Lequy and Romain Gaucher
    00003     All rights reserved.
    00004
    00005     Redistribution and use in source and binary forms, with or
    00006     without modification, are permitted provided that the following
    00007     conditions are met:
    00008
    00009         * Redistributions of source code must retain the above copyright
    00010           notice, this list of conditions and the following disclaimer.
    00011
    00012         * Redistributions in binary form must reproduce the above copyright
    00013           notice, this list of conditions and the following disclaimer in the
    00014           documentation and/or other materials provided with the distribution.
    00015
    00016         * Neither the name of Quentin Lequy or Romain Gaucher nor the names
    00017           of its contributors may be used to endorse or promote products
    00018           derived from this software without specific prior written permission.
    00019
    00020     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    00021     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00022     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00023     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    00024     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    00025     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    00026     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
    00027     AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00028     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00029     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00030 */
    00031
    00032 #ifndef __SOLVERAPI_H
    00033 #define __SOLVERAPI_H
    00034
    00035 #include "Solver.h"
    00036 #include <string>
    00037 #include <vector>
    00038 #include <list>
    00039 #include <map>
    00040
    00041 namespace Modelib {
    00042
    00043 enum SolverName
    00044 {
    00045     CPLEX=0,
    00046     GLPK=1,
    00047     GLPSOL=1,
    00048     NONE=42
    00049 };
    00050
    00051 typedef SolverName API;
    00052
    00061 class SolverAPI
    00062 {
    00063     SolverName  apiSolver;
    00064     std::string path;
    00065     std::string fileLP;
    00066     Solver     *solver;
    00067
    00068     Solution    solution;
    00069
    00070   protected:
    00072     void AllocSolver(const SolverName);
    00073
    00074   public:
    00075     SolverAPI(const SolverName = GLPK);
    00076     ~SolverAPI();
    00077
    00079     void Init(const std::string& , const std::string& _path="");
    00080
    00082     void Init(const SolverName, const std::string&, const std::string& _path="");
    00083
    00085     void SetAPI(const SolverName);
    00086
    00088     inline SolverName GetAPI() const {
    00089         if (!solver)
    00090             return NONE;
    00091         return apiSolver;
    00092     }
    00093
    00095     inline const char * GetfLP() const {
    00096         return fileLP.c_str();
    00097     }
    00099     inline void SetfLP(const std::string& flp) {
    00100         fileLP = flp;
    00101     }
    00102
    00103     //
    00104     // On retourne des références car ceci sera utilisé dans Model
    00105     // Et SolverAPI existe tant que Model existe !
    00106     //
    00107   public:
    00108     inline std::list<float>      & OutNumVarValues    ()     {return solution.variablesVAL;}
    00109     inline std::list<std::string>& GetNumVarNames     ()     {return solution.variablesNOM;}
    00110     inline std::list<float>      & OutConstraintValues()     {return solution.contraintesVAL;}
    00111     inline std::list<std::string>& GetConstraintNames ()     {return solution.contraintesNOM;}
    00112     inline std::string             & GetObjectiveNames  ()     {return solution.objective.first;}
    00113     inline float                     GetObjectiveValue  ()     {return solution.objective.second;}
    00114
    00115     //
    00116     // Interfaces des solveurs
    00117     //
    00118   public:
    00119     inline bool  AddOption(const std::string& opt)               {solver->AddOption(opt); return true;}
    00120     inline void  RemoveOption(const std::string& opt="zzERall")  {solver->RemoveOption(opt);}
    00121     inline float Solve()                                         {return solver->Solve(solution,fileLP);}
    00122
    00123     inline void  Infos(std::string& op, std::string& info) {
    00124         return solver->Infos(op,info);
    00125     }
    00126
    00127     // Résultats
    00128     inline bool IsSolved()  const {return solver->Solved(); }
    00129     inline bool IsOptimal() const {return solver->Optimal();}
    00130
    00131
    00132     //
    00133     // Compatibilités antérieures
    00134     //
    00135   public:
    00136     inline void Options(const std::string& opt) {solver->AddOption(opt);}
    00137     inline void RemoveOptions()  {solver->RemoveOption("zzERall");}
    00138
    00139     inline void SetMIP(bool isMIP) {solver->SetMIP(isMIP);}
    00140
    00141     //inline std::list<float>      & OutNumVarValues    ()     {return solution.variablesVAL;}
    00142     inline std::list<std::string>& GetNumVarNoms      ()     {return solution.variablesNOM;}
    00143     //inline std::list<float>      & OutConstraintValues()     {return solution.contraintesVAL;}
    00144     inline std::list<std::string>& GetConstraintNoms  ()     {return solution.contraintesNOM;}
    00145 };
    00146
    00147 }
    00148
    00149 #endif