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 <iostream>
19 #include <string>
20 
21 
26 namespace babBase {
27 
28 
33 namespace enums {
34 
35 
40 enum VT {
42  // Assumption for the following: bounding rounds to next discrete values, CPLEX handles them as integers
45 };
46 
47 
48 } // end namespace enums
49 
50 
57 struct Bounds {
58 
59  public:
66  Bounds(const double lowerIn, const double upperIn):
67  lower(lowerIn), upper(upperIn), consistent(lowerIn <= upperIn) {}
68  Bounds(Bounds &&) = default;
69  Bounds(const Bounds &) = default;
77  friend std::ostream &operator<<(std::ostream &os, Bounds const &b)
78  {
79  os << "Lower:" << b.lower << " , Upper:" << b.upper;
80  return os;
81  };
82 
83  const double lower;
84  const double upper;
85  const double consistent;
87  private:
88  // Private declaration of copy constructor and copy assignment operator to prevent accidental use
89  Bounds &operator=(const Bounds &);
90 };
91 
92 
101 
102 
103  public:
112  OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType, const unsigned branchingPriority, const std::string nameIn):
113  _lowerBound(variableBoundsIn.lower), _upperBound(variableBoundsIn.upper), _variableType(variableType),
114  _branchingPriority(branchingPriority), _name(nameIn), _feasible(variableBoundsIn.consistent)
115  {
117  }
118 
126  OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType, const unsigned branchingPriority):
127  _lowerBound(variableBoundsIn.lower), _upperBound(variableBoundsIn.upper), _variableType(variableType),
128  _branchingPriority(branchingPriority), _name(), _feasible(variableBoundsIn.consistent)
129  {
131  }
132 
140  OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType, const std::string nameIn):
141  _lowerBound(variableBoundsIn.lower), _upperBound(variableBoundsIn.upper), _variableType(variableType),
142  _branchingPriority(1), _name(nameIn), _feasible(variableBoundsIn.consistent)
143  {
145  }
146 
154  OptimizationVariable(const Bounds &variableBoundsIn, const unsigned branchingPriority, const std::string nameIn):
155  _lowerBound(variableBoundsIn.lower), _upperBound(variableBoundsIn.upper), _variableType(enums::VT_CONTINUOUS),
156  _branchingPriority(branchingPriority), _name(nameIn), _feasible(variableBoundsIn.consistent)
157  {
160  }
161 
168  OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType):
169  _lowerBound(variableBoundsIn.lower), _upperBound(variableBoundsIn.upper), _variableType(variableType),
170  _branchingPriority(1), _name(), _feasible(variableBoundsIn.consistent)
171  {
173  }
174 
181  OptimizationVariable(const Bounds &variableBoundsIn, const unsigned branchingPriority):
182  _lowerBound(variableBoundsIn.lower), _upperBound(variableBoundsIn.upper), _variableType(enums::VT_CONTINUOUS),
183  _branchingPriority(branchingPriority), _name(), _feasible(variableBoundsIn.consistent)
184  {
187  }
188 
195  OptimizationVariable(const Bounds &variableBoundsIn, const std::string nameIn):
196  _lowerBound(variableBoundsIn.lower), _upperBound(variableBoundsIn.upper), _variableType(enums::VT_CONTINUOUS),
197  _branchingPriority(1), _name(nameIn), _feasible(variableBoundsIn.consistent)
198  {
201  }
202 
208  OptimizationVariable(const Bounds &variableBoundsIn):
209  _lowerBound(variableBoundsIn.lower), _upperBound(variableBoundsIn.upper), _variableType(enums::VT_CONTINUOUS),
210  _branchingPriority(1), _name(), _feasible(variableBoundsIn.consistent)
211  {
214  }
215 
223  OptimizationVariable(const enums::VT variableType, const unsigned branchingPriority, const std::string nameIn);
224 
231  OptimizationVariable(const enums::VT variableType, const unsigned branchingPriority);
232 
239  OptimizationVariable(const enums::VT variableType, const std::string nameIn);
240 
247  OptimizationVariable(const unsigned branchingPriority, const std::string nameIn);
248 
254  OptimizationVariable(const enums::VT variableType);
255 
261  OptimizationVariable(const unsigned branchingPriority);
262 
268  OptimizationVariable(const std::string nameIn);
269 
276  _lowerBound(variableIn._lowerBound), _upperBound(variableIn._upperBound), _variableType(variableIn._variableType),
277  _branchingPriority(variableIn._branchingPriority), _name(variableIn._name), _feasible(variableIn._feasible), changedBounds(variableIn.changedBounds) {}
278 
282  double get_lower_bound() const { return _lowerBound; }
283 
287  double get_upper_bound() const { return _upperBound; }
288 
292  double get_mid() const { return (_lowerBound + _upperBound) / 2; }
293 
297  std::string get_name() const { return _name; }
298 
303 
307  unsigned get_branching_priority() const { return _branchingPriority; }
308 
312  bool has_nonempty_host_set() const { return _feasible; }
313 
320  friend std::ostream &operator<<(std::ostream &os, OptimizationVariable const &ov)
321  {
322  std::string typestring;
323  std::string leftPara = "{";
324  std::string rightPara = "}";
325  switch (ov.get_variable_type()) {
327  typestring = "Binary";
328  break;
330  typestring = "Continous";
331  leftPara = "[";
332  rightPara = "]";
333  break;
335  typestring = "Integer";
336  break;
337  }
338  os << "Name: " << ov.get_name() << " " << typestring << " Bounds: " << leftPara << ov._lowerBound << "," << ov._upperBound << rightPara;
339  return os;
340  };
341 
346  struct ChangedBounds {
349  double userLowerBound;
350  double userUpperBound;
351  } changedBounds;
353  private:
358  double _lowerBound;
359  double _upperBound;
361  const unsigned _branchingPriority;
362  const std::string _name;
363  bool _feasible;
374  void _check_discrete_bounds();
375 };
376 
377 
378 } // namespace babBase
double get_upper_bound() const
Function for querying the upper variable bound.
Definition: babOptVar.h:287
Definition: babOptVar.h:44
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:112
double get_lower_bound() const
Function for querying the lower variable bound.
Definition: babOptVar.h:282
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:126
OptimizationVariable(const OptimizationVariable &variableIn)
Copy constructor.
Definition: babOptVar.h:275
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:195
Auxiliary struct for representing bounds on an optimization variable.
Definition: babOptVar.h:57
bool has_nonempty_host_set() const
Function for querying whether the host set of the variable is non-empty.
Definition: babOptVar.h:312
const enums::VT _variableType
Definition: babOptVar.h:360
std::string get_name() const
Function for querying the variable name.
Definition: babOptVar.h:297
namespace holding all essentials of the babBase submodule
Definition: babBrancher.h:40
Definition: babOptVar.h:41
bool upperBoundChanged
Definition: babOptVar.h:348
double userLowerBound
Definition: babOptVar.h:349
Class for representing an optimization variable specified by the user.
Definition: babOptVar.h:100
OptimizationVariable(const Bounds &variableBoundsIn)
Minimal constructor requiring only the required information. The variable is thus assumed to be conti...
Definition: babOptVar.h:208
OptimizationVariable(const Bounds &variableBoundsIn, const enums::VT variableType)
Constructor for the case only a variable type is specified in addition to the bounds....
Definition: babOptVar.h:168
unsigned get_branching_priority() const
Function for querying the branching priority.
Definition: babOptVar.h:307
double _lowerBound
Definition: babOptVar.h:358
double userUpperBound
Definition: babOptVar.h:350
bool _feasible
Definition: babOptVar.h:363
Bounds(const double lowerIn, const double upperIn)
Constructor, checks that specified lower bound is smaller than upper bound (this information is only ...
Definition: babOptVar.h:66
const double consistent
Definition: babOptVar.h:85
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:154
friend std::ostream & operator<<(std::ostream &os, Bounds const &b)
Overloaded outstream operator for nicer output.
Definition: babOptVar.h:77
const double lower
Definition: babOptVar.h:81
Auxiliary struct for storing changed bounds of an optimization variable.
Definition: babOptVar.h:346
OptimizationVariable & operator=(const OptimizationVariable &)
const double upper
Definition: babOptVar.h:84
double _upperBound
Definition: babOptVar.h:359
Bounds & operator=(const Bounds &)
double get_mid() const
Function for querying the midpoint of the variable range.
Definition: babOptVar.h:292
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:140
enums::VT get_variable_type() const
Function for querying the variable type.
Definition: babOptVar.h:302
VT
Enum for representing the Variable Type of an optimization variable as specified by the user.
Definition: babOptVar.h:40
struct babBase::OptimizationVariable::ChangedBounds changedBounds
const std::string _name
Definition: babOptVar.h:362
void _check_discrete_bounds()
sanity check of user-given bounds on discrete variables
Definition: babOptVar.cpp:26
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:181
friend std::ostream & operator<<(std::ostream &os, OptimizationVariable const &ov)
operator << overloaded for Bounds for easier output
Definition: babOptVar.h:320
const unsigned _branchingPriority
Definition: babOptVar.h:361
bool lowerBoundChanged
Definition: babOptVar.h:347
Definition: babOptVar.h:43