Skip to content

Commit

Permalink
renaming + failed attempt at getting rid of firstNeighborIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Needham committed Jun 12, 2015
1 parent 19eb15a commit 347e002
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/main/java/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ public static Network create( String fileName, ModularityOptimizer.ModularityFun
int[] neighbor;

List<Relationship> relationships = new ArrayList<>( 10_000 );
Map<Integer,Node> nodesMap = new TreeMap<Integer,Node>()
{
};
Map<Integer,Node> nodes = new TreeMap<Integer,Node>();
try ( BufferedReader bufferedReader = new BufferedReader( new FileReader( fileName ) ) )
{
String line;
Expand All @@ -187,18 +185,18 @@ public static Network create( String fileName, ModularityOptimizer.ModularityFun
int sourceId = parseInt( parts[0] );
int destinationId = parseInt( parts[1] );

Node source = nodesMap.get( sourceId );
Node source = nodes.get( sourceId );
if ( source == null )
{
source = new Node( sourceId );
nodesMap.put( sourceId, source );
nodes.put( sourceId, source );
}

Node destination = nodesMap.get( destinationId );
Node destination = nodes.get( destinationId );
if ( destination == null )
{
destination = new Node( destinationId );
nodesMap.put( destinationId, destination );
nodes.put( destinationId, destination );
}
double weight = (parts.length > 2) ? parseDouble( parts[2] ) : 1;
destination.in( source, weight );
Expand All @@ -208,8 +206,8 @@ public static Network create( String fileName, ModularityOptimizer.ModularityFun
}
}

int numberOfNodes = nodesMap.size();
int[] degree = degree( nodesMap );
int numberOfNodes = nodes.size();
int[] degree = degree( nodes );
int[] firstNeighborIndex = new int[numberOfNodes + 1];
nEdges = 0;
for ( i = 0; i < numberOfNodes; i++ )
Expand Down Expand Up @@ -240,8 +238,7 @@ public static Network create( String fileName, ModularityOptimizer.ModularityFun
}
}

return modularityFunction.createNetwork( numberOfNodes, nEdges, firstNeighborIndex, neighbor, edgeWeight,
nodesMap );
return modularityFunction.createNetwork( numberOfNodes, nEdges, firstNeighborIndex, neighbor, edgeWeight, nodes );
}

private static int[] degree( Map<Integer,Node> nodesMap )
Expand Down Expand Up @@ -436,10 +433,8 @@ public ReducedNetwork calculateReducedNetwork()
{
reducedNetworkNEdges2 = 0;
for ( j = 0; j < clusters.get( i ).numberOfNodes(); j++ )
// for ( j = 0; j < nodePerCluster[i].length; j++ )
{
k = clusters.get( i ).nodesIds()[j];
// k = nodePerCluster[i][j];

for ( l = firstNeighborIndex[k]; l < firstNeighborIndex[k + 1]; l++ )
{
Expand Down Expand Up @@ -570,7 +565,6 @@ public boolean runLocalMovingAlgorithm( double resolution, Random random )
do
{
int nodeId = nodesInRandomOrder[i];

int numberOfNeighbouringClusters = 0;
for ( int k = firstNeighborIndex[nodeId]; k < firstNeighborIndex[nodeId + 1]; k++ )
{
Expand Down Expand Up @@ -935,6 +929,18 @@ private Network createSubnetwork( int clusterId, int[] subnetworkNode, int[] sub
{
int nodeId = clusters.get(clusterId).nodesIds()[i];

// for ( Relationship relationship : nodes.get(nodeId).relationships() )
// {
// int otherNodeId = relationship.otherNode( nodeId );
// if ( clusters.findClusterId( otherNodeId ) == clusterId )
// {
// subnetworkNeighbor[subnetworkNEdges] = otherNodeId;
// subnetworkEdgeWeight[subnetworkNEdges] = relationship.getWeight();
// subnetworkNEdges++;
// }
// }


// iterate all the neighbouring nodes of 'nodeId'
// firstNeighborIndex[nodeId] gives us this node
// firstNeighbor[nodeId +1] gives us the first neighbour of the next node
Expand Down

0 comments on commit 347e002

Please sign in to comment.