MAiNGO
ubp.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 ubp.h
11  *
12  * @brief File containing declaration of UpperBoundingSolver class used as base
13  * class for different upper bounding solver wrappers.
14  *
15  **********************************************************************************/
16 
17 #pragma once
18 
19 #include "constraint.h"
20 #include "logger.h"
21 #include "mcForward.h"
22 #include "returnCodes.h"
23 #include "settings.h"
24 #include "ubpStructure.h"
25 
26 #include "babNode.h"
27 #include "babUtils.h"
28 
29 #include <memory>
30 #include <vector>
31 
32 
33 namespace maingo {
34 
35 
36 namespace ubp {
37 
38 
39 struct DagObj;
40 
50 
51  public:
56  enum UBS_USE {
57  USE_PRE = 0,
59  };
60 
76  UpperBoundingSolver(mc::FFGraph &DAG, const std::vector<mc::FFVar> &DAGvars, const std::vector<mc::FFVar> &DAGfunctions, const std::vector<babBase::OptimizationVariable> &variables,
77  const unsigned nineqIn, const unsigned neqIn, const unsigned nineqSquashIn, Settings *settingsIn, Logger *loggerIn, std::vector<Constraint> *constraintPropertiesIn, UBS_USE useIn);
78 
82  virtual ~UpperBoundingSolver() {}
83 
92  virtual SUBSOLVER_RETCODE solve(babBase::BabNode const &currentNode, double &objectiveValue, std::vector<double> &solutionPoint);
93 
105  SUBSOLVER_RETCODE multistart(babBase::BabNode const &currentNode, double &objectiveValue, std::vector<double> &solutionPoint, std::vector<SUBSOLVER_RETCODE> &feasible, std::vector<double> &optimalObjectives, bool &initialPointFeasible);
106 
113  SUBSOLVER_RETCODE check_feasibility(const std::vector<double> &currentPoint, double &objectiveValue) const;
114 
115  protected:
125  virtual SUBSOLVER_RETCODE _solve_nlp(const std::vector<double> &lowerVarBounds, const std::vector<double> &upperVarBounds, double &objectiveValue, std::vector<double> &solutionPoint);
126 
136  SUBSOLVER_RETCODE _check_ineq(const std::vector<double> &modelOutput) const;
137 
143  SUBSOLVER_RETCODE _check_ineq_squash(const std::vector<double> &modelOutput) const;
144 
150  SUBSOLVER_RETCODE _check_eq(const std::vector<double> &modelOutput) const;
151 
157  SUBSOLVER_RETCODE _check_bounds(const std::vector<double> &currentPoint) const;
158 
164  SUBSOLVER_RETCODE _check_integrality(const std::vector<double> &currentPoint) const;
170  void _determine_structure();
171 
176 
181 
189  std::vector<double> _generate_multistart_point(bool &usedCenter, const std::vector<double> &lowerVarBounds, const std::vector<double> &upperVarBounds);
190 
197  std::shared_ptr<DagObj> _DAGobj;
199  std::vector<Constraint> *_constraintProperties;
206  unsigned _nvar;
207  unsigned _nineq;
208  unsigned _nineqSquash;
209  unsigned _neq;
210  std::vector<babBase::OptimizationVariable> _originalVariables;
211  std::vector<double> _originalUpperBounds;
212  std::vector<double> _originalLowerBounds;
217  private:
219  // Prevent use of default copy constructor and copy assignment operator by declaring them private:
222 };
223 
239 std::shared_ptr<UpperBoundingSolver> make_ubp_solver(mc::FFGraph &DAG, const std::vector<mc::FFVar> &DAGvars, const std::vector<mc::FFVar> &DAGfunctions,
240  const std::vector<babBase::OptimizationVariable> &variables, const unsigned nineqIn, const unsigned neqIn,
241  const unsigned nineqSquashIn, Settings *settingsIn, Logger *loggerIn, std::vector<Constraint> *constraintPropertiesIn,
243 
244 
245 } // end namespace ubp
246 
247 
248 } // end namespace maingo
std::shared_ptr< UpperBoundingSolver > make_ubp_solver(mc::FFGraph &DAG, const std::vector< mc::FFVar > &DAGvars, const std::vector< mc::FFVar > &DAGfunctions, const std::vector< babBase::OptimizationVariable > &variables, const unsigned nineqIn, const unsigned neqIn, const unsigned nineqSquashIn, Settings *settingsIn, Logger *loggerIn, std::vector< Constraint > *constraintPropertiesIn, UpperBoundingSolver::UBS_USE useIn)
Factory function for initializing different upper bounding solver wrappers.
Definition: ubpFactory.cpp:39
virtual SUBSOLVER_RETCODE solve(babBase::BabNode const &currentNode, double &objectiveValue, std::vector< double > &solutionPoint)
Function called by B&B solver for solving the upper bounding problem on the current node....
Definition: ubp.cpp:64
SUBSOLVER_RETCODE _check_eq(const std::vector< double > &modelOutput) const
Function checking if equality constraints are fulfilled.
Definition: ubp.cpp:743
unsigned _nineqSquash
Definition: ubp.h:208
Class representing a node in the Branch-and-Bound tree.
Definition: babNode.h:35
Struct for storing settings for MAiNGO.
Definition: settings.h:143
SUBSOLVER_RETCODE _check_bounds(const std::vector< double > &currentPoint) const
Function checking if bounds are fulfilled.
Definition: ubp.cpp:802
This class contains all logging and output information.
Definition: logger.h:100
std::vector< double > _originalUpperBounds
Definition: ubp.h:211
unsigned _neq
Definition: ubp.h:209
Base class for wrappers for handling the upper bounding problems.
Definition: ubp.h:49
SUBSOLVER_RETCODE
Enum for representing the return codes returned by the different sub-solvers (UpperBoundingSolver,...
Definition: returnCodes.h:40
Logger * _logger
Definition: ubp.h:196
namespace holding all essentials of MAiNGO
Definition: aleModel.h:31
Settings * _maingoSettings
Definition: ubp.h:195
UBS_USE
Enum for communicating what the intended purpose of the solver is. This determines which settings are...
Definition: ubp.h:56
unsigned _nvar
Definition: ubp.h:206
SUBSOLVER_RETCODE _check_ineq_squash(const std::vector< double > &modelOutput) const
Function checking if squash inequality constraints are fulfilled (no tolerance allowed)
Definition: ubp.cpp:782
std::vector< double > _originalLowerBounds
Definition: ubp.h:212
UBS_USE _intendedUse
Definition: ubp.h:198
Struct for storing structure information for the upper bounding solver.
Definition: ubpStructure.h:35
SUBSOLVER_RETCODE _check_integrality(const std::vector< double > &currentPoint) const
Function checking if discrete variables are indeed discrete.
Definition: ubp.cpp:829
virtual ~UpperBoundingSolver()
Virtual destructor, only needed to make sure the correct destructor of the derived classes is called.
Definition: ubp.h:82
UpperBoundingSolver & operator=(const UpperBoundingSolver &)
SUBSOLVER_RETCODE multistart(babBase::BabNode const &currentNode, double &objectiveValue, std::vector< double > &solutionPoint, std::vector< SUBSOLVER_RETCODE > &feasible, std::vector< double > &optimalObjectives, bool &initialPointFeasible)
Multistart heuristic for automatically solving the UBP from multiple starting points.
Definition: ubp.cpp:157
SUBSOLVER_RETCODE _check_ineq(const std::vector< double > &modelOutput) const
Function checking if inequality constraints are fulfilled.
Definition: ubp.cpp:763
std::vector< Constraint > * _constraintProperties
Definition: ubp.h:199
std::vector< double > _generate_multistart_point(bool &usedCenter, const std::vector< double > &lowerVarBounds, const std::vector< double > &upperVarBounds)
Function for generating a point used in multistart.
Definition: ubp.cpp:472
virtual SUBSOLVER_RETCODE _solve_nlp(const std::vector< double > &lowerVarBounds, const std::vector< double > &upperVarBounds, double &objectiveValue, std::vector< double > &solutionPoint)
Function for actually solving the NLP sub-problem. This needs to be re-defined in derived classes to ...
Definition: ubp.cpp:145
std::vector< babBase::OptimizationVariable > _originalVariables
Definition: ubp.h:210
std::shared_ptr< DagObj > _DAGobj
Definition: ubp.h:197
void _determine_sparsity_hessian()
Function for determining the non-zero entries in the Hessian of the Lagrangian function.
Definition: ubp.cpp:1024
UbpStructure _structure
Definition: ubp.h:213
void _determine_structure()
Function for determining the number of variables participating in each function and the type of a fun...
Definition: ubp.cpp:936
SUBSOLVER_RETCODE check_feasibility(const std::vector< double > &currentPoint, double &objectiveValue) const
Function for checking feasibility of a point.
Definition: ubp.cpp:881
unsigned _nineq
Definition: ubp.h:207
void _determine_sparsity_jacobian()
Function for setting the information about the sparsity structure in the Jacobian.
Definition: ubp.cpp:995