static void dump_dot_8(const NFA *nfa, FILE *f) { auto m = (const mcsheng *)getImplNfa(nfa); dumpDotPreambleDfa(f); for (u16 i = 1; i < m->state_count; i++) { describeNode(nfa, m, i, f); u16 t[ALPHABET_SIZE]; next_states(nfa, i, t); describeEdge(f, m, t, i); } fprintf(f, "}\n"); }
boost::optional<std::vector<pos>> random_walk_impl( const State &st, set_t &memo, std::mt19937 &mt, uint64_t &count) { if (st.bd.is_goal()) return std::vector<pos>(); if (count % 10000 == 0) std::cerr << count << std::endl; ++count; memo.insert(st.bd.units); auto nexts = next_states(st); std::vector<std::tuple<State, pos>> coodinates; for (auto &next : nexts) if (memo.count(std::get<0>(next).bd.units) == 0) coodinates.push_back(next); if (coodinates.empty()) return boost::none; std::shuffle(std::begin(coodinates), std::end(coodinates), mt); for (auto next : coodinates) { if (auto opt_res = random_walk_impl(std::get<0>(next), memo, mt, count)) { opt_res->push_back(std::get<1>(next)); return opt_res; } } return boost::none; }
void legion_network::calculate_states(const legion_stimulus & stimulus, const solve_type solver, const double t, const double step, const double int_step) { std::vector<void *> argv(2, NULL); std::vector<differ_result<double> > next_states(size()); argv[0] = (void *) this; unsigned int number_int_steps = (unsigned int) (step / int_step); for (unsigned int index = 0; index < size(); index++) { argv[1] = (void *) &index; differ_state<double> inputs { m_oscillators[index].m_excitatory, m_oscillators[index].m_inhibitory }; if (m_params.ENABLE_POTENTIAL) { inputs.push_back(m_oscillators[index].m_potential); } switch(solver) { case solve_type::FAST: { throw std::runtime_error("Forward Euler first-order method is not supported due to low accuracy."); } case solve_type::RK4: { if (m_params.ENABLE_POTENTIAL) { runge_kutta_4(&legion_network::adapter_neuron_states, inputs, t, t + step, number_int_steps, false /* only last states */, argv, next_states[index]); } else { runge_kutta_4(&legion_network::adapter_neuron_simplify_states, inputs, t, t + step, number_int_steps, false /* only last states */, argv, next_states[index]); } break; } case solve_type::RKF45: { if (m_params.ENABLE_POTENTIAL) { runge_kutta_fehlberg_45(&legion_network::adapter_neuron_states, inputs, t, t + step, 0.00001, false /* only last states */, argv, next_states[index]); } else { runge_kutta_fehlberg_45(&legion_network::adapter_neuron_simplify_states, inputs, t, t + step, 0.00001, false /* only last states */, argv, next_states[index]); } break; } default: { throw std::runtime_error("Unknown type of solver"); } } std::vector<unsigned int> * neighbors = get_neighbors(index); double coupling = 0.0; for (std::vector<unsigned int>::const_iterator index_neighbor_iterator = neighbors->begin(); index_neighbor_iterator != neighbors->end(); index_neighbor_iterator++) { coupling += m_dynamic_connections[index][*index_neighbor_iterator] * heaviside(m_oscillators[*index_neighbor_iterator].m_excitatory - m_params.teta_x); } delete neighbors; m_oscillators[index].m_buffer_coupling_term = coupling - m_params.Wz * heaviside(m_global_inhibitor - m_params.teta_xz); } differ_result<double> inhibitor_next_state; differ_state<double> inhibitor_input { m_global_inhibitor }; switch (solver) { case solve_type::RK4: { runge_kutta_4(&legion_network::adapter_inhibitor_state, inhibitor_input, t, t + step, number_int_steps, false /* only last states */, argv, inhibitor_next_state); break; } case solve_type::RKF45: { runge_kutta_fehlberg_45(&legion_network::adapter_inhibitor_state, inhibitor_input, t, t + step, 0.00001, false /* only last states */, argv, inhibitor_next_state); break; } } m_global_inhibitor = inhibitor_next_state[0].state[0]; for (unsigned int i = 0; i < size(); i++) { m_oscillators[i].m_excitatory = next_states[i][0].state[0]; m_oscillators[i].m_inhibitory = next_states[i][0].state[1]; if (m_params.ENABLE_POTENTIAL) { m_oscillators[i].m_potential = next_states[i][0].state[2]; } m_oscillators[i].m_coupling_term = m_oscillators[i].m_buffer_coupling_term; m_oscillators[i].m_noise = m_noise_distribution(m_generator); } }