Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JGraphT option for networks #65

Open
jozik opened this issue Dec 20, 2021 · 1 comment
Open

JGraphT option for networks #65

jozik opened this issue Dec 20, 2021 · 1 comment
Assignees

Comments

@jozik
Copy link
Member

jozik commented Dec 20, 2021

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
Copy link
Member

etatara commented Dec 21, 2021

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.");
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants