示例#1
0
        public static void AssertIsValid(
            MetaNeatGenome <T> metaNeatGenome,
            int id,
            int birthGeneration,
            ConnectionGenes <T> connGenes,
            int[] hiddenNodeIdArr,
            INodeIdMap nodeIndexByIdMap,
            DirectedGraph digraph,
            int[] connectionIndexMap)
        {
            // Mandatory ref tests.
            Debug.Assert(null != metaNeatGenome);
            Debug.Assert(null != connGenes);
            Debug.Assert(null != hiddenNodeIdArr);
            Debug.Assert(null != nodeIndexByIdMap);
            Debug.Assert(null != digraph);

            // Acyclic graph checks.
            if (metaNeatGenome.IsAcyclic)
            {
                AssertAcyclicGraph(metaNeatGenome, digraph, connectionIndexMap);
            }

            // Node counts.
            AssertNodeCounts(metaNeatGenome, hiddenNodeIdArr, nodeIndexByIdMap, digraph);

            // Hidden node IDs.
            Debug.Assert(ConnectionGenesUtils.ValidateHiddenNodeIds(hiddenNodeIdArr, connGenes._connArr, metaNeatGenome.InputOutputNodeCount));

            // Connections.
            AssertConnections(connGenes, digraph, nodeIndexByIdMap, connectionIndexMap);
        }
        /// <summary>
        /// Create a NeatGenome with the given meta data and connection genes.
        /// </summary>
        /// <param name="id">Genome ID.</param>
        /// <param name="birthGeneration">Birth generation.</param>
        /// <param name="connGenes">Connection genes.</param>
        /// <returns>A new NeatGenome instance.</returns>
        public NeatGenome <T> Create(
            int id,
            int birthGeneration,
            ConnectionGenes <T> connGenes)
        {
            // Determine the set of node IDs, and create a mapping from node IDs to node indexes.
            int[] hiddenNodeIdArr = ConnectionGenesUtils.CreateHiddenNodeIdArray(connGenes._connArr, _metaNeatGenome.InputOutputNodeCount, _workingIdSet);

            return(Create(id, birthGeneration, connGenes, hiddenNodeIdArr));
        }
示例#3
0
        public static void AssertIsValid(
            MetaNeatGenome <T> metaNeatGenome,
            int id,
            int birthGeneration,
            ConnectionGenes <T> connGenes,
            int[] hiddenNodeIdArr,
            INodeIdMap nodeIndexByIdMap,
            DirectedGraph digraph,
            int[]?connectionIndexMap)
        {
            // Check for mandatory object references.
            Debug.Assert(metaNeatGenome is object);
            Debug.Assert(connGenes is object);
            Debug.Assert(hiddenNodeIdArr is object);
            Debug.Assert(nodeIndexByIdMap is object);
            Debug.Assert(digraph is object);

            // Basic check on ID and birth generation.
            Debug.Assert(id >= 0);
            Debug.Assert(birthGeneration >= 0);

            // Acyclic graph checks.
            if (metaNeatGenome.IsAcyclic)
            {
                AssertAcyclicGraph(metaNeatGenome, digraph, connectionIndexMap);
            }

            // Node counts.
            AssertNodeCounts(metaNeatGenome, hiddenNodeIdArr, nodeIndexByIdMap, digraph);

            // Hidden node IDs.
            Debug.Assert(ConnectionGenesUtils.ValidateHiddenNodeIds(hiddenNodeIdArr, connGenes._connArr, metaNeatGenome.InputOutputNodeCount));

            // Connections.
            AssertConnections(connGenes, digraph, nodeIndexByIdMap, connectionIndexMap);
        }
        public static bool IsValid(
            MetaNeatGenome <T> metaNeatGenome,
            int id,
            int birthGeneration,
            ConnectionGenes <T> connGenes,
            int[] hiddenNodeIdArr,
            INodeIdMap nodeIndexByIdMap,
            DirectedGraph digraph,
            int[] connectionIndexMap)
        {
            // Mandatory ref tests.
            if (null == metaNeatGenome ||
                null == connGenes ||
                null == hiddenNodeIdArr ||
                null == nodeIndexByIdMap ||
                null == digraph)
            {
                return(false);
            }

            // Acyclic/cyclic specific checks.
            if (metaNeatGenome.IsAcyclic)
            {
                if (digraph.GetType() != typeof(AcyclicDirectedGraph) || null == connectionIndexMap)
                {
                    return(false);
                }
            }
            else
            {
                if (digraph.GetType() != typeof(DirectedGraph))
                {
                    return(false);
                }
            }


            // DepthInfo relates to acyclic graphs only, and is mandatory for acyclic graphs.
            // TODO: Enable once NeatGenomeAcyclicBuilder is finished.


            //if(metaNeatGenome.IsAcyclic)
            //{
            //    if(!IsValid_Acyclic(metaNeatGenome, depthInfo)) {
            //        return false;
            //    }
            //}

            // Node counts.
            if (!ValidateNodeCounts(metaNeatGenome, hiddenNodeIdArr, nodeIndexByIdMap, digraph))
            {
                return(false);
            }

            // Hidden node IDs.
            if (!ConnectionGenesUtils.ValidateHiddenNodeIds(hiddenNodeIdArr, connGenes._connArr, metaNeatGenome.InputOutputNodeCount))
            {
                return(false);
            }

            // Connections.
            if (!ValidateConnections(connGenes, digraph, nodeIndexByIdMap, connectionIndexMap))
            {
                return(false);
            }

            // All tests passed.
            return(true);
        }