Represents a node within a HyperNEAT substrate.
Ejemplo n.º 1
0
        /// <summary>
        /// Returns an IEnumerable that yields the mappings/connections defined by the mapping function (from the source nodes to
        /// the target nodes) as a sequence. The alternative of returning a list would require a very long list in extreme scenarios;
        /// this approach minimizes down memory usage.
        /// </summary>
        public IEnumerable <SubstrateConnection> GenerateConnections(SubstrateNodeSet srcNodeSet, SubstrateNodeSet tgtNodeSet)
        {
            // Test for scenario where srcNodeSet and tgtNodeSet are the same node set, that is, we are creating
            // connections within a nodeset and therefore we need to test (and honour) _allowLocalRecurrentConnections.
            if (srcNodeSet == tgtNodeSet)
            {
                // Mapping between nodes within a single node set.

                // Break the inner loop into two. This avoids having to make the local recurrent test connection
                // for every node pair - we only test when we actually have the same node as source and target.
                IList <SubstrateNode> nodeList = srcNodeSet.NodeList;
                int count = nodeList.Count;
                for (int i = 0; i < count; i++)
                {
                    // Loop over all nodes prior to the i'th.
                    SubstrateNode srcNode = nodeList[i];
                    for (int j = 0; j < i; j++)
                    {
                        if (_testNodePair(srcNode, nodeList[j]))
                        {
                            yield return(new SubstrateConnection(srcNode, nodeList[j]));
                        }
                    }

                    //  Test for local recurrent connection.
                    if (_allowLocalRecurrentConnections && _testNodePair(srcNode, srcNode))
                    {
                        yield return(new SubstrateConnection(srcNode, srcNode));
                    }

                    // Loop over all nodes after the i'th.
                    for (int j = i + 1; j < count; j++)
                    {
                        if (_testNodePair(srcNode, nodeList[j]))
                        {
                            yield return(new SubstrateConnection(srcNode, nodeList[j]));
                        }
                    }
                }
            }
            else
            {
                // Mapping between nodes in two distinct node sets.
                foreach (SubstrateNode srcNode in srcNodeSet.NodeList)
                {
                    foreach (SubstrateNode tgtNode in tgtNodeSet.NodeList)
                    {
                        if (_testNodePair(srcNode, tgtNode))
                        {
                            yield return(new SubstrateConnection(srcNode, tgtNode));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private bool TestNodePair_MaxDistance(SubstrateNode srcNode, SubstrateNode tgtNode)
 {
     return(CalcDistanceSquared(srcNode._position, tgtNode._position) < _maximumConnectionDistanceSquared);
 }
 private bool TestNodePair_MaxDistance(SubstrateNode srcNode,SubstrateNode tgtNode)
 {
     return CalcDistanceSquared(srcNode._position, tgtNode._position) < _maximumConnectionDistanceSquared;
 }
Ejemplo n.º 4
0
 private bool TestNodePair_NullTest(SubstrateNode srcNode, SubstrateNode tgtNode)
 {
     return(true);
 }
 private bool TestNodePair_NullTest(SubstrateNode srcNode,SubstrateNode tgtNode)
 {
     return true;
 }