Changeset 6083


Ignore:
Timestamp:
12/09/08 23:50:34 (5 years ago)
Author:
jdsiiro
Message:
  • adding <PrintCache?> command to print out the contents of a cache
  • bugfixes to inter-solver point cache management
  • adding additional tests of inter-solver point caches
Location:
colin/trunk
Files:
8 added
4 edited

Legend:

Unmodified
Added
Removed
  • colin/trunk/colin/ExecuteMngr.h

    r5786 r6083  
    9494 
    9595   /// Define a new command handler (ExecuteManager will own & delete pointer) 
    96    void register_command( const std::string& name, 
     96   bool register_command( const std::string& name, 
    9797                          ExecuteFunctor* fcn ); 
    9898 
  • colin/trunk/src/ExecuteMngr.cpp

    r6038 r6083  
    328328 
    329329 
    330 void 
     330bool 
    331331ExecuteManager::register_command( const std::string& name,  
    332332                                  ExecuteFunctor* fcn ) 
     
    342342      EXCEPTION_MNGR(std::runtime_error, "ExecuteManager::register_command(): " 
    343343                     "duplicate command name, \"" << ans.first->first << "\""); 
     344 
     345   return true; 
    344346} 
    345347 
  • colin/trunk/src/OptSolver_Base.cpp

    r6082 r6083  
    322322      (node, "clear", data->init_cache.reset, false); 
    323323 
     324   data->init_cache.points.clear(); 
    324325   TiXmlElement* elt = node->FirstChildElement();  
    325326   if ( elt == NULL ) 
     
    426427{ 
    427428   CacheHandle cache = CacheFactory().get_cache(data->final_cache.name); 
    428    if ( data->final_cache.reset ) 
     429   if ( data->final_cache.reset && ! cache.empty() ) 
    429430   { 
    430431      // Don't clear the cache (we might be using it for our input 
  • colin/trunk/src/ResponseCache.cpp

    r5786 r6083  
    1818#include <colin/ResponseCache.h> 
    1919#include <colin/ResponseCacheFactory.h> 
     20 
     21#include <colin/ExecuteMngr.h> 
     22#include <colin/ApplicationMngr.h> 
     23#include <colin/SolverMngr.h> 
     24 
    2025#include <utilib/TinyXML_helper.h> 
    2126 
     
    3439 
    3540namespace colin { 
     41 
     42class PrintCacheExecuteFunctor : public ExecuteManager::ExecuteFunctor 
     43{ 
     44public: 
     45   PrintCacheExecuteFunctor() 
     46   {} 
     47 
     48   virtual void execute(TiXmlElement* node) 
     49   { 
     50      string cache_name = ""; 
     51      utilib::get_string_attribute 
     52         ( node, "cache", cache_name, ImplicitInterSolverCacheName ); 
     53 
     54      string pname = ""; 
     55      bool found_problem = utilib::get_string_attribute 
     56         ( node, "problem", pname, ApplicationMngr().get_newest_application() ); 
     57 
     58      string sname = ""; 
     59      bool found_solver = utilib::get_string_attribute 
     60         ( node, "solver", sname, SolverMngr().get_newest_solver() ); 
     61 
     62 
     63      CacheHandle cache = CacheFactory().get_cache(cache_name); 
     64      if ( cache.empty() ) 
     65      { 
     66         std::cout << "<PrintCache> ERROR: unknown cache '"  
     67                   << cache_name << "'" << endl; 
     68         return; 
     69      } 
     70 
     71      if ( found_solver && found_problem ) 
     72         EXCEPTION_MNGR(std::runtime_error,  
     73                        "PrintCacheExecuteFunctor::execute(): " 
     74                        "cannot specify both problem_context and " 
     75                        "solver_context in "  
     76                        << utilib::get_element_info(node)); 
     77 
     78      ApplicationHandle problem; 
     79      if ( found_solver ) 
     80      { 
     81         SolverHandle solver = SolverMngr().get_solver(sname); 
     82         if ( ! solver.empty() ) 
     83            problem = solver->get_problem_handle(); 
     84      } 
     85      if ( problem.empty() ) 
     86         problem = ApplicationMngr().get_application(pname); 
     87      if ( problem.empty() ) 
     88         EXCEPTION_MNGR(std::runtime_error, 
     89                        "PrintCacheExecuteFunctor::execute(): " 
     90                        "cannot find problem context at " 
     91                        << utilib::get_element_info(node)); 
     92      AppRequest req = problem->set_domain(Any()); 
     93      std::cout << "Cache '" << cache_name << "' contains "; 
     94      cache->print(std::cout, req); 
     95   } 
     96}; 
     97 
     98namespace { 
     99 
     100const volatile bool registered = 
     101   ExecuteMngr().register_command("PrintCache", new PrintCacheExecuteFunctor); 
     102 
     103} // namespace colin::(local) 
     104 
    36105 
    37106//================================================================ 
     
    83152   list<AppResponse> responses; 
    84153   size_t count = getResponses(request, responses); 
    85    os << count << " Responses" << ( count > 0 ? ":" : "." ) << endl; 
     154   os << count << " Response"  
     155      << ( count > 0 ? (count > 1 ? "s:" : ":") : "." ) << endl; 
    86156 
    87157   stringstream tmp; 
    88158   for ( ; ! responses.empty(); responses.pop_front() ) 
    89159      tmp << responses.front(); 
    90    string buf; 
    91    while ( tmp >> buf ) 
    92       os << "  " << buf; 
     160   os << tmp.str(); 
    93161} 
    94162 
Note: See TracChangeset for help on using the changeset viewer.