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

- File List
- File Members

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

Go to the documentation of this file.

    00001 // ******************** FlopCpp **********************************************
    00002 // File: MP_constraint.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_constraint_hpp_
    00010 #define _MP_constraint_hpp_
    00011
    00012 #include <set>
    00013 #include <string>
    00014
    00015 #include "MP_set.hpp"
    00016 #include "MP_domain.hpp"
    00017 #include "MP_utilities.hpp"
    00018 #include "MP_expression.hpp"
    00019 #include "MP_boolean.hpp"
    00020 #include "MP_data.hpp"
    00021
    00022 namespace flopc {
    00023
    00024     class MP_constraint;
    00025     class Constant;
    00026     class MP_model;
    00027     class MP_variable;
    00028
    00032     enum  Sense_enum {LE,GE,EQ};
    00033
    00039     class Constraint {
    00040         friend class MP_constraint;
    00041         friend class MP_model;
    00042         friend Constraint operator<=(const MP_expression& l, const MP_expression& r);
    00043         friend Constraint operator<=(const Constant& l, const MP_expression& r);
    00044         friend Constraint operator<=(const MP_expression& l, const Constant& r);
    00045         friend Constraint operator<=(const VariableRef& l, const VariableRef& r);
    00046
    00047         friend Constraint operator>=(const MP_expression& l, const MP_expression& r);
    00048         friend Constraint operator>=(const Constant& l, const MP_expression& r);
    00049         friend Constraint operator>=(const MP_expression& l, const Constant& r);
    00050         friend Constraint operator>=(const VariableRef& l, const VariableRef& r);
    00051
    00052         friend Constraint operator==(const MP_expression& l, const MP_expression& r);
    00053         friend Constraint operator==(const Constant& l, const MP_expression& r);
    00054         friend Constraint operator==(const MP_expression& l, const Constant& r);
    00055         friend Constraint operator==(const VariableRef& l, const VariableRef& r);
    00056     private:
    00057         Constraint(const MP_expression& l, const MP_expression& r, Sense_enum s) :
    00058             left(l), right(r), sense(s) {}
    00059
    00060         MP_expression left,right;
    00061         Sense_enum sense;
    00062     };
    00063
    00069     inline Constraint operator<=(const MP_expression& l, const MP_expression& r) {
    00070         return Constraint(l, r, LE);
    00071     }
    00077     inline Constraint operator<=(const Constant& l, const MP_expression& r) {
    00078         return operator<=(MP_expression(l), r);
    00079     }
    00085     inline Constraint operator<=(const MP_expression& l, const Constant& r){
    00086         return operator<=(l, MP_expression(r));
    00087     }
    00093     inline Constraint operator<=(const VariableRef& l, const VariableRef& r) {
    00094         return *new Constraint(l, r, LE);
    00095     }
    00096
    00102     inline Constraint operator>=(const MP_expression& l, const MP_expression& r) {
    00103         return *new Constraint(l, r, GE);
    00104     }
    00110     inline Constraint operator>=(const Constant& l, const MP_expression& r){
    00111         return operator>=(MP_expression(l), r);
    00112     }
    00118     inline Constraint operator>=(const MP_expression& l, const Constant& r){
    00119         return operator>=(l, MP_expression(r));
    00120     }
    00126     inline Constraint operator>=(const VariableRef& l, const VariableRef& r) {
    00127         return *new Constraint(l, r, GE);
    00128     }
    00129
    00135     inline Constraint operator==(const MP_expression& l, const MP_expression& r) {
    00136         return *new Constraint(l, r, EQ);
    00137     }
    00143     inline Constraint operator==(const Constant& l, const MP_expression& r){
    00144         return operator==(MP_expression(l), r);
    00145     }
    00151     inline Constraint operator==(const MP_expression& l, const Constant& r) {
    00152         return operator==(l, MP_expression(r));
    00153     }
    00159     inline Constraint operator==(const VariableRef& l, const VariableRef& r) {
    00160         return *new Constraint(l, r, EQ);
    00161     }
    00162
    00163
    00164     class GenerateFunctor;
    00165
    00194     class MP_constraint : public RowMajor, public Named {
    00195     public:
    00197         MP_constraint(
    00198             const MP_set_base &s1 = MP_set::getEmpty(),
    00199             const MP_set_base &s2 = MP_set::getEmpty(),
    00200             const MP_set_base &s3 = MP_set::getEmpty(),
    00201             const MP_set_base &s4 = MP_set::getEmpty(),
    00202             const MP_set_base &s5 = MP_set::getEmpty()
    00203             );
    00204
    00205         MP_constraint& operator()(
    00206             const MP_index_exp& i1 = MP_index_exp::getEmpty(),
    00207             const MP_index_exp& i2 = MP_index_exp::getEmpty(),
    00208             const MP_index_exp& i3 = MP_index_exp::getEmpty(),
    00209             const MP_index_exp& i4 = MP_index_exp::getEmpty(),
    00210             const MP_index_exp& i5 = MP_index_exp::getEmpty()
    00211             )  {
    00212             I1 = i1; I2 = i2; I3 = i3; I4 = i4; I5 = i5;
    00213             return *this;
    00214         }
    00215
    00216         operator int() {
    00217             return offset + f(I1->evaluate(),I2->evaluate(),I3->evaluate(),
    00218                               I4->evaluate(),I5->evaluate());
    00219         }
    00220
    00221         virtual ~MP_constraint() {}
    00222
    00223         double price(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0) const;
    00224
    00225         void coefficients(GenerateFunctor& f);
    00226
    00227         int row_number() const;
    00228
    00229         MP_constraint& such_that(const MP_boolean& b) {
    00230             B = b;
    00231             return *this;
    00232         }
    00233
    00234         void insertVariables(std::set<MP_variable*>& v);
    00235
    00236         void operator=(const Constraint& v);
    00237
    00238         void display(std::string s="") const;
    00239
    00240         MP_model* M;
    00241         int offset;
    00242         MP_expression left,right;
    00243         Sense_enum sense;
    00244     private:
    00245         MP_boolean B;
    00246         const MP_set_base &S1, &S2, &S3, &S4, &S5;
    00247         MP_index_exp I1, I2, I3, I4, I5;
    00248     };
    00249
    00250 }  // End of namespace flopc
    00251 #endif