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  * @file evaluationContainer.h
11  *
12  * @brief File containing declaration of the EvaluationContainer struct used to
13  * communicate model results
14  *
15  **********************************************************************************/
16 
17 #pragma once
18 
19 #include "outputVariable.h"
20 
21 #include "ffunc.hpp"
22 
23 #include <vector>
24 
25 
26 namespace maingo {
27 
28 
33 struct modelFunction {
34 
41  modelFunction(const mc::FFVar var)
42  {
43  value.clear();
44  value.push_back(var);
45  name.clear();
46  name.push_back("");
47  }
48 
52  modelFunction(const mc::FFVar var, const std::string &str)
53  {
54  value.clear();
55  value.push_back(var);
56  name.clear();
57  name.push_back(str);
58  }
59 
63  void clear()
64  {
65  value.clear();
66  name.clear();
67  }
68 
72  void push_back(const mc::FFVar var)
73  {
74  value.push_back(var);
75  name.push_back("");
76  }
77 
81  void push_back(const mc::FFVar var, const std::string &str)
82  {
83  value.push_back(var);
84  name.push_back(str);
85  }
86 
90  void push_back(const std::vector<mc::FFVar> &vars)
91  {
92  for (size_t i = 0; i < vars.size(); i++) {
93  value.push_back(vars[i]);
94  name.push_back("");
95  }
96  }
97 
101  void push_back(const std::vector<mc::FFVar> &vars, const std::string &baseName)
102  {
103  if (vars.size() == 1) {
104  value.push_back(vars[0]);
105  name.push_back(baseName);
106  }
107  else if (baseName == "") {
108  push_back(vars);
109  }
110  else {
111  for (size_t i = 0; i < vars.size(); i++) {
112  value.push_back(vars[i]);
113  name.push_back(baseName + '_' + std::to_string(i + 1));
114  }
115  }
116  }
117 
121  size_t size() const
122  {
123  return value.size();
124  }
125 
129  void resize(const size_t size)
130  {
131  value.resize(size);
132  name.resize(size);
133  }
134 
138  void set_value(const mc::FFVar var, const unsigned i)
139  {
140  value[i] = var;
141  }
142 
146  void set_name(const std::string str, const unsigned i)
147  {
148  name[i] = str;
149  }
150 
154  inline modelFunction &operator=(const mc::FFVar var)
155  {
156  value.clear();
157  value.push_back(var);
158  name.clear();
159  name.push_back("");
160  return *this;
161  }
162 
166  inline mc::FFVar &operator[](const unsigned int i)
167  {
168  return value[i];
169  }
170 
174  inline mc::FFVar &at(const unsigned int i)
175  {
176  return value.at(i);
177  }
178 
179  std::vector<std::string> name;
180  std::vector<mc::FFVar> value;
181 };
182 
183 
199  std::vector<OutputVariable> output;
204  void clear()
205  {
206  objective.clear();
207  ineq.clear();
208  eq.clear();
211  ineqSquash.clear();
212  output.clear();
213  }
214 };
215 
216 } // end namespace maingo
void set_name(const std::string str, const unsigned i)
Function for seting name value at a given index.
Definition: evaluationContainer.h:146
void clear()
Clears all information, note that currently objective has not to be cleared, since it is overwritten.
Definition: evaluationContainer.h:204
void push_back(const mc::FFVar var)
Function for inserting a FFVar value at the end of the value vector.
Definition: evaluationContainer.h:72
modelFunction(const mc::FFVar var)
Constructor with FFVar value only.
Definition: evaluationContainer.h:41
modelFunction()
Definition: evaluationContainer.h:35
modelFunction eq
Definition: evaluationContainer.h:195
std::vector< OutputVariable > output
Definition: evaluationContainer.h:199
Struct for making work with the EvaluationContainer easier for the user and also to ensure backward c...
Definition: evaluationContainer.h:33
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:121
modelFunction ineqSquash
Definition: evaluationContainer.h:198
Struct for storing the values returned by model evaluation at the given point "var".
Definition: evaluationContainer.h:192
void clear()
Constructor with FFVar value only.
Definition: evaluationContainer.h:63
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:90
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:101
modelFunction objective
Definition: evaluationContainer.h:193
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:81
mc::FFVar & operator[](const unsigned int i)
[] operator for easier access to value vector
Definition: evaluationContainer.h:166
modelFunction ineq
Definition: evaluationContainer.h:194
modelFunction ineqRelaxationOnly
Definition: evaluationContainer.h:196
namespace holding all essentials of MAiNGO
Definition: aleModel.h:31
void resize(const size_t size)
Function for resizing of the underlying vectors.
Definition: evaluationContainer.h:129
mc::FFVar & at(const unsigned int i)
Function for accessing elements.
Definition: evaluationContainer.h:174
void set_value(const mc::FFVar var, const unsigned i)
Function for seting FFVar value at a given index.
Definition: evaluationContainer.h:138
modelFunction(const mc::FFVar var, const std::string &str)
Constructor with FFVar value and a name.
Definition: evaluationContainer.h:52
std::vector< std::string > name
Definition: evaluationContainer.h:179
~modelFunction()
Definition: evaluationContainer.h:36
modelFunction & operator=(const mc::FFVar var)
= operator for backward compatibility
Definition: evaluationContainer.h:154
modelFunction eqRelaxationOnly
Definition: evaluationContainer.h:197
std::vector< mc::FFVar > value
Definition: evaluationContainer.h:180