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 using std::cout;
12 using std::endl;
13 
14 #include <OsiSolverInterface.hpp>
15 #include "MP_constraint.hpp"
16 #include "MP_expression.hpp"
17 #include "MP_model.hpp"
18 #include "MP_constant.hpp"
19 #include "MP_data.hpp"
20 
21 using namespace flopc;
22 
23 
25  left = v->left;
26  right = v->right;
27  sense = v->sense;
28 }
29 
31  int i1 = S1.check(I1->evaluate());
32  int i2 = S2.check(I2->evaluate());
33  int i3 = S3.check(I3->evaluate());
34  int i4 = S4.check(I4->evaluate());
35  int i5 = S5.check(I5->evaluate());
36 
37  if (i1==outOfBound || i2==outOfBound || i3==outOfBound ||
38  i4==outOfBound || i5==outOfBound) {
39  return outOfBound;
40  } else {
41  return offset + f(I1->evaluate(),I2->evaluate(),I3->evaluate(),
42  I4->evaluate(),I5->evaluate());
43  }
44 }
45 
46 double MP_constraint::price(int i1, int i2, int i3, int i4, int i5) const {
47  return M->Solver->getRowPrice()[offset + f(i1,i2,i3,i4,i5)];
48 }
49 
51  const MP_set_base &s1,
52  const MP_set_base &s2,
53  const MP_set_base &s3,
54  const MP_set_base &s4,
55  const MP_set_base &s5) :
56  RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
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 
65 void MP_constraint::coefficients(vector<MP::Coef>& cfs) {
66  MP::GenerateFunctor f(this, cfs);
67 // f.setConstraint(this);
68 
69  vector<Constant> v;
70  if (left.isDefined() && right.isDefined()) {
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->Solver->getRowLower()[i]<<" "<<M->Solver->getRowActivity()[i]<<" "<<M->Solver->getRowUpper()[i]<<" "<<M->Solver->getRowPrice()[i]<<endl;
92  }
93  } else {
94  cout<<"No solution available!"<<endl;
95  }
96 }
MP_constraint & such_that(const MP_boolean &b)
MP_model & add(MP_constraint &constraint)
Adds a constrataint block to the model.
Definition: MP_model.cpp:77
double price(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0) const
void operator=(const Constraint &v)
const MP_set_base & S2
const MP_set_base & S1
const MP_set_base & S3
static MP_model * current_model
Definition: MP_model.hpp:237
int f(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0) const
void insertVariables(set< MP_variable * > &v)
int size() const
int check(int i) const
Definition: MP_set.hpp:38
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:90
All flopc++ code is contained within the flopc namespace.
Definition: flopc.cpp:11
OsiSolverInterface * Solver
Definition: MP_model.hpp:251
int row_number() const
void display(string s="") const
void coefficients(vector< MP::Coef > &cfs)
Internal representation of a "set".
Definition: MP_set.hpp:30
const MP_set_base & S5
const MP_set_base & S4