2

I have a dynamic graph changing over time and I am using Jgrapht library to store each instance of the graph in memory using
UndirectedGraph<Node, DefaultEdge> timeGraph = new SimpleGraph<Node, DefaultEdge>(DefaultEdge.class);

As it is intensive to hold multiple huge graphs in-memory, I wanted to know if there is a way to store each instance of the timeGraph as it is in a database like MongoDB (Neo4j or anyother) and import a particular graph to memory whenever necessary; instead of building the nodes and relationships again in the graph database.

P.S. I have tried exporting to graphML file format and importing each time, but it doesn't seem to help (due to my additional requirements of subgraph storing). customGraphMLImporter.GraphMLImport(i_timestep);

Looking for inputs so I can try out the options. Thanks.

Stennie
  • 63,885
  • 14
  • 149
  • 175
Steve
  • 45
  • 5
  • Please don't "randomly tag". Unless this questions applies *specifically* to a particular database (ie. Mongo or Neo, which are fundamentally different) those tags should be removed. – user2864740 May 17 '15 at 21:46
  • Sorry about that. @Stennie thank you for the edit. – Steve May 18 '15 at 09:24

1 Answers1

2

You have few options here:

  1. To use 3rd party graph-oriented database (like Neo4J), MongoDB is document oriented and isn't optimized for graph operations)
  2. Serialize your graph to file and store this files on a disk

Which option to choose is up to you, in case if you need all graph in memory of your application - I'd suggest to store it by yourself in plain files. (Because you can directly read all your graph into memory and use it without database overhead), if you need only part of your graph, I'd suggest using Neo4J with its API for graph traversal.

Stanislav Levental
  • 2,165
  • 1
  • 14
  • 28
  • Thank you for the response. Since I need all the graphs in memory, I guess i will look into the further usability by serializing into files. As I am new to the library, could you help provide an example (snippet or any material) explaining on how to serialize and de-serialize only the Jgrapht `Graph `? – Steve May 18 '15 at 09:13
  • 1
    class AbstractBaseGraph is serializable, this means that you can store it using simple java serialization API (I'd suggest using more convenient util wrapper from apache commons https://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/SerializationUtils.html) – Stanislav Levental May 18 '15 at 18:26