FLOPC++
MP_variable.cpp
Go to the documentation of this file.
1 // ******************** FlopCpp **********************************************
2 // File: MP_variable.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 <OsiSolverInterface.hpp>
13 #include "MP_variable.hpp"
14 #include "MP_domain.hpp"
15 #include "MP_constant.hpp"
16 #include "MP_model.hpp"
17 
18 using namespace flopc;
19 using namespace std;
20 
22  const MP_index_exp& i1,
23  const MP_index_exp& i2,
24  const MP_index_exp& i3,
25  const MP_index_exp& i4,
26  const MP_index_exp& i5) :
27  V(v),I1(i1),I2(i2),I3(i3),I4(i4),I5(i5) {
28  offset = v->offset;
29 }
30 
31 double VariableRef::level() const {
32  return V->M->solution[V->offset +
33  V->f(V->S1->evaluate(),
34  V->S2->evaluate(),
35  V->S3->evaluate(),
36  V->S4->evaluate(),
37  V->S5->evaluate())];
38 }
39 
40 int VariableRef::getColumn() const {
41  int i1 = V->S1->check(I1->evaluate());
42  int i2 = V->S2->check(I2->evaluate());
43  int i3 = V->S3->check(I3->evaluate());
44  int i4 = V->S4->check(I4->evaluate());
45  int i5 = V->S5->check(I5->evaluate());
46 
47  if (i1==outOfBound || i2==outOfBound || i3==outOfBound ||
48  i4==outOfBound || i5==outOfBound) {
49  return outOfBound;
50  } else {
51  return V->offset + V->f(i1,i2,i3,i4,i5);
52  }
53 }
54 
55 void VariableRef::generate(const MP_domain& domain,
56  vector<Constant > multiplicators,
57  GenerateFunctor& f,
58  double m) const {
59  f.setMultiplicator(multiplicators,m);
60  f.setTerminalExpression(this);
61  domain.Forall(&f);
62 }
63 
65  const MP_set_base &s2,
66  const MP_set_base &s3,
67  const MP_set_base &s4,
68  const MP_set_base &s5) :
69  RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
70  upperLimit(MP_data(s1,s2,s3,s4,s5)),
71  lowerLimit(MP_data(s1,s2,s3,s4,s5)),
72  S1(&s1),S2(&s2),S3(&s3),S4(&s4),S5(&s5),
73  offset(-1)
74 {
77  type = continuous;
78 }
79 
80 double MP_variable::level(int lcl_i1, int lcl_i2, int lcl_i3, int lcl_i4, int lcl_i5) {
81  return M->solution[offset + f(lcl_i1,lcl_i2,lcl_i3,lcl_i4,lcl_i5)];
82 }
83 
85  if (S1!=&MP_set::getEmpty()) cout << i1.evaluate() << " ";
86  if (S2!=&MP_set::getEmpty()) cout << i2.evaluate() << " ";
87  if (S3!=&MP_set::getEmpty()) cout << i3.evaluate() << " ";
88  if (S4!=&MP_set::getEmpty()) cout << i4.evaluate() << " ";
89  if (S5!=&MP_set::getEmpty()) cout << i5.evaluate() << " ";
90  cout<<" "<< M->solution[offset +
91  f(i1.evaluate(),
92  i2.evaluate(),
93  i3.evaluate(),
94  i4.evaluate(),
95  i5.evaluate())]<<endl;
96 }
97 
98 void MP_variable::display(const std::string &s) {
99  cout<<s<<endl;
100  if (offset >= 0) {
101  ((*S1)(i1)*(*S2)(i2)*(*S3)(i3)*(*S4)(i4)*(*S5)(i5)).Forall(this);
102  } else {
103  cout<<"No solution available!"<<endl;
104  }
105 }
const MP_index_exp I2
Definition: MP_variable.hpp:64
void operator()() const
Definition: MP_variable.cpp:84
static MP_set & getEmpty()
gets the distinct &#39;empty&#39; MP_set.
Definition: MP_set.cpp:17
MP_variable(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())
Definition: MP_variable.cpp:64
const MP_index_exp I3
Definition: MP_variable.hpp:64
void generate(const MP_domain &domain, std::vector< Constant > multiplicators, GenerateFunctor &f, double m) const
Definition: MP_variable.cpp:55
void Forall(const Functor *op) const
Special conditional operation on the domain.
Definition: MP_domain.cpp:85
MP_data upperLimit
Upper bound on the variable value.
int evaluate() const
Definition: MP_index.hpp:57
const MP_set_base * S1
void initialize(double d)
similar to value() but copies the same value to all entries.
Definition: MP_data.hpp:79
void display(const std::string &s="")
Definition: MP_variable.cpp:98
const MP_index_exp I4
Definition: MP_variable.hpp:64
double level() const
Definition: MP_variable.cpp:31
Representation of an expression involving an index.This is one of the main public interface classes...
Definition: MP_index.hpp:145
int f(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0) const
const MP_set_base * S5
MP_variable * V
Definition: MP_variable.hpp:62
int check(int i) const
Definition: MP_set.hpp:37
const int outOfBound
Distinct return value on conditions where an index goes out of bounds.
VariableRef(MP_variable *v, const MP_index_exp &i1, const MP_index_exp &i2, const MP_index_exp &i3, const MP_index_exp &i4, const MP_index_exp &i5)
Definition: MP_variable.cpp:21
double level(int i1=0, int i2=0, int i3=0, int i4=0, int i5=0)
Returns the value of the variable given the specific index values.
Definition: MP_variable.cpp:80
void setTerminalExpression(const TerminalExpression *c)
const MP_set_base * S2
Range over which some other constuct is defined.This is one of the main public interface classes...
Definition: MP_domain.hpp:61
int getColumn() const
Definition: MP_variable.cpp:40
Symantic representation of a variable.This is one of the main public interface classes. It should be directly declared by clients of the FlopC++. The parametersof construction are MP_set s which specify the indexes over which the variable is defined.
Definition: MP_variable.hpp:75
const MP_index_exp I5
Definition: MP_variable.hpp:64
Input data set.This is one of the main public interface classes. It is normally directly constructed ...
Definition: MP_data.hpp:71
Functor to facilitate generation of coefficients.
const MP_index_exp I1
Definition: MP_variable.hpp:64
const MP_set_base * S3
Internal representation of a &quot;set&quot;.
Definition: MP_set.hpp:28
void setMultiplicator(std::vector< Constant > &mults, double m)
const double * solution
Definition: MP_model.hpp:211
static MP_model & getDefaultModel()
Definition: MP_model.cpp:25
variableType type
const MP_set_base * S4
MP_data lowerLimit
Lower bound on the variable value.