Minimum Directed Steiner Tree

Glossary

Directed

Directed trait. The algorithm is well-defined on a directed graph.

Directed

Directed trait. The algorithm ignores the direction of the graph.

Directed

Directed trait. The algorithm does not run on a directed graph.

Undirected

Undirected trait. The algorithm is well-defined on an undirected graph.

Undirected

Undirected trait. The algorithm ignores the undirectedness of the graph.

Heterogeneous nodes

Heterogeneous nodes fully supported. The algorithm has the ability to distinguish between nodes of different types.

Heterogeneous nodes

Heterogeneous nodes allowed. The algorithm treats all selected nodes similarly regardless of their label.

Heterogeneous relationships

Heterogeneous relationships fully supported. The algorithm has the ability to distinguish between relationships of different types.

Heterogeneous relationships

Heterogeneous relationships allowed. The algorithm treats all selected relationships similarly regardless of their type.

Weighted relationships

Weighted trait. The algorithm supports a relationship property to be used as weight, specified via the relationshipWeightProperty configuration parameter.

Weighted relationships

Weighted trait. The algorithm treats each relationship as equally important, discarding the value of any relationship weight.

Introduction

A spanning tree is a graph such that there is exactly one path between any two nodes in the set. A graph can have many possible spanning tree subsets depending on the set of nodes/relationships selected.

Given a weighted graph where each node has a prize, the Prize-Collecting Steiner Tree problem asks for the spanning tree that satisfies the following conditions:

  • the sum of prizes for the nodes in the graph is mximized.

  • the sum of weights of relationships and prizes for nodes not in the tree is minimized.

The two constraints can combined to form a single maximization problem by simpling subtracting the second constraint for the former.

The Prize-Collecting Steiner Tree is NP-Complete and no efficient exact algorithms is known. The Neo4j GDS Library implements a practical 2-approximate algorithm from the literature. This means that the returned answer should be at least half as good as the optimal answer.

Considerations

By default, the Prize-Collecting Steiner Tree problem considers prizes only for nodes. In some cases, however, it can be useful to also consider prizes on relationships. The GDS implementation can handle prizes for relationships through the following transformation: Given a relationship with weight w and prize p, we suggest to replace w with w' = w - p. This should be done as a pre-processing step prior to projecting the in-memory graph.

Syntax

Prize-collecting Steiner Tree syntax per mode
Run the algorithm in stream mode on a named graph.
CALL gds.steinerTree.stream(
  graphName: String,
  configuration: Map
)
YIELD
  nodeId: Integer,
  parentId: Integer,
  weight: Float
Table 1. Parameters
Name Type Default Optional Description

graphName

String

n/a

no

The name of a graph stored in the catalog.

configuration

Map

{}

yes

Configuration for algorithm-specifics and/or graph filtering.

Table 2. Configuration
Name Type Default Optional Description

nodeLabels

List of String

['*']

yes

Filter the named graph using the given node labels. Nodes with any of the given labels will be included.

relationshipTypes

List of String

['*']

yes

Filter the named graph using the given relationship types. Relationships with any of the given types will be included.

concurrency

Integer

4

yes

The number of concurrent threads used for running the algorithm.

jobId

String

Generated internally

yes

An ID that can be provided to more easily track the algorithm’s progress.

logProgress

Boolean

true

yes

If disabled the progress percentage will not be logged.

relationshipWeightProperty

String

null

yes

Name of the relationship property to use as weights. If unspecified, the algorithm runs unweighted.

prizeProperty

String

n/a

no

The name of node property that denotes a node’s price.

Table 3. Results
Name Type Description

nodeId

Integer

A node in the discovered spanning tree.

parentId

Integer

The parent of nodeId in the spanning tree or nodeId if it is equal to the source node.

weight

Float

The weight of the relationship from parentId to nodeId.

Examples

All the examples below should be run in an empty database.

The examples use Cypher projections as the norm. Native projections will be deprecated in a future release.

In this section we will show examples of running the Prize-Collecting Steiner Tree algorithm algorithm on a concrete graph. The intention is to illustrate what the results look like and to provide a guide in how to make use of the algorithm in a real setting. We will do this on a small road network graph of a handful nodes connected in a particular pattern. The example graph looks like this:

Visualization of the example graph
The following will create the sample graph depicted in the figure:
CREATE (a:Place {id: 'A', prize: 5.0}),
       (b:Place {id: 'B', prize: 20.0}),
       (c:Place {id: 'C',prize: 11.0}),
       (d:Place {id: 'D',prize: 10.0}),
       (e:Place {id: 'E',prize: 8.0}),
       (f:Place {id: 'F',prize: 1.0}),
       (a)-[:LINK {cost:10}]->(f),
       (a)-[:LINK {cost:3}]->(b),
       (a)-[:LINK {cost:7}]->(e),
       (b)-[:LINK {cost:1}]->(c),
       (c)-[:LINK {cost:4}]->(d),
       (c)-[:LINK {cost:6}]->(e),
       (f)-[:LINK {cost:3}]->(d);
The following will project and store a named graph:
MATCH (source:Place)-[r:LINK]->(target:Place)
RETURN gds.graph.project(
  'graph',
  source,
  target,
{
    sourceNodeProperties: source { .prize },
    targetNodeProperties: target { .prize },
    relationshipProperties: r { .cost }
  },
  { undirectedRelationshipTypes: ['*'] }
)

Memory estimation

First off, we will estimate the cost of running the algorithm using the estimate procedure. This can be done with any execution mode. We will use the stream mode in this example. Estimating the algorithm is useful to understand the memory impact that running the algorithm on your graph will have. When you later actually run the algorithm in one of the execution modes the system will perform an estimation. If the estimation shows that there is a very high probability of the execution going over its memory limitations, the execution is prohibited. To read more about this, see Automatic estimation and execution blocking.

For more details on estimate in general, see Memory Estimation.

The following will estimate the memory requirements for running the algorithm in stream mode:
CALL gds.prizeSteinerTree.stream.estimate('graph', {
  relationshipWeightProperty: 'cost',
  prizeProperty: 'prize'
})
YIELD nodeCount, relationshipCount, bytesMin, bytesMax, requiredMemory
RETURN nodeCount, relationshipCount, bytesMin, bytesMax, requiredMemory
Table 4. Results
nodeCount relationshipCount bytesMin bytesMax requiredMemory

6

14

3873

561592

"[3873 Bytes ... 548 KiB]"

Stream

In the stream execution mode, the algorithm returns the weight for each relationship. This allows us to inspect the results directly or post-process them in Cypher without any side effects.

For more details on the stream mode in general, see Stream.

The following will run the Prize-Collecting Steiner Tree algorithm in stream mode and return results for each valid node.
CALL gds.prizeSteinerTree.stream('graph', {
  relationshipWeightProperty: 'cost',
  prizeProperty: 'prize'
})
YIELD nodeId,parentId, weight
RETURN gds.util.asNode(nodeId).id AS node, gds.util.asNode(parentId).id AS parent,weight
ORDER BY node
Table 5. Results
node parent weight

"A"

"B"

3.0

"B"

"C"

1.0

"D"

"C"

4.0

"E"

"C"

6.0

The algorithm finds a tree cntaing A,B,C,D, and E. The node F is skipped because it’s price is very low and connecting it with the other nodes would yield an inferior solution.