l3-network algorithms l3 – network algorithms ngen06(tek230) – algorithms in geographical...
TRANSCRIPT
L3-Network Algorithms
L3 – Network Algorithms
NGEN06(TEK230) –
Algorithms in Geographical Information Systems
by: Irene Rangel, updated Nov. 2015 by Abdulghani Hasan
L3-Network Algorithms
Background
By using the distances between nodes in a
network we can derive the shortest path,
Minimum number of nodes to pass,
and other interesting quantities in GIS.
Shortest path -> Dijkstra’s algorithm
L3-Network Algorithms
Content
1. General issues of networks
2. Dijkstra’s algorithm
3. Other shortest path algorithms
4. Neighbourhood graphs and clustering
5. Traveling salesman problem.
L3-Network Algorithms
Aim
Understand how an algorithm can use geographic information stored in a network.
Get knowledge about the shortest path problem and Dijkstra’s algorithm.
L3-Network Algorithms
General issues of networks
Many analysis in networks only consider the nodes and the edges.
• A network or graph has 2 main constitutes:– Nodes– Edges
street network
airplane routes
Geometric location of the nodes is uninteresting
Edges = (distances between nodes)
L3-Network Algorithms
General issues of networks
A B C D
A 0 2 1 -
B 2 0 3 2
C 1 3 0 4
D - 2 4 0
Networks can be stored in matrixes.
”-” implies that the nodes are not connected by any edge
In most cases relational databases or lists and trees are more suitable storage structures.
Not a good data storage since it requires a lot of memory.
L3-Network Algorithms
Graphicrepresentation
Adjacency matrixrepresentation
Adjacency listrepresentation
Source: Worboys and Duckham 2004
L3-Network Algorithms
Shortest path
• The path between two nodes that is shorter than all the other possible paths.
• In the shortest path problem we are not only restricted to Euclidean distances, but all the kind of distances are of interest.
• Dijkstra’s algorithm is one of the most well-known shortest path algorithms.
L3-Network Algorithms
Shortest path
Navigation
Start point target point
Accessibility
Many points target point
L3-Network Algorithms
Dijkstra’s algorithm
• Example of finding the shortest path between nodes A and D.
• We need 2 matrixes:– Adjacency matrix
– State matrix (dynamic)
A B C D
A 0 2 1 -
B 2 0 3 2
C 1 3 0 4
D - 2 4 0
Node Distance Path Visited
A 0 A Yes
B 2 A No
C 1 A No
D - No
L3-Network Algorithms
Dijkstra’s algorithm
State matrix– Distance keeps track of the current shortes distance from the
starting node to this node.– Path stores the previous node along the shortes path (found
so far) to this node.– Visited describes is the node has been visited in the
computations of the shortest path.
Start point is A
Node Distance Path Visited
A
B
C
D
Node Distance Path Visited
A 0 A Yes
B 2 A No
C 1 A No
D - No
Node Distance Path Visited
A 0
B 2
C 1
D
Node Distance Path Visited
A 0 A
B 2 A
C 1 A
D -
L3-Network Algorithms
Dijkstra’s algorithm
Initialized state matrix
Initialization of the state matrix:– The start node is marked as visited.– All the nodes that can be reached from the start node have been updated in the
columns distance and path.• Distance values are set to the distances between the start node and the
respective node (use the adjacency matrix).• Path values are set to the start node (the starting node is the current shortest
path to this particular node)– If there is no known path to some nodes, their distance is set to infinity and their
path value are undefined.
The state matrix is initialized for start point A
Node Distance Path Visited
A 0 A Yes
B 2 A No
C 1 A No
D - No
Node Distance Path Visited
A 0 A Yes
B 2 A No
C 1 A No
D - No
L3-Network Algorithms
Dijkstra’s algorithm
0. Initialize the state matrix.1. Find the node which has the shortest distance and is not yet
visited. Denote this as the current node.2. Mark the current node as visited.
Stop Criteria: End node visited?3. For each node (m) that is not yet visited do:
• If the node m and the current node has a common edge ANDthe sum of the distances for the start node to current node and from current node to node m (found in the adjacency matrix) is shorter than the current distance from the starting node to node m (stored in the state matrix)DOupdate the distance and the path for node m.
4. Proceed from (1) again until the end node is visited.
L3-Network Algorithms
Result of the shortest path algorithm
• Distance from start to end node• Path
Node Distance Path Visited
A 0 - Yes
B 2 A Yes
C 1 A Yes
D 4 B Yes
L3-Network Algorithms
Dijkstra’s algorithm
This algorithm does not search along a possible path direction
depth-first
BUT
rather in all directions
breadth-first.
L3-Network Algorithms
Does Dijkstra’s algorithm always give a correct answer?
Conditions for a metric:1. d(p,q)>=0, d(p,q)=0 p=q
2. d(p,q)=d(q,p) (symmetry)
3. d(p,q)<=d(p,r)+d(r,q) (triangle inequality)
L3-Network Algorithms
Other shortest path algorithms
Heuristic 1 – Direction limitation
A* algorithm
Euclidean distances, depth-first & breadth-first
Heuristic 2 – Hierarchical algorithm
Minor roads and major roads
Heuristic 2 – super nodes (transit nodes)
Algorithms with heuristics are not always giving the best answer (only a reasonably good answer is guaranteed).
L3-Network Algorithms
Breadth-first traversal
Q is a queu – property is first-in-first-out
b is the starting point
Source: Worboys and Duckham 2004
L3-Network Algorithms
Depth-first traversal
S is a stack – property is last-in-first-out
b is the starting point
Source: Worboys and Duckham 2004
L3-Network Algorithms
Neighbourhood graphs – minimum spanning tree (MST)
Minimum Spanning Tree (MST)
1. No isolated node
2.
L3-Network Algorithms
Source: Sedgewick 2002
Kruskal’s algorithm for computing MST
Original Ordered
Edges
L3-Network Algorithms
Neighbourhood graphs and Clustering
Minimum Spanning Tree (MST)
1. No isolated node
2.
Threshold distance
L3-Network Algorithms
Neighbourhood graphs and Clustering
Minimum Spanning Tree (MST)
1. No isolated node
2.
Threshold distance
L3-Network Algorithms
Traveling salesman problem (TSP)
L3-Network Algorithms
Traveling salesman problem (TSP)
1. Begin and end in the same node.
2. Visit all nodes.
3. Minimize total length of the route.
NP-complete
L3-Network Algorithms
Traveling salesman problem (TSP)
A possible way is to compute all possible combinations and chose the shortest one. This would, of course, take exponential time.
How to solve the TSP problems?
A more sensible approach, is to use heuristics. One approach is to start to compute the MST (by e.g. Kruskal’s algorithm).
The maximum length of the TSP is at most 2 times the total length of the MST
L3-Network Algorithms
Traveling salesman problem (TSP)
This solution can greatly been improve by making short cuts.
Start by the MST
Make iterative improvements when they found.
until no further improvements are possible.
A local optimum of the TSP is found.
How to solve the TSP problems?