hs071_main.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (C) 2005, 2009 International Business Machines and others.
  2. // All Rights Reserved.
  3. // This code is published under the Eclipse Public License.
  4. //
  5. // $Id: hs071_main.cpp 2398 2013-10-19 18:08:59Z stefan $
  6. //
  7. // Authors: Carl Laird, Andreas Waechter IBM 2005-08-10
  8. #include "IpIpoptApplication.hpp"
  9. #include "hs071_nlp.hpp"
  10. #include <iostream>
  11. using namespace Ipopt;
  12. int main4(int argv, char* argc[])
  13. {
  14. // Create a new instance of your nlp
  15. // (use a SmartPtr, not raw)
  16. SmartPtr<TNLP> mynlp = new HS071_NLP();
  17. // Create a new instance of IpoptApplication
  18. // (use a SmartPtr, not raw)
  19. // We are using the factory, since this allows us to compile this
  20. // example with an Ipopt Windows DLL
  21. SmartPtr<IpoptApplication> app = IpoptApplicationFactory();
  22. app->RethrowNonIpoptException(true);
  23. // Change some options
  24. // Note: The following choices are only examples, they might not be
  25. // suitable for your optimization problem.
  26. app->Options()->SetNumericValue("tol", 1e-7);
  27. app->Options()->SetStringValue("mu_strategy", "adaptive");
  28. app->Options()->SetStringValue("output_file", "ipopt.out");
  29. // The following overwrites the default name (ipopt.opt) of the
  30. // options file
  31. // app->Options()->SetStringValue("option_file_name", "hs071.opt");
  32. // Initialize the IpoptApplication and process the options
  33. ApplicationReturnStatus status;
  34. status = app->Initialize();
  35. if (status != Solve_Succeeded) {
  36. std::cout << std::endl << std::endl << "*** Error during initialization!" << std::endl;
  37. return (int) status;
  38. }
  39. // Ask Ipopt to solve the problem
  40. status = app->OptimizeTNLP(mynlp);
  41. if (status == Solve_Succeeded) {
  42. std::cout << std::endl << std::endl << "*** The problem solved!" << std::endl;
  43. }
  44. else {
  45. std::cout << std::endl << std::endl << "*** The problem FAILED!" << std::endl;
  46. }
  47. // As the SmartPtrs go out of scope, the reference count
  48. // will be decremented and the objects will automatically
  49. // be deleted.
  50. return (int) status;
  51. }