12 #ifndef COUENNE_PROBLEM_HPP
13 #define COUENNE_PROBLEM_HPP
15 #define FM_TRACE_OPTSOL
31 template <
class T>
class SmartPtr;
37 class RegisteredOptions;
39 class OsiTMINLPInterface;
62 void node(
int,
double,
double,
double,
int,
int);
74 #define COUENNE_EPS_SYMM 1e-8
129 inline bool operator() (
register const char *
a,
register const char *
b)
const
130 {
return strcmp (a, b) < 0;}
142 class CouenneCutGenerator;
146 class CouenneConstraint;
147 class CouenneObjective;
149 class CouenneBTPerfIndicator;
150 class CouenneRecordBestSol;
151 class CouenneSdpCuts;
396 void ChangeBounds (
const double * ,
const double *,
int )
const;
427 inline std::set <exprAux *, compExpr> *&
AuxSet ()
491 void print (std::ostream & = std::cout);
494 int readnl (
const struct ASL *);
498 expression *nl2e (
struct expr *,
const ASL *asl);
522 void writeAMPL (
const std::string &fname,
bool aux);
527 void writeGAMS (
const std::string &fname);
533 void writeLP (
const std::string &fname);
545 const CglTreeInfo
info,
553 const OsiSolverInterface &csi,
555 const CglTreeInfo &
info,
564 const CglTreeInfo &
info,
569 int redCostBT (
const OsiSolverInterface *psi,
608 bool checkNLP (
const double *solution,
double &obj,
bool recompute =
false)
const;
633 std::vector <std::pair <exprVar *, CouNumber> > &lcoeff);
639 std::vector <quadElem> &qcoeff);
669 const std::vector <CouenneObject *> &
Objects ()
const
673 int findSOS (CbcModel *CbcModelPtr,
674 OsiSolverInterface *solver,
675 OsiObject ** objects);
766 const CoinWarmStart *warmstart,
774 const CoinWarmStart *warmstart,
791 std::map <int, CouNumber> &indices);
834 const int from,
const int upto,
835 const std::vector<int> listInt,
836 const bool origVarOnly,
837 const bool stopAtFirstViol,
838 const double precision,
double &maxViol)
const;
842 const bool stopAtFirstViol,
843 const double precision,
double &maxViol)
const;
847 const bool stopAtFirstViol,
848 const double precision,
double &maxViol)
const;
852 const bool stopAtFirstViol,
853 const double precision,
double &maxViol)
const;
881 const bool careAboutObj,
882 const bool stopAtFirstViol,
884 const double precision)
const;
889 bool recompute_obj =
false,
890 const bool careAboutObj =
false,
891 const bool stopAtFirstViol =
true,
892 const bool checkAll =
false,
893 const double precision = -1)
const;
Cut Generator for linear convexifications.
void realign()
clear all spurious variables pointers not referring to the variables_ vector
const std::vector< CouenneObject * > & Objects() const
return object vector
CouNumber & Ub(int i) const
upper bound on
void setObjective(int indObj=0, expression *=NULL, const std::string &="min")
Add (non linear) objective function.
int impliedBounds(t_chg_bounds *) const
"Backward" bound tightening, aka implied bounds.
GlobalCutOff * pcutoff_
Pointer to a global cutoff object.
bool checkInt(const CouNumber *sol, const int from, const int upto, const std::vector< int > listInt, const bool origVarOnly, const bool stopAtFirstViol, const double precision, double &maxViol) const
check integrality of vars in sol with index between from and upto (original vars only if origVarOnly ...
const CouNumber feas_tolerance_default
void setLastPrioSort(int givenLastPS)
void addLEConstraint(expression *, expression *=NULL)
Add constraint, .
DepGraph * getDepGraph()
Return pointer to dependence graph.
int nVars() const
Total number of variables.
double maxCpuTime_
maximum cpu time
int fake_tighten(char direction, int index, const double *X, CouNumber *olb, CouNumber *oub, t_chg_bounds *chg_bds, t_chg_bounds *f_chg) const
single fake tightening.
CouenneProblem(ASL *=NULL, Bonmin::BabSetupBase *base=NULL, JnlstPtr jnlst=NULL)
Constructor.
int redCostBT(const OsiSolverInterface *psi, t_chg_bounds *chg_bds) const
procedure to strengthen variable bounds.
CouNumber & ub(register int index)
current upper bound
void addObjective(expression *, const std::string &="min")
Add (non linear) objective function.
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint * info
bool *& Commuted()
Get vector of commuted variables.
int max_fbbt_iter_
number of FBBT iterations
std::vector< CouenneObjective * > objectives_
Objectives.
multiSep
Type of multilinear separation.
status of lower/upper bound of a variable, to be checked/modified in bound tightening ...
std::vector< expression * > & commonExprs()
~CouenneProblem()
Destructor.
bool doABT_
do Aggressive bound tightening
int nIntVars_
Number of discrete variables.
int nOrigCons_
Number of original constraints (disregarding those that turned into auxiliary variable definition) ...
int tightenBounds(t_chg_bounds *) const
"Forward" bound tightening, that is, propagate bound of variable in an expression to the bounds of ...
double constObjVal_
constant value of the objective if no variable is declared in it
int call_iter(OsiSolverInterface *csi, t_chg_bounds *chg_bds, const CoinWarmStart *warmstart, Bonmin::BabInfo *babInfo, double *objcoe, enum nodeType type, int sense) const
exprAux * linStandardize(bool addAux, CouNumber c0, LinMap &lmap, QuadMap &qmap)
standardization of linear exprOp's
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
bool operator()(register const Node &a, register const Node &b)
void fillIntegerRank() const
fill freeIntegers_ array
CouNumber & lb(register int index)
current lower bound
std::vector< std::set< int > > dependence_
inverse dependence structure: for each variable x give set of auxiliary variables (or better...
std::string problemName_
problem name
DepGraph * graph_
Dependence (acyclic) graph: shows dependence of all auxiliary variables on one another and on origina...
void fint fint fint real * a
int * integerRank_
each element is true if variable is integer and, if auxiliary, depends on no integer ...
void print(std::ostream &=std::cout)
Display current representation of problem: objective, linear and nonlinear constraints, and auxiliary variables.
void setCutOff(CouNumber cutoff, const CouNumber *sol=NULL) const
Set cutoff.
int nUnusedOriginals()
number of unused originals
bool orbitalBranching() const
return true if orbital branching activated
CouenneSdpCuts * sdpCutGen_
Temporary pointer to SDP cut generator.
bool operator()(register const char *a, register const char *b) const
bool checkNLP0(const double *solution, double &obj, bool recompute_obj=false, const bool careAboutObj=false, const bool stopAtFirstViol=true, const bool checkAll=false, const double precision=-1) const
And finally a method to get both.
bool doFBBT() const
shall we do Feasibility Based Bound Tightening?
CouNumber bestObj_
Best known objective function.
bool checkAux(const CouNumber *sol, const bool stopAtFirstViol, const double precision, double &maxViol) const
returns true iff value of all auxiliaries are within bounds
bool checkAuxBounds_
check bounds on auxiliary variables when verifying MINLP feasibility of a solution.
int nOrigIntVars_
Number of original integer variables.
std::set< exprAux *, compExpr > * auxSet_
Expression map for comparison in standardization and to count occurrences of an auxiliary.
bool boundTightening(t_chg_bounds *, const CglTreeInfo info, Bonmin::BabInfo *=NULL) const
tighten bounds using propagation, implied bounds and reduced costs
These are cuts of the form.
Ipopt::SmartPtr< const Ipopt::Journalist > ConstJnlstPtr
int logAbtLev_
frequency of Aggressive bound tightening
void Print_Orbits() const
bool checkNLP2(const double *solution, const double obj, const bool careAboutObj, const bool stopAtFirstViol, const bool checkAll, const double precision) const
Return true if either solution or recomputed_solution obtained using getAuxs() from the original vari...
CouNumber & X(int i) const
CouNumber & Lb(int i) const
lower bound on
int * unusedOriginalsIndices()
return indices of neglected redundant variables
std::vector< expression * > commonexprs_
AMPL's common expressions (read from AMPL through structures cexps and cexps1)
bool doOBBT() const
shall we do Optimality Based Bound Tightening?
bool doOBBT_
do Optimality-based bound tightening
int findSOS(CbcModel *CbcModelPtr, OsiSolverInterface *solver, OsiObject **objects)
find SOS constraints in problem
int splitAux(CouNumber, expression *, expression *&, bool *, enum expression::auxSign &)
split a constraint w - f(x) = c into w's index (it is returned) and rest = f(x) + c ...
double checkObj(const CouNumber *sol, const double &precision) const
Recompute objective value for sol.
CouenneBTPerfIndicator * OBBTperfIndicator_
Performance indicator for OBBT – to be moved away from CouenneProblem.
int nUnusedOriginals_
number of unused originals
Domain * domain() const
return current point & bounds
exprAux * addAuxiliary(expression *)
Add auxiliary variable and associate it with expression given as argument (used in standardization) ...
int evalOrder(int i) const
get evaluation order index
CouNumber getCutOff() const
Get cutoff.
void initOptions(Ipopt::SmartPtr< Ipopt::OptionsList > options)
initializes parameters like doOBBT
std::vector< CouenneObject * > objects_
vector of pointer to CouenneObjects.
void writeGAMS(const std::string &fname)
Write nonlinear problem to a .gms file.
std::vector< CouenneConstraint * > * ConstraintClass(const char *str)
return particular constraint class.
void setBase(Bonmin::BabSetupBase *base)
save CouenneBase
int nIntVars() const
Number of integer variables.
CouNumber bestObj() const
Objective of best known solution.
CouNumber * getCutOffSol() const
Get cutoff solution.
void fint fint fint real fint real real real real real real real real real * e
void writeLP(const std::string &fname)
Write nonlinear problem to a .lp file.
bool doRCBT() const
shall we do reduced cost Bound Tightening?
A class to have all elements necessary to setup a branch-and-bound.
const std::vector< std::set< int > > & Dependence() const
return inverse dependence structure
Class to represent nonlinear constraints.
void restoreUnusedOriginals(CouNumber *=NULL) const
Some originals may be unused due to their zero multiplicity (that happens when they are duplicates)...
bool checkBounds(const CouNumber *sol, const bool stopAtFirstViol, const double precision, double &maxViol) const
Check bounds; returns true iff feasible for given precision.
bool doABT() const
shall we do Aggressive Bound Tightening?
int nOrigCons() const
Get number of original constraints.
CouenneProblem * clone() const
Clone method (for use within CouenneCutGenerator::clone)
void getAuxs(CouNumber *) const
Get auxiliary variables from original variables.
int ndefined_
Number of "defined variables" (aka "common expressions")
CouNumber opt_window_
window around known optimum (for testing purposes)
CouenneRecordBestSol * getRecordBestSol() const
returns recorded best solution
auxSign
"sign" of the constraint defining an auxiliary.
void addEQConstraint(expression *, expression *=NULL)
Add equality constraint .
void setupSymmetry()
empty if no NTY, symmetry data structure setup otherwise
ConstJnlstPtr Jnlst() const
Provide Journalist.
const std::string & problemName() const
return problem name
Bonmin::BabSetupBase * bonBase_
options
std::vector< int > numberInRank_
numberInRank_ [i] is the number of integer variables in rank i
std::vector< CouenneConstraint * > constraints_
Constraints.
int obbtInner(OsiSolverInterface *, OsiCuts &, t_chg_bounds *, Bonmin::BabInfo *) const
Optimality Based Bound Tightening – inner loop.
int testIntFix(int index, CouNumber xFrac, enum fixType *fixed, CouNumber *xInt, CouNumber *dualL, CouNumber *dualR, CouNumber *olb, CouNumber *oub, bool patient) const
Test fixing of an integer variable (used in getIntegerCandidate())
bool btCore(t_chg_bounds *chg_bds) const
core of the bound tightening procedure
CouenneConstraint * Con(int i) const
i-th constraint
int nDefVars() const
Number of def'd variables.
int obbt(const CouenneCutGenerator *cg, const OsiSolverInterface &csi, OsiCuts &cs, const CglTreeInfo &info, Bonmin::BabInfo *babInfo, t_chg_bounds *chg_bds)
Optimality Based Bound Tightening.
Bonmin::BabSetupBase * bonBase() const
options
expression * addVariable(bool isint=false, Domain *d=NULL)
Add original variable.
int * evalVector()
get evaluation order vector (numbering_)
int obbt_iter(OsiSolverInterface *csi, t_chg_bounds *chg_bds, const CoinWarmStart *warmstart, Bonmin::BabInfo *babInfo, double *objcoe, int sense, int index) const
Iteration on one variable.
double constObjVal() const
returns constant objective value if it contains no variables
bool created_pcutoff_
flag indicating if this class is creator of global cutoff object
Class for MINLP problems with symbolic information.
bool compare(register Node &a, register Node &b) const
int curnvars_
Number of elements in the x_, lb_, ub_ arrays.
bool fbbtReachedIterLimit_
true if FBBT exited for iteration limits as opposed to inability to further tighten bounds ...
std::map< const char *, std::vector< CouenneConstraint * > *, less_than_str > ConstraintClass_
Return particular constraint class.
bool aggressiveBT(Bonmin::OsiTMINLPInterface *nlp, t_chg_bounds *, const CglTreeInfo &info, Bonmin::BabInfo *=NULL) const
aggressive bound tightening.
exprVar * Var(int i) const
Return pointer to i-th variable.
std::vector< exprVar * > variables_
Variables (original, auxiliary, and defined)
int getIntegerCandidate(const double *xFrac, double *xInt, double *lb, double *ub) const
generate integer NLP point Y starting from fractional solution using bound tightening ...
std::vector< exprVar * > & Variables()
Return vector of variables (symbolic representation)
CouenneRecordBestSol * recBSol
int nOrigVars() const
Number of orig. variables.
std::set< exprAux *, compExpr > *& AuxSet()
Return pointer to set for comparisons.
CouNumber *& bestSol() const
Best known solution (read from file)
bool * commuted_
Variables that have commuted to auxiliary.
CouenneSdpCuts * getSdpCutGen()
Returns pointer to sdp cut generator.
enum TrilinDecompType trilinDecompType_
return type of decomposition of quadrilinear terms
Domain domain_
current point and bounds;
int * numbering_
numbering of variables.
std::vector< Node > node_info
int nOrigIntVars() const
Number of original integers.
CouNumber * Ub() const
Return vector of upper bounds.
void addGEConstraint(expression *, expression *=NULL)
Add constraint, .
bool standardize()
Break problem's nonlinear constraints in simple expressions to be convexified later.
void ChangeBounds(const double *, const double *, int) const
void installCutOff() const
Make cutoff known to the problem.
CouNumber * optimum_
Best solution known to be loaded from file – for testing purposes.
bool orbitalBranching_
use orbital branching?
enum TrilinDecompType getTrilinDecompType()
return type of decomposition of quadrilinear terms
void fillQuadIndices()
Look for quadratic terms to be used with SDP cuts.
void color_vertex(register int k)
void initAuxs() const
Initialize auxiliary variables and their bounds from original variables.
void flattenMul(expression *mul, CouNumber &coe, std::map< int, CouNumber > &indices)
re-organizes multiplication and stores indices (and exponents) of its variables
double CouNumber
main number type in Couenne
nodeType
type of a node in an expression tree
void setMaxCpuTime(double time)
set maximum CPU time
void reformulate(CouenneCutGenerator *=NULL)
preprocess problem in order to extract linear relaxations etc.
fixType
structure to record fixed, non-fixed, and continuous variables
int nOrigVars_
Number of original variables.
CouNumber feas_tolerance_
feasibility tolerance (to be used in checkNLP)
bool useQuadratic_
Use quadratic expressions?
void resetCutOff(CouNumber value=COUENNE_INFINITY) const
Reset cutoff.
ASL * asl_
AMPL structure pointer (temporary — looking forward to embedding into OS...)
void addRNGConstraint(expression *, expression *=NULL, expression *=NULL)
Add range constraint, .
void Compute_Symmetry() const
void node(int, double, double, double, int, int)
CouNumber * X() const
Return vector of variables.
void setNDefVars(int ndefined__)
bool readOptimum(std::string *fname=NULL)
Read best known solution from file given in argument.
int logObbtLev_
frequency of Optimality-based bound tightening
CouNumber & x(register int index)
current variable
enum multiSep multilinSep_
Type of Multilinear separation.
void createUnusedOriginals()
Some originals may be unused due to their zero multiplicity (that happens when they are duplicates)...
int nCons() const
Get number of constraints.
bool checkCons(const CouNumber *sol, const bool stopAtFirstViol, const double precision, double &maxViol) const
returns true iff value of all auxiliaries are within bounds
enum multiSep MultilinSep() const
return type of separator for multilinear terms
double getFeasTol()
returns feasibility tolerance
int * unusedOriginalsIndices_
some originals may be unused due to their zero multiplicity (that happens when they are duplicates)...
JnlstPtr jnlst_
SmartPointer to the Journalist.
void analyzeSparsity(CouNumber, LinMap &, QuadMap &)
analyze sparsity of potential exprQuad/exprGroup and change linear/quadratic maps accordingly...
bool checkNLP(const double *solution, double &obj, bool recompute=false) const
Check if solution is MINLP feasible.
void indcoe2vector(int *indexL, CouNumber *coeff, std::vector< std::pair< exprVar *, CouNumber > > &lcoeff)
translates pair (indices, coefficients) into vector with pointers to variables
CouenneObjective * Obj(int i) const
i-th objective
void setCheckAuxBounds(bool value)
set the value for checkAuxBounds.
bool doRCBT_
do reduced cost bound tightening
Ipopt::SmartPtr< Ipopt::Journalist > JnlstPtr
bool fbbtReachedIterLimit() const
true if latest call to FBBT terminated due to iteration limit reached
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Add list of options to be read from file.
void decomposeTerm(expression *term, CouNumber initCoe, CouNumber &c0, LinMap &lmap, QuadMap &qmap)
given (expression *) element of sum, returns (coe,ind0,ind1) depending on element: ...
bool checkAuxBounds() const
return true if bounds of auxiliary variables have to be satisfied whenever a solution is tested for M...
int getLastPrioSort() const
void auxiliarize(exprVar *, exprVar *=NULL)
Replace all occurrences of original variable with new aux given as argument.
int nObjs() const
Get number of objectives.
void bounds(register double a, register double b)
bool operator()(register const Node &a, register const Node &b)
int logObbtLev() const
How often shall we do OBBT?
void fillDependence(Bonmin::BabSetupBase *base, CouenneCutGenerator *=NULL)
fill dependence_ structure
CouenneBTPerfIndicator * FBBTperfIndicator_
Performance indicator for FBBT – to be moved away from CouenneProblem when we do it with FBBT...
double getMaxCpuTime() const
return maximum CPU time
void fillObjCoeff(double *&)
Fill vector with coefficients of objective function.
bool doFBBT_
do Feasibility-based bound tightening
std::vector< int > * Find_Orbit(int) const
Bonmin class for passing info between components of branch-and-cuts.
void setProblemName(std::string &problemName__)
Define a dynamic point+bounds, with a way to save and restore previous points+bounds through a LIFO s...
void writeAMPL(const std::string &fname, bool aux)
Write nonlinear problem to a .mod file (with lots of defined variables)
class for multiplications,
CouNumber * Lb() const
Return vector of lower bounds.
int logAbtLev() const
How often shall we do ABT?