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  **********************************************************************************/
11 
12 #pragma once
13 
14 #include "constraint.h"
15 #include "logger.h"
16 #include "mcForward.h"
17 #include "returnCodes.h"
18 #include "settings.h"
19 #include "ubpStructure.h"
20 
21 #include "babNode.h"
22 #include "babUtils.h"
23 
24 #include <memory>
25 #include <vector>
26 
27 
28 namespace maingo {
29 
30 
31 namespace ubp {
32 
33 
34 struct DagObj;
35 
45 
46  public:
51  enum UBS_USE {
52  USE_PRE = 0,
54  };
55 
71  UpperBoundingSolver(mc::FFGraph &DAG, const std::vector<mc::FFVar> &DAGvars, const std::vector<mc::FFVar> &DAGfunctions, const std::vector<babBase::OptimizationVariable> &variables,
72  const unsigned nineqIn, const unsigned neqIn, const unsigned nineqSquashIn, std::shared_ptr<Settings> settingsIn, std::shared_ptr<Logger> loggerIn, std::shared_ptr<std::vector<Constraint>> constraintPropertiesIn, UBS_USE useIn);
73 
77  virtual ~UpperBoundingSolver() {}
78 
87  virtual SUBSOLVER_RETCODE solve(babBase::BabNode const &currentNode, double &objectiveValue, std::vector<double> &solutionPoint);
88 
100  SUBSOLVER_RETCODE multistart(babBase::BabNode const &currentNode, double &objectiveValue, std::vector<double> &solutionPoint, std::vector<SUBSOLVER_RETCODE> &feasible, std::vector<double> &optimalObjectives, bool &initialPointFeasible);
101 
108  SUBSOLVER_RETCODE check_feasibility(const std::vector<double> &currentPoint, double &objectiveValue) const;
109 
110  protected:
120  virtual SUBSOLVER_RETCODE _solve_nlp(const std::vector<double> &lowerVarBounds, const std::vector<double> &upperVarBounds, double &objectiveValue, std::vector<double> &solutionPoint);
121 
131  SUBSOLVER_RETCODE _check_ineq(const std::vector<double> &modelOutput) const;
132 
138  SUBSOLVER_RETCODE _check_ineq_squash(const std::vector<double> &modelOutput) const;
139 
145  SUBSOLVER_RETCODE _check_eq(const std::vector<double> &modelOutput) const;
146 
152  SUBSOLVER_RETCODE _check_bounds(const std::vector<double> &currentPoint) const;
153 
159  SUBSOLVER_RETCODE _check_integrality(const std::vector<double> &currentPoint) const;
165  void _determine_structure();
166 
171 
176 
184  std::vector<double> _generate_multistart_point(bool &usedCenter, const std::vector<double> &lowerVarBounds, const std::vector<double> &upperVarBounds);
185 
190  std::shared_ptr<Settings> _maingoSettings;
191  std::shared_ptr<Logger> _logger;
192  std::shared_ptr<DagObj> _DAGobj;
194  std::shared_ptr<std::vector<Constraint>> _constraintProperties;
201  unsigned _nvar;
202  unsigned _nineq;
203  unsigned _nineqSquash;
204  unsigned _neq;
205  std::vector<babBase::OptimizationVariable> _originalVariables;
206  std::vector<double> _originalUpperBounds;
207  std::vector<double> _originalLowerBounds;
212  private:
214  // Prevent use of default copy constructor and copy assignment operator by declaring them private:
217 };
218 
234 std::shared_ptr<UpperBoundingSolver> make_ubp_solver(mc::FFGraph &DAG, const std::vector<mc::FFVar> &DAGvars, const std::vector<mc::FFVar> &DAGfunctions,
235  const std::vector<babBase::OptimizationVariable> &variables, const unsigned nineqIn, const unsigned neqIn,
236  const unsigned nineqSquashIn, std::shared_ptr<Settings> settingsIn, std::shared_ptr<Logger> loggerIn, std::shared_ptr<std::vector<Constraint>> constraintPropertiesIn,
238 
239 
240 } // end namespace ubp
241 
242 
243 } // 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, std::shared_ptr< Settings > settingsIn, std::shared_ptr< Logger > loggerIn, std::shared_ptr< std::vector< Constraint >> constraintPropertiesIn, UpperBoundingSolver::UBS_USE useIn)
Factory function for initializing different upper bounding solver wrappers.
Definition: ubpFactory.cpp:35
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:59
SUBSOLVER_RETCODE _check_eq(const std::vector< double > &modelOutput) const
Function checking if equality constraints are fulfilled.
Definition: ubp.cpp:753
unsigned _nineqSquash
Definition: ubp.h:203
Class representing a node in the Branch-and-Bound tree.
Definition: babNode.h:35
SUBSOLVER_RETCODE _check_bounds(const std::vector< double > &currentPoint) const
Function checking if bounds are fulfilled.
Definition: ubp.cpp:812
std::vector< double > _originalUpperBounds
Definition: ubp.h:206
unsigned _neq
Definition: ubp.h:204
std::shared_ptr< Settings > _maingoSettings
Definition: ubp.h:190
Base class for wrappers for handling the upper bounding problems.
Definition: ubp.h:44
SUBSOLVER_RETCODE
Enum for representing the return codes returned by the different sub-solvers (UpperBoundingSolver, LowerBoundingSolver).
Definition: returnCodes.h:36
namespace holding all essentials of MAiNGO
Definition: aleModel.h:25
UBS_USE
Enum for communicating what the intended purpose of the solver is. This determines which settings are...
Definition: ubp.h:51
unsigned _nvar
Definition: ubp.h:201
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:792
std::shared_ptr< std::vector< Constraint > > _constraintProperties
Definition: ubp.h:194
std::vector< double > _originalLowerBounds
Definition: ubp.h:207
UBS_USE _intendedUse
Definition: ubp.h:193
Struct for storing structure information for the upper bounding solver.
Definition: ubpStructure.h:30
SUBSOLVER_RETCODE _check_integrality(const std::vector< double > &currentPoint) const
Function checking if discrete variables are indeed discrete.
Definition: ubp.cpp:839
virtual ~UpperBoundingSolver()
Virtual destructor, only needed to make sure the correct destructor of the derived classes is called...
Definition: ubp.h:77
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:167
SUBSOLVER_RETCODE _check_ineq(const std::vector< double > &modelOutput) const
Function checking if inequality constraints are fulfilled.
Definition: ubp.cpp:773
std::shared_ptr< Logger > _logger
Definition: ubp.h:191
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:482
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:155
std::vector< babBase::OptimizationVariable > _originalVariables
Definition: ubp.h:205
std::shared_ptr< DagObj > _DAGobj
Definition: ubp.h:192
void _determine_sparsity_hessian()
Function for determining the non-zero entries in the Hessian of the Lagrangian function.
Definition: ubp.cpp:1042
UbpStructure _structure
Definition: ubp.h:208
void _determine_structure()
Function for determining the number of variables participating in each function and the type of a fun...
Definition: ubp.cpp:954
SUBSOLVER_RETCODE check_feasibility(const std::vector< double > &currentPoint, double &objectiveValue) const
Function for checking feasibility of a point.
Definition: ubp.cpp:891
unsigned _nineq
Definition: ubp.h:202
void _determine_sparsity_jacobian()
Function for setting the information about the sparsity structure in the Jacobian.
Definition: ubp.cpp:1013