4.9.2 Compiling and Running a PGX Algorithm

To be able to compile and run a custom PGX algorithm, you must perform several actions:

  1. Set two configuration parameters in the conf/pgx.conf file:
    • Set the graph_algorithm_language option to JAVA.
    • Set the java_home_dir option to the path to your Java home (use <system-java-home-dir> to have PGX infer Java home from the system properties).
    {
      "graph_algorithm_language": "JAVA",
      "java_home_dir": "<system-java-home-dir>"
    }
  2. Create a session (either implicitly in the shell or explicitly in Java). For example:
    cd $PGX_HOME
    ./bin/opg4j
  3. Compile a PGX Algorithm. For example:
    myAlgorithm = session.compileProgram("/path/to/MyAlgorithm.java")
  4. Run the algorithm. For example:
    graph = session.readGraphWithProperties("/path/to/config.edge.json")
    property = graph.createVertexProperty(PropertyType.INTEGER)
    myAlgorithm.run(graph, property)