MeshKit  1.0
IASolver.cpp
Go to the documentation of this file.
00001 // IASolver.cpp
00002 // Interval Assignment for Meshkit
00003 //
00004 #include "IASolver.hpp"
00005 #include "IPData.hpp"
00006 // #include "IAMilp.hpp"
00007 #include "IASolverRelaxed.hpp"
00008 #include "IASolverInt.hpp"
00009 
00010 #include <cstdlib>
00011 #include <stdio.h>
00012 #include <math.h>
00013 #include <limits.h>
00014 
00015 // timing tests
00016 #include <time.h> //zzyk
00017 #include <iostream>
00018 
00019 namespace MeshKit 
00020 {
00021     
00022 IASolver::IASolver(IAData *ia_data_ptr, IASolution *ia_solution_ptr)
00023   : IASolverToolInt( ia_data_ptr, ia_solution_ptr ),
00024    debugging(true) 
00025   // debugging(false) 
00026   {}
00027 
00029 IASolver::~IASolver() {}
00030 
00031 
00032 bool IASolver::solve_relaxed()
00033 {
00034   IASolverRelaxed relaxed(ia_data(), ia_solution(), !debugging); 
00035   bool succeeded=relaxed.solve();
00036   return succeeded;
00037 }  
00038 
00039 
00040 /* milp solution is too slow
00041 bool IASolver::solve_int()
00042 {
00043   IAMilp milp(this,this);
00044   bool succeeded=milp.solve();
00045   return succeeded;
00046 }  
00047 */
00048 
00049 bool IASolver::solve_int()
00050 {
00051   // set relaxed solution to this's solution (from solve_relaxed)
00052   IASolverInt solver_int(ia_data(), ia_solution(), !debugging);
00053   bool succeeded=solver_int.solve();
00054   return succeeded;
00055 }  
00056 
00057 bool IASolver::solve_even()
00058 {
00059   bool succeeded=true;
00060   return succeeded;
00061 }  
00062 
00063 
00064 bool IASolver::solve()
00065 {
00066 
00067   if (debugging)
00068   {
00069     printf("Solving subproblem %p\n", this);
00070     print_problem();
00071   }
00072   
00073   // todo: subdivide problem into independent sub-problems for speed
00074   //zzyk
00075   clock_t t = clock();
00076   bool relaxed_succeeded = solve_relaxed();
00077   print_solution();
00078 
00079   t = clock()-t;
00080   float seconds = ((float)t)/CLOCKS_PER_SEC;
00081   std::cout << "relaxed solution " << ((relaxed_succeeded) ? "succeeded" : "failed") <<  " took " << seconds << " seconds" << std::endl;
00082 
00083   t = clock();
00084   bool int_succeeded = relaxed_succeeded && solve_int();
00085   t = clock()-t;
00086   seconds = ((float)t)/CLOCKS_PER_SEC;
00087   std::cout << "integer solution " << ((int_succeeded) ? "succeeded" : "failed") << " took " << seconds << " seconds" << std::endl;
00088 
00089   bool even_succeeded = int_succeeded && solve_even();
00090   
00091   if (debugging)
00092   {
00093     printf("==========IA summary:\n"); 
00094     if (relaxed_succeeded)
00095     {
00096       printf(" relaxed succeeded\n");
00097       if (int_succeeded)
00098       {
00099         printf(" integer succeeded\n");
00100         if (even_succeeded)
00101         {
00102           printf(" even succeeded\n");
00103         }
00104         else
00105         {
00106           printf(" even failed\n");        
00107         }
00108       }
00109       else
00110       {
00111         printf(" integer failed\n");        
00112       }
00113     }
00114     else
00115     {
00116       printf(" relaxed failed\n");
00117     }  
00118     print_solution();
00119   }
00120           
00121   return even_succeeded;
00122 }
00123 
00124 
00125 } // namespace MeshKit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines