MAiNGO
lbpCplex.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 lbpCplex.h
11  *
12  * @brief File containing declaration of LbpCplex class used for solving the
13  * lower bounding problems.
14  *
15  **********************************************************************************/
16 
17 #pragma once
18 
19 #include "lbp.h"
20 
21 #include <ilcplex/ilocplex.h>
22 
23 
24 namespace maingo {
25 
26 
27 namespace lbp {
28 
29 
38 
39  public:
56  LbpCplex(mc::FFGraph &DAG, const std::vector<mc::FFVar> &DAGvars, const std::vector<mc::FFVar> &DAGfunctions,
57  const std::vector<babBase::OptimizationVariable> &variables, const unsigned nineqIn, const unsigned neqIn,
58  const unsigned nineqRelaxationOnlyIn, const unsigned neqRelaxationOnlyIn, const unsigned nineqSquashIn,
59  Settings *settingsIn, Logger *loggerIn, std::vector<Constraint> *constraintPropertiesIn);
60 
64  ~LbpCplex();
65 
69  void activate_more_scaling();
70 
71  protected:
78  void _set_variable_bounds(const std::vector<double> &lowerVarBounds, const std::vector<double> &upperVarBounds);
79 
90  void _update_LP_obj(const MC &resultRelaxation, const std::vector<double> &linearizationPoint, const std::vector<double> &lowerVarBounds,
91  const std::vector<double> &upperVarBounds, unsigned const &iLin, unsigned const &iObj);
92 
103  void _update_LP_ineq(const MC &resultRelaxation, const std::vector<double> &linearizationPoint, const std::vector<double> &lowerVarBounds,
104  const std::vector<double> &upperVarBounds, unsigned const &iLin, unsigned const &iIneq);
105 
117  void _update_LP_eq(const MC &resultRelaxationCv, const MC &resultRelaxationCc, const std::vector<double> &linearizationPoint, const std::vector<double> &lowerVarBounds,
118  const std::vector<double> &upperVarBounds, unsigned const &iLin, unsigned const &iEq);
119 
130  void _update_LP_ineqRelaxationOnly(const MC &resultRelaxation, const std::vector<double> &linearizationPoint, const std::vector<double> &lowerVarBounds,
131  const std::vector<double> &upperVarBounds, unsigned const &iLin, unsigned const &iIneqRelaxationOnly);
132 
144  void _update_LP_eqRelaxationOnly(const MC &resultRelaxationCv, const MC &resultRelaxationCc, const std::vector<double> &linearizationPoint, const std::vector<double> &lowerVarBounds,
145  const std::vector<double> &upperVarBounds, unsigned const &iLin, unsigned const &iEqRelaxationOnly);
146 
158  void _update_LP_ineq_squash(const MC &resultRelaxation, const std::vector<double> &linearizationPoint, const std::vector<double> &lowerVarBounds,
159  const std::vector<double> &upperVarBounds, unsigned const &iLin, unsigned const &iIneqSquash);
169  void _update_LP_obj(const vMC &resultRelaxationVMC, const std::vector<std::vector<double>> &linearizationPoint, const std::vector<double> &lowerVarBounds,
170  const std::vector<double> &upperVarBounds, unsigned const &iObj);
171 
181  void _update_LP_ineq(const vMC &resultRelaxationVMC, const std::vector<std::vector<double>> &linearizationPoint, const std::vector<double> &lowerVarBounds,
182  const std::vector<double> &upperVarBounds, unsigned const &iIneq);
183 
194  void _update_LP_eq(const vMC &resultRelaxationCvVMC, const vMC &resultRelaxationCcVMC, const std::vector<std::vector<double>> &linearizationPoint, const std::vector<double> &lowerVarBounds,
195  const std::vector<double> &upperVarBounds, unsigned const &iEq);
196 
206  void _update_LP_ineqRelaxationOnly(const vMC &resultRelaxationVMC, const std::vector<std::vector<double>> &linearizationPoint, const std::vector<double> &lowerVarBounds,
207  const std::vector<double> &upperVarBounds, unsigned const &iIneqRelaxationOnly);
208 
219  void _update_LP_eqRelaxationOnly(const vMC &resultRelaxationCvVMC, const vMC &resultRelaxationCcVMC, const std::vector<std::vector<double>> &linearizationPoint, const std::vector<double> &lowerVarBounds,
220  const std::vector<double> &upperVarBounds, unsigned const &iEqRelaxationOnly);
221 
232  void _update_LP_ineq_squash(const vMC &resultRelaxationVMC, const std::vector<std::vector<double>> &linearizationPoint, const std::vector<double> &lowerVarBounds,
233  const std::vector<double> &upperVarBounds, unsigned const &iIneqSquash);
234 
240  void _solve_LP(const babBase::BabNode &currentNode);
241 
248 
255  void _get_solution_point(std::vector<double> &solution, double &etaVal);
256 
263 
269  void _get_multipliers(std::vector<double> &multipliers);
270 
275 
283  void _modify_LP_for_feasopt_OBBT(const double &currentUBD, std::list<unsigned> &toTreatMax, std::list<unsigned> &toTreatMin);
284 
291  void _set_optimization_sense_of_variable(const unsigned &iVar, const int &optimizationSense);
292 
299  void _fix_variable(const unsigned &iVar, const bool fixToLowerBound);
300 
305 
312 
317 
318 #ifdef LP__OPTIMALITY_CHECK
319 
326 
333  SUBSOLVER_RETCODE _check_feasibility(const std::vector<double> &solution);
334 
345  SUBSOLVER_RETCODE _check_optimality(const babBase::BabNode &currentNode, const double newLBD, const std::vector<double> &solution, const double etaVal, const std::vector<double> &multipliers);
346 
347 #endif
348 
349 #ifdef LP__WRITE_CHECK_FILES
350 
355  virtual void _write_LP_to_file(std::string &fileName);
356 #endif
357 
358  private:
362  void _terminate_cplex();
363 
368  IloEnv cplxEnv;
369  IloModel cplxModel;
370  IloObjective cplxObjective;
371  IloNumVarArray cplxVars;
372  IloNumVar eta;
373  std::vector<IloRangeArray> linObj;
374  std::vector<IloRangeArray> linIneq;
375  std::vector<IloRangeArray> linEq1;
376  std::vector<IloRangeArray> linEq2;
377  std::vector<IloRangeArray> linIneqRelaxationOnly;
378  std::vector<IloRangeArray> linEqRelaxationOnly1;
379  std::vector<IloRangeArray> linEqRelaxationOnly2;
380  std::vector<IloRangeArray> linIneqSquash;
381  IloCplex cplex;
382  double etaCoeff;
383 #ifdef LP__OPTIMALITY_CHECK
384  IloRangeArray farkasCons;
385  IloNumArray farkasVals;
386  std::vector<IloNumArray> dualValsObj;
387  std::vector<IloNumArray> dualValsIneq;
388  std::vector<IloNumArray> dualValsEq1;
389  std::vector<IloNumArray> dualValsEq2;
390  std::vector<IloNumArray> dualValsIneqRelaxationOnly;
391  std::vector<IloNumArray> dualValsEqRelaxationOnly1;
392  std::vector<IloNumArray> dualValsEqRelaxationOnly2;
393  std::vector<IloNumArray> dualValsIneqSquash;
394 #endif
395 
396 };
397 
398 
399 } // end of namespace lbp
400 
401 
402 } // end of namespace maingo
Wrapper for handling the lower bounding problems as well as optimization-based bounds tightening (OBB...
Definition: lbp.h:60
std::vector< IloRangeArray > linIneqRelaxationOnly
Definition: lbpCplex.h:377
double _get_objective_value_solver()
Function returning the objective value of the lastly solved LP.
void _turn_off_specific_options()
Function for checking if a specific option has to be turned off for a given lower bounding solver....
Definition: lbpCplex.h:316
void activate_more_scaling()
Function called by the B&B solver to heuristically activate more scaling in the LBS.
void _update_LP_ineqRelaxationOnly(const MC &resultRelaxation, const std::vector< double > &linearizationPoint, const std::vector< double > &lowerVarBounds, const std::vector< double > &upperVarBounds, unsigned const &iLin, unsigned const &iIneqRelaxationOnly)
Auxiliary function for updating LP relaxation only inequalities, i.e., processing the linearization o...
void _solve_LP(const babBase::BabNode &currentNode)
Function for solving the currently constructed linear program.
void _set_variable_bounds(const std::vector< double > &lowerVarBounds, const std::vector< double > &upperVarBounds)
Function for setting the bounds of variables.
std::vector< IloRangeArray > linIneq
Definition: lbpCplex.h:374
IloObjective cplxObjective
Definition: lbpCplex.h:370
Class representing a node in the Branch-and-Bound tree.
Definition: babNode.h:35
SUBSOLVER_RETCODE _check_optimality(const babBase::BabNode &currentNode, const double newLBD, const std::vector< double > &solution, const double etaVal, const std::vector< double > &multipliers)
Function for checking if the solution point returned by CPLEX solver is really optimal using strong d...
std::vector< IloNumArray > dualValsIneqRelaxationOnly
Definition: lbpCplex.h:390
Struct for storing settings for MAiNGO.
Definition: settings.h:143
mc::vMcCormick< I > vMC
A type definition for a vector McCormick variable.
Definition: intervalLibrary.h:64
std::vector< IloNumArray > dualValsIneqSquash
Definition: lbpCplex.h:393
void _get_solution_point(std::vector< double > &solution, double &etaVal)
Function for setting the solution to the solution point of the lastly solved LP.
IloCplex cplex
Definition: lbpCplex.h:381
std::vector< IloNumArray > dualValsEqRelaxationOnly1
Definition: lbpCplex.h:391
std::vector< IloNumArray > dualValsEq2
Definition: lbpCplex.h:389
IloEnv cplxEnv
Definition: lbpCplex.h:368
void _restore_LP_coefficients_after_OBBT()
Function for restoring proper coefficients and options in the LP after OBBT.
void _update_LP_obj(const MC &resultRelaxation, const std::vector< double > &linearizationPoint, const std::vector< double > &lowerVarBounds, const std::vector< double > &upperVarBounds, unsigned const &iLin, unsigned const &iObj)
Auxiliary function for updating LP objective, i.e., processing the linearization of the objective fun...
This class contains all logging and output information.
Definition: logger.h:100
SUBSOLVER_RETCODE _check_feasibility(const std::vector< double > &solution)
Function for checking if the solution point returned by CPLEX solver is really feasible.
std::vector< IloNumArray > dualValsIneq
Definition: lbpCplex.h:387
void _deactivate_objective_function_for_OBBT()
Function deactivating all objective rows in the LP for feasibility OBBT.
IloModel cplxModel
Definition: lbpCplex.h:369
~LbpCplex()
Destructor.
SUBSOLVER_RETCODE
Enum for representing the return codes returned by the different sub-solvers (UpperBoundingSolver,...
Definition: returnCodes.h:40
void _fix_variable(const unsigned &iVar, const bool fixToLowerBound)
Virtual function for fixing a variable to one of its bounds.
SUBSOLVER_RETCODE _check_infeasibility(const babBase::BabNode &currentNode)
Function for checking if the solution point returned CPLEX is really infeasible using Farkas' Lemma.
namespace holding all essentials of MAiNGO
Definition: aleModel.h:31
mc::McCormick< I > MC
A type definition for a McCormick variable.
Definition: intervalLibrary.h:57
IloNumArray farkasVals
Definition: lbpCplex.h:385
void _update_LP_eq(const MC &resultRelaxationCv, const MC &resultRelaxationCc, const std::vector< double > &linearizationPoint, const std::vector< double > &lowerVarBounds, const std::vector< double > &upperVarBounds, unsigned const &iLin, unsigned const &iEq)
Auxiliary function for updating LP equalities, i.e., processing the linearization of the equality ( C...
IloRangeArray farkasCons
Definition: lbpCplex.h:384
std::vector< IloRangeArray > linEqRelaxationOnly2
Definition: lbpCplex.h:379
Wrapper for handling the lower bounding problems by interfacing CPLEX.
Definition: lbpCplex.h:37
std::vector< IloNumArray > dualValsEqRelaxationOnly2
Definition: lbpCplex.h:392
LP_RETCODE _get_LP_status()
Function returning the current status of the lastly solved linear program.
LbpCplex(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 nineqRelaxationOnlyIn, const unsigned neqRelaxationOnlyIn, const unsigned nineqSquashIn, Settings *settingsIn, Logger *loggerIn, std::vector< Constraint > *constraintPropertiesIn)
Constructor, stores information on the problem and initializes the CPLEX problem and solver instances...
void _get_multipliers(std::vector< double > &multipliers)
Function for setting the multipliers of the lastly solved LP.
std::vector< IloNumArray > dualValsObj
Definition: lbpCplex.h:386
void _update_LP_eqRelaxationOnly(const MC &resultRelaxationCv, const MC &resultRelaxationCc, const std::vector< double > &linearizationPoint, const std::vector< double > &lowerVarBounds, const std::vector< double > &upperVarBounds, unsigned const &iLin, unsigned const &iEqRelaxationOnly)
Auxiliary function for updating LP relaxation only equalities, i.e., processing the linearization of ...
void _update_LP_ineq(const MC &resultRelaxation, const std::vector< double > &linearizationPoint, const std::vector< double > &lowerVarBounds, const std::vector< double > &upperVarBounds, unsigned const &iLin, unsigned const &iIneq)
Auxiliary function for updating LP inequalities, i.e., processing the linearization of the inequality...
std::vector< IloRangeArray > linEqRelaxationOnly1
Definition: lbpCplex.h:378
std::vector< IloRangeArray > linObj
Definition: lbpCplex.h:373
void _modify_LP_for_feasopt_OBBT(const double &currentUBD, std::list< unsigned > &toTreatMax, std::list< unsigned > &toTreatMin)
Function modifying the LP for feasibility-optimality OBBT.
void _terminate_cplex()
Function for taking care of memory management by terminating Cplex (either called from destructor or ...
double etaCoeff
Definition: lbpCplex.h:382
std::vector< IloNumArray > dualValsEq1
Definition: lbpCplex.h:388
IloNumVar eta
Definition: lbpCplex.h:372
LP_RETCODE
Enum for representing the return codes returned when a linear program is solved.
Definition: returnCodes.h:73
bool _check_if_LP_really_infeasible()
Function for checking if the current linear program is really infeasible by, e.g.,...
void _update_LP_ineq_squash(const MC &resultRelaxation, const std::vector< double > &linearizationPoint, const std::vector< double > &lowerVarBounds, const std::vector< double > &upperVarBounds, unsigned const &iLin, unsigned const &iIneqSquash)
Auxiliary function for updating LP squash inequalities, i.e., processing the linearization of the squ...
std::vector< IloRangeArray > linEq2
Definition: lbpCplex.h:376
void _set_optimization_sense_of_variable(const unsigned &iVar, const int &optimizationSense)
Function for setting the optimization sense of variable iVar in OBBT.
std::vector< IloRangeArray > linEq1
Definition: lbpCplex.h:375
IloNumVarArray cplxVars
Definition: lbpCplex.h:371
std::vector< IloRangeArray > linIneqSquash
Definition: lbpCplex.h:380