2015-11-07 195 views
0

我正在使用Neo4j'neo4j-community-2.3.0-RC1'版本。 在我的数据库中只有1054个节点。 当我使用'allShotestPaths'函数进行路径查询时,为什么它很慢。 它需要大约1秒以上,以下是单元测试结果:Neo4j:为什么allShortestPaths函数的性能如此之慢?

√ search optimalPath Path (192ms) 
    √ search optimal Path by Lat Lng (1131ms) 

我应该优化查询?

MATCH path=allShortestPaths((start:潍坊_STATION)-[rels*..50]->(end:潍坊_STATION {name:"火车站"})) 
RETURN NODES(path) AS stations,relationships(path) AS path,length(path) AS stop_count, 
length(FILTER(index IN RANGE(1, length(rels)-1) WHERE (rels[index]).bus <> (rels[index - 1]).bus)) AS transfer_count, 
length(FILTER(rel IN rels WHERE type(rel)="WALK" )) AS walk_count 
order by transfer_count,walk_count,stop_count 

由纬度LNG查询最优路径:对 'optimalPath' 和 '最佳路径由纬度LNG'

optimalPath查询以下是querys

MATCH path=allShortestPaths((start:潍坊_STATION {name:"公交总公司"})-[rels*..50]->(end:潍坊_STATION {name:"火车站"})) 
WHERE 
round(
6378.137 *1000*2* 
asin(sqrt(
    sin((radians(start.lat)-radians(36.714))/2)^2+cos(radians(start.lat))*cos(radians(36.714))* 
    sin((radians(start.lng)-radians(119.1268))/2)^2 
)) 
)/1000 < 0.5  // this formula is used to calculate the distance between two GEO coordinate (latitude\longitude) 
RETURN NODES(path) AS stations,relationships(path) AS path,length(path) AS stop_count, 
length(FILTER(index IN RANGE(1, length(rels)-1) WHERE (rels[index]).bus <> (rels[index - 1]).bus)) AS transfer_count, 
length(FILTER(rel IN rels WHERE type(rel)="WALK" )) AS walk_count 
order by transfer_count,walk_count,stop_count 

,你可以在这里下载数据库:https://www.dropbox.com/s/zamkyh2aaw3voe6/data.rar?dl=0

我会很感激,如果有人能帮助我。感谢

+0

您上传的数据库遗漏了大部分商店文件。 –

+0

你见过沙滩鞋的功能吗? http://neo4j.com/docs/stable/query-functions-mathematical.html#functions-haversin –

+0

传入的{lat}和{lon}参数是什么? –

回答

1

一般情况下,不知道更多,我会拉的路径都展开前可以计算的谓词和表情,在比赛前。

而作为您的地理过滤器是独立的任何东西,除了你的参数和启动节点否则,你可以这样做:

MATCH (start:潍坊_STATION {name:"公交总公司"}) 

WHERE 
// this formula is used to calculate the distance between two GEO coordinate (latitude\longitude) 
round(6378.137 *1000*2* 
     asin(sqrt(sin((radians(start.lat)-radians({lat}))/2)^2 
     +cos(radians(start.lat))*cos(radians({lat}))* 
     sin((radians(start.lng)-radians({lng}))/2)^2)))/1000 
< 0.5  

MATCH (end:潍坊_STATION {name:"火车站"}) 
MATCH path=allShortestPaths((start)-[rels*..50]->(end)) 
RETURN NODES(path) AS stations, 
     relationships(path) AS path, 
     length(path) AS stop_count, 
     length(FILTER(index IN RANGE(1, length(rels)-1) 
      WHERE (rels[index]).bus <> (rels[index - 1]).bus)) AS transfer_count, 
     length(FILTER(rel IN rels WHERE type(rel)="WALK" )) AS walk_count 

ORDER BY transfer_count,walk_count,stop_count; 

看到这个测试(但其他查询同样快速):

neo4j-sh (?)$ MATCH (start:潍坊_STATION {name:"公交总公司"}) 
> 
> WHERE 
> // this formula is used to calculate the distance between two GEO coordinate (latitude\longitude) 
> round(6378.137 *1000*2* 
>  asin(sqrt(sin((radians(start.lat)-radians({lat}))/2)^2 
>  +cos(radians(start.lat))*cos(radians({lat}))* 
>  sin((radians(start.lng)-radians({lng}))/2)^2)))/1000 
> < 0.5  
> 
> MATCH (end:潍坊_STATION {name:"火车站"}) 
> MATCH path=allShortestPaths((start)-[rels*..50]->(end)) 
> WITH NODES(path) AS stations, 
>  relationships(path) AS path, 
>  length(path) AS stop_count, 
>  length(FILTER(index IN RANGE(1, length(rels)-1) 
>    WHERE (rels[index]).bus <> (rels[index - 1]).bus)) AS transfer_count, 
>  length(FILTER(rel IN rels WHERE type(rel)="WALK" )) AS walk_count 
> 
> ORDER BY transfer_count,walk_count,stop_count 
> RETURN count(*); 
+----------+ 
| count(*) | 
+----------+ 
| 320  | 
+----------+ 
1 row 
10 ms 
+0

我上传数据库再次dropbox.com/s/zamkyh2aaw3voe6/data.rar?dl=0,我上传整个“数据”文件夹,请检查一下,非常感谢 – pangguoming

+0

抱歉,查询的顶部,我必须删除{name:“公交总公司”},它会匹配(开始:潍坊_STATION)WHERE ..............然后th电子查询将花费超过1秒 – pangguoming

+0

我认为,这是一个难题。非常感谢您的回复 – pangguoming

相关问题