MeshKit  1.0
IASolverRelaxed.cpp
Go to the documentation of this file.
00001 // IASolverRelaxed.cpp
00002 // Interval Assignment for Meshkit
00003 //
00004 #include "meshkit/IASolverRelaxed.hpp"
00005 #include "meshkit/IANlp.hpp"
00006 
00007 #include <stdio.h>
00008 #include <math.h>
00009 #include <limits.h>
00010 
00011 #include "IpIpoptApplication.hpp"
00012 
00013 namespace MeshKit {
00014     
00015 IASolverRelaxed::IASolverRelaxed(const IAData *ia_data, IASolution *relaxed_solution,   
00016                                  const bool set_silent) : 
00017   IASolverTool( ia_data, relaxed_solution, true ),  // debug
00018   p_norm(3), 
00019 silent(set_silent), debugging(false) {}
00020 //silent(false), debugging(true) {}
00021 
00023 IASolverRelaxed::~IASolverRelaxed() {}
00024 
00025 bool IASolverRelaxed::solve()
00026 {
00027   
00028   // solve the nlp to get a non-integral solution, which we hope is close to a good integer solution    
00029   // adapted from HS071 ipopt example
00030 
00031   // p_norm set in constructor. 3 seems to work well, comes close to lex-max-min
00032   // smaller p has the effect of valuing the fidelity of shorter curves over longer curves more
00033   // larger p approaches min max
00034   IANlp *myianlp = new IANlp(iaData, iaSolution, silent);
00035   Ipopt::SmartPtr<TNLP> mynlp = myianlp; // Ipopt requires the use of smartptrs!
00036   
00037   Ipopt::SmartPtr<Ipopt::IpoptApplication> app = IpoptApplicationFactory();
00038   app->Options()->SetNumericValue("tol", 1e-7); // 2 seems close enough, could do less, say .1
00039   app->Options()->SetStringValue("mu_strategy", "adaptive");
00040   // print level 0 to 12, most. Ipopt Default is 5
00041   int print_level = (silent) ? 0 : 1; // 1, 5
00042   // int print_level = 5;
00043   app->Options()->SetIntegerValue("print_level", print_level);  
00044   // uncomment next line to write the solution to an output file
00045   // app->Options()->SetStringValue("output_file", "IA.out");  
00046   // The following overwrites the default name (ipopt.opt) of the options file
00047   // app->Options()->SetStringValue("option_file_name", "IA.opt");
00048   
00049   // Intialize the IpoptApplication and process the options
00050   Ipopt::ApplicationReturnStatus status;
00051   status = app->Initialize();
00052   if (status != Ipopt::Solve_Succeeded) {
00053     if (!silent)
00054       printf("\n\n*** Error during ipopt initialization!\n");
00055     return (int) status;
00056   }
00057   
00058   // Ask Ipopt to solve the problem
00059   status = app->OptimizeTNLP(mynlp); // the inherited IANlp
00060   // todo: also check for a valid solution even if ! Solve_Succeeded, such as a sub-optimal time-out
00061   bool is_solved = (status == Ipopt::Solve_Succeeded);
00062   bool is_satisfied = is_solved && equal_constraints( false, debugging );
00063   // don't check even-ness, as those are like the integrality constraints and are not solved here
00064   
00065   if (!silent)
00066   {
00067     if (is_solved) {
00068       printf("\n\n*** The relaxed problem solved!");
00069       if (!is_satisfied)
00070         printf(" But equality-constraints were VIOLATED!");
00071       printf("\n");
00072     }
00073     else {
00074       printf("\n\n*** The relaxed problem FAILED!\n");
00075     }
00076   }
00077   return is_satisfied;
00078 }  
00079 
00080 } // namespace MeshKit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines