private static void RespondToDendriteGrowthEvent(object sender, EventArgs_DendriteGrowth e)
        {
            TimeSpan difference = DateTime.Now.Subtract(start);
            String   s          = difference.Seconds + "." + difference.Milliseconds;

            Console.WriteLine("ProcessManager received dendrite growth event at " + s);
            //Dendrite dendrite = neuron.GetDendrite(e.DendriteId);

            //add Tasks to produce to dendrites added
            //====================================================================//
            //                               input                                //
            //====================================================================//
            //Producers to send neurotransmitters to dendrites
            for (int i = 0; i < NUM_INPUTAXON_PRODUCERS; i++)
            {
                Task newest = Task.Factory.StartNew((val) =>
                {
                    int id         = (int)val;
                    InputAxon axon = new InputAxon(nextInputAxonId++, INPUTAXON_PRODUCTION_FREQUENCY, 0);
                    inputs.Add(axon);
                    new Task_InputAxon(id, runLength, axon, INPUT_MAGNITUDE, start).ConnectAndProduce(neuron);
                }, nextInputAxonTaskId++);
                tasks.Add(newest);
            }
        }
        public override bool Equals(object obj) //tested
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            InputAxon a = (InputAxon)obj;

            return((this.id == a.id) && (this.inputType == a.inputType) && (this.productionFrequency == a.productionFrequency));
        }
 public Task_InputAxon(int id, TimeSpan runLength, InputAxon axon, int magnitude, DateTime start) //tested
 {
     Console.WriteLine("Task_InputAxon " + id + " is created.");
     this.id        = id;
     this.runLength = runLength;
     this.dendrite  = null;
     this.axon      = axon;
     this.neurotransmitterMagnitude = magnitude;
     this.start = start;
 }
Ejemplo n.º 4
0
        public bool TryConnect(InputAxon axon) //tested
        {
            if (numAvailableSynapses > 0)
            {
                //atomically try to form a connection
                InputAxon result = synapses.AddOrUpdate(axon.Id, axon, (key, oldValue) => oldValue);
                if (result.Equals(axon))
                {
                    Interlocked.Decrement(ref numAvailableSynapses);
                    return(true);
                }
            }

            return(false);
        }
        //constructors
        public Task_InputAxon(int id, TimeSpan runLength, InputAxon axon, int magnitude, DateTime start, Dendrite dendrite) //tested
        {
            Console.WriteLine("Task_AxonInput " + id + " is created.");
            this.id        = id;
            this.runLength = runLength;
            bool success = dendrite.TryConnect(axon);

            this.axon = axon;
            this.neurotransmitterMagnitude = magnitude;
            this.start = start;

            if (success)
            {
                this.dendrite = dendrite;
            }
        }
        public Dendrite SearchForOpenSynapse(InputAxon axon) //tested
        {
            Dendrite dendrite = null;

            foreach (Dendrite current in dendrites.Values)
            {
                bool success = current.TryConnect(axon);
                if (success)
                {
                    Console.WriteLine("Neuron found open synapse on dendrite.");
                    dendrite = current;
                    break; //stop searching
                }
            }

            return(dendrite);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //run neuron model
            Console.WriteLine("Running Neuron Model...");

            //look at the previous 2 seconds
            int      days         = 0;
            int      hours        = 0;
            int      minutes      = 0;
            int      seconds      = 2;
            int      milliseconds = 0;
            TimeSpan window       = new TimeSpan(days, hours, minutes, seconds, milliseconds);


            //initialize variables
            neuron = new Neuron(10,               //*cell body decay frequency
                                50,               //*cell body restore increment
                                window,           //*neuron secondary messenger window
                                200,              //*neuron secondary messenger frequency trigger
                                1,                //*number of dendrites to add in growth event
                                new int[] { 0 },  //*types of dendrites to add in growth event
                                10,               //*dendrite decay frequency
                                100,              //*dendrite production frequency
                                50,               //*dendrite restore increment
                                1,                //*number of synapses to add in growth event
                                window,           //*dendrite secondary messenger window
                                2,                //*dendrite secondary messenger frequency trigger
                                2,                //*number of starting synapses per dendrite
                                30,               //*dendrite significant voltage change amount //at 25, too frequent; at 26, no occurrence
                                1,                //*number of starting dendrites
                                new int[] { 0 }); //*types of dendrites to start

            tasks           = new List <Task>();
            runLength       = new TimeSpan(0, 0, 12);
            start           = DateTime.Now;
            nextInputAxonId = 0;
            inputs          = new List <InputAxon>();


            //listen for CellGrowthEvent from Neuron
            neuron.CellGrowthEvent += RespondToCellGrowthEvent;

            //listen for DendriteGrowthEvent from each Dendrite
            foreach (Dendrite d in neuron.Dendrites)
            {
                d.DendriteGrowthEvent += RespondToDendriteGrowthEvent;
            }


            //create tasks
            //====================================================================//
            //                            cell body                               //
            //====================================================================//
            //Consumers to retrieve electrical potential from cell body buffer
            for (int i = 0; i < NUM_CELLBODY_CONSUMERS; i++)
            {
                Task newest = Task.Factory.StartNew((val) =>
                {
                    int id = (int)val;
                    new Task_CellBody(id, runLength, neuron.Body, start).Consume();
                }, nextCellBodyTaskId++);
                tasks.Add(newest);
            }

            //Decayers to decay membrane potential of cell body
            for (int i = 0; i < NUM_CELLBODY_DECAYERS; i++)
            {
                Task newest = Task.Factory.StartNew((val) =>
                {
                    int id = (int)val;
                    new Task_CellBody(id, runLength, neuron.Body, start).Decay();
                }, nextCellBodyTaskId++);
                tasks.Add(newest);
            }

            //====================================================================//
            //                             dendrite                               //
            //====================================================================//
            //Consumers to retrieve neurotransmitters from dendrite buffer
            for (int i = 0; i < NUM_DENDRITE_CONSUMERS; i++)
            {
                Task newest = Task.Factory.StartNew((val) =>
                {
                    int id = (int)val;
                    new Task_Dendrite(id, runLength, neuron.GetDendrite(0), neuron.Body, start).Consume();
                }, nextDendriteTaskId++);
                tasks.Add(newest);
            }

            //Producers to send electrical potential to cell body buffer
            for (int i = 0; i < NUM_DENDRITE_PRODUCERS; i++)
            {
                Task newest = Task.Factory.StartNew((val) =>
                {
                    int id = (int)val;
                    new Task_Dendrite(id, runLength, neuron.GetDendrite(0), neuron.Body, start).Produce();
                }, nextDendriteTaskId++);
                tasks.Add(newest);
            }

            //Decayers to decay membrane potential of dendrites
            for (int i = 0; i < NUM_DENDRITE_DECAYERS; i++)
            {
                Task newest = Task.Factory.StartNew((val) =>
                {
                    int id = (int)val;
                    new Task_Dendrite(id, runLength, neuron.GetDendrite(0), neuron.Body, start).Decay();
                }, nextDendriteTaskId++);
                tasks.Add(newest);
            }



            //====================================================================//
            //                               input                                //
            //====================================================================//
            //Producers to send neurotransmitters to dendrites
            for (int i = 0; i < NUM_INPUTAXON_PRODUCERS; i++)
            {
                Task newest = Task.Factory.StartNew((val) =>
                {
                    int id         = (int)val;
                    InputAxon axon = new InputAxon(nextInputAxonId++, INPUTAXON_PRODUCTION_FREQUENCY, 0);
                    inputs.Add(axon);
                    new Task_InputAxon(id, runLength, axon, INPUT_MAGNITUDE, start, neuron.GetDendrite(0)).Produce();
                }, nextInputAxonTaskId++);
                tasks.Add(newest);
            }


            //currently if any consumers are trying to consume an empty buffer, they block the entire program??



            Task.WaitAll(tasks.ToArray(), cts.Token);

            //output results
            ConvertEventRecordsToArrays();
            //PrintXValuesArray();
            //PrintYValuesArray();
            Console.WriteLine("Stopped Neuron Model.");



            //display chart
            for (int i = 0; i < xValues.Length; i++)
            {
                chart1.Series[0].Points.AddXY(xValues[i], yValues[i]);
            }
            //chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            //color of grid background
            chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.Gainsboro;
            chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.Gainsboro;
        }
        private static void RespondToCellGrowthEvent(object sender, EventArgs_CellGrowth e)
        {
            Console.WriteLine("ProcessManager received cell growth event.");
            List <Dendrite> added = e.DendritesAdded;

            //add Tasks to manipulate dendrites added
            //====================================================================//
            //                             dendrite                               //
            //====================================================================//
            //Consumers to retrieve neurotransmitters from dendrite buffer
            for (int i = 0; i < NUM_DENDRITE_CONSUMERS; i++)
            {
                Task newest = Task.Factory.StartNew((val) =>
                {
                    int id = (int)val;
                    new Task_Dendrite(id, runLength, added[0], neuron.Body, start).Consume();
                }, nextDendriteTaskId++);
                tasks.Add(newest);
            }

            //Producers to send electrical potential to cell body buffer
            for (int i = 0; i < NUM_DENDRITE_PRODUCERS; i++)
            {
                Task newest = Task.Factory.StartNew((val) =>
                {
                    int id = (int)val;
                    new Task_Dendrite(id, runLength, added[0], neuron.Body, start).Produce();
                }, nextDendriteTaskId++);
                tasks.Add(newest);
            }

            //Decayers to decay membrane potential of dendrites
            for (int i = 0; i < NUM_DENDRITE_DECAYERS; i++)
            {
                Task newest = Task.Factory.StartNew((val) =>
                {
                    int id = (int)val;
                    new Task_Dendrite(id, runLength, added[0], neuron.Body, start).Decay();
                }, nextDendriteTaskId++);
                tasks.Add(newest);
            }



            //add Tasks to produce to dendrites added
            //====================================================================//
            //                               input                                //
            //====================================================================//
            //Producers to send neurotransmitters to dendrites
            for (int i = 0; i < NUM_INPUTAXON_PRODUCERS; i++)
            {
                Task newest = Task.Factory.StartNew((val) =>
                {
                    int id         = (int)val;
                    InputAxon axon = new InputAxon(nextInputAxonId++, INPUTAXON_PRODUCTION_FREQUENCY, 0);
                    inputs.Add(axon);
                    new Task_InputAxon(id, runLength, axon, INPUT_MAGNITUDE, start, added[0]).Produce();
                }, nextInputAxonTaskId++);
                tasks.Add(newest);
            }
        }