/usr/include/coin/MP_data.hpp is in coinor-libflopc++-dev 1.0.6-3.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | // ******************** FlopCpp **********************************************
// File: MP_data.hpp
// $Id$
// Author: Tim Helge Hultberg (thh@mat.ua.pt)
// Copyright (C) 2003 Tim Helge Hultberg
// All Rights Reserved.
// ****************************************************************************
#ifndef _MP_data_hpp_
#define _MP_data_hpp_
#include <vector>
#include "MP_index.hpp"
#include "MP_set.hpp"
#include "MP_constant.hpp"
#include "MP_boolean.hpp"
namespace flopc {
class MP_data;
/** @brief Reference to a set of data
@ingroup INTERNAL_USE
@note FOR INTERNAL USE: This is not normally used directly by the
calling code.
*/
class DataRef : public Constant_base, public Functor {
public:
DataRef(MP_data* d,
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,
int s = 0) :
D(d),I1(i1),I2(i2),I3(i3),I4(i4),I5(i5),C(0),stochastic(s) {}
~DataRef() {}
DataRef& such_that(const MP_boolean& b);
double evaluate() const;
int getStage() const;
const DataRef& operator=(const DataRef& r);
const DataRef& operator=(const Constant& c);
void evaluate_lhs(double v) const;
void operator()() const;
DataRef& probability(double p) { return *this; }
private:
MP_data* D;
MP_index_exp I1,I2,I3,I4,I5;
Constant C;
int stochastic;
MP_boolean B;
};
/** @brief Input data set.
@ingroup PublicInterface
This is one of the main public interface classes.
It is normally directly constructed given a set of indices (domain)
over which it is valid. If the data is not bound at construction,
either the value() or initialize() method must be called
which (deep) copies in the actual data.
If one wishes to refer to external data instead rather than
doing a deep copy, use the constructor which takes the value pointer
as an argument. This copies the original data pointer value
(rather than a deep copy).
<br> This is used for construction of :
@li objective coefficients
@li constraint coefficients
@li 'right hand sides'
*/
class MP_data : public RowMajor, public Functor , public Named {
friend class MP_variable;
friend class DisplayData;
friend class DataRef;
friend class MP_model;
public:
void operator()() const;
/// similar to value() but copies the same value to all entries.
void initialize(double d) {
for (int i=0; i<size(); i++) {
v[i] = d;
}
}
/** Constructs the MP_data object, and allocates space for data, and
initialize the data to zero.
*/
MP_data(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()) :
RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
S1(s1),S2(s2),S3(s3),S4(s4),S5(s5),
v(new double[size()]), manageData(true)
{
initialize(0);
}
/** Construct the object, and uses the data in the original array
(shallow copy)
*/
MP_data(double* value,
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()) :
RowMajor(s1.size(),s2.size(),s3.size(),s4.size(),s5.size()),
S1(s1),S2(s2),S3(s3),S4(s4),S5(s5),
v(value), manageData(false)
{ }
~MP_data() {
if (manageData == true) delete[] v;
}
/// Used to bind and deep copy data into the MP_data data structure.
void value(const double* d) {
for (int i=0; i<size(); i++) {
v[i] = d[i];
}
}
/// @todo purpose?
operator double() {
return operator()(0);
}
/** Looks up the data based on the index values passed in.
@note this is used internally, but may also be useful for spot
checking data or in other expressions.
*/
double& operator()(int lcli1, int lcli2=0, int lcli3=0, int lcli4=0, int lcli5=0) {
lcli1 = S1.check(lcli1);
lcli2 = S2.check(lcli2);
lcli3 = S3.check(lcli3);
lcli4 = S4.check(lcli4);
lcli5 = S5.check(lcli5);
int i = f(lcli1,lcli2,lcli3,lcli4,lcli5);
if (i == outOfBound) {
outOfBoundData = 0;
return outOfBoundData;
} else {
return v[i];
}
}
/** returns a DataRef which refers into the MP_data.
@note For internal use.
@todo can this be private?
*/
DataRef& operator() (
const MP_index_exp& lcli1 = MP_index_exp::getEmpty(),
const MP_index_exp& lcli2 = MP_index_exp::getEmpty(),
const MP_index_exp& lcli3 = MP_index_exp::getEmpty(),
const MP_index_exp& lcli4 = MP_index_exp::getEmpty(),
const MP_index_exp& lcli5 = MP_index_exp::getEmpty()
) {
myrefs.push_back(new DataRef(this, lcli1, lcli2, lcli3, lcli4, lcli5));
return *myrefs.back();
}
/// For displaying data in a human readable format.
void display(string s = "");
protected:
vector<DataRef*> myrefs;
private:
MP_data(const MP_data&); // Forbid copy constructor
MP_data& operator=(const MP_data&); // Forbid assignment
static double outOfBoundData;
MP_index i1,i2,i3,i4,i5;
const MP_set_base &S1,&S2,&S3,&S4,&S5;
double* v;
bool manageData;
};
class MP_stochastic_data : public MP_data {
public:
MP_stochastic_data(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()) :
MP_data(s1,s2,s3,s4,s5) {}
using flopc::MP_data::operator(); // From bugsquashing party. Some compiler needs this?
DataRef& operator() (
const MP_index_exp& lcli1 = MP_index_exp::getEmpty(),
const MP_index_exp& lcli2 = MP_index_exp::getEmpty(),
const MP_index_exp& lcli3 = MP_index_exp::getEmpty(),
const MP_index_exp& lcli4 = MP_index_exp::getEmpty(),
const MP_index_exp& lcli5 = MP_index_exp::getEmpty()
) {
myrefs.push_back(new DataRef(this, lcli1, lcli2, lcli3, lcli4, lcli5, 1));
return *myrefs.back();
}
};
} // End of namespace flopc
#endif
|