MP_constraint.cpp

Go to the documentation of this file.
00001 // ******************** FlopCpp **********************************************
00002 // File: MP_constraint.cpp
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 #include <iostream>
00010 #include <sstream>
00011 using std::cout;
00012 using std::endl;
00013 
00014 #include "MP_constraint.hpp"
00015 #include "MP_expression.hpp"
00016 #include "MP_model.hpp"
00017 #include "MP_constant.hpp"
00018 #include "MP_data.hpp"
00019 
00020 using namespace flopc;
00021 
00022 
00023 void MP_constraint::operator=(const Constraint &v) {
00024    left = v.left;
00025    right = v.right;
00026    sense = v.sense;
00027 }
00028 
00029 int MP_constraint::row_number() const {
00030     int i1 = S1.check(I1->evaluate());
00031     int i2 = S2.check(I2->evaluate());
00032     int i3 = S3.check(I3->evaluate());
00033     int i4 = S4.check(I4->evaluate());
00034     int i5 = S5.check(I5->evaluate());
00035     
00036     if (i1==outOfBound || i2==outOfBound || i3==outOfBound ||
00037         i4==outOfBound || i5==outOfBound) {
00038         return outOfBound;
00039     } else {
00040         return offset + f(I1->evaluate(),I2->evaluate(),I3->evaluate(),
00041                           I4->evaluate(),I5->evaluate()); 
00042     }
00043 }
00044 
00045 double MP_constraint::price(int i1, int i2, int i3, int i4, int i5) const {
00046     return  M->rowPrice[offset + f(i1,i2,i3,i4,i5)];
00047 }
00048  
00049 MP_constraint::MP_constraint(
00050     const MP_set_base &s1, 
00051     const MP_set_base &s2, 
00052     const MP_set_base &s3,
00053     const MP_set_base &s4, 
00054     const MP_set_base &s5) :
00055     RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
00056 //     pprice(MP_data(d1->getSet(),d2->getSet(),d3->getSet(),
00057 //                 d4->getSet(),d5->getSet())),
00058     M(MP_model::current_model),
00059     offset(-1),
00060     S1(s1),S2(s2),S3(s3),S4(s4),S5(s5),
00061     I1(0),I2(0),I3(0),I4(0),I5(0)
00062 {
00063     MP_model::current_model->add(*this);
00064 }
00065 
00066 void MP_constraint::coefficients(GenerateFunctor& f) {
00067     f.setConstraint(this);
00068 
00069     vector<Constant> v;
00070 
00071         if (I1.operator->()!=0) {
00072         left->generate(S1(I1)*S2(I2)*S3(I3)*S4(I4)*S5(I5).such_that(B),v,f,1.0);
00073         right->generate(S1(I1)*S2(I2)*S3(I3)*S4(I4)*S5(I5).such_that(B),v,f,-1.0);
00074          } else {
00075                 cout<<"FlopCpp Warning: Constraint declared but not defined."<<endl;
00076         }
00077 }
00078 
00079 void MP_constraint::insertVariables(set<MP_variable*>& v) {
00080     if (left.operator->()!=0) {
00081         left->insertVariables(v);
00082     }
00083     if (right.operator->()!=0) {
00084         right->insertVariables(v);
00085     }
00086 }
00087 
00088 void MP_constraint::display(string s) const {
00089     cout<<s<<endl;
00090     if (offset >=0) {
00091       for (int i=offset; i<offset+size(); i++) {
00092         cout<<i<<"  "<<M->bl[i]<<"  "<<M->rowActivity[i]<<"  "<<M->bu[i]<<"  "<<M->rowPrice[i]<<endl;
00093       }
00094     } else {
00095       cout<<"No solution available!"<<endl;
00096     }
00097 }

Generated on Fri Aug 26 03:02:58 2011 for FLOPC++ by  doxygen 1.4.7