graph.addNode( 0, tempNode );
}
int degreeBy2 = meanDegree / 2;
DNVNode tempNode2;
DNVEdge tempEdge;
int edgeId = numberOfNodes;
HashMap<String, DNVEdge> edgeMap = new HashMap<String, DNVEdge>();
System.out.println( "Generating nodes and edges..." );
for( int i = 0; i < numberOfNodes; i++ )
{
if( i % 10000 == 0 )
{
System.out.println( 1 + " : " + i );
}
tempNode = (DNVNode)graph.getNodeById( i );
for( int j = i - degreeBy2; j <= i + degreeBy2; j++ )
{
int index = j % numberOfNodes;
if( index < 0 )
{
index += numberOfNodes;
}
if( index != i )
{
tempNode2 = (DNVNode)graph.getNodeById( index );
tempEdge = edgeMap.get( i + "_" + index );
if( tempEdge == null )
{
tempEdge = edgeMap.get( index + "_" + i );
if( tempEdge == null )
{
tempEdge = new DNVEdge( tempNode, tempNode2, graph );
tempEdge.setId( edgeId++ );
graph.addNode( 0, tempEdge );
edgeMap.put( i + "_" + index, tempEdge );
edgeMap.put( index + "_" + i, tempEdge );
}
}
}
}
}
System.out.println( "Rewiring edges..." );
for( int i = 0; i < numberOfNodes; i++ )
{
if( i % 10000 == 0 )
{
System.out.println( 2 + " : " + i );
}
tempNode = (DNVNode)graph.getNodeById( i );
for( int j = i + 1; j < numberOfNodes; j++ )
{
if( Math.random() < rewireProbability )
{
tempEdge = edgeMap.remove( i + "_" + j );
edgeMap.remove( j + "_" + i );
if( tempEdge != null )
{
graph.removeNode( 0, tempEdge );
int index = (int)( Math.random() * numberOfNodes );
while( index == i )
index = (int)( Math.random() * numberOfNodes );
tempNode2 = (DNVNode)graph.getNodeById( index );
tempEdge = new DNVEdge( tempNode, tempNode2, graph );
tempEdge.setId( edgeId++ );
graph.addNode( 0, tempEdge );
}
}
}
}