MAiNGO
babOptVar.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 babOptVar.h
11  *
12  * @brief File containing definitions related to the specification of optmization variables.
13  *
14  **********************************************************************************/
15 
16 #pragma once
17 
18 #include "babBounds.h"
19 
20 #include <iostream>
21 #include <limits>
22 #include <string>
23 
24 
29 namespace babBase {
30 
31 
36 namespace enums {
37 
38 
43 enum VT {
47 };
48 
49 
50 } // end namespace enums
51 
52 
61 
62 
63  public:
72  OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType, const unsigned branchingPriority, const std::string nameIn):
73  _bounds(variableBoundsIn), _userSpecifiedBounds(variableBoundsIn), _variableType(variableType),
74  _branchingPriority(branchingPriority), _name(nameIn), _feasible(variableBoundsIn.are_consistent())
75  {
77  }
78 
86  OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType, const unsigned branchingPriority):
87  _bounds(variableBoundsIn), _userSpecifiedBounds(variableBoundsIn), _variableType(variableType),
88  _branchingPriority(branchingPriority), _name(), _feasible(variableBoundsIn.are_consistent())
89  {
91  }
92 
100  OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType, const std::string nameIn):
101  _bounds(variableBoundsIn), _userSpecifiedBounds(variableBoundsIn), _variableType(variableType),
102  _branchingPriority(1), _name(nameIn), _feasible(variableBoundsIn.are_consistent())
103  {
105  }
106 
114  OptimizationVariable(const Bounds &variableBoundsIn, const unsigned branchingPriority, const std::string nameIn):
115  _bounds(variableBoundsIn), _userSpecifiedBounds(variableBoundsIn), _variableType(enums::VT_CONTINUOUS),
116  _branchingPriority(branchingPriority), _name(nameIn), _feasible(variableBoundsIn.are_consistent())
117  {}
118 
125  OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType):
126  _bounds(variableBoundsIn), _userSpecifiedBounds(variableBoundsIn), _variableType(variableType),
127  _branchingPriority(1), _name(), _feasible(variableBoundsIn.are_consistent())
128  {
130  }
131 
138  OptimizationVariable(const Bounds &variableBoundsIn, const unsigned branchingPriority):
139  _bounds(variableBoundsIn), _userSpecifiedBounds(variableBoundsIn), _variableType(enums::VT_CONTINUOUS),
140  _branchingPriority(branchingPriority), _name(), _feasible(variableBoundsIn.are_consistent())
141  {}
142 
149  OptimizationVariable(const Bounds &variableBoundsIn, const std::string nameIn):
150  _bounds(variableBoundsIn), _userSpecifiedBounds(variableBoundsIn), _variableType(enums::VT_CONTINUOUS),
151  _branchingPriority(1), _name(nameIn), _feasible(variableBoundsIn.are_consistent())
152  {}
153 
159  OptimizationVariable(const Bounds &variableBoundsIn):
160  _bounds(variableBoundsIn), _userSpecifiedBounds(variableBoundsIn), _variableType(enums::VT_CONTINUOUS),
161  _branchingPriority(1), _name(), _feasible(variableBoundsIn.are_consistent())
162  {}
163 
171  OptimizationVariable(const enums::VT variableType, const unsigned branchingPriority, const std::string nameIn):
172  _bounds(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()),
173  _userSpecifiedBounds( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()),
174  _variableType(variableType), _branchingPriority(branchingPriority), _name(nameIn)
175  {
177  }
178 
185  OptimizationVariable(const enums::VT variableType, const unsigned branchingPriority):
186  _bounds(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()),
187  _userSpecifiedBounds( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()),
188  _variableType(variableType), _branchingPriority(branchingPriority), _name()
189  {
191  }
192 
199  OptimizationVariable(const enums::VT variableType, const std::string nameIn):
200  _bounds(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()),
201  _userSpecifiedBounds( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()),
202  _variableType(variableType), _branchingPriority(1), _name(nameIn)
203  {
205  }
206 
212  OptimizationVariable(const enums::VT variableType):
213  _bounds(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()),
214  _userSpecifiedBounds( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()),
215  _variableType(variableType), _branchingPriority(1), _name()
216  {
218  }
219 
226  OptimizationVariable(const unsigned branchingPriority, const std::string nameIn);
227 
233  OptimizationVariable(const unsigned branchingPriority);
234 
240  OptimizationVariable(const std::string nameIn);
241 
246 
250  double get_lower_bound() const { return _bounds.lower; }
251 
255  double get_upper_bound() const { return _bounds.upper; }
256 
261 
266 
270  double get_mid() const { return 0.5 * (_bounds.lower + _bounds.upper); }
271 
275  std::string get_name() const { return _name; }
276 
281 
285  unsigned get_branching_priority() const { return _branchingPriority; }
286 
290  bool has_nonempty_host_set() const { return _feasible; }
291 
295  bool bounds_changed_from_user_input() const { return ((_bounds != _userSpecifiedBounds) ? true : false); }
296 
303  friend std::ostream &operator<<(std::ostream &os, const OptimizationVariable &ov)
304  {
305  std::string typestring;
306  std::string leftPara = "{";
307  std::string rightPara = "}";
308  switch (ov.get_variable_type()) {
310  typestring = "Binary";
311  break;
313  typestring = "Continous";
314  leftPara = "[";
315  rightPara = "]";
316  break;
318  typestring = "Integer";
319  break;
320  }
321  os << "Name: " << ov.get_name() << " " << typestring << " Bounds: " << leftPara << ov._bounds.lower << "," << ov._bounds.upper << rightPara;
322  return os;
323  };
324 
325  private:
333  const unsigned _branchingPriority;
334  const std::string _name;
335  bool _feasible;
345 
355 };
356 
357 
358 } // namespace babBase
double get_upper_bound() const
Function for querying the upper variable bound.
Definition: babOptVar.h:255
bool bounds_changed_from_user_input() const
Function for querying whether the bounds have been modified (e.g., by rounding to integer values) com...
Definition: babOptVar.h:295
Definition: babOptVar.h:46
OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType, const unsigned branchingPriority, const std::string nameIn)
Constructor for the case all three optional parameters are used.
Definition: babOptVar.h:72
double get_lower_bound() const
Function for querying the lower variable bound.
Definition: babOptVar.h:250
double get_user_upper_bound() const
Function for querying the upper variable bound as originally specified by the user.
Definition: babOptVar.h:265
OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType, const unsigned branchingPriority)
Constructor for the case only a variable type and a branching priority is specified in addition to th...
Definition: babOptVar.h:86
Bounds _bounds
Definition: babOptVar.h:330
OptimizationVariable(const Bounds &variableBoundsIn, const std::string nameIn)
Constructor for the case only a name is specified in addition to the bounds. The variable is thus ass...
Definition: babOptVar.h:149
Auxiliary struct for representing bounds on an optimization variable.
Definition: babBounds.h:32
friend std::ostream & operator<<(std::ostream &os, const OptimizationVariable &ov)
operator << overloaded for Bounds for easier output
Definition: babOptVar.h:303
bool has_nonempty_host_set() const
Function for querying whether the host set of the variable is non-empty.
Definition: babOptVar.h:290
OptimizationVariable(const enums::VT variableType, const unsigned branchingPriority, const std::string nameIn)
Constructor for the case only a variable type, branching priority and a variable name are specified...
Definition: babOptVar.h:171
OptimizationVariable(const enums::VT variableType, const std::string nameIn)
Constructor for the case only a variable type and a variable name are specified. The variable bounds ...
Definition: babOptVar.h:199
const enums::VT _variableType
Definition: babOptVar.h:332
std::string get_name() const
Function for querying the variable name.
Definition: babOptVar.h:275
namespace holding all essentials of the babBase submodule
Definition: babOptVar.h:44
Class for representing an optimization variable specified by the user.
Definition: babOptVar.h:60
OptimizationVariable()
Default constructor The variable bounds are not defined. This function currently just throws an excep...
Definition: babOptVar.cpp:82
OptimizationVariable(const Bounds &variableBoundsIn)
Minimal constructor requiring only the required information. The variable is thus assumed to be conti...
Definition: babOptVar.h:159
OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType)
Constructor for the case only a variable type is specified in addition to the bounds. The variable is used for branching, and the name is empty.
Definition: babOptVar.h:125
double lower
Definition: babBounds.h:52
unsigned get_branching_priority() const
Function for querying the branching priority.
Definition: babOptVar.h:285
bool _feasible
Definition: babOptVar.h:335
OptimizationVariable(const Bounds &variableBoundsIn, const unsigned branchingPriority, const std::string nameIn)
Constructor for the case only a branching priority and a name is specified in addition to the bounds...
Definition: babOptVar.h:114
double get_user_lower_bound() const
Function for querying the lower variable bound as originally specified by the user.
Definition: babOptVar.h:260
const Bounds _userSpecifiedBounds
Definition: babOptVar.h:331
OptimizationVariable(const enums::VT variableType, const unsigned branchingPriority)
Constructor for the case only a variable type and branching priority are specified. The variable bounds are not defined. This function currently just throws an exception, except in case of a binary variable.
Definition: babOptVar.h:185
double get_mid() const
Function for querying the midpoint of the variable range.
Definition: babOptVar.h:270
double upper
Definition: babBounds.h:53
void _infer_and_set_bounds_or_throw()
Auxiliary function for determining bounds in case the user did not specify any.
Definition: babOptVar.cpp:93
OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType, const std::string nameIn)
Constructor for the case only a variable type and a name is specified in addition to the bounds...
Definition: babOptVar.h:100
enums::VT get_variable_type() const
Function for querying the variable type.
Definition: babOptVar.h:280
VT
Enum for representing the Variable Type of an optimization variable as specified by the user...
Definition: babOptVar.h:43
const std::string _name
Definition: babOptVar.h:334
OptimizationVariable(const Bounds &variableBoundsIn, const unsigned branchingPriority)
Constructor for the case only a branching priority is specified in addition to the bounds...
Definition: babOptVar.h:138
OptimizationVariable(const enums::VT variableType)
Constructor for the case only a variable type is specified. The variable bounds are not defined...
Definition: babOptVar.h:212
void _round_and_check_discrete_bounds()
sanity check of user-given bounds on discrete variables
Definition: babOptVar.cpp:26
const unsigned _branchingPriority
Definition: babOptVar.h:333
Definition: babOptVar.h:45