Page principale | Hiérarchie des classes | Liste des composants | Liste des fichiers | Composants

FichierProbleme.h

00001 
00002 #ifndef __FICHIER_PROBLEME_H
00003 #define __FICHIER_PROBLEME_H
00004 
00005 #include <string>
00006 #include <list>
00007 #include <vector>
00008 #include <map>
00009 #include <iostream>
00010 #include <algorithm>
00011 
00012 
00013 // type de comparaison
00014 enum CompType {LOWER_OR_EQUAL_THAN=0,LOWER_THAN=1,EQUAL=2,UPPER_OR_EQUAL_THAN=3,UPPER_THAN=4,DIFFERENT_THAN=5};
00015 // signes
00016 typedef enum {MINUS=0,PLUS} Signe;
00017 // outils de comparaisons
00018 static const std::string comp[6] = {
00019   "<=",
00020   "<",
00021   ">=",
00022   ">",
00023   "!=", // on vera si on utilise ca avec les expression
00024   //"/=",  // a!=b =)> a<b ou a>b
00025   "="   // = a la fin car on test d'abord les spécialisation des cas (composés)
00026 };
00027 // Les différentes parties d'un fichier LP
00028 enum {MAXIMIZE=0,SUBJECT,CONSTRAINT,BOUNDS,END,GENERALS,BINARIES,MINIMIZE,FREE};
00029 
00030 
00034 struct plExprNode
00035 {
00036   std::string var;
00037   std::string num;
00038   Signe       signe;
00039 
00042   plExprNode(const std::string& _var, const std::string& _num, const Signe _signe)
00043     : var(_var), num(_num), signe(_signe)
00044   {};
00045 
00049   plExprNode(const plExprNode& _node)
00050     : var(_node.var), num(_node.num), signe(_node.signe)
00051   {};
00052 };
00053 
00057 struct plConstraintNode
00058 {
00059   std::string minBound,maxBound;
00060   std::string num;
00061   std::string var;
00062   unsigned    comp1,comp2;
00063 
00064   plConstraintNode(const std::string& _var, const std::string& _num,
00065                    const std::string& _b1 , const std::string& _b2 ,
00066                    const unsigned     _c1 , const unsigned     _c2)
00067     : minBound(_b1), maxBound(_b2), num(_num), var(_var), comp1(_c1), comp2(_c2)
00068   {};
00069   
00073   plConstraintNode(const plConstraintNode& _node)
00074     : minBound(_node.minBound), maxBound(_node.maxBound), num(_node.num), var(_node.var), comp1(_node.comp1), comp2(_node.comp2)
00075   {};
00076 
00077 
00078   
00079   /*
00080 
00081     faire des constructeurs pour les formes simples
00082     x <= 0                   _num _var _comp1 _maxbound
00083     0 <= x                   _num _var _minbound _comp1
00084 
00085   */
00086 
00090   plConstraintNode(const std::string& _num, const std::string& _var,
00091                    const unsigned     _c1 , const std::string& _maxbound)
00092     : minBound("-inf"), maxBound(_maxbound), num(_num), var(_var), comp1(_c1), comp2(99)
00093   {};
00094 
00098   plConstraintNode(const std::string& _num, const std::string& _var,
00099                    const std::string& _minbound, const unsigned _c1 )
00100     : minBound(_minbound), maxBound("+inf"), num(_num), var(_var), comp1(_c1), comp2(99)
00101   {};
00102 
00103 
00104 };
00105 
00109 struct plSimpleConstraint
00110 {
00111   std::string bound;
00112   unsigned    comp ;
00113 
00114   plSimpleConstraint(const std::string& _bound, const unsigned _comp)
00115     : bound(_bound), comp(_comp)
00116   {};
00117 
00118   plSimpleConstraint(const plSimpleConstraint& _cstr)
00119     : bound(_cstr.bound), comp(_cstr.comp)
00120   {};
00121 
00122   plSimpleConstraint& operator=(const plSimpleConstraint& _cstr)
00123   {
00124     comp  = _cstr.comp;
00125     bound = _cstr.bound;
00126     return *this;
00127   }
00128 };
00129 
00130 
00139 struct plGlobalNode
00140 {
00141   std::string              nom ;
00142   std::list<plExprNode *>  expr;
00143   plSimpleConstraint       cont;
00144 
00145   plGlobalNode(const plGlobalNode& _node)
00146     : nom(_node.nom), cont(_node.cont)
00147   {
00148     //copy(_node.expr.begin(), _node.expr.end(),
00149     //           expr.begin());
00150     for (std::list<plExprNode *>::const_iterator _iter  = _node.expr.begin();
00151                                                  _iter != _node.expr.end()  ;
00152                                                ++_iter)
00153       expr.push_back(*_iter);
00154   }
00155   
00156   plGlobalNode(const std::string& _nom, const std::list<plExprNode *>& _expr, const plSimpleConstraint& _cont)
00157     : nom(_nom), cont(_cont)
00158   {
00159     //copy(_expr.begin(), _expr.end(),
00160     //      expr.begin());
00161     for (std::list<plExprNode *>::const_iterator _iter  = _expr.begin();
00162                                                  _iter != _expr.end()  ;
00163                                                ++_iter)
00164       expr.push_back(*_iter);
00165   }
00166   
00170   ~plGlobalNode()
00171   {
00172     for (std::list<plExprNode*>::iterator i=expr.begin();i!=expr.end();++i)
00173         delete (*i);
00174   }
00175 };
00176 
00177 
00185 struct Cmp
00186 {
00187   bool operator()(std::string& s1, std::string& s2) const
00188   {
00189     // tout ca, pour ca !
00190         return s1 <= s2;
00191   }
00192 };
00193 
00194 class Model;
00195 
00205 class FichierProbleme
00206 {
00207 protected:
00210   std::string nom;
00213   bool isMax; // si non alors c Minimize
00216   std::list<plExprNode *> exprObj;
00219   std::list<plGlobalNode *> exprConstraint;
00222   std::list<std::string> exprGeneral;
00225   std::list<std::string> exprBinary;
00228   std::list<plConstraintNode *> exprBounds;
00229 
00234   std::multimap<std::string,unsigned>      mmap;
00235 
00237   std::map<std::string,unsigned>       Comp2Int;
00238 
00241   std::list< std::pair<long,std::string> > commentaires;
00242 
00243 protected:
00245   FichierProbleme() {};
00246 
00247 public:
00249   virtual bool Open(const std::string& nom) = 0;
00250 
00251   friend std::ostream& operator<<(std::ostream&,const FichierProbleme&);
00252   bool operator>> (Model & m);
00253 
00256   virtual ~FichierProbleme()
00257   {
00258     //std::cout << "Destructeur: ~FichierProbleme()"  << std::endl;
00259     for (std::list<plExprNode*>::iterator i=exprObj.begin();i!=exprObj.end();++i)
00260         delete (*i);
00261     for (std::list<plGlobalNode*>::iterator i=exprConstraint.begin();i!=exprConstraint.end();++i)
00262         delete (*i);
00263     for (std::list<plConstraintNode*>::iterator i=exprBounds.begin();i!=exprBounds.end();++i)
00264         delete (*i);
00265     // le reste est auto-détruit grace aux auto_ptr<>
00266   };
00267 };
00268 
00269 
00270 #endif

Généré le Mon Jul 18 23:07:40 2005 pour Modelib par doxygen 1.3.6