Exemplo n.º 1
0
        /// <summary>
        /// Writes a list of NeatGenome(s) to XML within a containing 'Root'
        /// element and the activation function library that the genomes are
        /// associated with.
        /// </summary>
        /// <param name="xw">XmlWriter to write XML to.</param>
        /// <param name="genomeList">List of genomes to write as XML.</param>
        /// <param name="nodeFnIds">Indicates if node activation function IDs
        /// should be emitted. They are required
        /// for HyperNEAT genomes but not for NEAT.</param>
        public static void WriteComplete(XmlWriter xw, IList <NeatGenome> genomeList,
                                         bool nodeFnIds)
        {
            if (genomeList.Count == 0)
            {   // Nothing to do.
                return;
            }
            // <Root>
            xw.WriteStartElement(__ElemRoot);

            // Write activation function library from the first genome.
            // (we expect all genomes to use the same library).
            IActivationFunctionLibrary activationFnLib = genomeList[0].ActivationFnLibrary;

            NetworkXmlIO.Write(xw, activationFnLib);
            // <Networks>
            xw.WriteStartElement(__ElemNetworks);
            // Write genomes.
            foreach (NeatGenome genome in genomeList)
            {
                Debug.Assert(genome.ActivationFnLibrary == activationFnLib);
                Write(xw, genome, nodeFnIds);
            }
            // </Networks>
            xw.WriteEndElement();
            // </Root>
            xw.WriteEndElement();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Writes a single NeatGenome to XML within a containing 'Root' element
 /// and the activation function library that the genome is associated with.
 /// </summary>
 /// <param name="xw">XmlWriter to write XML to.</param>
 /// <param name="genome">Genome to write as XML.</param>
 /// <param name="nodeFnIds">Indicates if node activation function IDs
 /// should be emitted. They are required for HyperNEAT genomes but not
 /// for NEAT.</param>
 public static void WriteComplete(XmlWriter xw, NeatGenome genome, bool nodeFnIds)
 {
     // <Root>
     xw.WriteStartElement(__ElemRoot);
     // Write activation function library.
     NetworkXmlIO.Write(xw, genome.ActivationFnLibrary);
     // <Networks>
     xw.WriteStartElement(__ElemNetworks);
     // Write single genome.
     Write(xw, genome, nodeFnIds);
     // </Networks>
     xw.WriteEndElement();
     // </Root>
     xw.WriteEndElement();
 }