Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
This is a simple test of pandana functionality. If it runs with no errors | ||
you should see output something like: | ||
> python demos/example.py | ||
Generating contraction hierarchies with 4 threads. | ||
Setting CH node vector of size 1498 | ||
Setting CH edge vector of size 1702 | ||
[info src/contraction_hierarchies/src/libch.cpp:205] Range graph removed 1900 edges of 3404 | ||
. 10% . 20% . 30% . 40% . 50% . 60% . 70% . 80% . 90% . 100% | ||
100% | ||
Depending on whether your installed copy of pandana was built with OpenMP | ||
support it may be run with multiple threads or only 1. | ||
""" | ||
from __future__ import print_function | ||
|
||
import os.path | ||
import sys | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import pandana.network as pdna | ||
|
||
if len(sys.argv) > 1: | ||
# allow test file to be passed as an argument | ||
storef = sys.argv[1] | ||
else: | ||
# if no argument provided look for it in the test data | ||
storef = os.path.normpath(os.path.join( | ||
os.path.dirname(os.path.abspath(__file__)), | ||
'../pandana/tests/osm_sample.h5')) | ||
|
||
if not os.path.isfile(storef): | ||
raise IOError('Could not find test input file: {!r}'.format(storef)) | ||
|
||
print('Building network from file: {!r}'.format(storef)) | ||
|
||
store = pd.HDFStore(storef, "r") | ||
nodes, edges = store.nodes, store.edges | ||
net = pdna.Network(nodes.x, nodes.y, edges["from"], edges.to, | ||
edges[["weight"]]) | ||
store.close() | ||
print() | ||
|
||
# Demonstrate shortest path code | ||
print('Shortest path from first to last node:') | ||
a = nodes.index[0] | ||
print(a) | ||
b = nodes.index[-1] | ||
print(b) | ||
# Note that the 'weight' is 1.0 for each link, so results aren't very interesting | ||
print(net.shortest_path(a,b)) | ||
print(net.shortest_path_length(a,b,'weight')) |