14.5.2 Simplifying and Copying Graphs
You can create a simplified version of the graph by calling the simplify()
method.
PgxGraph simplify(Collection<VertexProperty<?, ?>> vertexProps, Collection<EdgeProperty<?>> edgeProps, MultiEdges multiEdges, SelfEdges selfEdges, TrivialVertices trivialVertices, Mode mode, String newGraphName)
simplify(self, vertex_properties=True, edge_properties=True, keep_multi_edges=False, keep_self_edges=False, keep_trivial_vertices=False, in_place=False, name=None)
The first two arguments (vertexProps
and edgeProps
) list which properties will be copied into the newly created simplified graph instance. PGX provides convenience constants VertexProperty.ALL
, EdgeProperty.ALL
and VertexProperty.NONE
, EdgeProperty.NONE
to specify all properties or none properties to be stored, respectively.
The next three arguments determine which operations will be performed to simplify the graph.
multiEdges
: ifMultiEdges.REMOVE_MULTI_EDGES
, eliminate multiple edges between a source vertex and a destination vertex, that is, leave at most one edge between two vertices.MultiEdges.KEEP_MULTI_EDGES
indicates to keep them. By default, PGX picks one edge out of the multi-edges and takes its properties. See Advanced Multi-Edge Handling for more fine-grained control over the edge properties during simplification.selfEdges
: ifSelfEdges.REMOVE_SELF_EDGES
, eliminate every edge whose source and destination are the same vertex.SelfEdges.KEEP_MULTI_EDGES
indicates to keep them.trivialVertices
: ifTrivialVertices.REMOVE_TRIVIAL_VERTICES
, eliminate all the vertices that have neither incoming edges nor outgoing edges.TrivialVertices.KEEP_TRIVIAL_VERTICES
indicates to keep them.
The mode
argument, if set to Mode.MUTATE_IN_PLACE
, requests that the mutation occurs directly on the specified graph instance without creating a new one. If set to Mode.CREATE_COPY
, the method will create a new graph instance with the new name in newGraphName
. If newGraphName
is omitted (or null
), PGX will generate a unique graph name.
The return value of this method is the simplified PgxGraph
instance.
The Mode.MUTATE_IN_PLACE
option is only applicable if the graph is marked as mutable. Every graph is immutable by default when loaded into PGX. To make a PgxGraph
mutable, the client should create a private copy of the graph first, using one of the following methods:
PgxGraph clone() PgxGraph clone(String newGraphName) PgxGraph clone(Collection<VertexProperty<?, ?>> vertexProps, Collection<EdgeProperty<?>> edgeProps, String newGraphName)
clone(self, vertex_properties=True, edge_properties=True, name=None)
As with simplify()
, the user can specify optional properties of the graph to copy with vertexProps
and edgeProps
. If no properties are specified, all of the original graph's properties will be copied into the new graph instance. The user can specify the name of the newly created graph instance with newGraphName
.
Parent topic: Graph Mutation and Subgraphs