26#include <knp/core/impexp.h>
62 using AllPopulations = boost::mp11::mp_transform<knp::core::Population, knp::neuron_traits::AllNeurons>;
72 using AllProjections = boost::mp11::mp_transform<knp::core::Projection, knp::synapse_traits::AllSynapses>;
83 using AllPopulationVariants = boost::mp11::mp_rename<AllPopulations, std::variant>;
93 using AllProjectionVariants = boost::mp11::mp_rename<AllProjections, std::variant>;
99 using PopulationContainer = std::vector<core::AllPopulationsVariant>;
103 using ProjectionContainer = std::vector<core::AllProjectionsVariant>;
108 using PopulationIterator = PopulationContainer::iterator;
112 using PopulationConstIterator = PopulationContainer::const_iterator;
117 using ProjectionIterator = ProjectionContainer::iterator;
121 using ProjectionConstIterator = ProjectionContainer::const_iterator;
133 explicit Network(
const core::UID &uid) : base_({uid, {}}) {}
146 template <
typename PopulationType>
153 template <
typename PopulationType>
170 template <
typename NeuronType>
171 [[nodiscard]] knp::core::Population<NeuronType> &
get_population(
const knp::core::UID &population_uid);
181 template <
typename NeuronType>
182 [[nodiscard]]
const knp::core::Population<NeuronType> &
get_population(
const knp::core::UID &population_uid)
const;
190 [[nodiscard]] core::AllPopulationsVariant &
get_population(
const knp::core::UID &population_uid);
209 template <
typename ProjectionType>
216 template <
typename ProjectionType>
227 template <
typename SynapseType>
229 knp::core::UID projection_uid, knp::core::UID pre_population_uid, knp::core::UID post_population_uid,
246 template <
typename SynapseType>
247 [[nodiscard]] knp::core::Projection<SynapseType> &
get_projection(
const knp::core::UID &projection_uid);
256 template <
typename SynapseType>
257 [[nodiscard]]
const knp::core::Projection<SynapseType> &
get_projection(
const knp::core::UID &projection_uid)
const;
264 [[nodiscard]] core::AllProjectionsVariant &
get_projection(
const knp::core::UID &projection_uid);
284 template <
typename SynapseType,
typename SourceNeuronType,
typename DestinationNeuronType>
286 const core::Population<SourceNeuronType> &src,
const core::Population<DestinationNeuronType> &dst,
287 typename projection::parameters_generators::SynGen2ParamsType<SynapseType> syn_gen =
288 projection::parameters_generators::default_synapse_gen<SynapseType>)
290 const auto &[src_uid, dst_uid] = get_populations_uid(src, dst);
292 projection::connect_populations<SynapseType, SourceNeuronType, DestinationNeuronType>(src, dst, syn_gen);
293 const auto proj_uid = new_proj.get_uid();
295 add_projection(std::move(new_proj));
311 template <
typename SynapseType,
typename SourceNeuronType,
typename DestinationNeuronType>
313 const core::Population<SourceNeuronType> &src,
const core::Population<DestinationNeuronType> &dst,
316 const auto &[src_uid, dst_uid] = get_populations_uid(src, dst);
317 auto new_proj = projection::connect_populations<SynapseType, SourceNeuronType, DestinationNeuronType>(
318 src, dst, syn_gen, num_iterations);
319 const auto proj_uid = new_proj.get_uid();
321 add_projection(std::move(new_proj));
373 [[nodiscard]]
const PopulationContainer &
get_populations()
const {
return populations_; }
378 [[nodiscard]]
const ProjectionContainer &
get_projections()
const {
return projections_; }
397 [[nodiscard]]
const knp::core::UID &
get_uid()
const {
return base_.uid_; }
404 [[nodiscard]]
auto &
get_tags() {
return base_.tags_; }
407 template <
typename SourceNeuronType,
typename DestinationNeuronType>
408 [[nodiscard]] std::tuple<core::UID, core::UID> get_populations_uid(
409 const core::Population<SourceNeuronType> &src,
const core::Population<DestinationNeuronType> &dst)
const
411 const auto src_uid = src.
get_uid();
412 if (!is_population_exists(src_uid))
414 throw std::logic_error(
"Source population with UID = " + std::string(src_uid) +
" doesn't exist.");
417 const auto dst_uid = dst.
get_uid();
418 if (!is_population_exists(dst_uid))
420 throw std::logic_error(
"Source population with UID = " + std::string(dst_uid) +
" doesn't exist.");
423 return std::make_tuple(src_uid, dst_uid);
426 template <
typename PopulationType>
427 void check_population_constraints(
const PopulationType &population)
const;
428 template <
typename ProjectionType>
429 void check_projection_constraints(
const ProjectionType &projection)
const;
432 knp::core::BaseData base_;
433 PopulationContainer populations_;
434 ProjectionContainer projections_;
const UID & get_uid() const
Get population UID.
std::function< std::optional< Synapse >(size_t)> SynapseGenerator
Synapse generation function type.
The Network class is a definition of a neural network that contains populations and projections.
void add_projection(core::AllProjectionsVariant &&projection)
Add a projection to the network.
const PopulationContainer & get_populations() const
Get population container from the network.
size_t populations_count() const
Count populations in the network.
core::AllPopulationsVariant & get_population(const knp::core::UID &population_uid)
Get a population with the given UID from the network.
const knp::core::Population< NeuronType > & get_population(const knp::core::UID &population_uid) const
Get a population with the given UID from the network.
void add_population(core::AllPopulationsVariant &&population)
Add a population to the network.
ProjectionConstIterator end_projections() const
Get an iterator pointing to the last element of the projection.
const ProjectionContainer & get_projections() const
Get projection container from the network.
PopulationIterator begin_populations()
Get an iterator pointing to the first element of the population.
void add_projection(knp::core::UID projection_uid, knp::core::UID pre_population_uid, knp::core::UID post_population_uid, typename knp::core::Projection< SynapseType >::SynapseGenerator generator, size_t synapse_count)
Add a projection to the network.
knp::core::Projection< SynapseType > & get_projection(const knp::core::UID &projection_uid)
Get a projection with the given UID from the network.
PopulationConstIterator begin_populations() const
Get an iterator pointing to the first element of the population.
Network()=default
Default network constructor.
knp::core::UID connect_populations(const core::Population< SourceNeuronType > &src, const core::Population< DestinationNeuronType > &dst, typename projection::parameters_generators::SynGen2ParamsType< SynapseType > syn_gen=projection::parameters_generators::default_synapse_gen< SynapseType >)
Connect presynaptic and postsynaptic populations and add projection to the network.
ProjectionConstIterator begin_projections() const
Get an iterator pointing to the first element of the projection.
bool is_population_exists(const knp::core::UID &population_uid) const
Check if population exists.
const knp::core::UID & get_uid() const
Get network UID.
void add_projection(typename std::decay< ProjectionType >::type &projection)
Add a projection to the network.
size_t projections_count() const
Count projections in the network.
PopulationConstIterator end_populations() const
Get an iterator pointing to the last element of the population.
auto & get_tags()
Get tags used by the network.
knp::core::Population< NeuronType > & get_population(const knp::core::UID &population_uid)
Get a population with the given UID from the network.
const knp::core::Projection< SynapseType > & get_projection(const knp::core::UID &projection_uid) const
Get a projection with the given UID from the network.
ProjectionIterator end_projections()
Get an iterator pointing to the last element of the projection.
core::AllProjectionsVariant & get_projection(const knp::core::UID &projection_uid)
Get a projection with the given UID from the network.
knp::core::UID connect_populations(const core::Population< SourceNeuronType > &src, const core::Population< DestinationNeuronType > &dst, typename knp::core::Projection< SynapseType >::SynapseGenerator syn_gen, size_t num_iterations)
Connect presynaptic and postsynaptic populations and add projection to the network.
void add_population(typename std::decay< PopulationType >::type &population)
Add a population to the network.
void add_projection(typename std::decay< ProjectionType >::type &&projection)
Add a projection to the network.
void remove_projection(const knp::core::UID &projection_uid)
Remove a projection with the given UID from the network.
void add_population(typename std::decay< PopulationType >::type &&population)
Add a population to the network.
void remove_population(const knp::core::UID &population_uid)
Remove a population with the given UID from the network.
Network(const core::UID &uid)
Network constructor with pre-defined UID.
bool is_projection_exists(const knp::core::UID &projection_uid) const
Check if projection exists.
PopulationIterator end_populations()
Get an iterator pointing to the last element of the population.
ProjectionIterator begin_projections()
Get an iterator pointing to the first element of the projection.
Class definition for backend base.
Class definition for core library basic entities.
List of all neuron type traits.
General population interface.
General projection interface.
Delta synapse type traits.