MAiNGO
evaluationContainer.h
Go to the documentation of this file.
1 /**********************************************************************************
2  * Copyright (c) 2019 Process Systems Engineering (AVT.SVT), RWTH Aachen University
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License 2.0 which is available at
6  * http://www.eclipse.org/legal/epl-2.0.
7  *
8  * SPDX-License-Identifier: EPL-2.0
9  *
10  **********************************************************************************/
11 
12 #pragma once
13 
14 #include "outputVariable.h"
15 
16 #include "ffunc.hpp"
17 
18 #include <vector>
19 
20 
21 namespace maingo {
22 
23 
28 struct ModelFunction {
29 
30  ModelFunction() = default;
31  ~ModelFunction() = default;
32  ModelFunction(const ModelFunction &) = default;
33  ModelFunction(ModelFunction &&) = default;
34  ModelFunction &operator=(const ModelFunction &) = default;
35  ModelFunction &operator=(ModelFunction &&) = default;
36 
40  ModelFunction(const mc::FFVar var)
41  {
42  value.clear();
43  value.push_back(var);
44  name.clear();
45  name.push_back("");
46  }
47 
51  ModelFunction(const mc::FFVar var, const std::string &str)
52  {
53  value.clear();
54  value.push_back(var);
55  name.clear();
56  name.push_back(str);
57  }
58 
62  ModelFunction(const std::vector<mc::FFVar> &vars)
63  {
64  value = vars;
65  name = std::vector<std::string>(value.size(), "");
66  }
67 
71  void clear()
72  {
73  value.clear();
74  name.clear();
75  }
76 
80  void push_back(const mc::FFVar var)
81  {
82  value.push_back(var);
83  name.push_back("");
84  }
85 
89  void push_back(const mc::FFVar var, const std::string &str)
90  {
91  value.push_back(var);
92  name.push_back(str);
93  }
94 
98  void push_back(const std::vector<mc::FFVar> &vars)
99  {
100  for (size_t i = 0; i < vars.size(); i++) {
101  value.push_back(vars[i]);
102  name.push_back("");
103  }
104  }
105 
109  void push_back(const std::vector<mc::FFVar> &vars, const std::string &baseName)
110  {
111  if (vars.size() == 1) {
112  value.push_back(vars[0]);
113  name.push_back(baseName);
114  }
115  else if (baseName == "") {
116  push_back(vars);
117  }
118  else {
119  for (size_t i = 0; i < vars.size(); i++) {
120  value.push_back(vars[i]);
121  name.push_back(baseName + '_' + std::to_string(i + 1));
122  }
123  }
124  }
125 
129  size_t size() const
130  {
131  return value.size();
132  }
133 
137  void resize(const size_t size)
138  {
139  value.resize(size);
140  name.resize(size);
141  }
142 
146  void set_value(const mc::FFVar var, const unsigned i)
147  {
148  value[i] = var;
149  }
150 
154  void set_name(const std::string str, const unsigned i)
155  {
156  name[i] = str;
157  }
158 
162  inline ModelFunction &operator=(const mc::FFVar var)
163  {
164  value.clear();
165  value.push_back(var);
166  name.clear();
167  name.push_back("");
168  return *this;
169  }
170 
174  inline mc::FFVar &operator[](const unsigned int i)
175  {
176  return value[i];
177  }
178 
182  inline mc::FFVar &at(const unsigned int i)
183  {
184  return value.at(i);
185  }
186 
190  inline bool operator==(const ModelFunction &other) const
191  {
192  return ((name == other.name) && (value == other.value));
193  }
194 
195  std::vector<std::string> name;
196  std::vector<mc::FFVar> value;
197 };
198 
199 
215  std::vector<OutputVariable> output;
220  void clear()
221  {
222  objective.clear();
223  ineq.clear();
224  eq.clear();
227  ineqSquash.clear();
228  output.clear();
229  }
230 };
231 
232 } // end namespace maingo
mc::FFVar & operator[](const unsigned int i)
[] operator for easier access to value vector
Definition: evaluationContainer.h:174
void clear()
Clears all information, note that currently objective has not to be cleared, since it is overwritten...
Definition: evaluationContainer.h:220
ModelFunction & operator=(const mc::FFVar var)
= operator for backward compatibility
Definition: evaluationContainer.h:162
ModelFunction(const mc::FFVar var)
Constructor with FFVar value only.
Definition: evaluationContainer.h:40
std::vector< std::string > name
Definition: evaluationContainer.h:195
void push_back(const std::vector< mc::FFVar > &vars, const std::string &baseName)
Function for inserting a vector of FFVar at the end of the value vector with names.
Definition: evaluationContainer.h:109
void set_name(const std::string str, const unsigned i)
Function for seting name value at a given index.
Definition: evaluationContainer.h:154
ModelFunction(const mc::FFVar var, const std::string &str)
Constructor with FFVar value and a name.
Definition: evaluationContainer.h:51
std::vector< OutputVariable > output
Definition: evaluationContainer.h:215
Struct for making work with the EvaluationContainer easier for the user and also to ensure backward c...
Definition: evaluationContainer.h:28
void set_value(const mc::FFVar var, const unsigned i)
Function for seting FFVar value at a given index.
Definition: evaluationContainer.h:146
void push_back(const mc::FFVar var, const std::string &str)
Function for inserting a FFVar and a name at the end of the vectors.
Definition: evaluationContainer.h:89
ModelFunction eqRelaxationOnly
Definition: evaluationContainer.h:213
bool operator==(const ModelFunction &other) const
Equality comparison operator.
Definition: evaluationContainer.h:190
Struct for storing the values returned by model evaluation at the given point "var".
Definition: evaluationContainer.h:208
void push_back(const std::vector< mc::FFVar > &vars)
Function for inserting a vector of FFVar at the end of the value vector.
Definition: evaluationContainer.h:98
ModelFunction objective
Definition: evaluationContainer.h:209
size_t size() const
Function returning the size of the value vector. Note that value and name vectors have the same size ...
Definition: evaluationContainer.h:129
void clear()
Function deleting everything in the model function.
Definition: evaluationContainer.h:71
ModelFunction ineq
Definition: evaluationContainer.h:210
namespace holding all essentials of MAiNGO
Definition: aleModel.h:25
ModelFunction ineqSquash
Definition: evaluationContainer.h:214
std::vector< mc::FFVar > value
Definition: evaluationContainer.h:196
ModelFunction eq
Definition: evaluationContainer.h:211
void resize(const size_t size)
Function for resizing of the underlying vectors.
Definition: evaluationContainer.h:137
ModelFunction(const std::vector< mc::FFVar > &vars)
Constructor with vector of FFVar.
Definition: evaluationContainer.h:62
mc::FFVar & at(const unsigned int i)
Function for accessing elements.
Definition: evaluationContainer.h:182
ModelFunction & operator=(const ModelFunction &)=default
void push_back(const mc::FFVar var)
Function for inserting a FFVar value at the end of the value vector.
Definition: evaluationContainer.h:80
ModelFunction ineqRelaxationOnly
Definition: evaluationContainer.h:212