lpsolver.h
Go to the documentation of this file.00001 /*************************************************************************** 00002 file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/trunk/modules/lp_solver/lpsolver.h $ 00003 version : $LastChangedRevision: 754 $ $LastChangedBy: jdetaeye $ 00004 date : $LastChangedDate: 2008-04-23 21:41:18 +0200 (Wed, 23 Apr 2008) $ 00005 ***************************************************************************/ 00006 00007 /*************************************************************************** 00008 * * 00009 * Copyright (C) 2007 by Johan De Taeye * 00010 * * 00011 * This library is free software; you can redistribute it and/or modify it * 00012 * under the terms of the GNU Lesser General Public License as published * 00013 * by the Free Software Foundation; either version 2.1 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * 00019 * General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Lesser General Public * 00022 * License along with this library; if not, write to the Free Software * 00023 * Foundation Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA * 00024 * * 00025 ***************************************************************************/ 00026 00027 /** @file lpsolver.h 00028 * @brief Header file for the module lp_solver. 00029 * 00030 * @namespace module_lp_solver 00031 * @brief A solver module based on a linear programming algorithm. 00032 * 00033 * The module is currently in beta-mode: it is usable as a proof of concept, 00034 * but isn't finished yet as an out-of-the-box integrated solver. 00035 * 00036 * The linear programming problem definition is very flexible.<br> 00037 * As a prototyping example, a capacity allocation problem is used. 00038 * Different business problems will obviously require a different formulation. 00039 * 00040 * The module uses the "Gnu Linear Programming Kit" library (aka GLPK) to 00041 * solve the LP model. 00042 * 00043 * The XML schema extension enabled by this module is (see mod_lpsolver.xsd): 00044 * <PRE> 00045 * <xsd:complexType name="solver_lp"> 00046 * <xsd:complexContent> 00047 * <xsd:extension base="solver"> 00048 * <xsd:choice minOccurs="0" maxOccurs="unbounded"> 00049 * <xsd:element name="verbose" xsi:type="xsd:boolean" /> 00050 * <xsd:element name="calendar" xsi:type="calendar" /> 00051 * </xsd:choice> 00052 * </xsd:extension> 00053 * </xsd:complexContent> 00054 * </xsd:complexType> 00055 * </PRE> 00056 */ 00057 00058 #include "frepple.h" 00059 using namespace frepple; 00060 00061 extern "C" 00062 { 00063 #include "glpk.h" 00064 } 00065 00066 namespace module_lp_solver 00067 { 00068 00069 /** Initialization routine for the library. */ 00070 MODULE_EXPORT const char* initialize(const CommandLoadLibrary::ParameterList& z); 00071 00072 /** @brief This class is a prototype of an Linear Programming (LP) Solver for 00073 * the planning problem or a subset of it. 00074 * 00075 * The class provides only a concept / prototype, and it is definately not 00076 * ready for full use in a production environment. It misses too much 00077 * functionality for this purpose. 00078 */ 00079 class LPSolver : public Solver 00080 { 00081 public: 00082 /** This method creates a new column in the model for every demand. It's 00083 * value represents the planned quantity of that demand. 00084 * @exception DataException Generated when no calendar has been specified. 00085 */ 00086 void solve(void* = NULL); 00087 00088 Calendar* getCalendar() const {return cal;} 00089 void setCalendar(Calendar* c) {cal = c;} 00090 00091 void beginElement(XMLInput& pIn, const Attribute& pAttr); 00092 virtual void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const; 00093 void endElement(XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement); 00094 00095 LPSolver(const string n) : Solver(n), cal(NULL) {}; 00096 ~LPSolver() {}; 00097 00098 virtual const MetaClass& getType() const {return metadata;} 00099 static const MetaClass metadata; 00100 virtual size_t getSize() const {return sizeof(LPSolver);} 00101 00102 private: 00103 /** This is an auxilary function. GLPK requires names to contain only 00104 * "graphic" characters. A space isn't one of those. Since our model 00105 * can contain HasHierarchy names with a space, we call this function to 00106 * replace the spaces with underscores. 00107 * Note however that we can't garantuee that the updated strings are 00108 * all unique after the replacement! 00109 */ 00110 static string replaceSpaces(string); 00111 00112 /** This object is the interface with the GLPK structures. */ 00113 LPX* lp; 00114 00115 /** Storing simplex configuration paramters. */ 00116 glp_smcp parameters; 00117 00118 /** Which buckets to use for the linearization of the problem. */ 00119 Calendar *cal; 00120 00121 /** A hook to intercept the terminal output of the solver library, and 00122 * redirect it into the frePPLe log file. 00123 */ 00124 static int solveroutputredirect(void* info, const char* msg) 00125 { 00126 logger << msg; 00127 logger.flush(); 00128 return 1; 00129 } 00130 00131 /** Solve for a goal in a hierarchical sequence. */ 00132 void solveObjective(const char*); 00133 00134 }; 00135 00136 } // End namespace
Documentation generated by
