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

Generated on Fri May 16 00:25:12 2008 for FLOPC++ by  doxygen 1.4.7