void agent_t::so_change_state( const state_t & new_state ) { ensure_operation_is_on_working_thread( "so_change_state" ); if( new_state.is_target( this ) ) { auto actual_new_state = new_state.actual_state_to_enter(); if( !( *actual_new_state == *m_current_state_ptr ) ) { // New state differs from the current one. // Actual state switch must be performed. do_state_switch( *actual_new_state ); // State listener should be informed. m_state_listener_controller->changed( *this, *m_current_state_ptr ); } } else SO_5_THROW_EXCEPTION( rc_agent_unknown_state, "unable to switch agent to alien state " "(the state that doesn't belong to this agent)" ); }
pair<bool,long long int> test2(state_t n, int depth, int v, comparador c,bool turn){ pair<bool,long long int> test_generados; long long int numSuc = 0; if(n.terminal() || depth == 0) { return make_pair(n.value() > v,0); } vector<state_t> sucesores = n.succ(turn); numSuc += sucesores.size(); for(int i=0; i < sucesores.size(); i++) { if(turn == true){ test_generados = test2(sucesores[i],depth-1,v,c,!turn); numSuc += test_generados.second; if(test_generados.first) return make_pair(true, numSuc); } if(turn == false ){ test_generados = test2(sucesores[i],depth-1,v,c,!turn); numSuc += test_generados.second; if(!test_generados.first) return make_pair(false, numSuc); } } if(turn == true){ return make_pair(false,numSuc); } if(turn == false){ return make_pair(true,numSuc); } }
void Rossler::jac(const_it_t &state, state_t & out, double time) { assert(out.size() == dim*dim); auto it = out.begin(); it[0] = 0; it[1] = -1; it[2] = -1; it += dim; it[0] = 1; it[1] = a; it[2] = 0; it += dim; it[0] = state[2]; it[1] = 0; it[2] = state[0]-c; }
void System::rhs_combined(const state_t &state, state_t & out, double time) { assert(out.size() == dim*(dim+1)); rhs(state, out, time); jac(ublas::subrange(state,0,dim), jacobian, time, dfdt); for (int i=1; i<out.size() / dim ; i++) { auto st = ublas::subrange(state,dim*i,dim*(i+1)); ublas::subrange(out, dim*i, dim*(i+1)) = ublas::prod(jacobian, st); } }
bool duel::can_change_state_to( const state_t& new_state ) { if (m_states.empty()) { return true; } return m_states.back()->is_valid_state_change_to(new_state->name()); }
static void pt_add_ready(state_t const s, pt_thread_t * const t) { if (s->ready_function && !s->ready && !s->running) { /* this should schedule protothread_run() */ s->ready_function(s->ready_env) ; } pt_link(&s->ready, t) ; }
pair<int,long long int> busqueda(state_t n, int depth,bool turn){ hash_table_t::iterator it; pair<int,long long int> valor_generados; pair<bool,long long int> test_generados; long long int numSuc = 0; it = tabla.find(n); if(it != tabla.end()) return make_pair((*it).second,0); if(n.terminal() || depth == 0) { return make_pair(n.value(),0); } vector<state_t> sucesores = n.succ(turn); numSuc += sucesores.size(); valor_generados = busqueda(sucesores[0],depth-1,!turn); numSuc += valor_generados.second; for(int i=1; i < sucesores.size(); i++) { if(turn == true){ test_generados = test2(sucesores[i],depth-1,valor_generados.first,comparador(true),!turn); numSuc += test_generados.second; if( test_generados.first){ valor_generados = busqueda(sucesores[i],depth-1,!turn); numSuc += valor_generados.second; } } if(turn == false){ test_generados = test(sucesores[i],depth-1,valor_generados.first,comparador(false),!turn); numSuc += test_generados.second; if(test_generados.first){ valor_generados = busqueda(sucesores[i],depth-1,!turn); numSuc+= valor_generados.second; } } } tabla.insert(make_pair(n, valor_generados.first)); return make_pair(valor_generados.first,numSuc); }
/*! * \since v.5.5.3 * \brief A helper function for creating subscription description. */ inline std::string make_subscription_description( const mbox_t & mbox_ref, std::type_index msg_type, const state_t & state ) { std::ostringstream s; s << "(mbox:'" << mbox_ref->query_name() << "', msg_type:'" << msg_type.name() << "', state:'" << state.query_name() << "')"; return s.str(); }
int F_(state_t n, int alpha, int beta, bool color) { cout << "soy F" << endl; if (n.terminal()) { cout << " soy terminal y valgo: " << n.value() << endl; return n.value() ;//* (color ? 1 : -1); } int m = numeric_limits<signed int>::min(); vector<int> succ_ = n.succ(color); if (succ_.size() != 0) { cout << " voy a jugar: " << succ_.front() << endl; state_t jugada = n.move(color, succ_.front()); cout << " hice jugada " << endl; succ_.erase(succ_.begin()); int valor = G_(jugada, alpha, beta, !color); m = MAX(m, valor); if ( m >= beta) { return m; } for(vector<int>::const_iterator iter=succ_.begin(),limit=succ_.end(); iter!=limit; ++iter) { jugada = n.move(color, *iter); int t = G_(jugada,m,m + 1, !color); if(t > m) { if(t >= beta) { m = t; } else { m = G_(jugada, t, beta, !color); } } if(m >= beta) { return beta; } } } else { return G_(n.move(color, 36), alpha, beta, !color); } return m; }
space_partition(state_t const& st, operator_t const& H, bool store_matrix_elements = true) : subspaces(st.size()), tmp_state(make_zero_state(st)) { auto size = tmp_state.size(); // Iteration over all initial basis states for (index_t i = 0; i < size; ++i) { tmp_state(i) = amplitude_t(1.0); state_t final_state = H(tmp_state); // Iterate over non-zero final amplitudes foreach(final_state, [&](index_t f, amplitude_t amplitude) { if (triqs::utility::is_zero(amplitude)) return; auto i_subspace = subspaces.find_set(i); auto f_subspace = subspaces.find_set(f); if (i_subspace != f_subspace) subspaces.link(i_subspace, f_subspace); if (store_matrix_elements) matrix_elements[std::make_pair(i, f)] = amplitude; }); tmp_state(i) = amplitude_t(0.); } _update_index(); }
int G_(state_t n, int alpha, int beta, bool color) { cout << "soy G" << endl; if (n.terminal()) { cout << " soy terminal y valgo: " << n.value() << endl; return n.value() ;//* (color ? 1 : -1);; } int m = numeric_limits<signed int>::max(); vector<int> succ_ = n.succ(color); if (succ_.size() != 0) { state_t jugada = n.move(color, succ_.front()); succ_.erase(succ_.begin()); int valor = F_(jugada, alpha, beta, !color); m = MIN(m, valor); if ( m <= alpha) { return m; } for(vector<int>::const_iterator iter=succ_.begin(),limit=succ_.end(); iter!=limit; ++iter) { cout << " expando: " << *iter << endl; jugada = n.move(color, *iter); int t = F_(jugada,m,m + 1,!color); if(t <= m) { if(t <= alpha) { m = t; } else { m = F_(jugada,alpha,t,!color); } } if(m <= alpha) { return alpha; } } } else { return F_(n.move(color, 36), alpha, beta, !color); } return m; }
size_t operator()(const state_t &state) const { return state.hash(); }
float f(const state_t& x) { f_eval_count ++; return x.squaredNorm() / static_cast<float>(x.size()); }