Changeset 7457


Ignore:
Timestamp:
05/10/12 11:53:54 (2 years ago)
Author:
jdsiiro
Message:

StateMachineLS:

  • fixing how step evaluations get queued with the evaluation manager
  • adding user-controllable verbosity
Location:
scolib/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • scolib/trunk/src/libs/StateMachineLS.cpp

    r7449 r7457  
    2727using std::make_pair; 
    2828using std::cerr; 
     29using std::cout; 
    2930using std::endl; 
    3031 
     
    112113namespace { 
    113114 
     115int algorithm_verbosity = 0; 
     116 
     117 
    114118template<typename T> 
    115119inline void 
     
    178182 
    179183 
    180 void  
    181 test_and_queue_step( std::vector<int> &current,  
    182                      std::vector<int> &move,  
    183                      StateMachineLS::Data::StateTransition &transition, 
    184                      int index, 
    185                      boost::function1<colin::EvaluationID, const Any> &f ) 
     184bool  
     185test_and_prep_step( std::vector<int> &current,  
     186                    std::vector<int> &move,  
     187                    StateMachineLS::Data::StateTransition &transition, 
     188                    int index ) 
    186189{ 
    187190   list<StateMachineLS::Data::CoReq>::iterator c_it = transition.coreq.begin(); 
    188191   for ( ; c_it != transition.coreq.end(); ++c_it ) 
    189192      if ( ! c_it->satisfied(current) ) 
    190          return; 
     193         return false; 
    191194 
    192195   move = current; 
     
    194197   for ( ; m_it != transition.move.end(); ++m_it ) 
    195198      move[m_it->first == -1 ? index : m_it->first] = m_it->second; 
    196    f(move); 
     199   if ( algorithm_verbosity > 1 ) 
     200      cout << "   ...trial point " << move << endl; 
     201   return true;//f(move); 
    197202} 
    198203 
     
    203208StateMachineLS::StateMachineLS() 
    204209   : state_definition_file(Property::Bind<string>("StateMachineLS.states")), 
     210     verbosity(Property::Bind<int>(2)), 
    205211     data(new Data) 
    206212{ 
     
    210216       "[default: StateMachineLS.states]", 
    211217       state_definition_file); 
     218 
     219   properties.declare 
     220      ("verbosity", 
     221       "Set the algorithm verbosity level" 
     222       "[default: 0]", 
     223       verbosity); 
    212224} 
    213225 
     
    225237   solver_status.model_status = colin::model_intermediate_nonoptimal; 
    226238 
    227    boost::function1<colin::EvaluationID, const Any> evalF  
    228       = boost::bind( &colin::Application_SingleObjective::AsyncEvalF, 
    229                      &*problem, eval_mngr(), _1, utilib::Any(), 0.0 ); 
    230239   int numVar = problem->num_int_vars; 
    231240   bool minimizing = problem->sense == colin::minimization; 
     
    234243   colin::AppResponse currentResponse; 
    235244   vector<int> currentPoint; 
    236    double currentObj; 
     245   double currentObj = 0; 
    237246 
    238247   colin::cache::View_Pareto best_point; 
     
    279288   double newObj; 
    280289 
     290   algorithm_verbosity = verbosity; 
     291 
    281292   size_t iter = 0; 
    282293   size_t numEval = 0; 
     
    286297           ( numEval < maxNumEval || ! maxNumEval ) ) 
    287298   { 
     299      if ( algorithm_verbosity > 0 ) 
     300         cout << "StateMachineLS: iteration " << iter << endl 
     301              << "   Incumbent solution " << currentObj  
     302              << " at " << currentPoint << endl; 
     303 
    288304      Data::states_t::iterator s_itEnd = data->state_transitions.end(); 
    289305      Data::states_t::iterator i_itEnd = data->index_transitions.end(); 
     
    297313               it != s_itEnd && it->first.index == i && it->first.value == v; 
    298314               ++it ) 
    299             test_and_queue_step(currentPoint, tmpDomain, it->second, i, evalF); 
     315            if ( test_and_prep_step(currentPoint, tmpDomain, it->second, i) ) 
     316               problem->AsyncEvalF(eval_mngr(), tmpDomain); 
    300317 
    301318         // Next, queue the implict index-based transitions 
     
    303320               it != i_itEnd && it->first.index == i; 
    304321               ++it ) 
    305             test_and_queue_step(currentPoint, tmpDomain, it->second, i, evalF); 
     322            if ( test_and_prep_step(currentPoint, tmpDomain, it->second, i) ) 
     323               problem->AsyncEvalF(eval_mngr(), tmpDomain); 
    306324 
    307325         // Finally, queue the implicit value-based transitions 
     
    309327               it != v_itEnd && it->first.value == v; 
    310328               ++it ) 
    311             test_and_queue_step(currentPoint, tmpDomain, it->second, i, evalF); 
     329            if ( test_and_prep_step(currentPoint, tmpDomain, it->second, i) ) 
     330               problem->AsyncEvalF(eval_mngr(), tmpDomain); 
    312331      } 
    313332 
     
    328347            eval.second.get_domain(tmpDomain, problem); 
    329348            currentResponse = eval.second; 
     349            cout << "   ...improving solution " << currentObj  
     350                 << " at " << tmpDomain << endl; 
    330351         } 
    331352      } 
  • scolib/trunk/src/scolib/StateMachineLS.h

    r7449 r7457  
    3939   utilib::Property state_definition_file; 
    4040 
     41   /// 
     42   utilib::Property verbosity; 
     43 
    4144   struct Data; 
    4245 
Note: See TracChangeset for help on using the changeset viewer.