- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/svn-release/Smi-0.93.1/FlopCpp/src/MP_expression.hpp

Go to the documentation of this file.

    00001 // ******************** FlopCpp **********************************************
    00002 // File: MP_expression.hpp
    00003 // $Id$
    00004 // Author: Tim Helge Hultberg (thh@mat.ua.pt)
    00005 // Copyright (C) 2003 Tim Helge Hultberg
    00006 // All Rights Reserved.
    00007 // ****************************************************************************
    00008
    00009 #ifndef _MP_expression_hpp_
    00010 #define _MP_expression_hpp_
    00011
    00012 #include <vector>
    00013 #include <set>
    00014
    00015 #include "MP_domain.hpp"
    00016 #include "MP_constant.hpp"
    00017 #include "MP_utilities.hpp"
    00018
    00019 namespace flopc {
    00020
    00021     class Boolean;
    00022     class MP_domain;
    00023     class MP_constraint;
    00024     class Row;
    00025     class MP_variable;
    00026     class VariableRef;
    00027     class CoefLess;
    00028
    00034     struct Coef {
    00035         Coef(int c, int r, double v, int s = 0) :
    00036             col(c), row(r), stage(s), val(v)  {}
    00037         int col, row, stage;
    00038         double val;
    00039     };
    00040
    00041     class TerminalExpression;
    00042
    00048     class GenerateFunctor : public Functor {
    00049     public:
    00050         GenerateFunctor(std::vector<Coef>& coefs) : Coefs(coefs) {}
    00051
    00052         virtual ~GenerateFunctor(){}
    00053
    00054         void setConstraint(MP_constraint* r) {
    00055             R = r;
    00056         }
    00057         void setMultiplicator(std::vector<Constant>& mults, double m) {
    00058             multiplicators = mults;
    00059             m_ = m;
    00060         }
    00061         void setTerminalExpression(const TerminalExpression* c) {
    00062             C = c;
    00063         }
    00064         virtual int row_number() const;
    00065
    00066         void operator()() const;
    00067
    00068         double m_;
    00069         std::vector<Constant> multiplicators;
    00070         MP_constraint* R;
    00071         const TerminalExpression* C;
    00072         std::vector<Coef>& Coefs;
    00073     };
    00074
    00080     class ObjectiveGenerateFunctor : public GenerateFunctor {
    00081     public:
    00082         ObjectiveGenerateFunctor(std::vector<Coef>& coefs) : GenerateFunctor(coefs) {}
    00083         virtual int row_number() const {
    00084             return -1;
    00085         }
    00086     };
    00087
    00093     class MP_expression_base {
    00094         friend class MP_expression;
    00095         friend class Handle<MP_expression_base*>;
    00096     private:
    00097         int count;
    00098     public:
    00099         MP_expression_base() : count(0) {}
    00100
    00101         virtual double level() const = 0;
    00102         virtual void generate(const MP_domain& domain,
    00103                               std::vector<Constant> multiplicators,
    00104                               GenerateFunctor& f,
    00105                               double m) const = 0;
    00106         virtual void insertVariables(std::set<MP_variable*>& v) const = 0;
    00107
    00108         virtual ~MP_expression_base() {}
    00109     };
    00110
    00122     class MP_expression : public Handle<MP_expression_base*> {
    00123         friend class MP_constraint;
    00124     public:
    00126         MP_expression() : Handle<MP_expression_base*>(0) {}
    00130         MP_expression(MP_expression_base* r) : Handle<MP_expression_base*>(r) {}
    00132         MP_expression(const Constant& c);
    00134         MP_expression(const VariableRef& v);
    00135         virtual ~MP_expression() {}
    00136     };
    00137
    00144     class TerminalExpression : public MP_expression_base {
    00145     public:
    00146         virtual double getValue() const = 0;
    00147         virtual int getColumn() const = 0;
    00148         virtual int getStage() const = 0;
    00149     };
    00150
    00157     class Expression_operator : public MP_expression_base {
    00158     public:
    00159         Expression_operator(const MP_expression& e1, const MP_expression& e2) :
    00160             left(e1),right(e2) {}
    00161         void insertVariables(std::set<MP_variable*>& v) const {
    00162             left->insertVariables(v);
    00163             right->insertVariables(v);
    00164         }
    00165     protected:
    00166         MP_expression left,right;
    00167     };
    00168
    00170     MP_expression operator+(const MP_expression& e1, const MP_expression& e2);
    00174     MP_expression operator+(const MP_expression& e1, const Constant& e2);
    00178     MP_expression operator+(const Constant& e1, const MP_expression& e2);
    00182     MP_expression operator-(const MP_expression& e1, const MP_expression& e2);
    00186     MP_expression operator-(const MP_expression& e1, const Constant& e2);
    00190     MP_expression operator-(const Constant& e1, const MP_expression& e2);
    00194     MP_expression operator*(const Constant& e1, const MP_expression& e2);
    00198     MP_expression operator*(const MP_expression& e1, const Constant& e2);
    00202     MP_expression sum(const MP_domain& d, const MP_expression& e);
    00203
    00204 } // End of namespace flopc
    00205 #endif