Repast / repast.simphony

Git repository for Repast Simphony development
repast.github.io
90 stars 21 forks source link

JGraphT option for networks #65

Open jozik opened 2 years ago

jozik commented 2 years ago

From Dec 16, repast-interest mailing list question:

Hi,

for my Repast Simphony Project I changed the underlying graph implementation for networks from JUNG (https://github.com/jrtom/jung) to JGraphT (https://github.com/jgrapht/jgrapht), because it gives me significant performance boosts speedwise. (network with 500.000+ agents)

I did this by implementing a class JGraphTNetwork extends DefaultProjection implements Network which provides the appropriate mapping to the JGraphT API and a class ContextJGraphTNetwork implements Network, ContextListener which basically just copies ContextJungNetwork. (not so good solution)

Is there in general a more easy way of doing this? When I want to export the network as graphml I also run into class newyork.graph.ContextJGraphTNetwork cannot be cast to class repast.simphony.context.space.graph.ContextJungNetwork Is there a way of fixing this?

Thank you very much. Best Tim

etatara commented 2 years ago

Simple test class that builds a large network and times the performance separate from the Repast runtime.

package repast.simphony.graph;

import repast.simphony.context.DefaultContext;
import repast.simphony.context.space.graph.ContextJungNetwork;
import repast.simphony.engine.environment.RunState;
import repast.simphony.space.graph.DefaultEdgeCreator;
import repast.simphony.space.graph.DirectedJungNetwork;
import repast.simphony.space.graph.Network;

public class BigNetTester {

    // VM Args:  -verbose:gc   
  //           -Xmx24000M  231s  100% CPU
    //           -Xmx24000M -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled   128s
    //           -Xmx24000M -Xms32M -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled 105s
  //           -Xmx24000M -Xms32M -XX:+UseConcMarkSweepGC 95s
    //           -Xmx24000M -Xms128M -XX:+UseConcMarkSweepGC 96s
    //           -Xmx24000M -Xms32M -XX:+UseG1GC   FAIL!  memory allocation
    //           -Xmx20000M -Xms32M -XX:+UseG1GC 150s  100% CPU

    public static void main(String[] args) {
        long startTime = System.nanoTime();
        RunState.init(null, null, null);

        DefaultContext<Integer> context = new DefaultContext<Integer>("A Context");

//      Network<Integer> net1 = NetworkFactoryFinder.createNetworkFactory(null).createNetwork(
//              "Network 1", context, true);

        Network<Integer> net1 = new ContextJungNetwork<Integer>(
                new DirectedJungNetwork<Integer>("Network 1",  new DefaultEdgeCreator<Integer>()), context);

        int numAgents = (int)1E6;

        Integer[] agents = new Integer[numAgents];

        for (int i = 0; i < numAgents; i++) {
            agents[i] = i;
            context.add(i);
        }

        System.out.println("Building network");

        for (int i = 20; i < numAgents; i++) {
            for (int j=0; j<20; j++) {
                net1.addEdge(agents[i-j], agents[i]);
            }

            if (i % 100000 == 0) System.out.println(i);
        }

        System.out.println("Created network with " + net1.numEdges() + " edges and " + net1.size() + " vertices.");
        long stopTime = System.nanoTime();
        System.out.println("Time: " + (stopTime-startTime)/1E9 + " s.");
    }
}