FLOPC++
MP_constraint.cpp
Go to the documentation of this file.
1 // ******************** FlopCpp **********************************************
2 // File: MP_constraint.cpp
3 // $Id$
4 // Author: Tim Helge Hultberg (thh@mat.ua.pt)
5 // Copyright (C) 2003 Tim Helge Hultberg
6 // All Rights Reserved.
7 //****************************************************************************
8 
9 #include <iostream>
10 #include <sstream>
11 
12 #include "MP_constraint.hpp"
13 #include "MP_expression.hpp"
14 #include "MP_model.hpp"
15 #include "MP_constant.hpp"
16 #include "MP_data.hpp"
17 
18 using namespace flopc;
19 using namespace std;
20 
21 
23  left = v.left;
24  right = v.right;
25  sense = v.sense;
26 }
27 
29  int i1 = S1.check(I1->evaluate());
30  int i2 = S2.check(I2->evaluate());
31  int i3 = S3.check(I3->evaluate());
32  int i4 = S4.check(I4->evaluate());
33  int i5 = S5.check(I5->evaluate());
34 
35  if (i1==outOfBound || i2==outOfBound || i3==outOfBound ||
36  i4==outOfBound || i5==outOfBound) {
37  return outOfBound;
38  } else {
39  return offset + f(I1->evaluate(),I2->evaluate(),I3->evaluate(),
40  I4->evaluate(),I5->evaluate());
41  }
42 }
43 
44 double MP_constraint::price(int i1, int i2, int i3, int i4, int i5) const {
45  return M->rowPrice[offset + f(i1,i2,i3,i4,i5)];
46 }
47 
49  const MP_set_base &s1,
50  const MP_set_base &s2,
51  const MP_set_base &s3,
52  const MP_set_base &s4,
53  const MP_set_base &s5) :
54  RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
55 // pprice(MP_data(d1->getSet(),d2->getSet(),d3->getSet(),
56 // d4->getSet(),d5->getSet())),
57  M(MP_model::current_model),
58  offset(-1),
59  S1(s1),S2(s2),S3(s3),S4(s4),S5(s5),
60  I1(0),I2(0),I3(0),I4(0),I5(0)
61 {
63 }
64 
66  f.setConstraint(this);
67 
68  vector<Constant> v;
69 
70  if (I1.operator->()!=0) {
71  left->generate(S1(I1)*S2(I2)*S3(I3)*S4(I4)*S5(I5).such_that(B),v,f,1.0);
72  right->generate(S1(I1)*S2(I2)*S3(I3)*S4(I4)*S5(I5).such_that(B),v,f,-1.0);
73  } else {
74  cout<<"FlopCpp Warning: Constraint declared but not defined."<<endl;
75  }
76 }
77 
78 void MP_constraint::insertVariables(set<MP_variable*>& v) {
79  if (left.operator->()!=0) {
80  left->insertVariables(v);
81  }
82  if (right.operator->()!=0) {
83  right->insertVariables(v);
84  }
85 }
86 
87 void MP_constraint::display(string s) const {
88  cout<<s<<endl;
89  if (offset >=0) {
90  for (int i=offset; i<offset+size(); i++) {
91  cout<<i<<" "<<M->bl[i]<<" "<<M->rowActivity[i]<<" "<<M->bu[i]<<" "<<M->rowPrice[i]<<endl;
92  }
93  } else {
94  cout<<"No solution available!"<<endl;
95  }
96 }
MP_constraint & such_that(const MP_boolean &b)
void display(std::string s="") const
void coefficients(GenerateFunctor &f)
double price(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0) const
MP_model & add(MP_constraint &c)
Adds a constrataint block to the model.
Definition: MP_model.cpp:68
void operator=(const Constraint &v)
const MP_set_base & S2
const MP_set_base & S1
const double * rowPrice
Definition: MP_model.hpp:213
MP_expression right
const MP_set_base & S3
const double * rowActivity
Definition: MP_model.hpp:214
static MP_model * current_model
Definition: MP_model.hpp:242
void insertVariables(std::set< MP_variable * > &v)
int size() const
const int outOfBound
Distinct return value on conditions where an index goes out of bounds.
MP_constraint(const MP_set_base &s1=MP_set::getEmpty(), const MP_set_base &s2=MP_set::getEmpty(), const MP_set_base &s3=MP_set::getEmpty(), const MP_set_base &s4=MP_set::getEmpty(), const MP_set_base &s5=MP_set::getEmpty())
construct the MP_constraint with appropriate sets for indexing.
This is the anchor point for all constructs in a FlopC++ model.The constructors take an OsiSolverInte...
Definition: MP_model.hpp:89
void setConstraint(MP_constraint *r)
int row_number() const
MP_expression left
Functor to facilitate generation of coefficients.
Internal representation of a &quot;set&quot;.
Definition: MP_set.hpp:28
const MP_set_base & S5
const MP_set_base & S4