public void InitialiseNetwork()
        {
            //Clear all the nodes
            foreach (Node Node in Nodes)
            {
                Node.ClearValue();
            }


            //Check if we have 'shortcuts' to the input and output nodes
            if (InputNodes.Count == 0 || OutputNodes.Count == 0)
            {
                InputNodes.Clear();
                OutputNodes.Clear();

                foreach (Node Node in Nodes)
                {
                    switch (Node.Type)
                    {
                    case eNeuralNodeType.eInput:
                        InputNodes.Add(Node);
                        break;

                    case eNeuralNodeType.eOutput:
                        OutputNodes.Add(Node);
                        break;
                    }
                }
            }
        }
        public void ClearNetwork()
        {
            //clear the vector of pointers to the input nodes
            InputNodes.Clear();
            OutputNodes.Clear();

            //delete all nodes from the network and clear the
            //vector
            Nodes.Clear();
        }
示例#3
0
        public virtual void ReadXml(XmlReader reader)
        {
            if (!reader.IsStartElement("BaseModule"))
            {
                logger.Error("Cannot load base module as <BaseModule> is missing from xml");
                throw new XmlException("Cannot load base module as <BaseModule> is missing from xml");
            }

            XElement bmnode = XElement.ReadFrom(reader) as XElement;


            int attrCount = reader.AttributeCount;

            _Guid = Guid.Parse(bmnode.Attribute("Guid").Value);
            var inputCount  = Int32.Parse(bmnode.Attribute("InputCount").Value);
            var outputCount = Int32.Parse(bmnode.Attribute("OutputCount").Value);
            var stateCount  = Int32.Parse(bmnode.Attribute("StateCount").Value);


            var attrib = bmnode.Attribute("ParameterCount");

            if (attrib != null)
            {
                this.ParameterCount = Int32.Parse(attrib.Value);
            }



            if (stateCount > 0)
            {
                var dict = bmnode.XPathSelectElement("dictionary");
                if (dict != null)
                {
                    var           dictReader    = dict.CreateReader();
                    XmlSerializer keySerializer = new XmlSerializer(typeof(SerializableDictionary <Guid, ModuleState>));
                    Store = (SerializableDictionary <Guid, ModuleState>)keySerializer.Deserialize(dictReader);
                }
            }

            var stateInfo = bmnode.XPathSelectElement("StateInfo");

            if (stateInfo != null)
            {
                var dict = stateInfo.XPathSelectElement("dictionary");
                if (dict != null)
                {
                    var           dictReader    = dict.CreateReader();
                    XmlSerializer keySerializer = new XmlSerializer(typeof(SerializableDictionary <string, string>));
                    StateInfo = (SerializableDictionary <string, string>)keySerializer.Deserialize(dictReader);
                }
            }

            InputNodes.Clear();
            foreach (var ioNode in bmnode.XPathSelectElements("//InputNodes/InputNode"))
            {
                var identifier  = Guid.Parse(ioNode.Attribute("Identifier").Value);
                var displayName = ioNode.Attribute("DisplayName").Value;
                var ext         = ioNode.Attribute("Extension").Value;

                var moduleNode = new InputNode(this, this.DisplayName, ext);
                moduleNode.Identity = identifier;

                if (Store.ContainsKey(identifier))
                {
                    moduleNode.State = Store[identifier];
                }
                else
                {
                    moduleNode.State = new ModuleState();
                }

                AddInputNode(moduleNode);
            }

            OutputNodes.Clear();
            foreach (var ioNode in bmnode.XPathSelectElements("//OutputNodes/OutputNode"))
            {
                var identifier  = Guid.Parse(ioNode.Attribute("Identifier").Value);
                var displayName = ioNode.Attribute("DisplayName").Value;
                var ext         = ioNode.Attribute("Extension").Value;

                var moduleNode = new OutputNode(this, this.DisplayName, ext);
                moduleNode.Identity = identifier;

                if (Store.ContainsKey(identifier))
                {
                    moduleNode.State = Store[identifier];
                }
                else
                {
                    moduleNode.State = new ModuleState();
                }
                AddOutputNode(moduleNode);
            }

            ReadParameter(bmnode);
        }