An algorithm for testing for the presence of at least one connectivity cycle within a network. Method. ======= 1) We loop over all nodes in the network and perform a depth-first traversal from each node. (Note. the order that the nodes are traversed does not affect the correctness of the method) 2) Each traversal keeps track of its ancestor nodes (the path to the current node) for each step in the traversal. Thus if the traversal encounters an ancestor node then a cycle has been detected. 3) A set of visited nodes is maintained. This persists between traversals and allows each traversal to avoid traversing into nodes that have already been traversed. Note. We must traverse from each node rather then just e.g. the input nodes, because the network may have connectivity dead ends or even isolated connectivity that therefore would not be traversed into by following connectivity from the input nodes only, hence we perform a traversal from each node and attempt to maintain algorithmic efficiency by avoiding traversal into nodes that have already been traversed into.
Esempio n. 1
0
 /// <summary>
 /// Constructs with the provided input/output node count, activation function library,
 /// node and connection lists.
 /// </summary>
 public NetworkDefinition(int inputNodeCount, int outputNodeCount,
                          IActivationFunctionLibrary activationFnLib,
                          NodeList nodeList, ConnectionList connectionList)
 {
     _inputNodeCount  = inputNodeCount;
     _outputNodeCount = outputNodeCount;
     _activationFnLib = activationFnLib;
     _nodeList        = nodeList;
     _connectionList  = connectionList;
     _isAcyclic       = !CyclicNetworkTest.IsNetworkCyclic(this);
 }
Esempio n. 2
0
        /// <summary>
        /// Constructs with the provided input/output node count, activation function library,
        /// node and connection lists.
        /// </summary>
        public NetworkDefinition(int inputNodeCount, int outputNodeCount,
                                 IActivationFunctionLibrary activationFnLib,
                                 INodeList nodeList, IConnectionList connectionList,
                                 bool isAcyclic)
        {
            _inputNodeCount  = inputNodeCount;
            _outputNodeCount = outputNodeCount;
            _activationFnLib = activationFnLib;
            _nodeList        = nodeList;
            _connectionList  = connectionList;
            _isAcyclic       = isAcyclic;

            Debug.Assert(isAcyclic == !CyclicNetworkTest.IsNetworkCyclic(this));
        }