00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "CbcModel.hpp"
00012 #include "CoinTime.hpp"
00013 #include "CoinHelperFunctions.hpp"
00014
00015 #include "CouenneFeasPump.hpp"
00016 #include "CouenneMINLPInterface.hpp"
00017 #include "CouenneProblem.hpp"
00018 #include "CouenneProblemElem.hpp"
00019 #include "CouenneCutGenerator.hpp"
00020
00021 #include "CouenneTNLP.hpp"
00022
00023 using namespace Ipopt;
00024 using namespace Couenne;
00025
00027 CouNumber CouenneFeasPump::solveNLP (const CouNumber *iSol, CouNumber *&nSol) {
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 bool firstNLP = (nlp_ == NULL);
00056
00057 if (firstNLP)
00058 nlp_ = new CouenneTNLP (problem_);
00059
00060 problem_ -> domain () -> push (problem_ -> nVars (),
00061 iSol,
00062 problem_ -> domain () -> lb (),
00063 problem_ -> domain () -> ub ());
00064
00065
00066
00067 expression
00068 *oldObj = problem_ -> Obj (0) -> Body (),
00069 *newObj = updateNLPObj (iSol);
00070
00071 newObj -> realign (problem_);
00072 problem_ -> setObjective (0, newObj);
00073 nlp_ -> setObjective (newObj);
00074
00075 if (problem_ -> Jnlst () -> ProduceOutput (J_ALL, J_NLPHEURISTIC)) {
00076 printf ("----------------------- now solving NLP:\n");
00077 problem_ -> print ();
00078 printf ("-----------------------\n");
00079 }
00080
00081
00082
00083
00084 nlp_ -> setInitSol (iSol);
00085
00087
00088 ApplicationReturnStatus status = firstNLP ?
00089 app_ -> OptimizeTNLP (nlp_) :
00090 app_ -> ReOptimizeTNLP (nlp_);
00091
00093
00094 if (nlp_ -> getSolution ())
00095
00096 if (nSol) CoinCopyN (nlp_ -> getSolution (), problem_ -> nVars (), nSol);
00097 else nSol = CoinCopyOfArray (nlp_ -> getSolution (), problem_ -> nVars ());
00098
00099 else problem_ -> Jnlst () -> Printf (J_WARNING, J_NLPHEURISTIC, "FP: warning, NLP returns a NULL solution\n");
00100
00101 if (nlp_ -> getSolution () && (problem_ -> Jnlst () -> ProduceOutput (J_ALL, J_NLPHEURISTIC))) {
00102 printf ("######################## NLP solution (nlp):\n");
00103 for (int i=0; i< problem_ -> nVars ();) {
00104 printf ("%+e ", nSol [i]);
00105 if (!(++i % 15)) printf ("\n");
00106 }
00107 }
00108
00109 delete newObj;
00110
00111 CouNumber retval;
00112
00113 problem_ -> setObjective (0, oldObj);
00114
00115 if ((status != Solve_Succeeded) &&
00116 (status != Solved_To_Acceptable_Level))
00117
00118 problem_ -> Jnlst () -> Printf
00119 (J_WARNING, J_NLPHEURISTIC, "Feasibility Pump: Error solving NLP problem\n");
00120
00121 retval = nlp_ -> getSolValue ();
00122
00123 problem_ -> domain () -> pop ();
00124
00125 return retval;
00126 }