PregelEx.Graph (PregelEx v0.1.3)

View Source

Summary

Functions

Advances all vertices in the graph to the next superstep.

Returns a specification to start this module under a supervisor.

Clears all outgoing messages for every vertex in the specified graph.

Clears all outgoing messages for a vertex.

Collects all outgoing messages from the vertices of the specified graph.

Invokes the :compute operation on all active vertices in the graph identified by graph_id.

Creates an edge between two vertices in the graph.

Delivers a list of messages to their respective recipient vertices within the specified graph.

Gets all outgoing edges for a vertex.

Gets all neighbor vertex IDs for a vertex (vertices with outgoing edges).

Lists all edges in the graph by collecting outgoing edges from all vertices.

Removes an edge between two vertices.

Sends a message from one vertex to another.

Functions

advance_all_vertices_superstep(graph_id)

Advances all vertices in the graph to the next superstep.

Given a graph_id, this function retrieves all vertex process IDs associated with the graph and sends each one a synchronous :advance_superstep message via GenServer.call/2. Returns :ok if successful, or propagates any error encountered when listing vertices.

Parameters

  • graph_id: The identifier of the graph whose vertices should be advanced.

Returns

  • :ok on success.
  • An error tuple if listing vertices fails.

check_termination_condition(graph_id)

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear_all_outgoing_messages(graph_id)

Clears all outgoing messages for every vertex in the specified graph.

Given a graph_id, this function retrieves all vertex process IDs associated with the graph, and sends each one a synchronous call to clear its outgoing messages.

Parameters

  • graph_id: The identifier of the graph whose vertices' outgoing messages should be cleared.

Returns

  • :ok if all outgoing messages were successfully cleared.
  • An error tuple if the vertices could not be listed.

Examples

iex> clear_all_outgoing_messages("my_graph")
:ok

clear_outgoing_messages(graph_id, vertex_id)

Clears all outgoing messages for a vertex.

collect_all_outgoing_messages(graph_id)

Collects all outgoing messages from the vertices of the specified graph.

Given a graph_id, this function retrieves the list of vertex process IDs, then queries each vertex for its outgoing messages using a GenServer call. It aggregates all messages into a single list and returns them in an {:ok, messages} tuple. If there is an error retrieving the vertices, the error is returned as is.

Parameters

  • graph_id: The identifier of the graph whose vertices' outgoing messages are to be collected.

Returns

  • {:ok, messages}: A tuple containing the list of all outgoing messages from all vertices.
  • error: Any error encountered while retrieving the list of vertices.

compute_all_active_vertices(graph_id)

Invokes the :compute operation on all active vertices in the graph identified by graph_id.

This function performs the following steps:

  1. Retrieves the list of vertex process IDs (PIDs) for the given graph_id.
  2. Filters the list to include only those vertices whose state is :active.
  3. For each active vertex, calls the :compute operation via GenServer.call/2.
  4. Returns :ok if successful, or propagates any error encountered during vertex retrieval.

Parameters

  • graph_id: The identifier of the graph whose active vertices should be computed.

Returns

  • :ok on success.
  • An error tuple if the vertex list could not be retrieved.

compute_vertex(graph_id, vertex_id)

create_edge(graph_id, from_vertex_id, to_vertex_id, opts \\ [])

Creates an edge between two vertices in the graph.

This adds the edge to the source vertex's outgoing edges list. The edge contains the destination vertex ID, weight, and optional properties.

Parameters

  • graph_id: The ID of the graph containing the vertices
  • from_vertex_id: The source vertex ID
  • to_vertex_id: The destination vertex ID
  • weight: The weight/cost of the edge (defaults to 1)
  • properties: Additional metadata for the edge (defaults to empty map)

Returns

  • on success
  • on failure

create_vertex(graph_id, name, function, opts \\ [])

@spec create_vertex(String.t(), String.t(), (map() -> map()), keyword()) ::
  {:ok, String.t(), pid()} | {:error, atom()}

deliver_messages_to_recipients(graph_id, messages)

Delivers a list of messages to their respective recipient vertices within the specified graph.

Each message is grouped by its recipient vertex ID. For each group, the function attempts to find the process ID (PID) of the recipient vertex using get_vertex_pid/2. If the vertex exists, the messages are delivered to it via a synchronous GenServer.call/2. If the vertex does not exist, the function handles the case gracefully (currently by doing nothing).

Parameters

  • graph_id: The identifier of the graph containing the vertices.
  • messages: A list of %PregelEx.Message{} structs to be delivered.

Returns

  • :ok after attempting to deliver all messages.

Notes

  • If a recipient vertex does not exist, the function does not deliver the messages and simply continues.
  • This function is side-effecting and intended for internal message passing within the PregelEx graph processing framework.

execute_superstep(graph_id)

get_final_value(graph_id)

get_vertex_count(graph_id)

get_vertex_edges(graph_id, vertex_id)

Gets all outgoing edges for a vertex.

get_vertex_neighbors(graph_id, vertex_id)

Gets all neighbor vertex IDs for a vertex (vertices with outgoing edges).

get_vertex_pid(graph_id, vertex_id)

get_vertex_state(graph_id, vertex_id)

list_edges(graph_id)

Lists all edges in the graph by collecting outgoing edges from all vertices.

list_vertices(graph_id)

remove_edge(graph_id, from_vertex_id, to_vertex_id)

Removes an edge between two vertices.

run(graph_id, opts \\ [])

run_with_limits(graph_id, superstep, log, max_supersteps, timeout)

send_message(graph_id, from_vertex_id, to_vertex_id, content)

Sends a message from one vertex to another.

start_link(graph_id)

stop_vertex(graph_id, vertex_id)