cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Plus court chemin entre deux ports(avec T) , mais dans le même bateau

Bonjour je cherche le plus court chemin entre deux ports, mais à condition de rester dans le même bateau ( le nom du bateau est un attribut de la relation), pour le moment je cree le graphe comme ça :
MERGE (a:Loc {name:"Casablanca"})
MERGE (b:Loc {name:"Algesiras"})
MERGE (c:Loc {name:"Genoa"})
MERGE (d:Loc {name:"Alexandria"})
MERGE (e:Loc {name:"Haifa"})
MERGE (f:Loc {name:"Agadir"})
MERGE (g:Loc {name:"Tangier city"})
MERGE (a)-[:ROAD {cost:50,BOAT:"CD"}]->(b)
MERGE (a)-[:ROAD {cost:50,BOAT:"CD"}]->(c)
MERGE (a)-[:ROAD {cost:100,BOAT:"CD"}]->(d)
MERGE (b)-[:ROAD {cost:40,BOAT:"CD"}]->(d)
MERGE (c)-[:ROAD {cost:40,BOAT:"AF"}]->(d)
MERGE (c)-[:ROAD {cost:80,BOAT:"CD"}]->(e)
MERGE (d)-[:ROAD {cost:30,BOAT:"CD"}]->(e)
MERGE (d)-[:ROAD {cost:80,BOAT:"OP"}]->(f)
MERGE (e)-[:ROAD {cost:40,BOAT:"DG"}]->(f)
MERGE (f)-[:ROAD {cost:40,BOAT:"AF"}]->(g);
,
Ma requete pour le court chemin ( le cost est bien la distance)

MATCH (start:Loc{name:"Algesiras"}), (end:Loc{name:"Agadir"})
CALL algo.shortestPath.stream(start, end, "cost")
YIELD nodeId, cost
MATCH (other:Loc) WHERE id(other) = nodeId
RETURN other.name AS name, cost

mais j'aimerai conditionner le resultat,et ne considerer que les liens qui ont le meme bateau .

Merciiii

1 REPLY 1

Bonsoir,
Voici une proposition :

MATCH (start:Loc{name:"Algesiras"}), (end:Loc{name:"Agadir"}),
p=(start)-[:ROAD*]->(end)
WITH p, head(relationships(p)) as r1
WHERE any(rel IN relationships(p) WHERE rel.BOAT = r1.BOAT)
WITH p, reduce(length = 0, r IN relationships(p)| length + r.cost) AS length
RETURN p, length ORDER BY length ASC LIMIT 1

Cela donne :

╒══════════════════════════════════════════════════════════════════════╤════════╕
│"p"                                                                   │"length"│
╞══════════════════════════════════════════════════════════════════════╪════════╡
│[{"name":"Algesiras"},{"cost":40,"BOAT":"CD"},{"name":"Alexandria"},{"│110     │
│name":"Alexandria"},{"cost":30,"BOAT":"CD"},{"name":"Haifa"},{"name":"│        │
│Haifa"},{"cost":40,"BOAT":"DG"},{"name":"Agadir"}]                    │        │
└──────────────────────────────────────────────────────────────────────┴────────┘
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online