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  **********************************************************************************/
11 
12 #pragma once
13 
14 #include "lbp.h"
15 
16 #include <ilcplex/ilocplex.h>
17 
18 
19 namespace maingo {
20 
21 
22 namespace lbp {
23 
24 
33 
34  public:
51  LbpCplex(mc::FFGraph &DAG, const std::vector<mc::FFVar> &DAGvars, const std::vector<mc::FFVar> &DAGfunctions,
52  const std::vector<babBase::OptimizationVariable> &variables, const unsigned nineqIn, const unsigned neqIn,
53  const unsigned nineqRelaxationOnlyIn, const unsigned neqRelaxationOnlyIn, const unsigned nineqSquashIn,
54  std::shared_ptr<Settings> settingsIn, std::shared_ptr<Logger> loggerIn, std::shared_ptr<std::vector<Constraint>> constraintPropertiesIn);
55 
59  ~LbpCplex();
60 
64  void activate_more_scaling();
65 
66  protected:
73  void _set_variable_bounds(const std::vector<double> &lowerVarBounds, const std::vector<double> &upperVarBounds);
74 
85  void _update_LP_obj(const MC &resultRelaxation, const std::vector<double> &linearizationPoint, const std::vector<double> &lowerVarBounds,
86  const std::vector<double> &upperVarBounds, unsigned const &iLin, unsigned const &iObj);
87 
98  void _update_LP_ineq(const MC &resultRelaxation, const std::vector<double> &linearizationPoint, const std::vector<double> &lowerVarBounds,
99  const std::vector<double> &upperVarBounds, unsigned const &iLin, unsigned const &iIneq);
100 
112  void _update_LP_eq(const MC &resultRelaxationCv, const MC &resultRelaxationCc, const std::vector<double> &linearizationPoint, const std::vector<double> &lowerVarBounds,
113  const std::vector<double> &upperVarBounds, unsigned const &iLin, unsigned const &iEq);
114 
125  void _update_LP_ineqRelaxationOnly(const MC &resultRelaxation, const std::vector<double> &linearizationPoint, const std::vector<double> &lowerVarBounds,
126  const std::vector<double> &upperVarBounds, unsigned const &iLin, unsigned const &iIneqRelaxationOnly);
127 
139  void _update_LP_eqRelaxationOnly(const MC &resultRelaxationCv, const MC &resultRelaxationCc, const std::vector<double> &linearizationPoint, const std::vector<double> &lowerVarBounds,
140  const std::vector<double> &upperVarBounds, unsigned const &iLin, unsigned const &iEqRelaxationOnly);
141 
153  void _update_LP_ineq_squash(const MC &resultRelaxation, const std::vector<double> &linearizationPoint, const std::vector<double> &lowerVarBounds,
154  const std::vector<double> &upperVarBounds, unsigned const &iLin, unsigned const &iIneqSquash);
164  void _update_LP_obj(const vMC &resultRelaxationVMC, const std::vector<std::vector<double>> &linearizationPoint, const std::vector<double> &lowerVarBounds,
165  const std::vector<double> &upperVarBounds, unsigned const &iObj);
166 
176  void _update_LP_ineq(const vMC &resultRelaxationVMC, const std::vector<std::vector<double>> &linearizationPoint, const std::vector<double> &lowerVarBounds,
177  const std::vector<double> &upperVarBounds, unsigned const &iIneq);
178 
189  void _update_LP_eq(const vMC &resultRelaxationCvVMC, const vMC &resultRelaxationCcVMC, const std::vector<std::vector<double>> &linearizationPoint, const std::vector<double> &lowerVarBounds,
190  const std::vector<double> &upperVarBounds, unsigned const &iEq);
191 
201  void _update_LP_ineqRelaxationOnly(const vMC &resultRelaxationVMC, const std::vector<std::vector<double>> &linearizationPoint, const std::vector<double> &lowerVarBounds,
202  const std::vector<double> &upperVarBounds, unsigned const &iIneqRelaxationOnly);
203 
214  void _update_LP_eqRelaxationOnly(const vMC &resultRelaxationCvVMC, const vMC &resultRelaxationCcVMC, const std::vector<std::vector<double>> &linearizationPoint, const std::vector<double> &lowerVarBounds,
215  const std::vector<double> &upperVarBounds, unsigned const &iEqRelaxationOnly);
216 
227  void _update_LP_ineq_squash(const vMC &resultRelaxationVMC, const std::vector<std::vector<double>> &linearizationPoint, const std::vector<double> &lowerVarBounds,
228  const std::vector<double> &upperVarBounds, unsigned const &iIneqSquash);
229 
235  void _solve_LP(const babBase::BabNode &currentNode);
236 
243 
250  void _get_solution_point(std::vector<double> &solution, double &etaVal);
251 
258 
264  void _get_multipliers(std::vector<double> &multipliers);
265 
270 
278  void _modify_LP_for_feasopt_OBBT(const double &currentUBD, std::list<unsigned> &toTreatMax, std::list<unsigned> &toTreatMin);
279 
286  void _set_optimization_sense_of_variable(const unsigned &iVar, const int &optimizationSense);
287 
294  void _fix_variable(const unsigned &iVar, const bool fixToLowerBound);
295 
300 
307 
312 
313 #ifdef LP__OPTIMALITY_CHECK
314 
321 
328  SUBSOLVER_RETCODE _check_feasibility(const std::vector<double> &solution);
329 
340  SUBSOLVER_RETCODE _check_optimality(const babBase::BabNode &currentNode, const double newLBD, const std::vector<double> &solution, const double etaVal, const std::vector<double> &multipliers);
341 
342 #endif
343 
344 #ifdef LP__WRITE_CHECK_FILES
345 
350  virtual void _write_LP_to_file(std::string &fileName);
351 #endif
352 
353  private:
357  void _terminate_cplex();
358 
363  IloEnv cplxEnv;
364  IloModel cplxModel;
365  IloObjective cplxObjective;
366  IloNumVarArray cplxVars;
367  IloNumVar eta;
368  std::vector<IloRangeArray> linObj;
369  std::vector<IloRangeArray> linIneq;
370  std::vector<IloRangeArray> linEq1;
371  std::vector<IloRangeArray> linEq2;
372  std::vector<IloRangeArray> linIneqRelaxationOnly;
373  std::vector<IloRangeArray> linEqRelaxationOnly1;
374  std::vector<IloRangeArray> linEqRelaxationOnly2;
375  std::vector<IloRangeArray> linIneqSquash;
376  IloCplex cplex;
377  double etaCoeff;
378 #ifdef LP__OPTIMALITY_CHECK
379  IloRangeArray farkasCons;
380  IloNumArray farkasVals;
381  std::vector<IloNumArray> dualValsObj;
382  std::vector<IloNumArray> dualValsIneq;
383  std::vector<IloNumArray> dualValsEq1;
384  std::vector<IloNumArray> dualValsEq2;
385  std::vector<IloNumArray> dualValsIneqRelaxationOnly;
386  std::vector<IloNumArray> dualValsEqRelaxationOnly1;
387  std::vector<IloNumArray> dualValsEqRelaxationOnly2;
388  std::vector<IloNumArray> dualValsIneqSquash;
389 #endif
390 
391 };
392 
393 
394 } // end of namespace lbp
395 
396 
397 } // end of namespace maingo
Wrapper for handling the lower bounding problems as well as optimization-based bounds tightening (OBB...
Definition: lbp.h:65
std::vector< IloRangeArray > linIneqRelaxationOnly
Definition: lbpCplex.h:372
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:311
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:369
IloObjective cplxObjective
Definition: lbpCplex.h:365
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:385
mc::vMcCormick< I > vMC
A type definition for a vector McCormick variable.
Definition: intervalLibrary.h:41
std::vector< IloNumArray > dualValsIneqSquash
Definition: lbpCplex.h:388
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:376
std::vector< IloNumArray > dualValsEqRelaxationOnly1
Definition: lbpCplex.h:386
std::vector< IloNumArray > dualValsEq2
Definition: lbpCplex.h:384
IloEnv cplxEnv
Definition: lbpCplex.h:363
void _restore_LP_coefficients_after_OBBT()
Function for restoring proper coefficients and options in the LP after OBBT.
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, std::shared_ptr< Settings > settingsIn, std::shared_ptr< Logger > loggerIn, std::shared_ptr< std::vector< Constraint >> constraintPropertiesIn)
Constructor, stores information on the problem and initializes the CPLEX problem and solver instances...
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...
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:382
void _deactivate_objective_function_for_OBBT()
Function deactivating all objective rows in the LP for feasibility OBBT.
IloModel cplxModel
Definition: lbpCplex.h:364
~LbpCplex()
Destructor.
SUBSOLVER_RETCODE
Enum for representing the return codes returned by the different sub-solvers (UpperBoundingSolver, LowerBoundingSolver).
Definition: returnCodes.h:36
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&#39; Lemma...
namespace holding all essentials of MAiNGO
Definition: aleModel.h:25
mc::McCormick< I > MC
A type definition for a McCormick variable.
Definition: intervalLibrary.h:34
IloNumArray farkasVals
Definition: lbpCplex.h:380
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:379
std::vector< IloRangeArray > linEqRelaxationOnly2
Definition: lbpCplex.h:374
Wrapper for handling the lower bounding problems by interfacing CPLEX.
Definition: lbpCplex.h:32
std::vector< IloNumArray > dualValsEqRelaxationOnly2
Definition: lbpCplex.h:387
LP_RETCODE _get_LP_status()
Function returning the current status of the lastly solved linear program.
void _get_multipliers(std::vector< double > &multipliers)
Function for setting the multipliers of the lastly solved LP.
std::vector< IloNumArray > dualValsObj
Definition: lbpCplex.h:381
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:373
std::vector< IloRangeArray > linObj
Definition: lbpCplex.h:368
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:377
std::vector< IloNumArray > dualValsEq1
Definition: lbpCplex.h:383
IloNumVar eta
Definition: lbpCplex.h:367
LP_RETCODE
Enum for representing the return codes returned when a linear program is solved.
Definition: returnCodes.h:69
bool _check_if_LP_really_infeasible()
Function for checking if the current linear program is really infeasible by, e.g., resolving it with different algorithms.
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:371
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:370
IloNumVarArray cplxVars
Definition: lbpCplex.h:366
std::vector< IloRangeArray > linIneqSquash
Definition: lbpCplex.h:375