Comments (13)
What does your graph look like?
from neo4j-apoc-procedures.
╒══════════════════════════════════════════════╕
│p │
╞══════════════════════════════════════════════╡
│[{name: BC}, {route: 3, cost: 4}, {name: BA}] │
├──────────────────────────────────────────────┤
│[{name: BC}, {route: 2, cost: 3}, {name: BA}] │
├──────────────────────────────────────────────┤
│[{name: BB}, {route: 1, cost: 10}, {name: BA}]│
├──────────────────────────────────────────────┤
│[{name: BC}, {route: 4, cost: 2}, {name: BB}] │
├──────────────────────────────────────────────┤
│[{name: BC}, {route: 5, cost: 3}, {name: BB}] │
├──────────────────────────────────────────────┤
│[{name: BD}, {route: 4, cost: 2}, {name: BB}] │
├──────────────────────────────────────────────┤
│[{name: BC}, {route: 3, cost: 3}, {name: BB}] │
├──────────────────────────────────────────────┤
│[{name: BC}, {route: 2, cost: 2}, {name: BB}] │
├──────────────────────────────────────────────┤
│[{name: BA}, {route: 1, cost: 10}, {name: BB}]│
├──────────────────────────────────────────────┤
│[{name: BB}, {route: 5, cost: 6}, {name: BC}] │
├──────────────────────────────────────────────┤
│[{name: BB}, {route: 5, cost: 5}, {name: BC}] │
├──────────────────────────────────────────────┤
│[{name: BB}, {route: 4, cost: 2}, {name: BC}] │
├──────────────────────────────────────────────┤
│[{name: BB}, {route: 5, cost: 3}, {name: BC}] │
├──────────────────────────────────────────────┤
│[{name: BB}, {route: 2, cost: 2}, {name: BC}] │
├──────────────────────────────────────────────┤
│[{name: BB}, {route: 3, cost: 3}, {name: BC}] │
├──────────────────────────────────────────────┤
│[{name: BA}, {route: 3, cost: 4}, {name: BC}] │
├──────────────────────────────────────────────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}] │
├──────────────────────────────────────────────┤
│[{name: BB}, {route: 4, cost: 2}, {name: BD}] │
└──────────────────────────────────────────────┘
from neo4j-apoc-procedures.
Another query, with 2 types of routes
MATCH (a:STATION {name: 'BA'}), (b:STATION{name: 'BD'})
CALL apoc.algo.dijkstra(a, b, 'ROUTE', 'cost') yield path as path, weight as weight
RETURN path, weight
╒═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╤══════╕
│path │weight│
╞═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╪══════╡
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 2, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 2, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 2, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 2, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 2, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 2, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 4, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 4, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 4, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 4, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 4, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 4, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 2, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 2, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 4, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────┼──────┤
│[{name: BA}, {route: 2, cost: 3}, {name: BC}, {route: 4, cost: 2}, {name: BB}, {route: 4, cost: 2}, {name: BD}]│7 │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────┘
from neo4j-apoc-procedures.
Thanks for the feedback. Could you please use bin/neo4j-shell
and send the output of dump
? This basically are couple of create commands allowing easily creating your graph in a unit test.
from neo4j-apoc-procedures.
Here you are. The first few rows should be irreverent. I am using version 3.0.0
begin
create index on :`Category`(`categoryID`);
create index on :`Product`(`productID`);
create index on :`Supplier`(`supplierID`);
commit
begin
create (_9:`STATION` {`name`:"BA"})
create (_10:`STATION` {`name`:"BB"})
create (_11:`STATION` {`name`:"BC"})
create (_12:`STATION` {`name`:"BD"})
create (_9)-[:`ROUTE` {`cost`:4, `route`:3}]->(_11)
create (_9)-[:`ROUTE` {`cost`:3, `route`:2}]->(_11)
create (_9)-[:`ROUTE` {`cost`:10, `route`:1}]->(_10)
create (_10)-[:`ROUTE` {`cost`:6, `route`:5}]->(_11)
create (_10)-[:`ROUTE` {`cost`:5, `route`:5}]->(_11)
create (_10)-[:`ROUTE` {`cost`:2, `route`:4}]->(_11)
create (_10)-[:`ROUTE` {`cost`:3, `route`:5}]->(_11)
create (_10)-[:`ROUTE` {`cost`:2, `route`:4}]->(_12)
create (_10)-[:`ROUTE` {`cost`:2, `route`:2}]->(_11)
create (_10)-[:`ROUTE` {`cost`:3, `route`:3}]->(_11)
create (_10)-[:`ROUTE` {`cost`:10, `route`:1}]->(_9)
create (_11)-[:`ROUTE` {`cost`:2, `route`:4}]->(_10)
create (_11)-[:`ROUTE` {`cost`:3, `route`:5}]->(_10)
create (_11)-[:`ROUTE` {`cost`:3, `route`:3}]->(_10)
create (_11)-[:`ROUTE` {`cost`:2, `route`:2}]->(_10)
create (_11)-[:`ROUTE` {`cost`:4, `route`:3}]->(_9)
create (_11)-[:`ROUTE` {`cost`:3, `route`:2}]->(_9)
create (_12)-[:`ROUTE` {`cost`:2, `route`:4}]->(_10)
;
commit
from neo4j-apoc-procedures.
In neo4j shell, I can see more details:
neo4j-sh (?)$ MATCH (a:STATION {name: 'BA'}), (b:STATION{name: 'BC'})
> CALL apoc.algo.dijkstra(a, b, 'ROUTE', 'cost') yield path as path, weight as weight
> RETURN path, weight
> ;
+------------------------------------------------------------------------------+
| path | weight |
+------------------------------------------------------------------------------+
| [Node[9]{name:"BA"},:ROUTE[42]{route:2,cost:3},Node[11]{name:"BC"}] | 3.0 |
| [Node[9]{name:"BA"},:ROUTE[44]{route:2,cost:3},Node[11]{name:"BC"}] | 3.0 |
+------------------------------------------------------------------------------+
2 rows
From RESTful call, the result is like the following:
POST http://ip:7474/db/data/node/9/paths
{
"to" : "11",
"cost_property" : "cost",
"relationships" : {
"type" : "ROUTE",
"direction" : "out"
},
"algorithm" : "dijkstra"
}
It returns:
[
{
"relationships": [
"http://192.168.88.23:7474/db/data/relationship/42"
],
"nodes": [
"http://192.168.88.23:7474/db/data/node/9",
"http://192.168.88.23:7474/db/data/node/11"
],
"directions": [
"->"
],
"start": "http://192.168.88.23:7474/db/data/node/9",
"length": 1,
"weight": 3,
"end": "http://192.168.88.23:7474/db/data/node/11"
}
]
from neo4j-apoc-procedures.
Another query mentioned above
neo4j-sh (?)$ MATCH (a:STATION {name: 'BA'}), (b:STATION{name: 'BD'})
> CALL apoc.algo.dijkstra(a, b, 'ROUTE', 'cost') yield path as path, weight as weight
> RETURN path, weight;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| path | weight |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| [Node[9]{name:"BA"},:ROUTE[42]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[48]{route:2,cost:2},Node[10]{name:"BB"},:ROUTE[50]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[44]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[48]{route:2,cost:2},Node[10]{name:"BB"},:ROUTE[50]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[44]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[48]{route:2,cost:2},Node[10]{name:"BB"},:ROUTE[51]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[42]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[46]{route:2,cost:2},Node[10]{name:"BB"},:ROUTE[50]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[44]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[46]{route:2,cost:2},Node[10]{name:"BB"},:ROUTE[50]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[44]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[46]{route:2,cost:2},Node[10]{name:"BB"},:ROUTE[51]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[42]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[54]{route:4,cost:2},Node[10]{name:"BB"},:ROUTE[50]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[44]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[54]{route:4,cost:2},Node[10]{name:"BB"},:ROUTE[50]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[44]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[54]{route:4,cost:2},Node[10]{name:"BB"},:ROUTE[51]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[42]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[52]{route:4,cost:2},Node[10]{name:"BB"},:ROUTE[50]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[44]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[52]{route:4,cost:2},Node[10]{name:"BB"},:ROUTE[50]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[44]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[52]{route:4,cost:2},Node[10]{name:"BB"},:ROUTE[51]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[42]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[48]{route:2,cost:2},Node[10]{name:"BB"},:ROUTE[51]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[42]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[46]{route:2,cost:2},Node[10]{name:"BB"},:ROUTE[51]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[42]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[54]{route:4,cost:2},Node[10]{name:"BB"},:ROUTE[51]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
| [Node[9]{name:"BA"},:ROUTE[42]{route:2,cost:3},Node[11]{name:"BC"},:ROUTE[52]{route:4,cost:2},Node[10]{name:"BB"},:ROUTE[51]{route:4,cost:2},Node[12]{name:"BD"}] | 7.0 |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
16 rows
105 ms
RESTful request:
POST http://IP:7474/db/data/node/9/paths
{
"to" : "12",
"cost_property" : "cost",
"relationships" : {
"type" : "ROUTE",
"direction" : "out"
},
"algorithm" : "dijkstra"
}
Result:
[
{
"relationships": [
"http://192.168.88.23:7474/db/data/relationship/42",
"http://192.168.88.23:7474/db/data/relationship/46",
"http://192.168.88.23:7474/db/data/relationship/51"
],
"nodes": [
"http://192.168.88.23:7474/db/data/node/9",
"http://192.168.88.23:7474/db/data/node/11",
"http://192.168.88.23:7474/db/data/node/10",
"http://192.168.88.23:7474/db/data/node/12"
],
"directions": [
"->",
"->",
"->"
],
"start": "http://192.168.88.23:7474/db/data/node/9",
"length": 3,
"weight": 7,
"end": "http://192.168.88.23:7474/db/data/node/12"
},
{
"relationships": [
"http://192.168.88.23:7474/db/data/relationship/42",
"http://192.168.88.23:7474/db/data/relationship/52",
"http://192.168.88.23:7474/db/data/relationship/51"
],
"nodes": [
"http://192.168.88.23:7474/db/data/node/9",
"http://192.168.88.23:7474/db/data/node/11",
"http://192.168.88.23:7474/db/data/node/10",
"http://192.168.88.23:7474/db/data/node/12"
],
"directions": [
"->",
"->",
"->"
],
"start": "http://192.168.88.23:7474/db/data/node/9",
"length": 3,
"weight": 7,
"end": "http://192.168.88.23:7474/db/data/node/12"
}
]
from neo4j-apoc-procedures.
more hints on the issue
neo4j-sh (?)$ MATCH (a:STATION {name: 'BA'}), (b:STATION{name: 'BC'}), p=((a)<-[]-(b)) RETURN p;
+---------------------------------------------------------------------+
| p |
+---------------------------------------------------------------------+
| [Node[9]{name:"BA"},:ROUTE[45]{route:3,cost:4},Node[11]{name:"BC"}] |
| [Node[9]{name:"BA"},:ROUTE[44]{route:2,cost:3},Node[11]{name:"BC"}] |
+---------------------------------------------------------------------+
2 rows
124 ms
neo4j-sh (?)$ MATCH (a:STATION {name: 'BA'}), (b:STATION{name: 'BC'}), p=((a)-[]->(b)) RETURN p;
+---------------------------------------------------------------------+
| p |
+---------------------------------------------------------------------+
| [Node[9]{name:"BA"},:ROUTE[43]{route:3,cost:4},Node[11]{name:"BC"}] |
| [Node[9]{name:"BA"},:ROUTE[42]{route:2,cost:3},Node[11]{name:"BC"}] |
+---------------------------------------------------------------------+
2 rows
65 ms
from neo4j-apoc-procedures.
I guess this is expected behaviour. You have 2 relationships connected BA and BC with the very same properties and inverse direction:
create (_9)-[:`ROUTE` {`cost`:3, `route`:2}]->(_11)
create (_11)-[:`ROUTE` {`cost`:3, `route`:2}]->(_9)
So getting both two paths for dijkstra is exactly the expected behaviour. Or did I miss something?
from neo4j-apoc-procedures.
I think as the relationship is unidirectional, one of them should be filtered.
from neo4j-apoc-procedures.
MATCH (a:STATION {name: 'BA'}), (b:STATION{name: 'BD'})
CALL apoc.algo.dijkstra(a, b, 'ROUTE', 'cost') yield path as path, weight as weight
RETURN path, weight
I think this statement mean that it is from BA to BD, so it should be directional.
from neo4j-apoc-procedures.
actually the syntax for relationships can be directional, in or out, it can also take multiple rels:
can you try "ROUTE>"
MATCH (a:STATION {name: 'BA'}), (b:STATION{name: 'BD'})
CALL apoc.algo.dijkstra(a, b, 'ROUTE>', 'cost') yield path as path, weight as weight
RETURN path, weight
from neo4j-apoc-procedures.
Nice, than this is not a bug, It is the problem of my misunderstanding. ;)
from neo4j-apoc-procedures.
Related Issues (20)
- Top k parameters in just one call, to retrieve k results
- In case of the llm generates a wrong query, improve by sending the query with the error to llm so it can improve instead of just generating new query, still retry with new query if no results
- Add a reverse explanation of the query: the input is a Cypher query the output is a natural language description of it, given the graph model.
- Given (a set of) queries return the schema + explanation of the subgraph
- Add a procedure for RAG you pass the user question plus a graph pattern (paths) and relevant attributes and it creates a prompt to answer the user question using the data on those paths and executes that with the llm provider and returns the answer
- apoc.export.csv.query() config for quotes: 'ifNeeded' not working HOT 3
- The apoc.cypher.runSchemaFile() never finishes execution HOT 2
- LoadLdapContainerTest.testLoadLDAPWithDefaultPort fails on TC
- Implement an apoc.convert.toYaml function
- Broken Dependencies with `apoc.mongo` HOT 1
- Upgrade hadoop to 3.4.0
- Textual representation of the export parquet output file HOT 1
- Add Watson Embedding API
- Add support for mixedbread.ai Embedding API
- Implement an apoc.convert.fromYaml function
- Move NLP documentation into the APOC pages
- Change apoc.ml.fromCypher prompt
- apoc.load.jdbcUpdate inside apoc.periodic.iterate leaves idle connections in 5.19.0 HOT 1
- apoc.load.csv does not close the file on consumption end
- Add Pinecone and Milvus support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neo4j-apoc-procedures.