CN109460491A - Timing shortest path query method based on Neo4j database - Google Patents
Timing shortest path query method based on Neo4j database Download PDFInfo
- Publication number
- CN109460491A CN109460491A CN201811223627.8A CN201811223627A CN109460491A CN 109460491 A CN109460491 A CN 109460491A CN 201811223627 A CN201811223627 A CN 201811223627A CN 109460491 A CN109460491 A CN 109460491A
- Authority
- CN
- China
- Prior art keywords
- dist
- neo4j
- path
- time
- query method
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 79
- 238000010586 diagram Methods 0.000 claims description 22
- 230000008569 process Effects 0.000 claims description 22
- 235000006679 Mentha X verticillata Nutrition 0.000 claims description 6
- 235000002899 Mentha suaveolens Nutrition 0.000 claims description 6
- 235000001636 Mentha x rotundifolia Nutrition 0.000 claims description 6
- 238000013459 approach Methods 0.000 claims description 2
- 238000012804 iterative process Methods 0.000 description 4
- 230000002123 temporal effect Effects 0.000 description 4
- 230000007547 defect Effects 0.000 description 3
- 238000013461 design Methods 0.000 description 3
- 238000013507 mapping Methods 0.000 description 3
- 238000012360 testing method Methods 0.000 description 3
- 238000002474 experimental method Methods 0.000 description 2
- 230000006872 improvement Effects 0.000 description 2
- 239000011159 matrix material Substances 0.000 description 2
- 230000008520 organization Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 235000013399 edible fruits Nutrition 0.000 description 1
- 238000009434 installation Methods 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000010845 search algorithm Methods 0.000 description 1
- 230000006641 stabilisation Effects 0.000 description 1
- 238000011105 stabilization Methods 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
Landscapes
- Navigation (AREA)
Abstract
The timing shortest path query method based on Neo4j database that the present invention relates to a kind of, the timing shortest path query function for proposing a kind of Neo4j database extends and card format embedding grammar.The present invention solves the disadvantage that the shortest path algorithm built in Neo4j database can not handle timing information.Propose the Temporal-Dijkstra algorithm for the inquiry of three kinds of timing shortest paths, solve problem of implementation of the timing shortest path on Neo4j, specific aim has modified initialization and the termination condition of traditional shortest path algorithm to improve efficiency, and it is deployed in Neo4j database as the realization of the Function Extension of Neo4j, corresponding query demand is handled by specific invocation of procedure sentence.It is experimentally confirmed, the present invention can be called correctly in actual database, and have very high practical value.
Description
Technical field
The present invention relates to Path Planning Technique fields, most short more particularly, to a kind of timing based on Neo4j database
Path query method.
Background technique
Neo4j is high performance NoSQL (database of a non-relational) graphic data base.In Neo4j, data quilt
In a network rather than in table, data are saved as the relationship between the node and node in figure for storage.For some application numbers
According to, such as traffic network data, social network data etc., it can directly be expressed as very much the node of figure and the concept of relationship.Make
It is natural that these data are stored with Neo4j, and service efficiency can be higher than relevant database.Facebook, Ali at present
Many major companies such as Ba Ba, Baidu are all using Neo4j.
The Data Storage Models of Neo4j be Node (node) and Relationship (relationship), and comprising
Property (attribute).Property (attribute) is saved using Key (key)-Value (value) pairs of bi-directional list.Node section
Point saves first attribute and first relations I D.Relationship relationship saves start node ID, end node ID, belongs to
Property.Pass through above-mentioned storage model, it may be convenient to traverse figure of some node as starting point.
Nomography built in Neo4j, including Dijkstra, A* algorithm.These algorithms shortest path calculated is all base
In the realization of oriented no weight graph, the hop count of shortest path calculated only between node is related, without considering letter in addition to this
Breath.However, when Neo4j is applied in storage public transport road network, when the shortest path between query node is inquired, often
It needs in view of the timing information on side, because public transport is limited by specific timing information.For example, with
The path for reaching B earliest, from A, is inquired at the 08:00 moment in family.At this time by built-in shortest path algorithm because can not utilize
Timing information in network, thus obtain result be A to B by least intermediate node as a result, this result path
May actually impassabitity or not earliest reach path, it is as a result wrong.Therefore it needs to design and Implement new algorithm, as
The extension of Neo4j functionally can calculate timing shortest path query, while the algorithm using the timing information in timing diagram
Also efficient realization should be done according to the bottom storage organization characteristic of Neo4j.
Timing diagram refers to that sideband has the digraph with the weight information of time correlation.In timing diagram, while store out
Time and arrival time information are sent out, is only being less than departure time arrival starting point, the side could passed through, in arrival time arrival pair
The terminal answered.For example, in traffic network, because the shift of public transport limits, the same starting point is when different
Between leave for the same destination, the consumed time is different.For example, from A by bus to B, it is assumed that bus
Train number is 08:05-08:15,08:15-08:25 ..., if user sets out at the 08:00 moment, can be reached in 08:15, consumption
When be 15 minutes.If user sets out at the 08:08 moment, then it can be arrived at the destination in 08:25, time-consuming is 17 minutes.In timing
In figure, same starting and terminal point, due to departure time difference, leading to the wastage in bulk or weight time (and the vehicles taken) is also not
With.In timing diagram, the inquiry of shortest path is and time dynamical correlation.
The shortest path inquiry of three kinds of time correlations can be derived from the model of timing diagram:
(1) path query EAP (Earliest Arrival Path) is reached earliest.In td moment user in starting point A, ask
Ask the time for the B that reaches home earliest and the path of corresponding process.
(2) set out path query LDP (Latest Departure Path) the latest.It reaches home being not later than the ta moment
B is asked and is asked the latest from the time of starting point A and the corresponding path passed through.
(3) most short time-consuming path query SDP (Shortest Duration Path).Go out being greater than the td moment from starting point A
Hair, being not later than the ta moment reaches home B, asks and asks the time-consuming shortest path from A to B.
Patent disclosed in existing application relevant to Neo4j, includes the side for integrating Neo4j database Yu J2EE platform
Method and system etc..These patents are all also not have patent that can extend using method the upper layer application and data of Neo4j
The method process of Neo4j database bottom, to solve defect of the Neo4j in terms of application timing diagram solves timing shortest path.
Therefore this invention address that Neo4j timing shortest path query aspects extension work.
Summary of the invention
The problem to be solved in the present invention is to overcome the problems, such as that Neo4j can not calculate the defect of timing shortest path inquiry, extension
Neo4j timing diagram shortest path query function, and be embedded into Neo4j database in the form of plug-in unit.
To realize the above goal of the invention, the technical solution adopted is that:
A kind of timing shortest path query method based on Neo4j database, include it is earliest reach path query method,
Path query method of setting out the latest and most short time-consuming path query method, it is characterised in that: specifically include the following contents:
It defines timing diagram G=(V, E), wherein V is the vertex set of G, and E is the directed edge collection of G;
Path query method is reached earliest:
(1) node of Neo4j timing diagram is divided into two groups: 1) S: finds out the set for reaching the vertex in path earliest;
2) U=V-S: the vertex set for reaching path earliest is not yet determined;
(2) S={ V is enabled0, dist (Vi)=∞, wherein V0Expression is set out node, ViIndicate destination node, dist (Vi) table
Show follow node V0It sets out after moment T and reaches destination node ViEarliest arrival time;
(3) side e < V if it exists0,Vi,Td,Ta, b > meet Td>=T and Ta<dist(Vi), then remember dist (Vi)=Ta;Otherwise
Remember dist (Vi)=∞;TdIndicate follow node V0The time set out, TaIt indicates to reach destination node ViTime, b indicate choosing
The vehicles selected;
(4) from vertex X of the timing apart from minimum and not in S, addition S is chosen in U, then the smallest arrival time is
dist(X);
(5) after X being added, side e < X, V if it existsi,Td’,Ta', b ' > and meet Td' >=dist (X) and Ta’<dist
(Vi), then note dist (V is updatedi)=Ta';
(6) it repeats the above steps (4) and step (5), until S=V;
It sets out the latest path query method
(1) node of Neo4j timing diagram is divided into two groups: 1) S: finds out the set on the vertex in path of setting out the latest;
2) U=V-S: the vertex set in path of setting out the latest is not yet determined;
(2) S={ V is enabled0},dist(Vi)=- ∞, wherein V0Expression is set out node, ViIndicate destination node, dist (Vi) table
Hair node V is shown0To destination node ViDeparture time the latest;
(3) side e < V if it existsi,V0,Td,Ta, b > meet Ta≤ T and Td>dist(Vi), then remember dist (Vi)=Td;Otherwise
Remember dist (Vi)=- ∞;
(4) from vertex X of the departure time the latest and not in S, addition S is chosen in U, then arrival time the latest is
dist(X);
(5) after X being added, side e < V if it existsi,X,Td’,Ta', b ' > and meet Ta'≤dist (X) and Td’>dist
(Vi), then update note dist (Vi)=Td';
(6) it repeats the above steps (4) and step (4), until S=V;
Most short time-consuming path query method
(1) initialization node set S is sky;
(2) for V0Each edge e < V0,Vi,Td,Ta, b >: obtain departure time Td, by TdIt is added in set S;
(3) initializing variable minT=∞, minTd=Td;
(4) for the time T in each Sd, call and reach the correspondence that path query method obtains each departure time earliest
Earliest arrival time Td;
(5) if minT > Ta-Td, (6) are thened follow the steps, otherwise jump procedure (4);
(6) minT=T is updateda-Td, minTd=Td;
(7) with most short time-consuming path query method to acquisite approachs EAP, this path is time-consuming shortest path SDP;
Path query method, path query method of setting out the latest and most short time-consuming path query method application will be reached earliest
Into Neo4j database and embedding data library.
Preferably, path query method of setting out by earliest arrival path query method, the latest and most short time-consuming path query
Method is applied in Neo4j database and embedding data library that detailed process is as follows:
(1), it NEO4J process: is called using CALL sentence;
(2), NEO4J writes Self-definition process;
(3), class and method are write;
(4), class and relevant reference packet are packaged as jar packet;
(5), restart NEO4J database, process can be called correctly.
Compared with prior art, the beneficial effects of the present invention are:
The invention proposes the extension of the timing shortest path query function of Neo4j database and card format embedding grammars.This
Invention solves the disadvantage that the shortest path algorithm built in Neo4j database can not handle timing information.When proposing for three kinds
The Temporal-Dijkstra algorithm of sequence shortest path inquiry, solves problem of implementation of the timing shortest path on Neo4j, for
Property has modified initialization and the termination condition of traditional shortest path algorithm to improve efficiency, and the Function Extension as Neo4j
Realization has been deployed in Neo4j database, handles corresponding query demand by specific invocation of procedure sentence.Pass through experiment
It proves, the present invention can be called correctly in actual database, and have very high practical value.
Detailed description of the invention
The timing diagram G that Fig. 1 is illustrated for the present invention.
Fig. 2 be Fig. 1 of the present invention in part while number and its number indicate while.
Fig. 3 is the physical structure of Neo4j database interior joint and relationship storage file of the present invention.
Fig. 4 is that EAP-Temporal-Dijkstra algorithm of the present invention applies the search process in Fig. 1.
Fig. 5 is the iterative process of query case 1 of the present invention.
Fig. 6 is that LDP-Temporal-Dijkstra algorithm of the present invention applies the search process in Fig. 1.
Fig. 7 is the iterative process of query case 2 of the present invention.
Fig. 8 is implementation flow chart of the Temporal-Dijkstra algorithm of the present invention in Neo4j database.
Fig. 9 is vertex data and number of edges evidence in national road network database used in experimental section of the present invention.
Figure 10 is Temporal-Dijkstra algorithm of the present invention inquiry times in actual database closely inquiry
With query time relational graph.
Figure 11 is Temporal-Dijkstra algorithm of the present invention in actual database medium and long distance inquiry times and looks into
Ask time chart.
Specific embodiment
The attached figures are only used for illustrative purposes and cannot be understood as limitating the patent;
Below in conjunction with drawings and examples, the present invention is further elaborated.
Embodiment 1
The problem to be solved in the present invention is to overcome the problems, such as that Neo4j can not calculate the defect of timing shortest path inquiry, extension
Neo4j timing diagram shortest path query function, and be embedded into Neo4j database in the form of plug-in unit.
Related definition of the invention is provided first:
1 (timing diagram Temporal Graph): timing diagram G=(V, E) is defined, wherein V is the vertex set of G, and E is having for G
To side collection, e ∈ E is made of four-tuple, e=<u, v, Td,Ta>, wherein u, v ∈ V, u indicate that the arc tail of directed edge, v indicate oriented
The arc head on side, TdIt is the departure time from u to v, TaIt is the arrival time from u to v.Timing diagram G is applied to public traffic network
When, a line, i.e. e=<u, v, T are indicated with five-tupled,Ta, b >, indicate vehicles b in moment TdSlave site u sets out, when
Carve TaReach website v.
For example, Fig. 1, which is one, 6 vertex vs 1, v2, and v3, v4, v5, the public traffic network temporal diagram on v6 and 14 side,
Part side in Fig. 1 is numbered, as shown in Figure 2.The departure time on the side ordered pair<Td in each edge, Ta>indicate
(arrival time) is Td (Ta), the side of different shape (solid line, dotted line, dotted line) indicate different public transport (b1, b2,
b3).For example, side e1 is expressed as<v1, v2,10,11, b1>.
Define 2 (path P ath): the paths P on timing diagram G is defined as a sequence < e on side in G1,e2,…,ek
>, so as to any i ∈ [1, k-1], ei+1Arc tail be equal to eiArc head, and ei+1Departure time be more than or equal to eiArrival
Time.
For example, edge sequence<e1 in Fig. 1, e2, e3>it is a paths, because the arc tail of e2 is v2, the arc head equal to e1,
And the departure time of e2 is more than or equal to the arrival time of e1, and the arc tail of e3 is equal to the arc head of e2, and the departure time of e3 is big
In the arrival time for being equal to e2.And edge sequence<e2, e4>it is not path, because the departure time of e4 is less than the arrival time of e2,
It is unsatisfactory for the definition in path.
Define 3 (reaching path query Earliest Arrival Path Query earliest).Provide two tops in figure G
Point u and v and start time t, one earliest reach path query be meet (1) be no earlier than t moment from u (2) reach eventually
The path of the earliest estimated arrival time of point v.
For example, reaching path query earliest, start vertex v 1, representative points v6 in Fig. 1, start time 8. then meets item
The earliest arrival path of part is<e9, e2>.
Define 4 (set out path query Latest Departure Path Query the latest).Two tops in given figure G
Point u and v and arrival time t ', one is set out path query the latest and is not later than the t ' moment to meet (1) and reaches v (2) and go out from u
The path at the moment of setting out the latest of hair.
For example, the path query that sets out the latest, starts vertex v 1, representative points v6 in Fig. 1, arrival time 12. then meets
The earliest arrival path of condition is<e1, e2>.
Define 5 (most short time-consuming path query Shortest Duration Path Query).Two tops in given figure G
The point u and v and moment t and arrival time t ' that sets out, one most short time-consuming path query are no earlier than t moment for satisfaction (1) and go out from u
Hair (2) is not later than the shortest path of total time-consuming for reaching v at the t ' moment.
For example, most short time-consuming path query, in Fig. 1, start vertex v 1, representative points v6, start time 6, when arrival
Carve 12.Then qualified most short time-consuming path is<e1, e2>.
The present invention is to solve above-mentioned technical problem by the following technical programs:
Part1: timing shortest path algorithm, solution is that the temporal information of timing diagram how to be utilized to solve timing shortest path
Problem.For three kinds of different timing shortest path inquiries, EAP-Temporal-Dijkstra algorithm is proposed respectively to solve most
Early reach path query, LDP-Temporal-Dijkstra algorithm solves the path query that sets out the latest, SDP-Temporal-
Dijkstra's algorithm solves most short time-consuming path query.
For three kinds of timing shortest path algorithms, it is all based on and solves to reach path query earliest
The improvement of the resolving ideas of EAP-Temporal-Dijkstra algorithm, therefore introduce first
EAP-Temporal-Dijkstra algorithm idea.
EAP-Temporal-Dijkstra algorithm idea:
Node collection is divided into two groups: (1) S: having found out set (2) U=V-S for reaching the vertex in path earliest: not yet
Determine the vertex set for reaching path earliest.
The earliest arrival time of symbol dist (v) expression source node u to v.Seek a node V0In moment T to other nodes
Earliest arrival path, algorithm description is as follows:
1. initially enabling S={ V0, U=V-S, dist (Vi)=∞.
Side e < V if it exists0,Vi,Td,Ta, b > and meet Td>=T, Ta<dist(Vi), then remember dist (Vi)=Ta.Otherwise remember
dist(Vi)=∞.
2. S, then this smallest arrival is added for vertex X minimum and not in S from a timing distance is chosen in U
Time is exactly dist (X).
After 3. X is added, side e < X, V if it existsi,Td,Ta, b > and meet Td>=dist (X) and Ta< dist (Vi), then more
New note dist (Vi)=Ta。
4. repeat the above steps 2 and step 3, until S=V.
It can be seen that the timing shortest path for solving source point to terminal from the process of algorithm, process needs to solve source point and arrives
The timing shortest path of many intermediate vertexs, terminates when iterating to representative points always.
The specific execution step of algorithm is given below:
EAP-Temporal-Dijkstra algorithm
LDP-Temporal-Dijkstra algorithm idea:
Node collection is divided into two groups: (1) S: having found out set (2) U=V-S on the vertex in path of setting out the latest: not yet
Determine the vertex set in path of setting out the latest.
The departure time the latest of symbol dist (u) expression source node u to v.It asks and arrives V before other nodes moment T0's
It sets out the latest path, algorithm description is as follows:
1. initially enabling S={ V0, U=V-S, dist (Vi)=- ∞.
Side e < V if it existsi,V0,Td,Ta, b > and meet Ta≤ T, Td>dist(Vi), then remember dist (Vi)=Td.Otherwise remember
dist(Vi)=- ∞.
2. the vertex X from a departure time maximum is chosen in U and not in S, is added S, then when this maximum arrival
Between be exactly dist (X).
After 3. X is added, side e < V if it existsi,X,Td,Ta, b > and meet Ta≤ dist (X) and Td> dist (Vi), then more
New note dist (Vi)=Td。
4. repeat the above steps 2 and step 3, until S=V.
LDP-Temporal-Dijkstra algorithm is substantially with EAP-Temporal-Dijkstra algorithm be as.
The starting and terminal point of this algorithm is exchanged, departure time and arrival time exchange, so that it may be to solve for the problem of reaching path earliest.
Algorithm given below specifically executes step:
LDP-Temporal-Dijkstra algorithm
Most short time-consuming timing shortest path SDP inquiry:
Since each edge has the limitation of a departure time, if the departure time is not that some of starting point goes out setting out for side
Moment, then will waste time on waiting is set out, thus, it could be seen that the departure time in most short time-consuming path must be that some goes out
The departure time on side.Using this thought, can by obtain starting point it is all go out sides departure time, multiple arrived earliest to do
It up to path query, is then subtracted to set out with arrival time and obtains total time-consuming constantly, and as a result by the path of most short time-consuming
It returns.
It is that algorithm specifically executes step below:
Part2: it is described below how the algorithm of design is realized on Neo4j;How Neo4j database interior joint is obtained
With the temporal information on side.
Traditional figure storage organization has adjacency matrix and adjacency list, so substantially shortest path algorithm is all based on adjoining
It is realized on matrix and adjacency list.Therefore timing shortest path algorithm set forth above to be stored according to the data of Neo4j and is tied
Structure does corresponding implementation, rather than referring to traditional implementation.
As soon as Neo4j has the characteristics that important, it is for ensuring that the speed of relational query, that is, exempts to index adjacent attribute, number
The reference with its adjacent node can be safeguarded according to each node in library.Exempt to index adjoining to be that chart database realizes high efficient traverse
Key, the key of Neo4j bottom node store structure design are to exempt from the adjacent realization mechanism of index.As shown in figure 3, two kinds of Neo4j
The physical structure of data type (node and relationship).
Node (is directed toward the single-track link table of connection and attribute, neostore.nodestore.db): first character section indicates
The flag bit whether used, behind 4 bytes, represent be associated with this node first relationship ID, followed by 4
Character represents first Property ID, followed by 5 characters be the label for representing present node, be directed toward the mark of the node
Label storage, last character is as reserved bit.
Contact (doubly linked list, neostore.relationshipstore.db): first character section indicates whether to be made
Flag bit, behind 4 bytes, represent the ID of start node, followed by 4 characters, represent the ID for terminating node, so
After be relationship type occupy 5 bytes, then successively followed by start node up and down contact and end node upper lower node,
And whether an instruction current record is located at the foremost of connection chain
Each nodes records include first connection in the pointer and connection chain of first attribute for being directed toward the node
The pointer of system.The relationship for reading a node traverses entire doubly linked list, it is known that find since first relationship of direction
Interested relationship.Once have found the record of interested relationship, the present invention can very easily search relationship category
The ID of property and start node and end node, finds looked for node immediately after.
Crucial one of step is exactly gradually to extend S in Temporal-Dijkstra algorithm.In conjunction with Neo4j data inventory
The characteristic of storage, the present invention can obtain after selecting current optimal time and corresponding node ID in EAT/LDT in O (1) time
To corresponding vertex, entire doubly linked list is then begun stepping through according to the relationship that the node is directed toward.In ergodic process, to each
Relationship obtains departure time and arrival time attribute information by traversal.After getting these crucial data, so that it may carry out
Optimize operating for update.
The following are the methods in Neo4j3.4.0 Core API, obtaining critical data.
The method for obtaining the node of corresponding ID are as follows:
Node getNodeById(longid)
The method for obtaining the relationship of node are as follows:
Iterable<Relationship>getRelationships(Directiondir)
The method of the attribute of acquisition relationship are as follows:
Object getProperty(Stringkey)
Part 3: how following explanation initializes when Neo4j database node data are more improves efficiency, and terminates
How condition defines.
Each vertex that is initialized as of traditional related dijkstra's algorithm establishes a node and arrives the most short distance of starting point
From mapping, the shortest distance of all nodes is then obtained behind all vertex of iteration, by mapping obtain terminal to starting point most
Short distance.Such way, can be with trouble-free operation when vertex quantity is not high.But in actual database, such as traffic network
In, the substantial amounts of database interior joint, the number of nodes passed through in user's actual queries between Origin And Destination is far smaller than
Total node number.Therefore, traditional initialization and termination condition should be modified.
In the present invention, the concept for taking the openList and closeList of similar A* algorithm, respectively corresponds in algorithm
EAT/LDT mapping table and set S.S is all to have found out most that the node set of sequence, EAT/LDT table are to be related at present most in short-term
Sequence distance in short-term.In initialization, S only has start point data, EAT/LDT node only associated with start point/end point it is most short
Timing information.Then pass through continuous iteration, the termination condition of algorithm are as follows: 1) S is added in terminal, has found starting point at this time to eventually
The timing shortest distance of point or point 2) all in EAT/LDT are all in S, and starting and terminal point is exactly unreachable in timing at this time
's.
Part4: Temporal-Dijkstra algorithm is applied in Neo4j database and in embedding data library
It is listed below the committed step for being embedded in the process:
1, NEO4J process: being called using CALL sentence, can choose addition parameter, and most of processes return to fixed column
Record stream.For example, calling the in-line procedure of database, all labels of database are listed.
2, NEO4J can write Self-definition process.
3, class and method are write.Key point: a, it is using the return value of Procedure note b, method to method
Stream<T>。
4, class and relevant reference packet are packaged as jar packet.Jar packet is placed under the $ Home/plugins of Neo4j, such as
Fruit does not have any setting that please be placed under the catalogue plugins of installation, and if there is being separately provided, configuration is arranged in
Below plugins.
5, restart NEO4J database, process can be called correctly.
Embodiment 2
As shown in Figure 1, this is a timing diagram, it can indicate a transportation network, be connected between vertex by directed edge,
Timing information is had on side, represents departure time and arrival time and corresponding vehicle information.
Query case 1
It inquires EAP (v1, v6,8).The present invention calls EAP-Temporal-Dijkstra algorithm to solve.V1 is added
The side that goes out of S, first v1 meet td >=8 arrival corresponding points time and have e5, e9 earliest, utilize e5, the timing information of e9 updates
EAT, Pre, PreRel table.Second of iteration chooses the smallest vertex v 2 of arrival time T in EAT.V2 is added in S, for
V2, which meets td >=10 side that goes out, e2, e6, then utilizes e2, the timing information of e6 updates EAT, Pre, PreRel table.For the third time
Iteration, selecting the smallest point not in S in EAT is v6.Since v6 is target endpoint, so search terminates at this time.By looking into
Ask table EAT, Pre, PreRel can obtain EAP's (v1, v6,8) the result is that<e9, e2>.Fig. 4 is EAP- of the present invention
Temporal-Dijkstra algorithm applies the search process in Fig. 1.Specific iterative process is as shown in Figure 5.
Query case 2
It inquires LDP (v1, v6,12).The present invention calls LDP-Temporal-Dijkstra algorithm to solve.First from
The side that enters of terminal v6 starts, and there is e2 on the side that enters for meeting ta≤12, and the present invention updates LDT, Next using the timing information of e2,
NextRel table.Second of iteration chooses the vertex v 2 for being not belonging to S and having the maximum departure time 11 in LDT.First by v2
Be added in S, then choose meet ta≤11 enter side e1, e12, then utilize e2, the timing information of e12 updates LDT, Next,
NextRel table.Third time iteration is chosen and is not belonging to S in LDT and has the vertex v 1 of maximum departure time 10.Since v1 is to look into
The initial vertex of inquiry.So search terminates at this time.LDP (v1, v6,12) can be obtained by inquiry table LDT, Next, NextRel
Query result<e1, e2>.Specific iterative process is as shown in Figure 7.Fig. 6 is LDP-Temporal- of the present invention
Dijkstra's algorithm applies the search process in Fig. 1.
Query case 3
It inquires 3:SDP (v1, v6,8,12).Obtain all departure times of v1 and satisfaction first>=8 and<12 have: 8,
9,10. calling EAP-Temporal-Dijkstra algorithms calculate separately EAP (v1, v6,8), EAP (v1, v6,9), EAP (v1,
V6,10), obtain arrival time EAT be respectively 12,12,12. therefore time-consuming be 4,3,2 respectively.Therefore SDP (v1, v6,8,12)
=EAP (v1, v6,10)=v1-e1-v2-e2-v5.
As shown in figure 8, Temporal-Dijkstra algorithm described above is passed through the side of the Core API of calling Neo4j
Method application is realized, is then deployed in Neo4j.By the Cypher invocation of procedure sentence such as CALLeap (1,6,8) of Neo4j,
CALLldp (1,6,12), CALL (1,6,8,12) obtain query result.
Experimental result and analysis
Testing data set used is Chinese national road network data, high-speed rail website and shift, subway comprising each city in the whole nation
Website and shift, operative flight point and shift, hot spot data etc..As shown in figure 9, testing the national road tested for this
The data of net system form.
In this Basis of Database, as shown in Figure 10, the experiment of progress test be between the subway station in the same city,
It is random to generate departure time or arrival time, 50,100,150,200 eap are executed respectively to be obtained after ldp, sdp inquiry
As a result spent total query time.Finally, the average query time expended every time of inquiry is all to maintain stabilization, and
Time is shorter.Eap and ldp query time is close, and inquires the required time lower than sdp.
Experimental result shown in Figure 11 is when setting out website and purpose website distance farther out, it is random generate the departure time or
Arrival time executes 50,100,150,200 eap, after ldp, sdp inquiry, when obtaining total inquiry spent by result respectively
Between.Analyzed from experimental result, every kind inquiry query time still keep stable, and acceptable query time range it
It is interior.Sdp query time is greater than ldp query time, and ldp query time is greater than eap query time.
It is compared by the experimental result of Figure 10 Figure 11, it can be seen that when needing more middle nodes between beginning and end
When point, the timing shortest path inquiry spent time also can relative increase, but still in tolerance interval, while query time sdp >
Ldp/eap is remained unchanged.It is can be seen that from SDP-Temporal-Dijkstra algorithm because usually requiring to call multiple EAP-
Temporal-Dijkstra algorithm so query time can be relatively long, but also gets result in the acceptable short time.
So all timing shortest path search algorithms have actual application value after expanding to Neo4j database.
Obviously, the above embodiment of the present invention be only to clearly illustrate example of the present invention, and not be pair
The restriction of embodiments of the present invention.For those of ordinary skill in the art, may be used also on the basis of the above description
To make other variations or changes in different ways.There is no necessity and possibility to exhaust all the enbodiments.It is all this
Made any modifications, equivalent replacements, and improvements etc., should be included in the claims in the present invention within the spirit and principle of invention
Protection scope within.
Claims (2)
- It include the earliest path query method, most of reaching 1. a kind of timing shortest path query method based on Neo4j database Evening sets out path query method and most short time-consuming path query method, it is characterised in that: specifically includes the following contents:It defines timing diagram G=(V, E), wherein V is the vertex set of G, and E is the directed edge collection of G;Path query method is reached earliest:(1) node of Neo4j timing diagram is divided into two groups: 1) S: finds out the set for reaching the vertex in path earliest;2) U= V-S: the vertex set for reaching path earliest is not yet determined;(2) S={ V is enabled0, dist (Vi)=∞, wherein V0Expression is set out node, ViIndicate destination node, dist (Vi) indicate from Set out node V0It sets out after moment T and reaches destination node ViEarliest arrival time;(3) side e < V if it exists0,Vi,Td,Ta, b > meet Td>=T and Ta<dist(Vi), then remember dist (Vi)=Ta;Otherwise remember dist(Vi)=∞;TdIndicate follow node V0The time set out, TaIt indicates to reach destination node ViTime, b indicate selection The vehicles;(4) the vertex X from a timing distance minimum is chosen in U and not in S, is added S, then the smallest arrival time is dist (X);(5) after X being added, side e < X, V if it existsi,Td’,Ta', b ' > and meet Td' >=dist (X) and Ta' < dist (Vi), then Update note dist (Vi)=Ta';(6) it repeats the above steps (4) and step (5), until S=V;It sets out the latest path query method(1) node of Neo4j timing diagram is divided into two groups: 1) S: finds out the set on the vertex in path of setting out the latest;2) U= V-S: the vertex set in path of setting out the latest is not yet determined;(2) S={ V is enabled0},dist(Vi)=- ∞, wherein V0Expression is set out node, ViIndicate destination node, dist (Vi) represent Send out node V0To destination node ViDeparture time the latest;(3) side e < V if it existsi,V0,Td,Ta, b > meet Ta≤ T and Td>dist(Vi), then remember dist (Vi)=Td;Otherwise remember dist(Vi)=- ∞;(4) from vertex X of the departure time the latest and not in S is chosen in U, S is added, then arrival time the latest is dist (X);(5) after X being added, side e < V if it existsi,X,Td’,Ta', b ' > and meet Ta'≤dist (X) and Td’>dist(Vi), then Update note dist (Vi)=Td';(6) it repeats the above steps (4) and step (4), until S=V;Most short time-consuming path query method(1) initialization node set S is sky;(2) for V0Each edge e < V0,Vi,Td,Ta, b >: obtain departure time Td, by TdIt is added in set S;(3) initializing variable minT=∞, minTd=Td;(4) for the time T in each Sd, call earliest arrival path query method to obtain the correspondence of each departure time earliest Arrival time Td;(5) if minT > Ta-Td, (6) are thened follow the steps, otherwise jump procedure (4);(6) minT=T is updateda-Td, minTd=Td;(7) with most short time-consuming path query method to acquisite approachs EAP, this path is time-consuming shortest path SDP;Path query method, path query method of setting out the latest and most short time-consuming path query method will be reached earliest to be applied to In Neo4j database and embedding data library.
- 2. the timing shortest path query method according to claim 1 based on Neo4j database, it is characterised in that:Path query method, path query method of setting out the latest and most short time-consuming path query method will be reached earliest to be applied to Detailed process is as follows in Neo4j database and embedding data library:(1), it NEO4J process: is called using CALL sentence;(2), NEO4J writes Self-definition process;(3), class and method are write;(4), class and relevant reference packet are packaged as jar packet;(5), restart NEO4J database, process can be called correctly.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811223627.8A CN109460491B (en) | 2018-10-19 | 2018-10-19 | Neo4j database-based time sequence shortest path query method |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201811223627.8A CN109460491B (en) | 2018-10-19 | 2018-10-19 | Neo4j database-based time sequence shortest path query method |
Publications (2)
Publication Number | Publication Date |
---|---|
CN109460491A true CN109460491A (en) | 2019-03-12 |
CN109460491B CN109460491B (en) | 2021-12-10 |
Family
ID=65607952
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201811223627.8A Active CN109460491B (en) | 2018-10-19 | 2018-10-19 | Neo4j database-based time sequence shortest path query method |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109460491B (en) |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111309989A (en) * | 2020-02-13 | 2020-06-19 | 平安科技(深圳)有限公司 | Graph database-based shortest path query method and related equipment |
CN111966843A (en) * | 2020-08-14 | 2020-11-20 | 北京同心尚科技发展有限公司 | Graph database construction method, path search method and device and electronic equipment |
CN112231350A (en) * | 2020-10-13 | 2021-01-15 | 汉唐信通(北京)科技有限公司 | Enterprise business opportunity mining method and device based on knowledge graph |
CN114969165A (en) * | 2022-07-27 | 2022-08-30 | 腾讯科技(深圳)有限公司 | Data query request processing method, device, equipment and storage medium |
CN117290560A (en) * | 2023-11-23 | 2023-12-26 | 支付宝(杭州)信息技术有限公司 | Method and device for acquiring graph data in graph calculation task |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102768506A (en) * | 2012-07-18 | 2012-11-07 | 复旦大学 | FPGA (Field Programmable Gate Array) timing driven layout method with timing constraints |
CN103106280A (en) * | 2013-02-22 | 2013-05-15 | 浙江大学 | Uncertain space-time trajectory data range query method under road network environment |
JP2016177327A (en) * | 2015-03-18 | 2016-10-06 | 伸彦 井戸 | Method of associating two element strings having feature in configuration of directed acyclic graph and cost of lattice point for applying dynamic programming |
JP2017026542A (en) * | 2015-07-27 | 2017-02-02 | 日本電信電話株式会社 | Position estimation device, position estimation method, and position estimation program |
CN107677277A (en) * | 2017-09-30 | 2018-02-09 | 哈尔滨理工大学 | A kind of determining method of path based on dijkstra's algorithm |
CN108121788A (en) * | 2017-12-19 | 2018-06-05 | 北京大学 | Subgraph query method |
-
2018
- 2018-10-19 CN CN201811223627.8A patent/CN109460491B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102768506A (en) * | 2012-07-18 | 2012-11-07 | 复旦大学 | FPGA (Field Programmable Gate Array) timing driven layout method with timing constraints |
CN103106280A (en) * | 2013-02-22 | 2013-05-15 | 浙江大学 | Uncertain space-time trajectory data range query method under road network environment |
JP2016177327A (en) * | 2015-03-18 | 2016-10-06 | 伸彦 井戸 | Method of associating two element strings having feature in configuration of directed acyclic graph and cost of lattice point for applying dynamic programming |
JP2017026542A (en) * | 2015-07-27 | 2017-02-02 | 日本電信電話株式会社 | Position estimation device, position estimation method, and position estimation program |
CN107677277A (en) * | 2017-09-30 | 2018-02-09 | 哈尔滨理工大学 | A kind of determining method of path based on dijkstra's algorithm |
CN108121788A (en) * | 2017-12-19 | 2018-06-05 | 北京大学 | Subgraph query method |
Cited By (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111309989A (en) * | 2020-02-13 | 2020-06-19 | 平安科技(深圳)有限公司 | Graph database-based shortest path query method and related equipment |
CN111966843A (en) * | 2020-08-14 | 2020-11-20 | 北京同心尚科技发展有限公司 | Graph database construction method, path search method and device and electronic equipment |
CN112231350A (en) * | 2020-10-13 | 2021-01-15 | 汉唐信通(北京)科技有限公司 | Enterprise business opportunity mining method and device based on knowledge graph |
CN112231350B (en) * | 2020-10-13 | 2022-04-12 | 汉唐信通(北京)科技有限公司 | Enterprise business opportunity mining method and device based on knowledge graph |
CN114969165A (en) * | 2022-07-27 | 2022-08-30 | 腾讯科技(深圳)有限公司 | Data query request processing method, device, equipment and storage medium |
CN114969165B (en) * | 2022-07-27 | 2022-11-01 | 腾讯科技(深圳)有限公司 | Data query request processing method, device, equipment and storage medium |
CN117290560A (en) * | 2023-11-23 | 2023-12-26 | 支付宝(杭州)信息技术有限公司 | Method and device for acquiring graph data in graph calculation task |
CN117290560B (en) * | 2023-11-23 | 2024-02-23 | 支付宝(杭州)信息技术有限公司 | Method and device for acquiring graph data in graph calculation task |
Also Published As
Publication number | Publication date |
---|---|
CN109460491B (en) | 2021-12-10 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109460491A (en) | Timing shortest path query method based on Neo4j database | |
Pyrga et al. | Efficient models for timetable information in public transportation systems | |
EP3824419A1 (en) | System and method for routing optimization | |
CN107483614A (en) | Content scheduling method and communication network based on CDN Yu P2P networks | |
Sommer | Approximate shortest path and distance queries in networks | |
CN104426770A (en) | Routing lookup method, routing lookup device and method for constructing B-Tree tree structure | |
CN103473298B (en) | Data archiving method and device and storage system | |
CN106651213A (en) | Processing method and device for service orders | |
CN107464133A (en) | A kind of method and device for launching advertisement | |
CN106250226A (en) | Task Scheduling Mechanism based on concordance hash algorithm and system | |
CN113987105B (en) | Label perception graphics stream sketch construction method and application based on sliding window | |
CN104572486B (en) | A kind of electric energy meter data dynamic storage method | |
CN111931077B (en) | Data processing method, device, electronic equipment and storage medium | |
RU2019140930A (en) | METHOD FOR DATA PROCESSING FOR OBTAINING IN REAL TIME CUSTOMIZED INFORMATION ON TRANSPORTATION MOVEMENT | |
Schulz | Timetable information and shortest paths. | |
Casey et al. | Critical review of time-dependent shortest path algorithms: A multimodal trip planner perspective | |
CN103326925A (en) | Message push method and device | |
CN107291454A (en) | A kind of method and Commentary Systems that comment is added in the comment list of event | |
CN107122805A (en) | A kind of user clustering method and apparatus | |
CN104008205A (en) | Content routing inquiry method and system | |
CN105302889B (en) | The conversion method and device of data store organisation | |
CN105138581B (en) | A kind of write-in of mobile message and read method and system | |
El-Gharably et al. | Optimization using simulation of the vehicle routing problem | |
CN103905545A (en) | Reinforced LRU cache replacement method in content-centric network | |
CN103345475A (en) | Method for obtaining and maintaining (IP and domain name) information based on passive mode |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |