Esempio n. 1
0
    // Private Functions //
    // ExpandCluster                                                                                                     //
    // Requires and initial search node and a list of its neighbours, along with full list of search nodes for expansion //
    // Returns a Cluster Class object - which deals with its own variables                                               //
    private Cluster ExpandCluster( SearchNode initialPoint, List< SearchNode > neighbours, SearchNode[] nodesToBeSearched )
    {
        // Create new cluster
        Cluster cluster = new Cluster();

        // Flag and add initial point to cluster
        initialPoint.SetAsPartOfCluster( true );
        cluster.AddSearchNode( initialPoint );

        // Loop through passed neighbour points
        for( int i = 0; i < neighbours.Count; i++ ) {
            // If it has NOT been visited
            if( !neighbours[ i ].HasBeenVisited() ) {
                // Now flag as visited
                neighbours[ i ].SetVisited( true );

                // Get neighbours of each point
                List< SearchNode > localNeighbours = GetNeighbours( neighbours[ i ], nodesToBeSearched );

                // If this point has enough neighbours
                if( localNeighbours.Count >= mMinimumPoints ) {
                    for( int j = 0; j < localNeighbours.Count; j++ ) {
                        // If this point isnt already a neighbour or has NOT been previously visited
                        // Add it as a brand new neighbour
                        //if( ( !localNeighbours[ j ].IsNeighbour() ) && ( !localNeighbours[ j ].HasBeenVisited() ) ) {
                        if( !localNeighbours[ j ].HasBeenVisited() ) {
                            // Add ONLY add localNeighbours that are 'joined' with nodes in neighbours
                            if( CheckIfJoined( localNeighbours[ j ], neighbours ) ) {
                                neighbours.Add( localNeighbours[ j ] );
                            }
                        }
                    }

                    // If this point is not part of a cluster - flag and add it!
                    if( !neighbours[ i ].PartOfCluster() ) {
                        neighbours[ i ].SetAsPartOfCluster( true );
                        cluster.AddSearchNode( neighbours[ i ] );
                    }
                }
            }
        }

        // Return final cluster
        return cluster;
    }