14 using namespace Couenne;
33 #include "CoinTime.hpp"
42 #ifdef COIN_HAS_FILTERSQP
48 #include "OsiBranchingObject.hpp"
54 using namespace Ipopt;
55 using namespace Couenne;
62 roptions->SetRegisteringCategory(
"nlp interface option", RegisteredOptions::BonminCategory);
63 roptions->AddStringOption3(
"nlp_solver",
64 "Choice of the solver for local optima of continuous nlp's",
66 "Ipopt",
"Interior Point OPTimizer (https://projects.coin-or.org/Ipopt)",
67 "filterSQP",
"Sequential quadratic programming trust region "
68 "algorithm (http://www-unix.mcs.anl.gov/~leyffer/solvers.html)",
69 "all",
"run all available solvers at each node",
70 "Note that option will work only if the specified solver has been installed. Ipopt will usualy be installed with Bonmin by default. For FilterSQP please see http://www-unix.mcs.anl.gov/~leyffer/solvers.html on how to obtain it and https://projects.coin-or.org/Bonmin/wiki/HintTricks on how to configure Bonmin to use it.");
71 roptions->setOptionExtraInfo(
"nlp_solver",15);
72 roptions->AddBoundedIntegerOption(
"nlp_log_level",
73 "specify NLP solver interface log level (independent from ipopt print_level).",
75 "Set the level of output of the CouenneMINLPInterface : "
76 "0 - none, 1 - normal, 2 - verbose"
78 roptions->setOptionExtraInfo(
"nlp_log_level",15);
80 roptions->AddStringOption2(
"file_solution",
81 "Write a file bonmin.sol with the solution",
86 roptions->AddStringOption3(
"warm_start",
87 "Select the warm start method",
89 "none",
"No warm start",
90 "optimum",
"Warm start with direct parent optimum",
91 "interior_point",
"Warm start with an interior point of direct parent",
92 "This will affect the function getWarmStart(), and as a consequence the warm starting in the various algorithms.");
93 roptions->setOptionExtraInfo(
"warm_start",8);
95 roptions->SetRegisteringCategory(
"Nlp solution robustness", RegisteredOptions::BonminCategory);
97 roptions->AddLowerBoundedNumberOption(
"max_random_point_radius",
98 "Set max value r for coordinate of a random point.",
100 "When picking a random point coordinate i will be in the interval [min(max(l,-r),u-r), max(min(u,r),l+r)] "
101 "(where l is the lower bound for the variable and u is its upper bound)");
102 roptions->setOptionExtraInfo(
"max_random_point_radius",8);
104 roptions->AddStringOption3(
"random_point_type",
"method to choose a random starting point",
106 "Jon",
"Choose random point uniformly between the bounds",
107 "Andreas",
"perturb the starting point of the problem within a prescribed interval",
108 "Claudia",
"perturb the starting point using the perturbation radius suffix information",
110 roptions->setOptionExtraInfo(
"random_point_type",8);
112 roptions->AddLowerBoundedNumberOption(
"random_point_perturbation_interval",
113 "Amount by which starting point is perturbed when choosing to pick random point by perturbating starting point",
116 roptions->setOptionExtraInfo(
"random_point_perturbation_interval",8);
119 roptions->AddLowerBoundedIntegerOption
120 (
"num_iterations_suspect",
121 "Number of iterations over which a node is considered \"suspect\" (for debugging purposes only, see detailed documentation).",
123 "When the number of iterations to solve a node is above this number, the subproblem at this"
124 " node is considered to be suspect and it will be outputed in a file (set to -1 to deactivate this).");
125 roptions->setOptionExtraInfo(
"num_iterations_suspect",15);
129 roptions->AddLowerBoundedIntegerOption(
"num_retry_unsolved_random_point",
130 "Number $k$ of times that the algorithm will try to resolve an unsolved NLP with a random starting point "
131 "(we call unsolved an NLP for which Ipopt is not "
132 "able to guarantee optimality within the specified tolerances).",
134 "When Ipopt fails to solve a continuous NLP sub-problem, if $k > 0$, the algorithm will "
135 "try again to solve the failed NLP with $k$ new randomly chosen starting points "
136 " or until the problem is solved with success.");
137 roptions->setOptionExtraInfo(
"num_retry_unsolved_random_point",15);
140 roptions->SetRegisteringCategory(
"Options for non-convex problems", RegisteredOptions::BonminCategory);
143 roptions->AddLowerBoundedIntegerOption(
"num_resolve_at_root",
144 "Number $k$ of tries to resolve the root node with different starting points.",
146 "The algorithm will solve the root node with $k$ random starting points"
147 " and will keep the best local optimum found.");
148 roptions->setOptionExtraInfo(
"num_resolve_at_root",8);
150 roptions->AddLowerBoundedIntegerOption(
"num_resolve_at_node",
151 "Number $k$ of tries to resolve a node (other than the root) of the tree with different starting point.",
153 "The algorithm will solve all the nodes with $k$ different random starting points "
154 "and will keep the best local optimum found.");
155 roptions->setOptionExtraInfo(
"num_resolve_at_node",8);
157 roptions->AddLowerBoundedIntegerOption(
"num_resolve_at_infeasibles",
158 "Number $k$ of tries to resolve an infeasible node (other than the root) of the tree with different starting point.",
160 "The algorithm will solve all the infeasible nodes with $k$ different random starting points "
161 "and will keep the best local optimum found.");
162 roptions->setOptionExtraInfo(
"num_resolve_at_infeasibles",8);
171 roptions->SetRegisteringCategory(
"Outer Approximation cuts generation", RegisteredOptions::BonminCategory);
173 roptions->AddStringOption2(
"disjunctive_cut_type",
174 "Determine if and what kind of disjunctive cuts should be computed.",
176 "none",
"No disjunctive cuts.",
177 "most-fractional",
"If discrete variables present, compute disjunction for most-fractional variable");
178 roptions->setOptionExtraInfo(
"disjunctive_cut_type",7);
180 roptions->AddStringOption2(
"oa_cuts_scope",
"Specify if OA cuts added are to be set globally or locally valid",
182 "local",
"Cuts are treated as globally valid",
183 "global",
"Cuts are treated as locally valid",
185 roptions->setOptionExtraInfo(
"oa_cuts_scope",7);
187 roptions->AddStringOption2(
"add_only_violated_oa",
"Do we add all OA cuts or only the ones violated by current point?",
190 "yes",
"Add only violated Cuts",
"");
191 roptions->setOptionExtraInfo(
"add_only_violated_oa",7);
193 roptions->AddStringOption4(
"cut_strengthening_type",
194 "Determines if and what kind of cut strengthening should be performed.",
196 "none",
"No strengthening of cuts.",
197 "sglobal",
"Strengthen global cuts.",
198 "uglobal-slocal",
"Unstrengthened global and strengthened local cuts",
199 "sglobal-slocal",
"Strengthened global and strengthened local cuts",
201 roptions->setOptionExtraInfo(
"cut_strengthening_type",7);
203 roptions->AddLowerBoundedNumberOption(
"tiny_element",
"Value for tiny element in OA cut",
205 "We will remove \"cleanly\" (by relaxing cut) an element lower"
207 roptions->setOptionExtraInfo(
"tiny_element",7);
209 roptions->AddLowerBoundedNumberOption(
"very_tiny_element",
"Value for very tiny element in OA cut",
211 "Algorithm will take the risk of neglecting an element lower"
213 roptions->setOptionExtraInfo(
"very_tiny_element",7);
215 roptions->AddLowerBoundedIntegerOption(
"oa_cuts_log_level",
216 "level of log when generating OA cuts.",
218 "0: outputs nothing,\n"
219 "1: when a cut is generated, its violation and index of row from which it originates,\n"
220 "2: always output violation of the cut.\n"
221 "3: output generated cuts incidence vectors.");
222 roptions->setOptionExtraInfo(
"oa_cuts_log_level",7);
229 CouenneMINLPInterface::registerOptions
237 #ifdef COIN_HAS_FILTERSQP
238 FilterSolver::RegisterOptions(roptions);
240 #ifdef COIN_HAS_IPOPT
241 IpoptSolver::RegisterOptions(roptions);
244 catch(RegisteredOptions::OPTION_ALREADY_REGISTERED) {
256 CouenneMINLPInterface::Messages::Messages
257 ():CoinMessages((
int)OSITMINLPINTERFACE_DUMMY_END)
259 strcpy(source_ ,
"NLP");
261 "After %d tries found a solution of %g (previous best %g).");
264 "After %d tries found an solution of %g infeasible problem.");
267 "After %d tries found an solution of %g unsolved problem.");
269 "Problem not solved with warm start but solved without");
272 "Trying to resolve NLP with different starting point (%d attempts).");
274 "Problem initially not solved but solved with a random starting point (success on %d attempt)");
276 "Warning : continuing branching, while there are unrecovered failures at nodes");
278 ADD_MSG(SUSPECT_PROBLEM,
std_m, 2,
"NLP number %d is suspect (see bounds and start file)");
279 ADD_MSG(IPOPT_SUMMARY,
std_m, 2,
"Ipopt return (for %s): status %2d, iter count %4d, time %g");
280 ADD_MSG(BETTER_SOL,
std_m, 2,
"Solution of value %g found on %d'th attempt");
284 " Num Status Obj It time");
286 " %-8d %-11s %-23.16g %-8d %-3g");
287 ADD_MSG(LOG_LINE,
std_m, 1,
" %c r%-7d %-11s %-23.16g %-8d %-3g");
289 ADD_MSG(ALTERNATE_OBJECTIVE,
std_m, 1,
"Objective value recomputed with alternate objective: %g.");
292 "resolve called before any call to initialSol can not use warm starts.");
293 ADD_MSG(ERROR_NO_TNLPSOLVER,
warn_m, 1,
"Can not parse options when no IpApplication has been created");
295 "OA on non-convex constraint is very experimental.");
296 ADD_MSG(SOLVER_DISAGREE_STATUS,
warn_m, 1,
"%s says problem %s, %s says %s.");
297 ADD_MSG(SOLVER_DISAGREE_VALUE,
warn_m, 1,
"%s gives objective %.16g, %s gives %.16g.");
303 CouenneMINLPInterface::OaMessageHandler::print(OsiRowCut &row){
304 FILE * fp = filePointer();
305 const int &
n = row.row().getNumElements();
306 fprintf(fp,
"Row cut has %d elements. Lower bound: %g, upper bound %g.\n", n, row.lb(), row.ub());
307 const int * idx = row.row().getIndices();
308 const double * val = row.row().getElements();
309 for(
int i = 0 ; i <
n ; i++){
310 fprintf(fp,
"%g, x%d",val[i], idx[i]);
316 CouenneMINLPInterface::OaMessages::OaMessages(): CoinMessages((
int) OA_MESSAGES_DUMMY_END){
317 strcpy(source_,
"OaCg");
318 ADD_MSG(VIOLATED_OA_CUT_GENERATED,
std_m, 1,
"Row %d, cut violation is %g: Outer approximation cut generated.");
320 ADD_MSG(CUT_NOT_VIOLATED_ENOUGH,
std_m, 2,
"Row %d, cut violation is %g: Outer approximation cut not generated.");
322 ADD_MSG(OA_CUT_GENERATED,
std_m, 1,
"Row %d: Outer approximation cut not generated.");
324 bool CouenneMINLPInterface::hasPrintedOptions=0;
330 CouenneMINLPInterface::CouenneMINLPInterface():
331 OsiSolverInterface(),
334 problem_to_optimize_(NULL),
335 feasibility_mode_(false),
344 OsiDualObjectiveLimit_(1e200),
345 hasVarNamesFile_(true),
346 nCallOptimizeTNLP_(0),
347 totalNlpSolveTime_(0),
349 maxRandomRadius_(1e08),
350 randomGenerationType_(0),
351 max_perturbation_(COIN_DBL_MAX),
353 numRetryInitial_(-1),
354 numRetryResolve_(-1),
355 numRetryInfeasibles_(-1),
356 numRetryUnsolved_(1),
358 pretendFailIsInfeasible_(0),
359 hasContinuedAfterNlpFailure_(false),
360 numIterationSuspect_(-1),
361 hasBeenOptimized_(false),
363 feasibilityProblem_(NULL),
373 exposeWarmStart_(false),
375 cutStrengthener_(NULL),
379 oaHandler_ =
new OaMessageHandler;
380 oaHandler_->setLogLevel(0);
389 createApplication(roptions, options, journalist);
406 options->GetEnumValue(
"nlp_solver", ival,
"bonmin.");
409 testOthers_ =
false;;
410 #ifdef COIN_HAS_FILTERSQP
413 throw SimpleError(
"createApplication",
414 "Bonmin not configured to run with FilterSQP.");
419 #ifdef COIN_HAS_IPOPT
420 app_ =
new IpoptSolver(roptions, options, journalist);
422 throw SimpleError(
"createApplication",
423 "Bonmin not configured to run with Ipopt.");
427 #ifdef COIN_HAS_FILTERSQP
430 throw SimpleError(
"createApplication",
431 "Bonmin not configured to run with Ipopt.");
433 #ifdef COIN_HAS_IPOPT
434 debug_apps_.push_back(
new IpoptSolver(roptions, options, journalist));
438 if (!app_->Initialize(
"")) {
439 throw CoinError(
"Error during initialization of app_",
"createApplication",
"CouenneMINLPInterface");
442 i != debug_apps_.end() ; i++){
443 (*i)->Initialize(
"");
445 extractInterfaceParams();
455 problem_ =
new TMINLP2TNLP(tminlp_);
456 feasibilityProblem_ =
new TNLP2FPNLP
458 if(feasibility_mode_){
459 problem_to_optimize_ =
GetRawPtr(feasibilityProblem_);
469 CouenneMINLPInterface::readOptionFile(
const std::string & fileName)
473 if (fileName !=
"") {
475 is.open(fileName.c_str());
477 catch(std::bad_alloc) {
478 throw CoinError(
"Not enough memory to open option file.\n",
"readOptionFile",
"CouenneMINLPInterface");
481 options()->ReadFromStream(*app_->journalist(), is);
482 extractInterfaceParams();
488 OsiSolverInterface(source),
489 tminlp_(source.tminlp_),
491 problem_to_optimize_(NULL),
492 feasibility_mode_(source.feasibility_mode_),
497 OsiDualObjectiveLimit_(source.OsiDualObjectiveLimit_),
498 hasVarNamesFile_(source.hasVarNamesFile_),
499 nCallOptimizeTNLP_(0),
500 totalNlpSolveTime_(0),
502 maxRandomRadius_(source.maxRandomRadius_),
503 randomGenerationType_(source.randomGenerationType_),
504 max_perturbation_(source.max_perturbation_),
505 pushValue_(source.pushValue_),
506 numRetryInitial_(source.numRetryInitial_),
507 numRetryResolve_(source.numRetryResolve_),
508 numRetryInfeasibles_(source.numRetryInfeasibles_),
509 numRetryUnsolved_(source.numRetryUnsolved_),
511 pretendFailIsInfeasible_(source.pretendFailIsInfeasible_),
512 hasContinuedAfterNlpFailure_(source.hasContinuedAfterNlpFailure_),
513 numIterationSuspect_(source.numIterationSuspect_),
514 hasBeenOptimized_(source.hasBeenOptimized_),
516 feasibilityProblem_(NULL),
520 nnz_jac(source.nnz_jac),
525 veryTiny_(source.veryTiny_),
526 infty_(source.infty_),
527 exposeWarmStart_(source.exposeWarmStart_),
529 cutStrengthener_(source.cutStrengthener_),
532 strong_branching_solver_(source.strong_branching_solver_)
534 if(defaultHandler()){
535 messageHandler()->setLogLevel(source.messageHandler()->logLevel());
538 if(source.messageHandler())
539 passInMessageHandler(source.messageHandler());
543 feasibilityProblem_ =
new TNLP2FPNLP
545 if(feasibility_mode_)
546 problem_to_optimize_ =
GetRawPtr(feasibilityProblem_);
549 pretendFailIsInfeasible_ = source.pretendFailIsInfeasible_;
551 setAuxiliaryInfo(source.getAuxiliaryInfo());
553 app_ = source.app_->clone();
555 i != source.debug_apps_.end() ; i++){
556 debug_apps_.push_back((*i)->clone());
558 testOthers_ = source.testOthers_;
561 throw SimpleError(
"Don't know how to copy an empty IpoptInterface.",
565 warmstart_ = source.warmstart_ ? source.warmstart_->clone() : NULL;
568 obj_ =
new double[source.getNumCols()];
569 CoinCopyN(source.obj_, source.getNumCols(), obj_);
573 oaHandler_ =
new OaMessageHandler(*source.oaHandler_);;
578 CouenneMINLPInterface::clone(
bool copyData )
const
589 OsiSolverInterface::operator=(rhs);
590 OsiDualObjectiveLimit_ = rhs.OsiDualObjectiveLimit_;
591 nCallOptimizeTNLP_ = rhs.nCallOptimizeTNLP_;
592 totalNlpSolveTime_ = rhs.nCallOptimizeTNLP_;
593 totalIterations_ = rhs.totalIterations_;
594 maxRandomRadius_ = rhs.maxRandomRadius_;
595 hasVarNamesFile_ = rhs.hasVarNamesFile_;
596 pushValue_ = rhs.pushValue_;
603 tminlp_ = rhs.tminlp_;
604 problem_ =
new TMINLP2TNLP(tminlp_);
606 app_ = rhs.app_->clone();
608 warmstart_ = rhs.warmstart_ ? rhs.warmstart_->clone() : NULL;
610 feasibilityProblem_ =
new TNLP2FPNLP
612 nnz_jac = rhs.nnz_jac;
614 if(constTypes_ != NULL) {
615 delete [] constTypes_;
618 if(rhs.constTypes_ != NULL) {
619 constTypes_ =
new TNLP::LinearityType[getNumRows()];
620 CoinCopyN(rhs.constTypes_, getNumRows(), constTypes_);
632 if(rhs.jValues_!=NULL && rhs.jRow_ != NULL && rhs.jCol_ != NULL && nnz_jac>0) {
633 jValues_ =
new double [nnz_jac];
634 jCol_ =
new Index [nnz_jac];
635 jRow_ =
new Index [nnz_jac];
636 CoinCopyN(rhs.jValues_ , nnz_jac,jValues_ );
637 CoinCopyN(rhs.jCol_ , nnz_jac,jCol_ );
638 CoinCopyN(rhs.jRow_ , nnz_jac,jRow_ );
640 else if(nnz_jac > 0) {
641 throw CoinError(
"Arrays for storing jacobian are inconsistant.",
646 veryTiny_ = rhs.veryTiny_;
648 exposeWarmStart_ = rhs.exposeWarmStart_;
655 feasibilityProblem_ = NULL;
664 obj_ =
new double[rhs.getNumCols()];
665 CoinCopyN(rhs.obj_, rhs.getNumCols(), obj_);
668 hasVarNamesFile_ = rhs.hasVarNamesFile_;
670 nCallOptimizeTNLP_ = rhs.nCallOptimizeTNLP_;
671 totalNlpSolveTime_ = rhs.totalNlpSolveTime_;
672 totalIterations_ = rhs.totalIterations_;
673 maxRandomRadius_ = rhs.maxRandomRadius_;
674 pushValue_ = rhs.pushValue_;
675 numRetryInitial_ = rhs.numRetryInitial_;
676 numRetryResolve_ = rhs.numRetryResolve_;
677 numRetryInfeasibles_ = rhs.numRetryInfeasibles_;
678 numRetryUnsolved_ = rhs.numRetryUnsolved_;
679 pretendFailIsInfeasible_ = rhs.pretendFailIsInfeasible_;
680 numIterationSuspect_ = rhs.numIterationSuspect_;
682 hasBeenOptimized_ = rhs.hasBeenOptimized_;
683 cutStrengthener_ = rhs.cutStrengthener_;
686 oaHandler_ =
new OaMessageHandler(*rhs.oaHandler_);
687 strong_branching_solver_ = rhs.strong_branching_solver_;
697 messageHandler()->message(ERROR_NO_TNLPSOLVER, messages_)<<CoinMessageEol;
701 return app_->options();
707 messageHandler()->message(ERROR_NO_TNLPSOLVER, messages_)<<CoinMessageEol;
711 return app_->options();
715 CouenneMINLPInterface::~CouenneMINLPInterface ()
721 delete [] constTypes_;
728 CouenneMINLPInterface::freeCachedColRim()
730 if(reducedCosts_!=NULL) {
731 delete [] reducedCosts_;
732 reducedCosts_ = NULL;
738 CouenneMINLPInterface::freeCachedRowRim()
740 if(rowsense_!=NULL) {
748 if(rowrange_!=NULL) {
759 CouenneMINLPInterface::freeCachedData()
765 const char * CouenneMINLPInterface::OPT_SYMB=
"OPT";
766 const char * CouenneMINLPInterface::FAILED_SYMB=
"FAILED";
767 const char * CouenneMINLPInterface::UNBOUND_SYMB=
"UNBOUNDED";
768 const char * CouenneMINLPInterface::INFEAS_SYMB=
"INFEAS";
775 CouenneMINLPInterface::resolveForCost(
int numsolve,
bool keepWarmStart)
783 Coin::SmartPtr<SimpleReferencedPtr<CoinWarmStart> > ws_backup = NULL;
784 if(!exposeWarmStart_ && keepWarmStart){
790 vector<double> point(getNumCols()*3+ getNumRows());
791 double bestBound = getObjValue();
792 CoinCopyN(getColSolution(),
793 getNumCols(), point());
794 CoinCopyN(getRowPrice(),
795 2*getNumCols()+ getNumRows(),
796 point() + getNumCols());
798 if(isProvenOptimal())
799 messageHandler()->message(SOLUTION_FOUND,
801 <<1<<getObjValue()<<bestBound
804 messageHandler()->message(INFEASIBLE_SOLUTION_FOUND,
808 for(
int f = 0;
f < numsolve ;
f++) {
809 messageHandler()->message(WARNING_RESOLVING,
811 <<
f+1<< CoinMessageEol ;
812 randomStartingPoint();
813 solveAndCheckErrors(0,0,
"resolveForCost");
818 if(isProvenOptimal() &&
819 getObjValue()<bestBound) {
821 messageHandler()->message(BETTER_SOL, messages_)<<getObjValue()<<
f+1<< CoinMessageEol;
822 CoinCopyN(getColSolution(),
823 getNumCols(), point());
824 CoinCopyN(getRowPrice(),
825 2*getNumCols()+ getNumRows(),
826 point() + getNumCols());
827 bestBound = getObjValue();
830 messageHandler()->message(LOG_LINE, messages_)
831 <<c<<
f+1<<statusAsString()<<getObjValue()<<app_->IterationCount()<<app_->CPUTime()<<CoinMessageEol;
834 if(isProvenOptimal())
835 messageHandler()->message(SOLUTION_FOUND,
837 <<
f+2<<getObjValue()<<bestBound
839 else if(!isAbandoned())
840 messageHandler()->message(UNSOLVED_PROBLEM_FOUND,
845 messageHandler()->message(INFEASIBLE_SOLUTION_FOUND,
850 setColSolution(point());
851 setRowPrice(point() + getNumCols());
852 app_->enableWarmStart();
854 optimizationStatus_ = app_->ReOptimizeTNLP(
GetRawPtr(problem_to_optimize_));
855 hasBeenOptimized_ =
true;
857 if(!exposeWarmStart_ && keepWarmStart) {
858 app_->setWarmStart(ws_backup->ptr(),
problem_);
863 CouenneMINLPInterface::resolveForRobustness(
int numsolve)
872 CoinWarmStart * ws_backup = NULL;
873 if(!exposeWarmStart_){
876 ws_backup = app_->getUsedWarmStart(
problem_);
880 app_->disableWarmStart();
881 problem()->resetStartingPoint();
882 messageHandler()->message(WARNING_RESOLVING,
884 <<1<< CoinMessageEol ;
885 solveAndCheckErrors(0,0,
"resolveForRobustness");
892 messageHandler()->message(LOG_LINE, messages_)
893 <<c<<1<<statusAsString()<<getObjValue()<<app_->IterationCount()<<
894 app_->CPUTime()<<CoinMessageEol;
898 messageHandler()->message(WARN_SUCCESS_WS, messages_) << CoinMessageEol ;
900 app_->enableWarmStart();
901 if (!exposeWarmStart_) {
902 app_->setWarmStart(ws_backup,
problem_);
909 for(
int f = 0;
f < numsolve ;
f++) {
910 messageHandler()->message(WARNING_RESOLVING,
912 <<
f+2<< CoinMessageEol ;
914 randomStartingPoint();
915 solveAndCheckErrors(0,0,
"resolveForRobustness");
918 messageHandler()->message(IPOPT_SUMMARY, messages_)
919 <<
"resolveForRobustness"<<optimizationStatus_<<app_->IterationCount()<<app_->CPUTime()<<CoinMessageEol;
926 messageHandler()->message(LOG_LINE, messages_)
927 <<c<<
f+2<<statusAsString()<<getObjValue()
928 <<app_->IterationCount()<<app_->CPUTime()<<CoinMessageEol;
932 messageHandler()->message(WARN_SUCCESS_RANDOM, messages_)
933 <<
f+2 << CoinMessageEol ;
935 app_->enableWarmStart();
936 if (!exposeWarmStart_) {
937 app_->setWarmStart(ws_backup,
problem_);
946 if(!exposeWarmStart_){
947 app_->setWarmStart(ws_backup,
problem_);
950 if(pretendFailIsInfeasible_) {
951 if(pretendFailIsInfeasible_ == 1) {
952 messageHandler()->message(WARN_CONTINUING_ON_FAILURE,
955 hasContinuedAfterNlpFailure_ = 1;
960 std::string probName;
961 getStrParam(OsiProbName,probName);
962 throw newUnsolvedError(app_->errorCode(),
problem_,
972 int CouenneMINLPInterface::getNumCols()
const
981 CouenneMINLPInterface::getNumRows()
const
987 CouenneMINLPInterface::getColLower()
const
993 CouenneMINLPInterface::getColUpper()
const
1002 const OsiSolverInterface::OsiNameVec&
1003 CouenneMINLPInterface::getVarNames() {
1004 return getColNames();
1009 void CouenneMINLPInterface::extractSenseRhsAndRange()
const
1011 assert(rowsense_==NULL&&rhs_==NULL&&rowrange_==NULL);
1012 int numrows =
problem_->num_constraints();
1013 if(numrows == 0)
return;
1014 const double * rowLower = getRowLower();
1015 const double * rowUpper = getRowUpper();
1016 rowsense_ =
new char [numrows];
1017 rhs_ =
new double [numrows];
1018 rowrange_ =
new double [numrows];
1019 for(
int i = 0 ; i < numrows ; i++) {
1021 convertBoundToSense(rowLower[i], rowUpper[i], rowsense_[i], rhs_[i], rowrange_[i]);
1035 CouenneMINLPInterface::getRowSense()
const
1037 if(rowsense_==NULL) {
1038 extractSenseRhsAndRange();
1052 CouenneMINLPInterface::getRightHandSide()
const
1055 extractSenseRhsAndRange();
1069 CouenneMINLPInterface::getRowRange()
const
1071 if(rowrange_==NULL) {
1072 extractSenseRhsAndRange();
1078 CouenneMINLPInterface::getRowLower()
const
1084 CouenneMINLPInterface::getRowUpper()
const
1091 CouenneMINLPInterface::isContinuous(
int colNumber)
const
1093 return (
problem_->var_types()[colNumber]==TMINLP::CONTINUOUS);
1098 CouenneMINLPInterface::isBinary(
int colNumber)
const
1100 return (
problem_->var_types()[colNumber]==TMINLP::BINARY);
1110 return ((
problem_->var_types()[colNumber]==TMINLP::BINARY)||
1116 CouenneMINLPInterface::isIntegerNonBinary(
int colNumber)
const
1122 CouenneMINLPInterface::isFreeBinary(
int colNumber)
const
1124 return ((
problem_->var_types()[colNumber]==TMINLP::BINARY)
1125 &&((getColUpper()[colNumber]-getColLower()[colNumber]) > 1 - 1
e-09));
1130 CouenneMINLPInterface::getInfinity()
const
1132 return COIN_DBL_MAX;
1137 CouenneMINLPInterface::getColSolution()
const
1139 if(hasBeenOptimized_)
1147 CouenneMINLPInterface::getRowPrice()
const
1149 if(hasBeenOptimized_)
1157 CouenneMINLPInterface::getReducedCost()
const
1159 (*handler_)<<
"WARNING : trying to access reduced cost in Ipopt always retrun 0"<<CoinMessageEol;
1160 if(reducedCosts_==NULL) {
1161 reducedCosts_ =
new double [getNumCols()];
1162 CoinFillN(reducedCosts_,getNumCols(),0.);
1164 return reducedCosts_;
1170 CouenneMINLPInterface::getRowActivity()
const
1179 CouenneMINLPInterface::getIterationCount()
const
1181 return app_->IterationCount();
1188 CouenneMINLPInterface::setColLower(
int elementIndex,
double elementValue )
1191 problem_->SetVariableLowerBound(elementIndex,elementValue);
1192 hasBeenOptimized_ =
false;
1198 CouenneMINLPInterface::setColUpper(
int elementIndex,
double elementValue )
1201 problem_->SetVariableUpperBound(elementIndex,elementValue);
1202 hasBeenOptimized_ =
false;
1208 CouenneMINLPInterface::setColLower(
const double* array )
1212 hasBeenOptimized_ =
false;
1218 CouenneMINLPInterface::setColUpper(
const double* array )
1222 hasBeenOptimized_ =
false;
1228 CouenneMINLPInterface::setRowLower(
int elementIndex,
double elementValue )
1230 throw SimpleError(
"Not implemented yet but should be if necessary.",
1232 hasBeenOptimized_ =
false;
1238 CouenneMINLPInterface::setRowUpper(
int elementIndex,
double elementValue )
1240 throw SimpleError(
"Not implemented yet but should be if necessary.",
1242 hasBeenOptimized_ =
false;
1247 CouenneMINLPInterface::setRowType(
int index,
char sense,
double rightHandSide,
1250 throw SimpleError(
"Not implemented yet but should be if necessary.",
1252 hasBeenOptimized_ =
false;
1259 CouenneMINLPInterface::setObjSense(
double s)
1261 throw SimpleError(
"Can not change objective sense of an Ipopt problem.",
1263 hasBeenOptimized_ =
false;
1276 CouenneMINLPInterface::setColSolution(
const double *colsol)
1278 problem_->setxInit(getNumCols(), colsol);
1279 hasBeenOptimized_ =
false;
1293 CouenneMINLPInterface::setRowPrice(
const double * rowprice)
1295 problem_->setDualsInit(getNumCols()*2 + getNumRows(), rowprice);
1296 hasBeenOptimized_ =
false;
1306 CouenneMINLPInterface::getEmptyWarmStart ()
const
1307 {
return app_->getEmptyWarmStart();}
1311 CouenneMINLPInterface::getWarmStart()
const
1313 if (exposeWarmStart_) {
1314 return internal_getWarmStart();;
1317 return getEmptyWarmStart();
1323 CouenneMINLPInterface::setWarmStart(
const CoinWarmStart*
ws)
1325 if (exposeWarmStart_) {
1326 return internal_setWarmStart(ws);
1334 CouenneMINLPInterface::internal_getWarmStart()
const
1336 if (exposeWarmStart_ && warmstart_) {
1337 return warmstart_->clone();
1340 return getEmptyWarmStart();
1346 CouenneMINLPInterface::internal_setWarmStart(
const CoinWarmStart* ws)
1350 hasBeenOptimized_ =
false;
1351 if (exposeWarmStart_) {
1355 if(app_->warmStartIsValid(ws)) {
1356 warmstart_ = ws->clone();
1361 const CoinWarmStartPrimalDual* pdws =
1362 dynamic_cast<const CoinWarmStartPrimalDual*
>(
ws);
1366 warmstart_ =
new IpoptWarmStart(*pdws);
1378 CouenneMINLPInterface::setContinuous(
int index)
1380 problem_->SetVariableType(index, TMINLP::CONTINUOUS);
1381 hasBeenOptimized_ =
false;
1385 CouenneMINLPInterface::setInteger(
int index)
1388 hasBeenOptimized_ =
false;
1393 CouenneMINLPInterface::getObjValue()
const
1403 CouenneMINLPInterface::setIntParam(OsiIntParam key,
int value)
1407 bool retval =
false;
1409 case OsiMaxNumIteration:
1412 case OsiMaxNumIterationHotStart:
1419 case OsiLastIntParam:
1424 (*handler_)<<
"Unhandled case in setIntParam\n"<<CoinMessageEol;
1433 CouenneMINLPInterface::setDblParam(OsiDblParam key,
double value)
1437 bool retval =
false;
1439 case OsiDualObjectiveLimit:
1440 OsiDualObjectiveLimit_ = value;
1443 case OsiPrimalObjectiveLimit:
1444 (*handler_)<<
"Can not set primal objective limit parameter"<<CoinMessageEol;
1447 case OsiDualTolerance:
1448 (*handler_)<<
"Can not set dual tolerance parameter"<<CoinMessageEol;
1451 case OsiPrimalTolerance:
1452 (*handler_)<<
"Can not set primal tolerance parameter"<<CoinMessageEol;
1455 retval = OsiSolverInterface::setDblParam(key,value);
1457 case OsiLastDblParam:
1462 (*handler_) <<
"Unhandled case in setDblParam"<<CoinMessageEol;
1472 CouenneMINLPInterface::setStrParam(OsiStrParam key,
const std::string & value)
1479 OsiSolverInterface::setStrParam(key,value);
1480 return retval =
true;
1483 case OsiLastStrParam:
1492 CouenneMINLPInterface::getIntParam(OsiIntParam key,
int& value)
const
1496 value = -COIN_INT_MAX;
1497 bool retval =
false;
1499 case OsiMaxNumIteration:
1502 case OsiMaxNumIterationHotStart:
1505 case OsiLastIntParam:
1510 (*handler_) <<
"Unhandled case in setIntParam"<<CoinMessageEol;
1518 CouenneMINLPInterface::getDblParam(OsiDblParam key,
double& value)
const
1522 bool retval =
false;
1524 case OsiDualObjectiveLimit:
1525 value = OsiDualObjectiveLimit_;
1528 case OsiPrimalObjectiveLimit:
1529 value = getInfinity();
1532 case OsiDualTolerance:
1535 case OsiPrimalTolerance:
1536 options()->GetNumericValue(
"tol", value,
"");
1541 retval = OsiSolverInterface::getDblParam(key, value);
1543 case OsiLastDblParam:
1554 CouenneMINLPInterface::getStrParam(OsiStrParam key, std::string & value)
const
1560 OsiSolverInterface::getStrParam(key, value);
1565 case OsiLastStrParam:
1573 CouenneMINLPInterface::randomStartingPoint()
1575 int numcols = getNumCols();
1576 const double * colLower = getColLower();
1577 const double * colUpper = getColUpper();
1578 double * sol =
new double[numcols];
1579 const Number * x_init =
problem_->x_init_user();
1580 const double* perturb_radius = NULL;
1581 if (randomGenerationType_ == perturb_suffix) {
1582 const TMINLP::PerturbInfo* pertubinfo = tminlp_->perturbInfo();
1584 perturb_radius = pertubinfo->GetPerturbationArray();
1586 if (!perturb_radius) {
1587 throw SimpleError(
"Can't use perturb_radius if no radii are given.",
1588 "randomStartingPoint");
1591 for(
int i = 0 ; i < numcols ; i++) {
1592 int randomGenerationType = randomGenerationType_;
1593 if(x_init[i] < colLower[i] || x_init[i] > colUpper[i])
1594 randomGenerationType = uniform;
1595 if(randomGenerationType_ == uniform){
1596 double lower = std::min(-maxRandomRadius_,colUpper[i] - maxRandomRadius_);
1597 lower = std::max(colLower[i], lower);
1598 double upper = std::max(maxRandomRadius_,colLower[i] + maxRandomRadius_);
1599 upper = std::min(colUpper[i],upper);
1600 lower = std::min(upper,lower);
1601 upper = std::max(upper, lower);
1602 double interval = upper - lower;
1603 sol[i] = CoinDrand48()*(interval) + lower;}
1604 else if (randomGenerationType_ == perturb){
1605 const double lower = std::max(x_init[i] - max_perturbation_, colLower[i]);
1606 const double upper = std::min(x_init[i] + max_perturbation_, colUpper[i]);
1607 const double interval = upper - lower;
1608 sol[i] = lower + CoinDrand48()*(interval);
1610 else if (randomGenerationType_ == perturb_suffix){
1611 const double radius = perturb_radius[i];
1612 const double lower = std::max(x_init[i] - radius*max_perturbation_, colLower[i]);
1613 const double upper = std::min(x_init[i] + radius*max_perturbation_, colUpper[i]);
1614 const double interval = upper - lower;
1615 sol[i] = lower + CoinDrand48()*(interval);
1618 app_->disableWarmStart();
1619 setColSolution(sol);
1626 int CouenneMINLPInterface::initializeJacobianArrays()
1628 Index
n,
m, nnz_h_lag;
1629 TNLP::IndexStyleEnum index_style;
1630 tminlp_->get_nlp_info( n, m, nnz_jac, nnz_h_lag, index_style);
1632 if(jRow_ != NULL)
delete jRow_;
1633 if(jCol_ != NULL)
delete jCol_;
1634 if(jValues_ != NULL)
delete jValues_;
1636 jRow_ =
new Index[nnz_jac];
1637 jCol_ =
new Index[nnz_jac];
1638 jValues_ =
new Number[nnz_jac];
1639 tminlp_->eval_jac_g(n, NULL, 0, m, nnz_jac, jRow_, jCol_, NULL);
1640 if(index_style == Ipopt::TNLP::FORTRAN_STYLE)
1642 for(
int i = 0 ; i < nnz_jac ; i++){
1648 if(constTypes_ != NULL)
delete [] constTypes_;
1651 constTypes_ =
new TNLP::LinearityType[getNumRows()];
1652 tminlp_->get_constraints_linearity(getNumRows(), constTypes_);
1654 for(
int i = 0; i < getNumRows() ; i++) {
1655 if(constTypes_[i]==TNLP::NON_LINEAR) {
1665 CouenneMINLPInterface::getConstraintsViolation(
const double *
x,
double &obj)
1667 int numcols = getNumCols();
1668 int numrows = getNumRows();
1669 double *
g =
new double[numrows];
1670 tminlp_->eval_g(numcols, x, 1, numrows, g);
1671 const double * rowLower = getRowLower();
1672 const double * rowUpper = getRowUpper();
1676 for(
int i = 0; i< numrows ; i++) {
1677 if(!constTypes_ || constTypes_[i] == TNLP::NON_LINEAR) {
1678 double rowViolation = 0;
1679 if(rowLower[i] > -1e10)
1680 rowViolation = std::max(0.,rowLower[i] - g[i]);
1682 if(rowUpper[i] < 1e10);
1683 rowViolation = std::max(rowViolation, g[i] - rowUpper[i]);
1685 norm = rowViolation > norm ? rowViolation : norm;
1688 tminlp_->eval_f(numcols, x, 1, obj);
1695 CouenneMINLPInterface::getNonLinearitiesViolation(
const double *x,
const double obj)
1698 double norm = getConstraintsViolation(x, f);
1699 assert((f - obj) > -1
e-08);
1700 norm = (f - obj) > norm ? f - obj : norm;
1708 bool cleanNnz(
double &value,
double colLower,
double colUpper,
1709 double rowLower,
double rowUpper,
double colsol,
1710 double & lb,
double &ub,
double tiny,
double veryTiny)
1712 if(fabs(value)>= tiny)
return 1;
1714 if(fabs(value)<veryTiny)
return 0;
1717 double infty = 1e20;
1718 bool colUpBounded = colUpper < 10000;
1719 bool colLoBounded = colLower > -10000;
1720 bool rowNotLoBounded = rowLower <= -
infty;
1721 bool rowNotUpBounded = rowUpper >=
infty;
1722 bool pos = value > 0;
1724 if(colLoBounded && pos && rowNotUpBounded) {
1725 lb += value * (colsol - colLower);
1729 if(colLoBounded && !pos && rowNotLoBounded) {
1730 ub += value * (colsol - colLower);
1734 if(colUpBounded && !pos && rowNotUpBounded) {
1735 lb += value * (colsol - colUpper);
1739 if(colUpBounded && pos && rowNotLoBounded) {
1740 ub += value * (colsol - colUpper);
1744 if(pos) value = tiny;
1753 CouenneMINLPInterface::getOuterApproximation(OsiCuts &cs,
const double * x,
bool getObj,
const double *
x2,
double theta,
bool global)
1758 int n,
m, nnz_jac_g, nnz_h_lag;
1759 TNLP::IndexStyleEnum index_style;
1760 problem_to_optimize_->get_nlp_info( n, m, nnz_jac_g, nnz_h_lag, index_style);
1761 if(jRow_ == NULL || jCol_ == NULL || jValues_ == NULL)
1762 initializeJacobianArrays();
1763 assert(jRow_ != NULL);
1764 assert(jCol_ != NULL);
1765 double * g =
new double[
m];
1767 problem_to_optimize_->eval_jac_g(n, x, 1, m, nnz_jac_g, NULL, NULL, jValues_);
1768 problem_to_optimize_->eval_g(n,x,1,m,g);
1780 problem_to_optimize_->eval_jac_g(n, x, 1, m, nnz_jac_g, NULL, NULL, jValues_);
1781 problem_to_optimize_->eval_g(n,x,1,m,g);
1783 CoinPackedVector * cuts =
new CoinPackedVector[nNonLinear_ + 1];
1784 double * lb =
new double[nNonLinear_ + 1];
1785 double * ub =
new double[nNonLinear_ + 1];
1787 int * row2cutIdx =
new int[
m];
1790 const double * rowLower = getRowLower();
1791 const double * rowUpper = getRowUpper();
1792 const double * colLower = getColLower();
1793 const double * colUpper = getColUpper();
1794 const double * duals = getRowPrice() + 2 *
n;
1796 for (
int i=0; i<
n; i++)
1797 printf (
"variable %d: [%g,%g]\n", i, rowLower [i], rowUpper [i]);
1799 double infty = getInfinity();
1800 double nlp_infty = infty_;
1802 for(
int rowIdx = 0; rowIdx <
m ; rowIdx++) {
1803 if(constTypes_[rowIdx] == TNLP::NON_LINEAR) {
1805 if(fabs(duals[rowIdx]) == 0.)
1807 row2cutIdx[rowIdx] = -1;
1809 (*handler_)<<
"non binding constraint"<<CoinMessageEol;
1814 row2cutIdx[rowIdx] = numCuts;
1815 if(rowLower[rowIdx] > - nlp_infty)
1816 lb[numCuts] = rowLower[rowIdx] - g[rowIdx];
1818 lb[numCuts] = -
infty;
1819 if(rowUpper[rowIdx] < nlp_infty)
1820 ub[numCuts] = rowUpper[rowIdx] - g[rowIdx];
1822 ub[numCuts] =
infty;
1823 if(rowLower[rowIdx] > -infty && rowUpper[rowIdx] < infty)
1825 if(duals[rowIdx] >= 0)
1826 lb[numCuts] = -
infty;
1827 if(duals[rowIdx] <= 0)
1828 ub[numCuts] =
infty;
1834 row2cutIdx[rowIdx] = -1;
1838 for(
int i = 0 ; i < nnz_jac_g ; i++) {
1839 const int &rowIdx = jRow_[i];
1840 const int & cutIdx = row2cutIdx[ rowIdx ];
1842 const int &colIdx = jCol_[i];
1844 if(
cleanNnz(jValues_[i],colLower[colIdx], colUpper[colIdx],
1845 rowLower[rowIdx], rowUpper[rowIdx],
1848 ub[cutIdx], tiny_, veryTiny_)) {
1849 cuts[cutIdx].insert(colIdx,jValues_[i]);
1850 if(lb[cutIdx] > - infty)
1851 lb[cutIdx] += jValues_[i] * x[colIdx];
1852 if(ub[cutIdx] < infty)
1853 ub[cutIdx] += jValues_[i] * x[colIdx];
1858 int * cut2rowIdx = NULL;
1859 if (
IsValid(cutStrengthener_) || oaHandler_->logLevel() > 0) {
1860 cut2rowIdx =
new int [numCuts];
1861 for(
int rowIdx = 0 ; rowIdx <
m ; rowIdx++){
1862 if(row2cutIdx[rowIdx] >= 0){
1863 cut2rowIdx[row2cutIdx[rowIdx]] = rowIdx;
1868 for(
int cutIdx = 0; cutIdx < numCuts; cutIdx++) {
1871 double rhs = cuts[cutIdx].dotProduct(x2);
1872 double violation = 0.;
1873 violation = std::max(violation, rhs - ub[cutIdx]);
1874 violation = std::max(violation, lb[cutIdx] - rhs);
1875 if(violation < theta) {
1876 if(oaHandler_->logLevel() > 0)
1877 oaHandler_->message(CUT_NOT_VIOLATED_ENOUGH, oaMessages_)<<cut2rowIdx[cutIdx]<<violation<<CoinMessageEol;
1879 if(oaHandler_->logLevel() > 0)
1880 oaHandler_->message(VIOLATED_OA_CUT_GENERATED, oaMessages_)<<cut2rowIdx[cutIdx]<<violation<<CoinMessageEol;
1882 else if (oaHandler_->logLevel() > 0)
1883 oaHandler_->message(OA_CUT_GENERATED, oaMessages_)<<cut2rowIdx[cutIdx]<<CoinMessageEol;
1887 if (
IsValid(cutStrengthener_)) {
1888 const int& rowIdx = cut2rowIdx[cutIdx];
1890 cutStrengthener_->ComputeCuts(cs,
GetRawPtr(tminlp_),
1892 cuts[cutIdx], lb[cutIdx], ub[cutIdx], g[rowIdx],
1893 rowLower[rowIdx], rowUpper[rowIdx],
1896 (*messageHandler()) <<
"error in cutStrengthener_->ComputeCuts\n";
1901 newCut.setGloballyValidAsInteger(1);
1903 newCut.setEffectiveness(99.99e99);
1904 newCut.setLb(lb[cutIdx]);
1905 newCut.setUb(ub[cutIdx]);
1906 newCut.setRow(cuts[cutIdx]);
1909 if(oaHandler_->logLevel()>2){
1910 oaHandler_->print(newCut);}
1916 delete [] row2cutIdx;
1917 delete [] cut2rowIdx;
1919 if(getObj && !
problem_->hasLinearObjective()) {
1920 double * obj =
new double [
n];
1921 problem_to_optimize_->eval_grad_f(n, x, 1,obj);
1923 problem_to_optimize_->eval_f(n, x, 1, f);
1927 lb[nNonLinear_] = -
f;
1928 ub[nNonLinear_] = -
f;
1930 for(
int i = 0; i<
n ; i++) {
1931 if(
cleanNnz(obj[i],colLower[i], colUpper[i],
1935 ub[nNonLinear_],tiny_, 1
e-15)) {
1938 lb[nNonLinear_] += obj[i] * x[i];
1939 ub[nNonLinear_] += obj[i] * x[i];
1946 double rhs = v.dotProduct(x2);
1947 double violation = std::max(0., rhs - ub[nNonLinear_]);
1948 if(violation < theta) genCut =
false;
1951 if (
IsValid(cutStrengthener_)) {
1952 lb[nNonLinear_] = -
infty;
1954 cutStrengthener_->ComputeCuts(cs,
GetRawPtr(tminlp_),
1956 v, lb[nNonLinear_], ub[nNonLinear_],
1957 ub[nNonLinear_], -infty, 0.,
1960 (*handler_)<<
"error in cutStrengthener_->ComputeCuts"<<CoinMessageEol;
1966 newCut.setGloballyValidAsInteger(1);
1967 newCut.setEffectiveness(99.99e99);
1969 newCut.setLb(-COIN_DBL_MAX);
1970 newCut.setUb(ub[nNonLinear_]);
1987 CouenneMINLPInterface::getConstraintOuterApproximation(OsiCuts &cs,
int rowIdx,
1989 const double * x2,
bool global)
1992 int * indices =
new int[getNumCols()];
1993 double *
values =
new double[getNumCols()];
1995 problem_->eval_grad_gi(getNumCols(), x, 1, rowIdx, nnz, indices, values);
1996 problem_->eval_gi(getNumCols(),x,1, rowIdx, g);
1998 CoinPackedVector cut;
2003 const double rowLower = getRowLower()[rowIdx];
2004 const double rowUpper = getRowUpper()[rowIdx];
2005 const double * colLower = getColLower();
2006 const double * colUpper = getColUpper();
2007 const double dual = (getRowPrice() + 2 * getNumCols())[rowIdx];
2008 double infty = getInfinity();
2009 double nlp_infty = infty_;
2011 if(rowLower > - nlp_infty)
2015 if(rowUpper < nlp_infty)
2019 if(rowLower > -infty && rowUpper < infty)
2027 for(
int i = 0 ; i <
nnz; i++) {
2028 const int &colIdx = indices[i];
2030 if(
cleanNnz(values[i],colLower[colIdx], colUpper[colIdx],
2034 ub, tiny_, veryTiny_)) {
2035 cut.insert(colIdx,values[i]);
2037 lb += values[i] * x[colIdx];
2039 ub += values[i] * x[colIdx];
2046 newCut.setGloballyValidAsInteger(1);
2048 newCut.setEffectiveness(99.99e99);
2059 CouenneMINLPInterface::switchToFeasibilityProblem(
int n,
const double * x_bar,
const int *inds,
2060 double a,
double s,
int L){
2061 if(!
IsValid(feasibilityProblem_)) {
2062 throw SimpleError(
"No feasibility problem",
"getFeasibilityOuterApproximation");
2064 feasibilityProblem_->set_use_feasibility_pump_objective(
true);
2065 feasibilityProblem_->set_dist2point_obj(n,(
const Number *) x_bar,(
const Index *) inds);
2066 feasibilityProblem_->setLambda(a);
2067 feasibilityProblem_->setSigma(s);
2068 feasibilityProblem_->setNorm(L);
2069 feasibilityProblem_->set_use_cutoff_constraint(
false);
2070 feasibilityProblem_->set_use_local_branching_constraint(
false);
2071 problem_to_optimize_ =
GetRawPtr(feasibilityProblem_);
2072 feasibility_mode_ =
true;
2076 CouenneMINLPInterface::switchToFeasibilityProblem(
int n,
const double * x_bar,
const int *inds,
2077 double rhs_local_branching_constraint){
2078 if(!
IsValid(feasibilityProblem_)) {
2079 throw SimpleError(
"No feasibility problem",
"getFeasibilityOuterApproximation");
2081 feasibilityProblem_->set_use_feasibility_pump_objective(
false);
2082 feasibilityProblem_->set_dist2point_obj(n,(
const Number *) x_bar,(
const Index *) inds);
2083 feasibilityProblem_->set_use_cutoff_constraint(
false);
2084 feasibilityProblem_->set_use_local_branching_constraint(
true);
2085 feasibilityProblem_->set_rhs_local_branching_constraint(rhs_local_branching_constraint);
2086 problem_to_optimize_ =
GetRawPtr(feasibilityProblem_);
2087 feasibility_mode_ =
true;
2091 CouenneMINLPInterface::switchToOriginalProblem(){
2093 feasibility_mode_ =
false;
2097 CouenneMINLPInterface::solveFeasibilityProblem(
int n,
const double * x_bar,
const int *inds,
2098 double a,
double s,
int L)
2100 if(!
IsValid(feasibilityProblem_)) {
2101 throw SimpleError(
"No feasibility problem",
"getFeasibilityOuterApproximation");
2103 feasibilityProblem_->set_use_feasibility_pump_objective(
true);
2104 feasibilityProblem_->set_dist2point_obj(n,(
const Number *) x_bar,(
const Index *) inds);
2105 feasibilityProblem_->setLambda(a);
2106 feasibilityProblem_->setSigma(s);
2107 feasibilityProblem_->setNorm(L);
2108 feasibilityProblem_->set_use_cutoff_constraint(
false);
2109 feasibilityProblem_->set_use_local_branching_constraint(
false);
2110 nCallOptimizeTNLP_++;
2111 totalNlpSolveTime_-=CoinCpuTime();
2113 app2->options()->SetIntegerValue(
"print_level", (Index) 0);
2114 optimizationStatus_ = app2->OptimizeTNLP(
GetRawPtr(feasibilityProblem_));
2115 totalNlpSolveTime_+=CoinCpuTime();
2116 hasBeenOptimized_=
true;
2117 return getObjValue();
2121 CouenneMINLPInterface::solveFeasibilityProblem(
int n,
const double * x_bar,
const int *inds,
2122 int L,
double cutoff)
2124 if(!
IsValid(feasibilityProblem_)) {
2125 throw SimpleError(
"No feasibility problem",
"getFeasibilityOuterApproximation");
2127 feasibilityProblem_->set_use_feasibility_pump_objective(
true);
2128 feasibilityProblem_->set_dist2point_obj(n,(
const Number *) x_bar,(
const Index *) inds);
2129 feasibilityProblem_->setLambda(1.0);
2130 feasibilityProblem_->setSigma(0.0);
2131 feasibilityProblem_->setNorm(L);
2132 feasibilityProblem_->set_use_cutoff_constraint(
true);
2133 feasibilityProblem_->set_cutoff(cutoff);
2134 feasibilityProblem_->set_use_local_branching_constraint(
false);
2135 nCallOptimizeTNLP_++;
2136 totalNlpSolveTime_-=CoinCpuTime();
2138 app2->options()->SetIntegerValue(
"print_level", (Index) 0);
2139 optimizationStatus_ = app2->OptimizeTNLP(
GetRawPtr(feasibilityProblem_));
2140 totalNlpSolveTime_+=CoinCpuTime();
2141 hasBeenOptimized_=
true;
2142 return getObjValue();
2146 CouenneMINLPInterface::getFeasibilityOuterApproximation(
int n,
const double * x_bar,
const int *inds, OsiCuts &cs,
bool addOnlyViolated,
bool global)
2148 double ret_val = solveFeasibilityProblem(n, x_bar, inds, 1, 0, 2);
2149 getOuterApproximation(cs, getColSolution(), 0, (addOnlyViolated? x_bar:NULL)
2158 CouenneMINLPInterface::extractLinearRelaxation(OsiSolverInterface &si,
2159 const double * x,
bool getObj)
2161 double * rowLow = NULL;
2162 double * rowUp = NULL;
2168 TNLP::IndexStyleEnum index_style;
2170 problem_to_optimize_->get_nlp_info( n, m, nnz_jac_g, nnz_h_lag, index_style);
2173 if(jRow_ == NULL || jCol_ == NULL || jValues_ == NULL)
2174 initializeJacobianArrays();
2177 problem_to_optimize_->eval_jac_g(n, x, 1, m, nnz_jac_g, NULL, NULL, jValues_);
2180 double *g =
new double[
m];
2181 problem_to_optimize_->eval_g(n, x, 1, m, g);
2183 rowLow =
new double[
m];
2184 rowUp =
new double[
m];
2185 int * nonBindings =
new int[
m];
2186 int numNonBindings = 0;
2187 const double * rowLower = getRowLower();
2188 const double * rowUpper = getRowUpper();
2189 const double * colLower = getColLower();
2190 const double * colUpper = getColUpper();
2191 const double * duals = getRowPrice() + 2*
n;
2192 assert(m==getNumRows());
2193 double infty = si.getInfinity();
2194 double nlp_infty = infty_;
2196 for(
int i = 0 ; i <
m ; i++) {
2197 if(constTypes_[i] == TNLP::NON_LINEAR) {
2199 if(rowLower[i] > -nlp_infty && rowUpper[i] < nlp_infty && fabs(duals[i]) == 0.)
2201 nonBindings[numNonBindings++] = i;
2205 if(rowLower[i] > - nlp_infty){
2206 rowLow[i] = (rowLower[i] - g[i]) - 1
e-07;
2208 messageHandler()->message(WARNING_NON_CONVEX_OA, messages_)<<CoinMessageEol;
2213 rowLow[i] = -
infty;
2214 if(rowUpper[i] < nlp_infty)
2215 rowUp[i] = (rowUpper[i] - g[i]) + 1
e-07;
2220 if(rowLower[i] > -nlp_infty && rowUpper[i] < nlp_infty)
2223 rowLow[i] = -
infty;
2229 if(rowLower[i] > -nlp_infty){
2231 rowLow[i] = (rowLower[i] - g[i]);
2234 rowLow[i] = -
infty;
2235 if(rowUpper[i] < nlp_infty){
2237 rowUp[i] = (rowUpper[i] - g[i]);
2248 for(
int i = 0 ; i < nnz_jac_g ; i++) {
2251 cleanNnz(jValues_[i],colLower[jCol_[i]], colUpper[jCol_[i]],
2252 rowLower[jRow_[i]], rowUpper[jRow_[i]],
2255 rowUp[jRow_[i]], tiny_, veryTiny_)) {
2256 rowLow[jRow_[i]] += jValues_[i] * x[jCol_ [i]];
2257 rowUp[jRow_[i]] += jValues_[i] *x[jCol_[i]];
2261 double value = jValues_[i] * getColSolution()[jCol_[i]];
2262 rowLow[jRow_[i]] += value;
2263 rowUp[jRow_[i]] += value;
2266 CoinPackedMatrix mat(
true, jRow_, jCol_, jValues_, nnz_jac_g);
2267 mat.setDimensions(m,n);
2270 mat.deleteRows(numNonBindings, nonBindings);
2272 int numcols=getNumCols();
2273 double *obj =
new double[numcols];
2274 for(
int i = 0 ; i < numcols ; i++)
2278 si.loadProblem(mat, getColLower(), getColUpper(), obj, rowLow, rowUp);
2281 delete [] nonBindings;
2283 for(
int i = 0 ; i < getNumCols() ; i++) {
2288 bool addObjVar =
false;
2289 if(
problem_->hasLinearObjective()){
2295 problem_to_optimize_->eval_f(n, obj, 1, zero);
2296 si.setDblParam(OsiObjOffset, -zero);
2301 problem_to_optimize_->eval_grad_f(n, x, 1,obj);
2302 si.setObjective(obj);
2313 si.addCol(a,-si.getInfinity(), si.getInfinity(), 1.);
2317 problem_to_optimize_->eval_grad_f(n, x, 1,obj);
2319 problem_to_optimize_->eval_f(n, x, 1, ub);
2322 CoinPackedVector objCut;
2323 CoinPackedVector * v = &objCut;
2325 for(
int i = 0; i<
n ; i++) {
2328 if(
cleanNnz(obj[i],colLower[i], colUpper[i],
2332 ub, tiny_, veryTiny_)) {
2333 v->insert(i,obj[i]);
2334 lb += obj[i] * x[i];
2335 ub += obj[i] * x[i];
2340 if(
cleanNnz(obj[i],colLower[i], colUpper[i],
2344 ub, 1
e-03, 1
e-08)) {
2345 v->insert(i,obj[i]);
2346 lb += obj[i] * x[i];
2347 ub += obj[i] * x[i];
2352 si.addRow(objCut, lb, ub);
2361 CouenneMINLPInterface::applyRowCuts(
int numberCuts,
const OsiRowCut * cuts)
2365 const OsiRowCut ** cutsPtrs =
new const OsiRowCut*[numberCuts];
2366 for(
int i = 0 ; i < numberCuts ; i++)
2368 cutsPtrs[i] = &cuts[i];
2370 problem_->addCuts(numberCuts, cutsPtrs);
2375 CouenneMINLPInterface::solveAndCheckErrors(
bool warmStarted,
bool throwOnFailure,
2376 const char * whereFrom)
2378 totalNlpSolveTime_-=CoinCpuTime();
2380 optimizationStatus_ = app_->ReOptimizeTNLP(
GetRawPtr(problem_to_optimize_));
2382 optimizationStatus_ = app_->OptimizeTNLP(
GetRawPtr(problem_to_optimize_));
2383 totalNlpSolveTime_+=CoinCpuTime();
2384 nCallOptimizeTNLP_++;
2385 hasBeenOptimized_ =
true;
2389 if(!hasPrintedOptions) {
2390 hasPrintedOptions = 1;
2392 app_->options()->SetStringValue(
"print_user_options",
"no",
false,
true);
2395 bool otherDisagree = false ;
2397 if(optimizationStatus_ == TNLPSolver::notEnoughFreedom)
2399 (*messageHandler())<<
"Too few degrees of freedom...."<<CoinMessageEol;
2400 int numrows = getNumRows();
2401 int numcols = getNumCols();
2403 const double * colLower = getColLower();
2404 const double * colUpper = getColUpper();
2407 const double * rowLower = getRowLower();
2408 const double * rowUpper = getRowUpper();
2410 int numberFixed = 0;
2411 for(
int i = 0 ; i < numcols ; i++)
2413 if(colUpper[i] - colLower[i] <=
INT_BIAS)
2418 int numberEqualities = 0;
2419 for(
int i = 0 ; i < numrows ; i++)
2421 if(rowUpper[i] - rowLower[i] <=
INT_BIAS)
2426 if(numcols - numberFixed > numberEqualities || numcols < numberEqualities)
2428 std::string probName;
2429 getStrParam(OsiProbName, probName);
2430 throw newUnsolvedError(app_->errorCode(),
problem_, probName);
2432 double * saveColLow = CoinCopyOfArray(getColLower(), getNumCols());
2433 double * saveColUp = CoinCopyOfArray(getColUpper(), getNumCols());
2435 for(
int i = 0; i < numcols && numcols - numberFixed <= numberEqualities ; i++)
2437 if(colUpper[i] - colLower[i] <=
INT_BIAS)
2439 setColLower(i, saveColLow[i]-1
e-06);
2440 setColUpper(i, saveColLow[i]+1
e-06);
2444 solveAndCheckErrors(warmStarted, throwOnFailure, whereFrom);
2446 for(
int i = 0; i < numcols && numcols - numberFixed < numrows ; i++)
2448 problem_->SetVariableLowerBound(i,saveColLow[i]);
2449 problem_->SetVariableUpperBound(i,saveColUp[i]);
2451 delete [] saveColLow;
2452 delete [] saveColUp;
2457 if(!app_->isRecoverable(optimizationStatus_))
2459 std::string probName;
2460 getStrParam(OsiProbName, probName);
2461 throw newUnsolvedError(app_->errorCode(),
problem_, probName);
2463 else if(testOthers_ && !app_->isError(optimizationStatus_)){
2468 i != debug_apps_.end() ; i++){
2469 TNLPSolver::ReturnStatus otherStatus = (*i)->OptimizeTNLP(
GetRawPtr(problem_copy));
2470 messageHandler()->message(LOG_LINE, messages_)
2471 <<
'd'<<f++<<statusAsString(otherStatus)<<problem_copy->obj_value()
2472 <<(*i)->IterationCount()<<(*i)->CPUTime()<<CoinMessageEol;
2473 if(!(*i)->isError(otherStatus)){
2474 CoinRelFltEq eq(1
e-05);
2475 if(otherStatus != optimizationStatus_){
2476 otherDisagree =
true;
2477 messageHandler()->message(SOLVER_DISAGREE_STATUS, messages_)
2478 <<app_->solverName()<<statusAsString()
2479 <<(*i)->solverName()<<statusAsString(otherStatus)<<CoinMessageEol;
2481 else if(isProvenOptimal() && !eq(
problem_->obj_value(),problem_copy->obj_value()))
2483 otherDisagree =
true;
2484 messageHandler()->message(SOLVER_DISAGREE_VALUE, messages_)
2485 <<app_->solverName()<<
problem_->obj_value()
2486 <<(*i)->solverName()<<problem_copy->obj_value()<<CoinMessageEol;
2492 totalIterations_ += app_->IterationCount();
2494 catch(SimpleError &E)
2498 throw SimpleError(
"No statistics available from Ipopt",whereFrom);
2504 if(
problem_->hasUpperBoundingObjective()){
2505 const double * sol = getColSolution();
2506 bool integerSol =
true;
2507 double intTol = 1
e-08;
2509 int nObjects = numberObjects();
2510 OsiObject **
object = objects();
2511 for(
int i = 0 ; i< nObjects ; i++){
2513 if(
object[i]->infeasibility(
this,dummy) > intTol)
2521 int numcols = getNumCols();
2522 for(
int i = 0 ; i < numcols ; i++){
2524 if(fabs(sol[i] - floor(sol[i]+0.5)) > intTol){
2531 if(integerSol&&isProvenOptimal()){
2532 double help=
problem_->evaluateUpperBoundingFunction(sol);
2535 OsiAuxInfo * auxInfo = getAuxiliaryInfo();
2540 if(help<bonInfo->bestObj2())
2543 bonInfo->
setBestSolution2(getNumCols(), const_cast<double *>(getColSolution()));
2545 messageHandler()->message(ALTERNATE_OBJECTIVE, messages_)
2546 <<help<<CoinMessageEol;
2550 printf(
"\nWARNING: the algorithm selected does not consider the second objective function\n");
2554 messageHandler()->message(IPOPT_SUMMARY, messages_)
2555 <<whereFrom<<optimizationStatus_<<app_->IterationCount()<<app_->CPUTime()<<CoinMessageEol;
2557 if((nCallOptimizeTNLP_ % 20) == 1)
2558 messageHandler()->message(LOG_HEAD, messages_)<<CoinMessageEol;
2561 if ( (numIterationSuspect_ >= 0 && (getIterationCount()>numIterationSuspect_ || isAbandoned())) ||
2563 messageHandler()->message(SUSPECT_PROBLEM,
2564 messages_)<<nCallOptimizeTNLP_<<CoinMessageEol;
2565 std::string subProbName;
2566 getStrParam(OsiProbName, subProbName);
2567 std::ostringstream os;
2568 os<<
"_"<<nCallOptimizeTNLP_;
2569 subProbName+=os.str();
2570 problem_->outputDiffs(subProbName, NULL);
2579 void CouenneMINLPInterface::initialSolve()
2588 if(!hasPrintedOptions) {
2590 app_->options()->GetEnumValue(
"print_user_options",printOptions,
"bonmin.");
2592 app_->options()->SetStringValue(
"print_user_options",
"yes",
true,
true);
2594 if(exposeWarmStart_)
2595 app_->disableWarmStart();
2596 solveAndCheckErrors(0,1,
"initialSolve");
2599 if(!hasPrintedOptions) {
2600 hasPrintedOptions = 1;
2601 app_->options()->SetStringValue(
"print_user_options",
"no");
2602 app_->options()->SetIntegerValue(
"print_level",0);
2605 messageHandler()->message(LOG_FIRST_LINE, messages_)<<nCallOptimizeTNLP_
2608 <<app_->IterationCount()
2612 int numRetry = firstSolve_ ? numRetryInitial_ : numRetryResolve_;
2614 resolveForRobustness(numRetryUnsolved_);
2618 resolveForCost(numRetry, numRetryInitial_ > 0);
2620 numRetryInitial_ = 0;
2622 firstSolve_ =
false;
2626 if (! warmstart_ && ! isAbandoned()) {
2627 if (exposeWarmStart_) {
2628 warmstart_ = app_->getWarmStart(
problem_);
2636 CouenneMINLPInterface::resolve()
2641 int has_warmstart = warmstart_ == NULL ? 0 : 1;
2642 if(warmstart_ == NULL) has_warmstart = 0;
2643 else if(!app_->warmStartIsValid(warmstart_)) has_warmstart = 1;
2644 else has_warmstart = 2;
2645 if (has_warmstart < 2) {
2650 app_->setWarmStart(warmstart_,
problem_);
2655 app_->options()->SetStringValue(
"warm_start_same_structure",
"yes");
2658 app_->options()->SetStringValue(
"warm_start_same_structure",
"no");
2662 app_->enableWarmStart();
2663 else app_->disableWarmStart();
2664 solveAndCheckErrors(1,1,
"resolve");
2666 messageHandler()->message(LOG_FIRST_LINE, messages_)<<nCallOptimizeTNLP_
2669 <<app_->IterationCount()
2670 <<app_->CPUTime()<<CoinMessageEol;
2673 resolveForRobustness(numRetryUnsolved_);
2675 else if(numRetryResolve_ ||
2676 (numRetryInfeasibles_ && isProvenPrimalInfeasible() ))
2677 resolveForCost(std::max(numRetryResolve_, numRetryInfeasibles_), 0);
2681 if (! warmstart_ && ! isAbandoned()) {
2682 if (exposeWarmStart_) {
2683 warmstart_ = app_->getWarmStart(
problem_);
2693 bool CouenneMINLPInterface::isAbandoned()
const
2696 (optimizationStatus_==TNLPSolver::iterationLimit)||
2697 (optimizationStatus_==TNLPSolver::computationError)||
2698 (optimizationStatus_==TNLPSolver::illDefinedProblem)||
2699 (optimizationStatus_==TNLPSolver::illegalOption)||
2700 (optimizationStatus_==TNLPSolver::externalException)|
2701 (optimizationStatus_==TNLPSolver::exception)
2706 bool CouenneMINLPInterface::isProvenOptimal()
const
2708 return (optimizationStatus_==TNLPSolver::solvedOptimal) ||
2709 (optimizationStatus_==TNLPSolver::solvedOptimalTol);
2712 bool CouenneMINLPInterface::isProvenPrimalInfeasible()
const
2714 return (optimizationStatus_ == TNLPSolver::provenInfeasible);
2717 bool CouenneMINLPInterface::isProvenDualInfeasible()
const
2719 return (optimizationStatus_ == TNLPSolver::unbounded);
2722 bool CouenneMINLPInterface::isPrimalObjectiveLimitReached()
const
2724 (*handler_)<<
"Warning : isPrimalObjectiveLimitReached not implemented yet"<<CoinMessageEol;
2728 bool CouenneMINLPInterface::isDualObjectiveLimitReached()
const
2731 return (optimizationStatus_==TNLPSolver::unbounded);
2735 bool CouenneMINLPInterface::isIterationLimitReached()
const
2737 return (optimizationStatus_==TNLPSolver::iterationLimit);
2741 CouenneMINLPInterface::extractInterfaceParams()
2745 app_->options()->GetIntegerValue(
"nlp_log_level", logLevel,
"bonmin.");
2746 messageHandler()->setLogLevel(logLevel);
2748 #ifdef COIN_HAS_FILTERSQP
2749 FilterSolver * filter =
dynamic_cast<FilterSolver *
>(
GetRawPtr(app_));
2753 app_->options()->GetNumericValue(
"max_random_point_radius",maxRandomRadius_,
"bonmin.");
2755 #ifdef COIN_HAS_FILTERSQP
2756 if(filter && !is_given){
2758 maxRandomRadius_ = 10.;
2762 int oaCgLogLevel = 0;
2763 app_->options()->GetIntegerValue(
"oa_cuts_log_level", oaCgLogLevel,
"bonmin.");
2764 oaHandler_->setLogLevel(oaCgLogLevel);
2766 int exposeWs =
false;
2767 app_->options()->GetEnumValue(
"warm_start", exposeWs,
"bonmin.");
2768 setExposeWarmStart(exposeWs > 0);
2770 app_->options()->GetIntegerValue(
"num_retry_unsolved_random_point", numRetryUnsolved_,
"bonmin.");
2771 app_->options()->GetIntegerValue(
"num_resolve_at_root", numRetryInitial_,
"bonmin.");
2772 app_->options()->GetIntegerValue(
"num_resolve_at_node", numRetryResolve_,
"bonmin.");
2773 app_->options()->GetIntegerValue(
"num_resolve_at_infeasibles", numRetryInfeasibles_,
"bonmin.");
2774 app_->options()->GetIntegerValue(
"num_iterations_suspect", numIterationSuspect_,
"bonmin.");
2775 app_->options()->GetEnumValue(
"nlp_failure_behavior",pretendFailIsInfeasible_,
"bonmin.");
2776 app_->options()->GetNumericValue
2777 (
"warm_start_bound_frac" ,pushValue_,
"bonmin.");
2778 app_->options()->GetNumericValue(
"tiny_element",tiny_,
"bonmin.");
2779 app_->options()->GetNumericValue(
"very_tiny_element",veryTiny_,
"bonmin.");
2780 app_->options()->GetNumericValue(
"random_point_perturbation_interval",max_perturbation_,
"bonmin.");
2781 app_->options()->GetEnumValue(
"random_point_type",randomGenerationType_,
"bonmin.");
2782 int cut_strengthening_type;
2783 app_->options()->GetEnumValue(
"cut_strengthening_type", cut_strengthening_type,
"bonmin.");
2785 if (cut_strengthening_type !=
CS_None) {
2787 cutStrengthener_ =
new CutStrengthener(app_->clone(), app_->options());
2795 strong_branching_solver_ = strong_branching_solver;
2799 #ifdef STRONG_COMPARE
2800 static double objorig;
2804 CouenneMINLPInterface::markHotStart()
2806 if (
IsValid(strong_branching_solver_)) {
2807 #ifdef STRONG_COMPARE
2809 OsiSolverInterface::markHotStart();
2810 objorig = getObjValue();
2812 optimizationStatusBeforeHotStart_ = optimizationStatus_;
2813 strong_branching_solver_->markHotStart(
this);
2817 OsiSolverInterface::markHotStart();
2822 CouenneMINLPInterface::solveFromHotStart()
2824 if (
IsValid(strong_branching_solver_)) {
2825 #ifdef STRONG_COMPARE
2827 OsiSolverInterface::solveFromHotStart();
2828 double obj_nlp = getObjValue() - objorig;
2830 optimizationStatus_ = strong_branching_solver_->solveFromHotStart(
this);
2831 hasBeenOptimized_ =
true;
2832 #ifdef STRONG_COMPARE
2833 double obj_other = getObjValue() - objorig;
2834 printf(
"AWDEBUG: Strong Branching results: NLP = %15.8e Other = %15.8e\n",
2835 obj_nlp, obj_other);
2840 OsiSolverInterface::solveFromHotStart();
2845 CouenneMINLPInterface::unmarkHotStart()
2847 if (
IsValid(strong_branching_solver_)) {
2848 #ifdef STRONG_COMPARE
2850 OsiSolverInterface::unmarkHotStart();
2852 strong_branching_solver_->unmarkHotStart(
this);
2853 optimizationStatus_ = optimizationStatusBeforeHotStart_;
2857 OsiSolverInterface::unmarkHotStart();
2861 const double * CouenneMINLPInterface::getObjCoefficients()
const
2863 const int n = getNumCols();
2866 obj_ =
new double[
n];
2869 const double* x_sol =
problem_->x_sol();
2870 bool retval =
problem_->eval_grad_f(n, x_sol, new_x, obj_);
2874 fprintf(stderr,
"ERROR WHILE EVALUATING GRAD_F in CouenneMINLPInterface::getObjCoefficients()\n");
CouNumber solve(CouNumber *solution)
solves and returns the optimal objective function and the solution
void setBestSolution2(int n, double *d)
pos
position where the operator should be printed when printing the expression
void setInitSol(const CouNumber *sol)
sets the initial solution for the NLP solver
void fint fint fint real * a
bool IsValid(const OSSmartPtr< U > &smart_ptr)
Ipopt interior point algorithm
void setBestObj2(double o)
Set an alternate objective value.
CouenneProblem * problem() const
return pointer to Couenne problem
Solver
Solvers for solving nonlinear programs.
The IpoptSolver class solves problems using Ipopt.
void fint fint fint real fint real real real real * f
Ipopt::OptionsList * options() const
return pointer to options
SimpleReferenced< X > * make_referenced(X other)
void fint fint fint real fint real real real real real real real real real * e
filterSQP Sequential Quadratic Programming algorithm
CouenneProblem * clone() const
Clone method (for use within CouenneCutGenerator::clone)
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real * s
static bool WarnedForNonConvexOa
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real * ws
double CouNumber
main number type in Couenne
static bool cleanNnz(double &value, double colLower, double colUpper, double rowLower, double rowUpper, double colsol, double &lb, double &ub, double tiny, double veryTiny)
#define ADD_MSG(Id, Type, Level, MSG)
static void register_OA_options(SmartPtr< RegisteredOptions > roptions)
void fint fint fint real fint real real real real real real * g
CouenneProblem * problem_
Symbolic representation of the problem.
int nnz
ATTENTION: Filter expect the jacobian to be ordered by row.
static void register_general_options(SmartPtr< RegisteredOptions > roptions)
Register options.
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
Bonmin class for passing info between components of branch-and-cuts.
void fint fint fint real fint real * x
bool isInteger(CouNumber x)
is this number integer?