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 #include "Model.h" 00033 #include "Utils.h" 00034 #include "System.h" 00035 00036 // Les différents solveurs implémentés 00037 #include "GlpkSolver.h" 00038 #include "CplexSolver.h" 00039 00040 #include <iostream> 00041 #include <stdexcept> 00042 00043 namespace Modelib { 00044 00045 00046 using namespace std; 00047 00051 void SolverAPI::AllocSolver(const SolverName api) 00052 { 00053 switch(api) 00054 { 00055 case GLPK|GLPSOL: 00056 solver = new GlpkSolver(); 00057 break; 00058 00059 case CPLEX: 00060 solver = new CplexSolver(); 00061 break; 00062 00063 default: 00064 solver = 0; 00065 throw "(SolverAPI::AllocSolver) - Allocation impossible, solveur inconnu"; 00066 break; 00067 } 00068 } 00069 00070 00076 SolverAPI::SolverAPI(const SolverName api) 00077 : apiSolver(api), solver(0) 00078 { 00079 fileLP = "temp.lp"; 00080 try { 00081 AllocSolver(api); 00082 } 00083 catch (string& e) { 00084 cout << e << endl; 00085 } 00086 } 00087 00091 SolverAPI::~SolverAPI() 00092 { 00093 if (solver) delete solver; 00094 } 00095 00102 void SolverAPI::Init(const std::string& tempFile, const std::string& _path) 00103 { 00104 assert(solver); 00105 fileLP = tempFile; 00106 path = _path; 00107 } 00108 00117 void SolverAPI::Init(const SolverName api, const std::string& tempFile, const std::string& _path) 00118 { 00119 SetAPI(api); 00120 fileLP = tempFile; 00121 path = _path; 00122 } 00123 00127 void SolverAPI::SetAPI(const SolverName api) 00128 { 00129 solution.Clear(); 00130 if (apiSolver != api) 00131 { 00132 apiSolver = api; 00133 delete solver; 00134 try { 00135 AllocSolver(api); 00136 } 00137 catch (string& e) 00138 { 00139 cout << e << endl; 00140 } 00141 } 00142 } 00143 00144 }