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

FichierProbleme.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 
00033 #ifndef __FICHIER_PROBLEME_H
00034 #define __FICHIER_PROBLEME_H
00035 
00036 #include <string>
00037 #include <list>
00038 #include <vector>
00039 #include <map>
00040 #include <iostream>
00041 #include <algorithm>
00042 
00043 namespace Modelib {
00044 
00045 // type de comparaison
00046 enum CompType {LOWER_OR_EQUAL_THAN=0,LOWER_THAN=1,EQUAL=2,UPPER_OR_EQUAL_THAN=3,UPPER_THAN=4,DIFFERENT_THAN=5};
00047 // signes
00048 typedef enum {MINUS=0,PLUS} Signe;
00049 // outils de comparaisons
00050 static const std::string comp[6] = {
00051   "<=",
00052   "<",
00053   ">=",
00054   ">",
00055   "!=", // on vera si on utilise ca avec les expression
00056   //"/=",  // a!=b =)> a<b ou a>b
00057   "="   // = a la fin car on test d'abord les spécialisation des cas (composés)
00058 };
00059 // Les différentes parties d'un fichier LP
00060 enum {MAXIMIZE=0,SUBJECT,CONSTRAINT,BOUNDS,END,GENERALS,BINARIES,MINIMIZE,FREE};
00061 
00062 
00066 struct plExprNode
00067 {
00068   std::string var;
00069   std::string num;
00070   Signe       signe;
00071 
00074   plExprNode(const std::string& _var, const std::string& _num, const Signe _signe)
00075     : var(_var), num(_num), signe(_signe)
00076   {};
00077 
00081   plExprNode(const plExprNode& _node)
00082     : var(_node.var), num(_node.num), signe(_node.signe)
00083   {};
00084 };
00085 
00089 struct plConstraintNode
00090 {
00091   std::string minBound,maxBound;
00092   std::string num;
00093   std::string var;
00094   unsigned    comp1,comp2;
00095 
00096   plConstraintNode(const std::string& _var, const std::string& _num,
00097                    const std::string& _b1 , const std::string& _b2 ,
00098                    const unsigned     _c1 , const unsigned     _c2)
00099     : minBound(_b1), maxBound(_b2), num(_num), var(_var), comp1(_c1), comp2(_c2)
00100   {};
00101   
00105   plConstraintNode(const plConstraintNode& _node)
00106     : minBound(_node.minBound), maxBound(_node.maxBound), num(_node.num), var(_node.var), comp1(_node.comp1), comp2(_node.comp2)
00107   {};
00108 
00109 
00110   
00111   /*
00112 
00113     faire des constructeurs pour les formes simples
00114     x <= 0                   _num _var _comp1 _maxbound
00115     0 <= x                   _num _var _minbound _comp1
00116 
00117   */
00118 
00122   plConstraintNode(const std::string& _num, const std::string& _var,
00123                    const unsigned     _c1 , const std::string& _maxbound)
00124     : minBound("-inf"), maxBound(_maxbound), num(_num), var(_var), comp1(_c1), comp2(99)
00125   {};
00126 
00130   plConstraintNode(const std::string& _num, const std::string& _var,
00131                    const std::string& _minbound, const unsigned _c1 )
00132     : minBound(_minbound), maxBound("+inf"), num(_num), var(_var), comp1(_c1), comp2(99)
00133   {};
00134 
00135 
00136 };
00137 
00141 struct plSimpleConstraint
00142 {
00143   std::string bound;
00144   unsigned    comp ;
00145 
00146   plSimpleConstraint(const std::string& _bound, const unsigned _comp)
00147     : bound(_bound), comp(_comp)
00148   {};
00149 
00150   plSimpleConstraint(const plSimpleConstraint& _cstr)
00151     : bound(_cstr.bound), comp(_cstr.comp)
00152   {};
00153 
00154   plSimpleConstraint& operator=(const plSimpleConstraint& _cstr)
00155   {
00156     comp  = _cstr.comp;
00157     bound = _cstr.bound;
00158     return *this;
00159   }
00160 };
00161 
00162 
00171 struct plGlobalNode
00172 {
00173   std::string              nom ;
00174   std::list<plExprNode *>  expr;
00175   plSimpleConstraint       cont;
00176 
00177   plGlobalNode(const plGlobalNode& _node)
00178     : nom(_node.nom), cont(_node.cont)
00179   {
00180     //copy(_node.expr.begin(), _node.expr.end(),
00181     //           expr.begin());
00182     for (std::list<plExprNode *>::const_iterator _iter  = _node.expr.begin();
00183                                                  _iter != _node.expr.end()  ;
00184                                                ++_iter)
00185       expr.push_back(*_iter);
00186   }
00187   
00188   plGlobalNode(const std::string& _nom, const std::list<plExprNode *>& _expr, const plSimpleConstraint& _cont)
00189     : nom(_nom), cont(_cont)
00190   {
00191     //copy(_expr.begin(), _expr.end(),
00192     //      expr.begin());
00193     for (std::list<plExprNode *>::const_iterator _iter  = _expr.begin();
00194                                                  _iter != _expr.end()  ;
00195                                                ++_iter)
00196       expr.push_back(*_iter);
00197   }
00198   
00202   ~plGlobalNode()
00203   {
00204     for (std::list<plExprNode*>::iterator i=expr.begin();i!=expr.end();++i)
00205         delete (*i);
00206   }
00207 };
00208 
00209 
00217 struct Cmp
00218 {
00219   bool operator()(std::string& s1, std::string& s2) const
00220   {
00221     // tout ca, pour ca !
00222     return s1 <= s2;
00223   }
00224 };
00225 
00226 class Model;
00227 
00237 class FichierProbleme
00238 {
00239 protected:
00242   std::string nom;
00245   bool isMax; // si non alors c Minimize
00248   std::list<plExprNode *> exprObj;
00251   std::list<plGlobalNode *> exprConstraint;
00254   std::list<std::string> exprGeneral;
00257   std::list<std::string> exprBinary;
00260   std::list<plConstraintNode *> exprBounds;
00261 
00266   std::multimap<std::string,unsigned>      mmap;
00267 
00269   std::map<std::string,unsigned>       Comp2Int;
00270 
00273   std::list< std::pair<long,std::string> > commentaires;
00274 
00275 protected:
00277   FichierProbleme() {};
00278 
00279 public:
00281   virtual bool Open(const std::string& nom) = 0;
00282 
00283   friend std::ostream& operator<<(std::ostream&,const FichierProbleme&);
00284   bool operator>> (Model & m);
00285 
00288   virtual ~FichierProbleme()
00289   {
00290     //std::cout << "Destructeur: ~FichierProbleme()"  << std::endl;
00291     for (std::list<plExprNode*>::iterator i=exprObj.begin();i!=exprObj.end();++i)
00292         delete (*i);
00293     for (std::list<plGlobalNode*>::iterator i=exprConstraint.begin();i!=exprConstraint.end();++i)
00294         delete (*i);
00295     for (std::list<plConstraintNode*>::iterator i=exprBounds.begin();i!=exprBounds.end();++i)
00296         delete (*i);
00297     // le reste est auto-détruit grace aux auto_ptr<>
00298   };
00299 };
00300 
00301 
00302 }
00303 
00304 #endif

Généré le Sun Oct 2 19:13:11 2005 pour Modelib par  doxygen 1.4.4