4.10.2 カスタムPGXアルゴリズムのコンパイルおよび実行

カスタムPGXアルゴリズムをコンパイルおよび実行できるようにするには、次の処理を実行する必要があります。
  1. conf/pgx.confファイルに次の2つの構成パラメータを設定します。
    • graph_algorithm_languageオプションをJAVAに設定します。
    • java_home_dirオプションを、Javaホームへのパスに設定します(<system-java-home-dir>を使用して、PGXにシステム・プロパティからJavaホームを推測させます)。
    {
      "graph_algorithm_language": "JAVA",
      "java_home_dir": "<system-java-home-dir>"
    }
  2. セッションを作成します。
    cd /opt/oracle/graph
    ./bin/opg4j 
    import oracle.pgx.algorithm.*;
    PgxSession session = Pgx.createSession("my-session");
    session = instance.create_session("my-session")
  3. PGXアルゴリズムをコンパイルします。次に例を示します。
    opg4j> var myAlgorithm = session.compileProgram("/path/to/MyAlgorithm.java")
    myAlgorithm ==> CompiledProgram[name=MyAlgorithm]
    import oracle.pgx.algorithm.CompiledProgram;
    CompiledProgram myAlgorithm = session.compileProgram("/path/to/MyAlgorithm.java");
    my_algorithm = session.compile_program("/path/to/MyAlgorithm.java")
  4. アルゴリズムを実行します。次に例を示します。
    opg4j> var graph =session.readGraphWithProperties("/path/to/bank_graph_analytics.json")
    graph ==> PgxGraph[name=bank_graph_analytics,N=1000,E=5001,created=1633504705054]
    opg4j> var property = graph.createVertexProperty(PropertyType.INTEGER)
    property ==> VertexProperty[name=vertex_prop_integer_9,type=integer,graph=bank_graph_analytics]
    opg4j> myAlgorithm.run(graph, property)
    $6 ==> {
      "success" : true,
      "canceled" : false,
      "exception" : null,
      "returnValue" : 42,
      "executionTimeMs" : 0
    }
    import oracle.pgx.algorithm.VertexProperty;
    PgxGraph graph = session.readGraphWithProperties("/path/to/bank_graph_analytics.json");
    VertexProperty property = graph.createVertexProperty(PropertyType.INTEGER);
    myAlgorithm.run(graph, property);
    graph = session.read_graph_with_properties("/path/to/bank_graph_analytics.json")
    property = graph.create_vertex_property("integer")
    my_algorithm.run(graph, property)
    {'success': True, 'canceled': False, 'exception': None, 'return_value': 42, 'execution_time(ms)': 1}