public void RepositionsSynapse()
        {
            RegionModel  addedRegion;
            SynapseModel addedSynapse;

            SetupRegionWithSynapse(out addedRegion, out addedSynapse);

            NeuronModel neuron1 = m_model.Regions.First().Neurons.First();
            NeuronModel neuron2 = m_model.Regions.First().Neurons.Last();

            SynapseModel synapse = m_model.Regions.First().Synapses.First();

            neuron1.Position *= 2;
            ResponseMessage diff = ModelResponseBuilder.Build(repositionedNeurons: new List <NeuronModel> {
                neuron1
            });

            ApplyModelDiff(diff);

            Assert.Equal(neuron1.Position, synapse.Position);

            neuron2.Position *= 3;
            diff              = ModelResponseBuilder.Build(repositionedNeurons: new List <NeuronModel> {
                neuron2
            });
            ApplyModelDiff(diff);

            Assert.Equal(neuron2.Position, neuron1.Position + synapse.TargetPosition);
        }
        public void AddsNewConnector()
        {
            RegionModel addedRegion = SetupRegion(m_applier, m_model, 1);

            ConnectorModel addedConnector1 = new InputConnectorModel(addedRegion, "input", 4);
            ConnectorModel addedConnector2 = new OutputConnectorModel(addedRegion, "output", 3);

            ResponseMessage diff =
                ModelResponseBuilder.Build(addedConnectors: new List <ConnectorModel> {
                addedConnector1, addedConnector2
            });

            ApplyModelDiff(diff);

            RegionModel region = m_model.Regions.First();

            Assert.Equal(1, region.InputConnectors.Models.Count());
            Assert.Equal(1, region.OutputConnectors.Models.Count());

            ComparisonResult result1 = CompareLogic(ConnectorComparisonConfig)
                                       .Compare(addedConnector1, region.InputConnectors.First());
            ComparisonResult result2 = CompareLogic(ConnectorComparisonConfig)
                                       .Compare(addedConnector2, region.OutputConnectors.First());

            Assert.True(result1.AreEqual, result1.DifferencesString);
            Assert.True(result2.AreEqual, result2.DifferencesString);
        }
Esempio n. 3
0
        public void WritesReadsModelResponse()
        {
            const string regionName = "test region name";
            const string regionType = "test region type";

            var observer = new ObserverDefinition(1, 2, "foo");
            var data     = new byte[] { 1, 2, 3 };

            var observerData = new ObserverDataContainer(observer,
                                                         new ObserverData(metadata: null, plainData: data, floatData: null));

            var addedRegions = new List <RegionModel>
            {
                new RegionModel(1, regionName, regionType, new Vector3(10, 20, 30), new Vector3(40, 30, 20))
            };
            var message = ModelResponseBuilder.Build(addedRegions: addedRegions,
                                                     observers: new List <ObserverDataContainer> {
                observerData
            });

            ModelResponse modelResponse = message.GetResponse(new ModelResponse());

            Assert.Equal(regionName, modelResponse.GetAddedRegions(0).Name);
            Assert.Equal(observer.Type, modelResponse.GetObserverResults(0).Observer.Type);
            Assert.Equal(data[0], modelResponse.GetObserverResults(0).GetPlainData(0));
        }
        private static RegionModel SetupRegion(ModelDiffApplier applier, SimulationModel model, uint id)
        {
            var sourceRegion = new RegionModel(id, "foo", "bar", new Vector3(1, 2, 3), new Vector3(6, 5, 4));

            ResponseMessage diff = ModelResponseBuilder.Build(addedRegions: new List <RegionModel> {
                sourceRegion
            });

            applier.ApplyModelDiff(model, diff.GetResponse(new ModelResponse()));
            return(sourceRegion);
        }
        private void SetupRegionWithNeuron(out RegionModel addedRegion, out NeuronModel addedNeuron)
        {
            addedRegion = SetupRegion(m_applier, m_model, 1);
            addedNeuron = new NeuronModel(1, "neuronType", addedRegion, Vector3.One);

            ResponseMessage diff = ModelResponseBuilder.Build(addedNeurons: new List <NeuronModel> {
                addedNeuron
            });

            ApplyModelDiff(diff);
        }
        public void RemovesRegion()
        {
            RegionModel addedRegion = SetupRegion(m_applier, m_model, 1);

            ResponseMessage diff = ModelResponseBuilder.Build(removedRegions: new List <RegionModel> {
                addedRegion
            });

            ApplyModelDiff(diff);

            Assert.Empty(m_model.Regions);
        }
        public void RepositionsRegion()
        {
            RegionModel addedRegion = SetupRegion(m_applier, m_model, 1);

            addedRegion.Position = Vector3.UnitZ;
            ResponseMessage diff = ModelResponseBuilder.Build(repositionedRegions: new List <RegionModel> {
                addedRegion
            });

            ApplyModelDiff(diff);

            Assert.Equal(Vector3.UnitZ, m_model.Regions.First().Position);
        }
        public void RemovesNeuron()
        {
            RegionModel addedRegion;
            NeuronModel addedNeuron;

            SetupRegionWithNeuron(out addedRegion, out addedNeuron);

            ResponseMessage diff = ModelResponseBuilder.Build(removedNeurons: new List <NeuronModel> {
                addedNeuron
            });

            ApplyModelDiff(diff);

            Assert.Empty(m_model.Regions[addedRegion.Index].Neurons);
        }
        public void RepositionsNeuron()
        {
            RegionModel addedRegion;
            NeuronModel addedNeuron;

            SetupRegionWithNeuron(out addedRegion, out addedNeuron);

            addedNeuron.Position = Vector3.UnitZ;
            ResponseMessage diff = ModelResponseBuilder.Build(repositionedNeurons: new List <NeuronModel> {
                addedNeuron
            });

            ApplyModelDiff(diff);

            Assert.Equal(Vector3.UnitZ, m_model.Regions[addedRegion.Index].Neurons[addedNeuron.Index].Position);
        }
        public void SpikesSynapse()
        {
            RegionModel  addedRegion;
            SynapseModel addedSynapse;

            SetupRegionWithSynapse(out addedRegion, out addedSynapse);

            ResponseMessage diff = ModelResponseBuilder.Build(spikedSynapses: new List <SynapseModel> {
                addedSynapse
            });

            ApplyModelDiff(diff);

            var region = m_model.Regions[addedRegion.Index];

            Assert.True(region.Synapses.First().IsSpiked);
        }
        public void RemovesConnection()
        {
            ConnectionModel addedConnection = SetupRegionsWithConnectors();

            ResponseMessage diff = ModelResponseBuilder.Build(removedConnections: new List <ConnectionModel> {
                addedConnection
            });

            ApplyModelDiff(diff);

            RegionModel region1 = m_model.Regions.First();
            RegionModel region2 = m_model.Regions.Skip(1).First();

            Assert.Empty(region1.OutputConnectors.First().Connections);
            Assert.Empty(region2.InputConnectors.First().Connections);
            Assert.Empty(m_model.Connections);
        }
        private void SetupRegionWithSynapse(out RegionModel addedRegion, out SynapseModel addedSynapse)
        {
            addedRegion = SetupRegion(m_applier, m_model, 1);

            var addedNeuron1 = new NeuronModel(1, "neuronType", addedRegion, Vector3.One);
            var addedNeuron2 = new NeuronModel(2, "neuronType", addedRegion, Vector3.UnitY);

            addedSynapse = new SynapseModel(addedRegion, addedNeuron1, addedRegion, addedNeuron2);

            ResponseMessage diff = ModelResponseBuilder.Build(
                addedNeurons: new List <NeuronModel> {
                addedNeuron1, addedNeuron2
            },
                addedSynapses: new List <SynapseModel> {
                addedSynapse
            });

            ApplyModelDiff(diff);
        }
        public void RemovesSynapse()
        {
            RegionModel  addedRegion;
            SynapseModel addedSynapse;

            SetupRegionWithSynapse(out addedRegion, out addedSynapse);

            ResponseMessage diff = ModelResponseBuilder.Build(removedSynapses: new List <SynapseModel> {
                addedSynapse
            });

            ApplyModelDiff(diff);

            var region = m_model.Regions[addedRegion.Index];

            Assert.Empty(region.Synapses);
            Assert.Empty(region.Neurons[1].Outputs);
            Assert.Empty(region.Neurons[2].Inputs);
        }
            public Task <TResponse> Request <TRequest, TResponse>(IConversation <TRequest, TResponse> conversation, int timeoutMs) where TRequest : Table where TResponse : Table, new()
            {
                var request = conversation.RequestData as GetModelRequest;

                if (request == null)
                {
                    throw new ArgumentException("Can only respond to a model request");
                }

                Filter = Filter ?? request.Filter;

                return(Task <TResponse> .Factory.StartNew(() =>
                {
                    var regionModel = new RegionModel(1, "foo", "bar", Vector3.One, Vector3.Zero);

                    return ModelResponseBuilder.Build(new List <RegionModel> {
                        regionModel
                    })
                    .GetResponse(new ModelResponse()) as TResponse;
                }));
            }
        public void LoadsObserverData()
        {
            var observerDefinition = new ObserverDefinition(1, 1, "foo");
            var metadata           = new int[] { 28, 28, 3 };
            var plainData          = new byte[] { 1, 2, 3 };
            var floatData          = new float[] { 4.5f, 6.7f };

            var observer = new ObserverDataContainer(
                observerDefinition, new ObserverData(metadata: metadata, plainData: plainData, floatData: floatData));

            ResponseMessage diff = ModelResponseBuilder.Build(observers: new List <ObserverDataContainer> {
                observer
            });

            ApplyModelDiff(diff);

            var observerData = m_model.Observers.Values.First();

            Assert.Equal(metadata, observerData.Metadata);
            Assert.Equal(plainData, observerData.PlainData);
            Assert.Equal(floatData, observerData.FloatData);
        }
        private ConnectionModel SetupRegionsWithConnectors()
        {
            RegionModel addedRegion1 = SetupRegion(m_applier, m_model, 1);
            RegionModel addedRegion2 = SetupRegion(m_applier, m_model, 2);

            var addedConnector1 = new OutputConnectorModel(addedRegion1, "output", 3);
            var addedConnector2 = new InputConnectorModel(addedRegion2, "input", 4);

            var addedConnection = new ConnectionModel(addedConnector1, addedConnector2);

            ResponseMessage diff =
                ModelResponseBuilder.Build(
                    addedConnectors: new List <ConnectorModel> {
                addedConnector1, addedConnector2
            },
                    addedConnections: new List <ConnectionModel> {
                addedConnection
            });

            ApplyModelDiff(diff);
            return(addedConnection);
        }
        public void RemovesConnector()
        {
            RegionModel addedRegion = SetupRegion(m_applier, m_model, 1);

            ConnectorModel addedConnector = new InputConnectorModel(addedRegion, "input", 4);

            ResponseMessage diff =
                ModelResponseBuilder.Build(addedConnectors: new List <ConnectorModel> {
                addedConnector
            });

            ApplyModelDiff(diff);

            diff = ModelResponseBuilder.Build(removedConnectors: new List <ConnectorModel> {
                addedConnector
            });

            ApplyModelDiff(diff);

            var region = m_model.Regions.First();

            Assert.Empty(region.InputConnectors);
        }