public void IsConnectionCyclic1()
        {
            var cyclicCheck = new CyclicConnectionCheck();

            var connArr = new DirectedConnection[3];

            connArr[0] = new DirectedConnection(0, 1);
            connArr[1] = new DirectedConnection(1, 2);
            connArr[2] = new DirectedConnection(2, 3);

            // True tests (cycle).
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(0, 0)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(1, 1)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(2, 2)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(3, 3)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(1, 0)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(2, 0)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(3, 0)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(2, 1)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(3, 1)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(3, 2)));

            // False tests (no cycle).
            Assert.False(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(0, 2)));
            Assert.False(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(0, 3)));
            Assert.False(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(1, 3)));
            Assert.False(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(2, 3)));
        }
        public void IsConnectionCyclic2()
        {
            var cyclicCheck = new CyclicConnectionCheck();

            var connArr = new DirectedConnection[8];

            connArr[0] = new DirectedConnection(0, 1);
            connArr[1] = new DirectedConnection(0, 2);
            connArr[2] = new DirectedConnection(0, 3);
            connArr[3] = new DirectedConnection(1, 4);
            connArr[4] = new DirectedConnection(4, 2);
            connArr[5] = new DirectedConnection(2, 5);
            connArr[6] = new DirectedConnection(3, 6);
            connArr[7] = new DirectedConnection(3, 2);
            Array.Sort(connArr);

            // True tests (cycle).
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(2, 1)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(2, 4)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(5, 2)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(5, 0)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(5, 4)));
            Assert.True(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(6, 0)));

            // False tests (no cycle).
            Assert.False(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(3, 5)));
            Assert.False(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(1, 3)));
            Assert.False(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(6, 1)));
            Assert.False(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(6, 2)));
            Assert.False(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(6, 4)));
            Assert.False(cyclicCheck.IsConnectionCyclic(connArr, new DirectedConnection(3, 4)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="metaNeatGenome">NEAT genome metadata.</param>
        /// <param name="genomeBuilder">NeatGenome builder.</param>
        /// <param name="genomeIdSeq">Genome ID sequence; for obtaining new genome IDs.</param>
        /// <param name="generationSeq">Generation sequence; for obtaining the current generation number.</param>
        public AddAcyclicConnectionStrategy(
            MetaNeatGenome <T> metaNeatGenome,
            INeatGenomeBuilder <T> genomeBuilder,
            Int32Sequence genomeIdSeq,
            Int32Sequence generationSeq)
        {
            _metaNeatGenome = metaNeatGenome;
            _genomeBuilder  = genomeBuilder;
            _genomeIdSeq    = genomeIdSeq;
            _generationSeq  = generationSeq;

            _weightSamplerA = UniformDistributionSamplerFactory.CreateStatelessSampler <T>(metaNeatGenome.ConnectionWeightScale, true);
            _weightSamplerB = UniformDistributionSamplerFactory.CreateStatelessSampler <T>(metaNeatGenome.ConnectionWeightScale * 0.01, true);
            _cyclicCheck    = new CyclicConnectionCheck();
        }