void initialize(List <AnimatedNeuron> neurons, List <AnimatedSynapse> synapses, List <AnimatedReceptor> receptors) { action = true; treshold = 1; this.neurons = new List <BalancedNeuron>(); this.receptors = new List <BalancedReceptor>(); this.synapses = new List <BalancedSynapse>(); map = new Dictionary <AnimatedElement, BalancedElement>(); foreach (AnimatedNeuron an in neurons) { BalancedNeuron neuron = new BalancedNeuron(an); this.neurons.Add(neuron); map.Add(an, neuron); } foreach (AnimatedReceptor ar in receptors) { BalancedReceptor receptor = new BalancedReceptor(ar); this.receptors.Add(receptor); map.Add(ar, receptor); } foreach (AnimatedSynapse synapse in synapses) { this.synapses.Add(new BalancedSynapse(synapse, map)); } extra = false; }
public void repulse(BalancedNeuron neuron, float factor) { if (neuron == pre || neuron == post) { return; } PointF pos = new PointF(neuron.Position.X - synapse.Pre.Position.X, neuron.Position.Y - synapse.Pre.Position.Y); float a = synapse.Vector.Position.Y; float b = synapse.Vector.Position.X; float c = b * pos.X + a * pos.Y; float x, y; float eq; // punkt równowagi if (a == 0) { x = c / b; y = 0; eq = x / b; } else if (b == 0) { x = 0; y = c / a; eq = y / a; } else { x = c * b / (synapse.Vector.Length * synapse.Vector.Length); eq = x / b; y = a * eq; } if (eq < 0 || eq > 1) { return; } float force = 0; float tau = 0; float distance = Math.Abs(b * pos.Y - a * pos.X) / synapse.Vector.Length; if (distance < Constant.Radius) { tau = k / Constant.Diameter; force = 3 * factor * tau * tau; } else if (distance < Constant.Diameter) { tau = k / Constant.Radius; force = factor * tau * tau * (2.5f * Constant.Radius - distance) / Constant.Diameter; } else { tau = k / distance; force = factor * tau * tau; } PointF shift = new PointF(force * (pos.X - x) / distance, force * (pos.Y - y) / distance); neuron.move(shift.X, shift.Y); eq = -eq; post.move(shift.X * eq, shift.Y * eq); eq = -1 - eq; pre.move(shift.X * eq, shift.Y * eq); }