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

Generated on Sun Nov 6 03:14:50 2011 for FLOPC++ by  doxygen 1.4.7