Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-23-2021 12:48 PM
Hi All
I have success to handle minimal Stp now (neo4j 4.1 with gds) following: Minimum Weight Spanning Tree - Neo4j Graph Data Science
[...
MATCH (n:Place{id: 'D'})
CALL gds.alpha.spanningTree.maximum.write({
nodeProjection: 'Place',
relationshipProjection: {
LINK: {
type: 'LINK',
properties: 'cost'
}
},
startNodeId: id(n),
relationshipWeightProperty: 'cost',
writeProperty: 'MAXST',
weightWriteProperty: 'writeCost'
})
YIELD createMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN createMillis,computeMillis, writeMillis, effectiveNodeCount;
..]
But I would like to run Stp in a set of links relations. How can I filter which links can be used by minimal stp algorithm ? some that allow me to select links (based on properties) to part of relationshipProjection.
Solved! Go to Solution.
03-26-2021 08:10 AM
Hello Fabio,
Using Cypher projection instead of Native projection is the way to go for you. For this, you need to replace "nodeProjection" and "relationshipProjection" by "nodeQuery" and "relationshipQuery" with some expected returns, see in the code block below. See docs here.
CALL gds.alpha.spanningTree.maximum.write({
nodeQuery:"MATCH (p:Place) RETURN id(p) as id",
relationshipQuery: "MATCH (s:Place)-[r:LINK]->(t) WHERE <examplefilter> RETURN id(s) as source, id(t) as target, r.cost as cost",
relationshipWeightProperty: 'weight',
writeProperty: 'MAXST',
weightWriteProperty: 'writeCost'
})
YIELD createMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN createMillis,computeMillis, writeMillis, effectiveNodeCount;
As a side note, you're right, when possible, always use Native projection instead of Cypher projection as it's more efficient ; but in some cases you don't have a choice, e.g. for filters, or when you need some transformation like merging a path into a single relationship.
03-26-2021 08:10 AM
Hello Fabio,
Using Cypher projection instead of Native projection is the way to go for you. For this, you need to replace "nodeProjection" and "relationshipProjection" by "nodeQuery" and "relationshipQuery" with some expected returns, see in the code block below. See docs here.
CALL gds.alpha.spanningTree.maximum.write({
nodeQuery:"MATCH (p:Place) RETURN id(p) as id",
relationshipQuery: "MATCH (s:Place)-[r:LINK]->(t) WHERE <examplefilter> RETURN id(s) as source, id(t) as target, r.cost as cost",
relationshipWeightProperty: 'weight',
writeProperty: 'MAXST',
weightWriteProperty: 'writeCost'
})
YIELD createMillis, computeMillis, writeMillis, effectiveNodeCount
RETURN createMillis,computeMillis, writeMillis, effectiveNodeCount;
As a side note, you're right, when possible, always use Native projection instead of Cypher projection as it's more efficient ; but in some cases you don't have a choice, e.g. for filters, or when you need some transformation like merging a path into a single relationship.
03-26-2021 03:05 PM
Hi Marius,
Thanks a lot. Works perfectly. I add only a startNode. again many thanks.
All the sessions of the conference are now available online