1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
use crate::Scalar; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[repr(C)] pub struct Config { pub propagation_speed: Scalar, pub neuron_impulse_decay: Scalar, pub default_action_potential: Scalar, pub action_potential_treshold: Scalar, pub receptors_excitation: Scalar, pub receptors_inhibition: Scalar, pub default_receptors: (Scalar, Scalar), pub synapse_inactivity_time: Scalar, pub synapse_reconnection_range: Option<Scalar>, pub synapse_overdose_receptors: Option<Scalar>, pub synapse_reconnection_no_loop: bool, pub allow_sensors_both_way_connections: bool, pub allow_effectors_both_way_connections: bool, pub only_one_outgoing_neuron_connection: bool, pub only_one_incoming_neuron_connection: bool, } impl Default for Config { fn default() -> Self { Self { propagation_speed: 1.0, neuron_impulse_decay: 1.0, default_action_potential: 1.0, action_potential_treshold: 1.0, receptors_excitation: 1.0, receptors_inhibition: 0.1, default_receptors: (0.5, 1.5), synapse_inactivity_time: 0.1, synapse_reconnection_range: None, synapse_overdose_receptors: Some(10.0), synapse_reconnection_no_loop: true, allow_sensors_both_way_connections: false, allow_effectors_both_way_connections: false, only_one_outgoing_neuron_connection: true, only_one_incoming_neuron_connection: false, } } } impl Config { pub fn merge(&self, other: &Self) -> Self { Self { propagation_speed: merge_scalar(self.propagation_speed, other.propagation_speed), neuron_impulse_decay: merge_scalar( self.neuron_impulse_decay, other.neuron_impulse_decay, ), default_action_potential: merge_scalar( self.default_action_potential, other.default_action_potential, ), action_potential_treshold: merge_scalar( self.action_potential_treshold, other.action_potential_treshold, ), receptors_excitation: merge_scalar( self.receptors_excitation, other.receptors_excitation, ), receptors_inhibition: merge_scalar( self.receptors_inhibition, other.receptors_inhibition, ), default_receptors: ( merge_scalar(self.default_receptors.0, other.default_receptors.0), merge_scalar(self.default_receptors.1, other.default_receptors.1), ), synapse_inactivity_time: merge_scalar( self.synapse_inactivity_time, other.synapse_inactivity_time, ), synapse_reconnection_range: match ( self.synapse_reconnection_range, other.synapse_reconnection_range, ) { (None, None) => None, (Some(a), None) => Some(a), (None, Some(b)) => Some(b), (Some(a), Some(b)) => Some(merge_scalar(a, b)), }, synapse_overdose_receptors: match ( self.synapse_overdose_receptors, other.synapse_overdose_receptors, ) { (None, None) => None, (Some(a), None) => Some(a), (None, Some(b)) => Some(b), (Some(a), Some(b)) => Some(merge_scalar(a, b)), }, synapse_reconnection_no_loop: self.synapse_reconnection_no_loop || other.synapse_reconnection_no_loop, allow_sensors_both_way_connections: self.allow_sensors_both_way_connections || other.allow_sensors_both_way_connections, allow_effectors_both_way_connections: self.allow_effectors_both_way_connections || other.allow_effectors_both_way_connections, only_one_outgoing_neuron_connection: self.only_one_outgoing_neuron_connection || other.only_one_outgoing_neuron_connection, only_one_incoming_neuron_connection: self.only_one_incoming_neuron_connection || other.only_one_incoming_neuron_connection, } } } fn merge_scalar(a: Scalar, b: Scalar) -> Scalar { (a + b) * 0.5 }