void reproduce( population_type& pop , fitness_type& fitness ) { GPCXX_ASSERT( pop.size() == fitness.size() ); GPCXX_ASSERT( m_rates.size() == m_operators.size() ); GPCXX_ASSERT( m_operators.size() > 0 ); std::vector< size_t > indices; sort_indices( fitness , indices ); population_type new_pop; new_pop.reserve( pop.size() ); // elite for( size_t i=0 ; i<m_number_elite ; ++i ) { index_vector elite_in_indices; index_vector elite_out_indices; size_t index = indices[i] ; elite_in_indices.push_back( index ); elite_out_indices.push_back( new_pop.size() ); new_pop.push_back( pop[ index ] ); m_observer( -1 , elite_in_indices , elite_out_indices ); } size_t n = pop.size(); std::discrete_distribution< int > dist( m_rates.begin() , m_rates.end() ); while( new_pop.size() < n ) { int choice = dist( m_rng ); auto& op = m_operators[ choice ]; auto selection = op.selection( pop , fitness ); index_vector in; for( auto s : selection ) in.push_back( s - pop.begin() ); auto trees = op.operation( selection ); index_vector out; for( auto iter = trees.begin() ; ( iter != trees.end() ) && ( new_pop.size() < n ) ; ++iter ) { out.push_back( new_pop.size() ); m_final_transform( *iter ); new_pop.push_back( std::move( *iter ) ); } m_observer( choice , in , out ); } pop = std::move( new_pop ); }
void ToggleButton::update(float) { shared_ptr<util::Input> input = util::Input::getInstance(); m_pointerInsideBorders = isInsideBorders(input->mouseVirtualAdjustedX, input->mouseVirtualAdjustedY); bool shouldToggle = m_pointerInsideBorders && input->action1Pressed; if (m_skin == Skin::RadioButton && !m_toggled && shouldToggle) { m_observer(m_id); } else if (m_skin != Skin::RadioButton && shouldToggle) { toggle(); m_observer(m_id); } }