├── .gitignore
├── .gitmodules
├── .travis.yml
├── LICENSE
├── README.md
├── appengine
├── app.yaml
├── css
│ ├── bootstrap.min.css
│ ├── codemirror.css
│ ├── github.css
│ ├── layout.css
│ ├── perfenforce.css
│ ├── queryvis.css
│ ├── select2-bootstrap.css
│ ├── select2.css
│ └── solarized.css
├── data
│ ├── histogram_4_0.csv
│ ├── histogram_4_1.csv
│ ├── histogram_4_2.csv
│ ├── histogram_4_3.csv
│ ├── profiling_4_0.csv
│ ├── profiling_4_1.csv
│ ├── profiling_4_2.csv
│ ├── profiling_4_3.csv
│ ├── sent_4_0.csv
│ ├── sent_4_1.csv
│ └── sent_4_2.csv
├── dateutil
├── demo3_examples.py
├── examples
├── examples.py
├── fonts
│ ├── glyphicons-halflings-regular.eot
│ ├── glyphicons-halflings-regular.svg
│ ├── glyphicons-halflings-regular.ttf
│ └── glyphicons-halflings-regular.woff
├── img
│ ├── myria-logo.svg
│ ├── select2-spinner.gif
│ ├── select2.png
│ └── select2x2.png
├── js
│ ├── angular.min.js
│ ├── bootstrap.min.js
│ ├── chroma.js
│ ├── chroma.min.js
│ ├── codemirror.js
│ ├── colorbrewer.js
│ ├── colorlegend.js
│ ├── d3.js
│ ├── d3.min.js
│ ├── d3.selection.popover.js
│ ├── d3.selection.tooltip.js
│ ├── editor.js
│ ├── fragmentoverview.js
│ ├── fragmentvis.js
│ ├── graph.js
│ ├── jquery-2.1.1.min.js
│ ├── jquery-2.1.1.min.map
│ ├── jquery.panzoom.js
│ ├── jquery.panzoom.min.js
│ ├── jquery.tablesorter.min.js
│ ├── jquery.timeago.js
│ ├── lodash.min.js
│ ├── main.js
│ ├── myrial.js
│ ├── networkvis.js
│ ├── operatorvis.js
│ ├── perfenforce.js
│ ├── prolog.js
│ ├── queries.js
│ ├── querystats.js
│ ├── queryvis.js
│ ├── runmode.js
│ ├── select2.min.js
│ ├── sql.js
│ ├── svg-crowbar.js
│ ├── underscore-min.js
│ ├── underscore-min.map
│ └── viz.js
├── jupyter_not_found.txt
├── myria
├── myria_web_main.py
├── networkx
│ ├── __init__.py
│ ├── algorithms
│ │ ├── __init__.py
│ │ ├── assortativity
│ │ │ ├── __init__.py
│ │ │ ├── connectivity.py
│ │ │ ├── correlation.py
│ │ │ ├── mixing.py
│ │ │ ├── neighbor_degree.py
│ │ │ ├── pairs.py
│ │ │ └── tests
│ │ │ │ ├── base_test.py
│ │ │ │ ├── test_connectivity.py
│ │ │ │ ├── test_correlation.py
│ │ │ │ ├── test_mixing.py
│ │ │ │ ├── test_neighbor_degree.py
│ │ │ │ └── test_pairs.py
│ │ ├── bipartite
│ │ │ ├── __init__.py
│ │ │ ├── basic.py
│ │ │ ├── centrality.py
│ │ │ ├── cluster.py
│ │ │ ├── projection.py
│ │ │ ├── redundancy.py
│ │ │ ├── spectral.py
│ │ │ └── tests
│ │ │ │ ├── test_basic.py
│ │ │ │ ├── test_centrality.py
│ │ │ │ ├── test_cluster.py
│ │ │ │ ├── test_project.py
│ │ │ │ └── test_spectral_bipartivity.py
│ │ ├── block.py
│ │ ├── boundary.py
│ │ ├── centrality
│ │ │ ├── __init__.py
│ │ │ ├── betweenness.py
│ │ │ ├── betweenness_subset.py
│ │ │ ├── closeness.py
│ │ │ ├── communicability_alg.py
│ │ │ ├── current_flow_betweenness.py
│ │ │ ├── current_flow_betweenness_subset.py
│ │ │ ├── current_flow_closeness.py
│ │ │ ├── degree_alg.py
│ │ │ ├── eigenvector.py
│ │ │ ├── flow_matrix.py
│ │ │ ├── load.py
│ │ │ └── tests
│ │ │ │ ├── test_betweenness_centrality.py
│ │ │ │ ├── test_betweenness_centrality_subset.py
│ │ │ │ ├── test_closeness_centrality.py
│ │ │ │ ├── test_communicability.py
│ │ │ │ ├── test_current_flow_betweenness_centrality.py
│ │ │ │ ├── test_current_flow_betweenness_centrality_subset.py
│ │ │ │ ├── test_current_flow_closeness.py
│ │ │ │ ├── test_degree_centrality.py
│ │ │ │ ├── test_eigenvector_centrality.py
│ │ │ │ └── test_load_centrality.py
│ │ ├── chordal
│ │ │ ├── __init__.py
│ │ │ ├── chordal_alg.py
│ │ │ └── tests
│ │ │ │ └── test_chordal.py
│ │ ├── clique.py
│ │ ├── cluster.py
│ │ ├── community
│ │ │ ├── __init__.py
│ │ │ ├── kclique.py
│ │ │ └── tests
│ │ │ │ └── test_kclique.py
│ │ ├── components
│ │ │ ├── __init__.py
│ │ │ ├── attracting.py
│ │ │ ├── biconnected.py
│ │ │ ├── connected.py
│ │ │ ├── strongly_connected.py
│ │ │ ├── tests
│ │ │ │ ├── test_attracting.py
│ │ │ │ ├── test_biconnected.py
│ │ │ │ ├── test_connected.py
│ │ │ │ ├── test_strongly_connected.py
│ │ │ │ └── test_weakly_connected.py
│ │ │ └── weakly_connected.py
│ │ ├── core.py
│ │ ├── cycles.py
│ │ ├── dag.py
│ │ ├── distance_measures.py
│ │ ├── distance_regular.py
│ │ ├── euler.py
│ │ ├── flow
│ │ │ ├── __init__.py
│ │ │ ├── maxflow.py
│ │ │ ├── mincost.py
│ │ │ └── tests
│ │ │ │ ├── test_maxflow.py
│ │ │ │ ├── test_maxflow_large_graph.py
│ │ │ │ └── test_mincost.py
│ │ ├── graphical.py
│ │ ├── isolate.py
│ │ ├── isomorphism
│ │ │ ├── __init__.py
│ │ │ ├── isomorph.py
│ │ │ ├── isomorphvf2.py
│ │ │ ├── matchhelpers.py
│ │ │ ├── tests
│ │ │ │ ├── iso_r01_s80.A99
│ │ │ │ ├── iso_r01_s80.B99
│ │ │ │ ├── si2_b06_m200.A99
│ │ │ │ ├── si2_b06_m200.B99
│ │ │ │ ├── test_isomorphism.py
│ │ │ │ ├── test_isomorphvf2.py
│ │ │ │ └── test_vf2userfunc.py
│ │ │ └── vf2userfunc.py
│ │ ├── link_analysis
│ │ │ ├── __init__.py
│ │ │ ├── hits_alg.py
│ │ │ ├── pagerank_alg.py
│ │ │ └── tests
│ │ │ │ ├── test_hits.py
│ │ │ │ └── test_pagerank.py
│ │ ├── matching.py
│ │ ├── mis.py
│ │ ├── mst.py
│ │ ├── operators.py
│ │ ├── product.py
│ │ ├── richclub.py
│ │ ├── shortest_paths
│ │ │ ├── __init__.py
│ │ │ ├── astar.py
│ │ │ ├── dense.py
│ │ │ ├── generic.py
│ │ │ ├── tests
│ │ │ │ ├── test_astar.py
│ │ │ │ ├── test_dense.py
│ │ │ │ ├── test_generic.py
│ │ │ │ ├── test_unweighted.py
│ │ │ │ └── test_weighted.py
│ │ │ ├── unweighted.py
│ │ │ └── weighted.py
│ │ ├── smetric.py
│ │ ├── swap.py
│ │ ├── tests
│ │ │ ├── test_block.py
│ │ │ ├── test_boundary.py
│ │ │ ├── test_clique.py
│ │ │ ├── test_cluster.py
│ │ │ ├── test_core.py
│ │ │ ├── test_cycles.py
│ │ │ ├── test_dag.py
│ │ │ ├── test_distance_measures.py
│ │ │ ├── test_distance_regular.py
│ │ │ ├── test_euler.py
│ │ │ ├── test_graphical.py
│ │ │ ├── test_matching.py
│ │ │ ├── test_mis.py
│ │ │ ├── test_mst.py
│ │ │ ├── test_operators.py
│ │ │ ├── test_product.py
│ │ │ ├── test_richclub.py
│ │ │ ├── test_smetric.py
│ │ │ ├── test_swap.py
│ │ │ └── test_vitality.py
│ │ ├── traversal
│ │ │ ├── __init__.py
│ │ │ ├── breadth_first_search.py
│ │ │ ├── depth_first_search.py
│ │ │ └── tests
│ │ │ │ ├── test_bfs.py
│ │ │ │ └── test_dfs.py
│ │ └── vitality.py
│ ├── classes
│ │ ├── __init__.py
│ │ ├── digraph.py
│ │ ├── function.py
│ │ ├── graph.py
│ │ ├── multidigraph.py
│ │ ├── multigraph.py
│ │ └── tests
│ │ │ ├── historical_tests.py
│ │ │ ├── test_digraph.py
│ │ │ ├── test_digraph_historical.py
│ │ │ ├── test_function.py
│ │ │ ├── test_graph.py
│ │ │ ├── test_graph_historical.py
│ │ │ ├── test_multidigraph.py
│ │ │ └── test_multigraph.py
│ ├── convert.py
│ ├── drawing
│ │ ├── __init__.py
│ │ ├── layout.py
│ │ ├── nx_agraph.py
│ │ ├── nx_pydot.py
│ │ ├── nx_pylab.py
│ │ └── tests
│ │ │ ├── test_agraph.py
│ │ │ ├── test_layout.py
│ │ │ ├── test_pydot.py
│ │ │ └── test_pylab.py
│ ├── exception.py
│ ├── external
│ │ ├── __init__.py
│ │ └── decorator
│ │ │ ├── __init__.py
│ │ │ ├── _decorator.py
│ │ │ └── _decorator3.py
│ ├── generators
│ │ ├── __init__.py
│ │ ├── atlas.py
│ │ ├── bipartite.py
│ │ ├── classic.py
│ │ ├── degree_seq.py
│ │ ├── directed.py
│ │ ├── ego.py
│ │ ├── geometric.py
│ │ ├── hybrid.py
│ │ ├── intersection.py
│ │ ├── line.py
│ │ ├── random_clustered.py
│ │ ├── random_graphs.py
│ │ ├── small.py
│ │ ├── social.py
│ │ ├── stochastic.py
│ │ ├── tests
│ │ │ ├── test_atlas.py
│ │ │ ├── test_bipartite.py
│ │ │ ├── test_classic.py
│ │ │ ├── test_degree_seq.py
│ │ │ ├── test_directed.py
│ │ │ ├── test_ego.py
│ │ │ ├── test_geometric.py
│ │ │ ├── test_hybrid.py
│ │ │ ├── test_intersection.py
│ │ │ ├── test_line.py
│ │ │ ├── test_random_clustered.py
│ │ │ ├── test_random_graphs.py
│ │ │ ├── test_small.py
│ │ │ ├── test_stochastic.py
│ │ │ └── test_threshold.py
│ │ └── threshold.py
│ ├── linalg
│ │ ├── __init__.py
│ │ ├── attrmatrix.py
│ │ ├── graphmatrix.py
│ │ ├── laplacianmatrix.py
│ │ ├── spectrum.py
│ │ └── tests
│ │ │ ├── test_graphmatrix.py
│ │ │ ├── test_laplaican.py
│ │ │ └── test_spectrum.py
│ ├── readwrite
│ │ ├── __init__.py
│ │ ├── adjlist.py
│ │ ├── edgelist.py
│ │ ├── gexf.py
│ │ ├── gml.py
│ │ ├── gpickle.py
│ │ ├── graphml.py
│ │ ├── json_graph
│ │ │ ├── __init__.py
│ │ │ ├── adjacency.py
│ │ │ ├── node_link.py
│ │ │ ├── serialize.py
│ │ │ ├── tests
│ │ │ │ ├── test_adjacency.py
│ │ │ │ ├── test_node_link.py
│ │ │ │ ├── test_serialize.py
│ │ │ │ └── test_tree.py
│ │ │ └── tree.py
│ │ ├── leda.py
│ │ ├── multiline_adjlist.py
│ │ ├── nx_shp.py
│ │ ├── nx_yaml.py
│ │ ├── p2g.py
│ │ ├── pajek.py
│ │ ├── sparsegraph6.py
│ │ └── tests
│ │ │ ├── test_adjlist.py
│ │ │ ├── test_edgelist.py
│ │ │ ├── test_gexf.py
│ │ │ ├── test_gml.py
│ │ │ ├── test_gpickle.py
│ │ │ ├── test_graphml.py
│ │ │ ├── test_leda.py
│ │ │ ├── test_p2g.py
│ │ │ ├── test_pajek.py
│ │ │ ├── test_shp.py
│ │ │ ├── test_sparsegraph6.py
│ │ │ └── test_yaml.py
│ ├── relabel.py
│ ├── release.py
│ ├── tests
│ │ ├── __init__.py
│ │ ├── benchmark.py
│ │ ├── test.py
│ │ ├── test_convert.py
│ │ ├── test_convert_numpy.py
│ │ ├── test_convert_scipy.py
│ │ ├── test_exceptions.py
│ │ └── test_relabel.py
│ ├── utils
│ │ ├── __init__.py
│ │ ├── decorators.py
│ │ ├── misc.py
│ │ ├── random_sequence.py
│ │ ├── rcm.py
│ │ ├── tests
│ │ │ ├── test_decorators.py
│ │ │ ├── test_misc.py
│ │ │ ├── test_random_sequence.py
│ │ │ └── test_rcm.py
│ │ └── union_find.py
│ └── version.py
├── pagination.py
├── parsetab.py
├── ply
│ ├── __init__.py
│ ├── cpp.py
│ ├── ctokens.py
│ ├── lex.py
│ └── yacc.py
├── pyparsing.py
├── raco
├── requests
├── robots.txt
├── six.py
├── sqlalchemy
├── static
│ ├── apple-touch-icon-114x114-precomposed.png
│ ├── apple-touch-icon-120x120-precomposed.png
│ ├── apple-touch-icon-144x144-precomposed.png
│ ├── apple-touch-icon-152x152-precomposed.png
│ ├── apple-touch-icon-72x72-precomposed.png
│ ├── apple-touch-icon-76x76-precomposed.png
│ ├── apple-touch-icon-precomposed.png
│ └── favicon.ico
├── templates
│ ├── base.html
│ ├── datasets.html
│ ├── editor.html
│ ├── perfenforce.html
│ ├── queries.html
│ └── visualization.html
├── test
│ ├── test_myria_down.py
│ └── test_myria_up.py
└── test_style.py
├── customize-bootstrap
├── README.md
└── variables.less.diff
├── deploy.sh
├── docs
└── index.md
└── requirements-dev.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 | .DS_Store
3 | .*.swp
4 | appengine/VERSION
5 | appengine/BRANCH
6 | /google_appengine
7 | /google_appengine*.zip
8 | .idea
9 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "datalogcompiler"]
2 | path = submodules/raco
3 | url = https://github.com/uwescience/datalogcompiler.git
4 | branch = master
5 | [submodule "myria-python"]
6 | path = submodules/myria-python
7 | url = https://github.com/uwescience/myria-python.git
8 | branch = master
9 | [submodule "requests"]
10 | path = submodules/requests
11 | url = https://github.com/kennethreitz/requests/
12 | [submodule "submodules/sqlalchemy"]
13 | path = submodules/sqlalchemy
14 | url = https://github.com/zzzeek/sqlalchemy.git
15 | [submodule "submodules/dateutil"]
16 | path = submodules/dateutil
17 | url = https://github.com/dateutil/dateutil.git
18 | [submodule "submodules/six"]
19 | path = submodules/six
20 | url = https://github.com/gsutil-mirrors/six.git
21 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: python
2 | python:
3 | - "2.7"
4 | install:
5 | - curl -O https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.22.zip && unzip -q google_appengine_1.9.22.zip
6 | - pip install -r requirements-dev.txt
7 | script: nosetests test/test_myria_down.py test/test_myria_up.py test_style.py -w appengine --with-gae --gae-lib-root=google_appengine
8 | sudo: false
9 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012-2015 University of Washington
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 | Neither the name of the University of Washington nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8 |
9 | THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10 |
--------------------------------------------------------------------------------
/appengine/app.yaml:
--------------------------------------------------------------------------------
1 | application: myria-web
2 | version: 1
3 | runtime: python27
4 | api_version: 1
5 | threadsafe: true
6 |
7 | handlers:
8 | - url: /favicon\.ico
9 | expiration: "7d"
10 | static_files: static/favicon.ico
11 | upload: static/favicon\.ico
12 | - url: /(apple-touch.*\.png)
13 | expiration: "7d"
14 | static_files: static/\1
15 | upload: static/apple.*\.png
16 | - url: /jupyter_not_found
17 | static_files: jupyter_not_found.txt
18 | upload: jupyter_not_found.txt
19 | - url: /css
20 | static_dir: css
21 | - url: /fonts
22 | static_dir: fonts
23 | - url: /img
24 | static_dir: img
25 | - url: /js
26 | static_dir: js
27 | - url: /data
28 | static_dir: data
29 | - url: /robots\.txt
30 | static_files: robots.txt
31 | upload: robots\.txt
32 | # This handler must be last
33 | - url: /.*
34 | script: myria_web_main.app
35 | secure: always
36 |
37 | libraries:
38 | - name: webapp2
39 | version: latest
40 | - name: jinja2
41 | version: latest
42 |
43 | env_variables:
44 | MYRIAX_REST_HOST: localhost
45 | MYRIAX_REST_PORT: 8753
46 | MYRIA_JUPYTER_PORT: 8888
47 |
--------------------------------------------------------------------------------
/appengine/css/layout.css:
--------------------------------------------------------------------------------
1 | .navbar-inverse .navbar-brand {
2 | padding-top: 5px;
3 | padding-bottom: 5px;
4 | }
5 |
6 | .navbar-inverse {
7 | margin-bottom: 10px;
8 | }
9 |
10 | .modal-header input[type=range] {
11 | width: 250px;
12 | height: 10px;
13 | margin: 0 30px 0 5px;
14 | }
15 |
16 | .my-fluid-container {
17 | width: 100%;
18 | }
19 |
20 | html {
21 | position: relative;
22 | min-height: 100%;
23 | }
24 | body {
25 | /* Margin bottom by footer height */
26 | margin-bottom: 60px;
27 | }
28 |
29 | #footer {
30 | position: absolute;
31 | bottom: 0;
32 | width: 100%;
33 | /* Set the fixed height of the footer here */
34 | height: 60px;
35 | background-color: #f5f5f5;
36 | }
37 |
38 | .container .credit {
39 | margin: 20px 0;
40 | }
41 |
42 | .spacer {
43 | padding-top: 10px;
44 | }
45 |
46 | input[type=range].zoom-range {
47 | display: inline;
48 | }
49 |
50 | #editor-tabs li a {
51 | padding: 8px 3px;
52 | }
53 |
54 | .dataset-search {
55 | width: 100%;
56 | }
57 |
58 | .triple-input .form-control {
59 | width: 33.33%;
60 | border-right-width: 0px;
61 | }
62 | .triple-input .form-control:focus {
63 | border-right-width: 1px;
64 | }
65 |
66 | .back-to-top {
67 | position: fixed;
68 | bottom: 8px;
69 | right: 8px;
70 | padding: 8px 12px;
71 | z-index: 10;
72 | background-color: rgba(255, 255, 255, 0.7);
73 | }
74 |
75 | #svg-modal-body {
76 | padding: 0;
77 | }
78 |
79 | .CodeMirror {
80 | border: 1px solid #eee;
81 | height: auto;
82 | }
83 |
84 | .CodeMirror-hscrollbar {
85 | display: none !important;
86 | }
87 |
88 | .select2-result-label strong {
89 | text-decoration: underline;
90 | }
91 |
92 | #examples-list .list-group-item {
93 | padding-top: 0;
94 | padding-bottom: 0;
95 | }
96 |
97 | #examples-list pre {
98 | font-size: 10px;
99 | }
100 |
101 | #examples-list {
102 | overflow: auto;
103 | }
104 |
105 | #loadexamples-list .list-group-item {
106 | padding-top: 0;
107 | padding-bottom: 0;
108 | }
109 |
110 | #loadexamples-list pre {
111 | font-size: 10px;
112 | }
113 |
114 | #loadexamples-list {
115 | overflow: auto;
116 | }
117 |
118 | #myria_svg {
119 | width: 100%;
120 | }
121 |
122 | .tablesorter-header[aria-disabled=false] {
123 | cursor: pointer;
124 | }
125 |
126 | .query-panel-heading .form-group {
127 | margin-bottom: 0;
128 | }
129 |
130 | .query-panel-heading .panel-title {
131 | margin-top: 7px;
132 | }
--------------------------------------------------------------------------------
/appengine/css/perfenforce.css:
--------------------------------------------------------------------------------
1 | .glyphicon.spinning {
2 | animation: spin 1s infinite linear;
3 | -webkit-animation: spin2 1s infinite linear;
4 | }
5 |
6 | @keyframes spin {
7 | from { transform: scale(1) rotate(0deg);}
8 | to { transform: scale(1) rotate(360deg);}
9 | }
10 |
11 | @-webkit-keyframes spin2 {
12 | from { -webkit-transform: rotate(0deg);}
13 | to { -webkit-transform: rotate(360deg);}
14 | }
15 |
16 | .glyphicon-left {
17 | margin-right: 7px;
18 | }
19 |
20 | .page-anchor {
21 | line-height: 1em;
22 | display: inline-block;
23 | text-decoration: none;
24 | margin-top: 500px;
25 | }
26 |
27 | #previousQueryList
28 | {
29 | height: 100px;
30 | overflow: auto;
31 | border: 1px solid black;
32 | }
33 |
34 | ul {
35 | padding: 0;
36 | }
37 | li {
38 | margin: 0;
39 | list-style-type: none;
40 | }
41 |
42 |
43 | .list-group-item{
44 | border: 1px solid #808080;
45 | }
46 |
47 | .top-buffer { margin-top:40px; }
--------------------------------------------------------------------------------
/appengine/data/sent_4_2.csv:
--------------------------------------------------------------------------------
1 | workerId,nanoTime,numTuples,destWorkerId
2 | 3,1040212134,143,1
3 | 3,2059371044,3259,1
4 | 3,3065649769,5422,1
5 | 3,3549528390,10000,1
6 | 3,4236235180,10000,1
7 | 3,4897241800,3093,1
8 | 1,1031169627,209,1
9 | 1,2049172616,1402,1
10 | 1,3057253192,2858,1
11 | 1,4078224688,5901,1
12 | 1,4888275121,1566,1
13 | 7,1036117216,159,1
14 | 7,2055480109,3272,1
15 | 7,3060842477,4045,1
16 | 7,4140191100,4041,1
17 | 7,4893253135,739,1
18 | 5,1001856273,140,1
19 | 5,2076853745,1003,1
20 | 5,2413825865,10000,1
21 | 5,2441449427,10000,1
22 | 5,2480383113,10000,1
23 | 5,2518129100,10000,1
24 | 5,2556666536,10000,1
25 | 5,2595475333,10000,1
26 | 5,2639974919,10000,1
27 | 5,2733050327,10000,1
28 | 5,2783048573,10000,1
29 | 5,2819065828,10000,1
30 | 5,2857651639,10000,1
31 | 5,2895833651,10000,1
32 | 5,2932926858,10000,1
33 | 5,2970162367,10000,1
34 | 5,3024694567,10000,1
35 | 5,3077566857,10000,1
36 | 5,3290031871,10000,1
37 | 5,3366705113,10000,1
38 | 5,3438554481,10000,1
39 | 5,3510310986,10000,1
40 | 5,3587130299,10000,1
41 | 5,3659335785,10000,1
42 | 5,3722179458,10000,1
43 | 5,3794343402,10000,1
44 | 5,3853666293,10000,1
45 | 5,3923608935,10000,1
46 | 5,3991528316,10000,1
47 | 5,4068186032,10000,1
48 | 5,4147132636,10000,1
49 | 5,4221442157,10000,1
50 | 5,4281493775,10000,1
51 | 5,4468693435,10000,1
52 | 5,4489147709,10000,1
53 | 5,4512187018,10000,1
54 | 5,4547537806,10000,1
55 | 5,4649467543,10000,1
56 | 5,4700225098,10000,1
57 | 5,4727947368,10000,1
58 | 5,4804216202,10000,1
59 | 5,4889306968,10000,1
60 | 5,4909136289,10000,1
61 | 5,4941848562,10000,1
62 | 5,4959749354,10000,1
63 | 5,4985471821,10000,1
64 | 5,5045634269,2673,1
65 | 2,980267924,128,1
66 | 2,1988198944,1037,1
67 | 2,3006043295,3393,1
68 | 2,4154062648,4044,1
69 | 2,4955249558,693,1
70 | 6,1033411968,135,1
71 | 6,2034185617,2430,1
72 | 6,3058293289,1731,1
73 | 6,4158173610,4225,1
74 | 6,4958239761,898,1
75 | 4,1023091563,205,1
76 | 4,2024121979,728,1
77 | 4,3023832324,1710,1
78 | 4,4147103057,2659,1
79 | 4,4947294558,365,1
80 | 8,1020043267,222,1
81 | 8,2021275872,1608,1
82 | 8,3046053510,2228,1
83 | 8,4145079480,4090,1
84 | 8,4946289187,429,1
85 |
--------------------------------------------------------------------------------
/appengine/dateutil:
--------------------------------------------------------------------------------
1 | ../submodules/dateutil/dateutil
--------------------------------------------------------------------------------
/appengine/examples:
--------------------------------------------------------------------------------
1 | ../submodules/raco/examples
--------------------------------------------------------------------------------
/appengine/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uwescience/myria-web/b1c175a5cbe76d4f2219b192635085ece1326588/appengine/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/appengine/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uwescience/myria-web/b1c175a5cbe76d4f2219b192635085ece1326588/appengine/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/appengine/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uwescience/myria-web/b1c175a5cbe76d4f2219b192635085ece1326588/appengine/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/appengine/img/select2-spinner.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uwescience/myria-web/b1c175a5cbe76d4f2219b192635085ece1326588/appengine/img/select2-spinner.gif
--------------------------------------------------------------------------------
/appengine/img/select2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uwescience/myria-web/b1c175a5cbe76d4f2219b192635085ece1326588/appengine/img/select2.png
--------------------------------------------------------------------------------
/appengine/img/select2x2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uwescience/myria-web/b1c175a5cbe76d4f2219b192635085ece1326588/appengine/img/select2x2.png
--------------------------------------------------------------------------------
/appengine/js/d3.selection.popover.js:
--------------------------------------------------------------------------------
1 | // adapted from: https://gist.github.com/mrfr0g/5968059
2 |
3 | (function () {
4 | // Bootstrap provided getPosition uses offsetWidth and offsetHeight to calculate
5 | // the positioning of the popover. SVG Elements do not have this property because
6 | // SVG does not layout elements, it assumes elements are always positioned.
7 | // This replaces their implementation for SVG elements, and utilizes getBoundingClientRect.
8 | var getPosition = $.fn.popover.Constructor.prototype.getPosition;
9 | $.fn.popover.Constructor.prototype.getPosition = function (inside) {
10 | var svgParent = this.$element.parents('svg');
11 | // Only apply to SVG children
12 | // Test for iOS 3/BlackBerry
13 | if(svgParent.length && Element.prototype.getBoundingClientRect) {
14 | // Get initial offset
15 | var offset = this.$element.offset(),
16 | // Get rect (with width/height values)
17 | rect = this.$element[0].getBoundingClientRect();
18 |
19 | offset.width = rect.width;
20 | offset.height = rect.height;
21 |
22 | // Return the completed object
23 | return offset;
24 | }
25 | return getPosition.call(this, inside);
26 | };
27 |
28 | // Attach the popover method to d3's selection object
29 | d3.selection.prototype.popover = function (/* Accepts value, or function */ accessorOrValue) {
30 | this.each(function (d) {
31 | var popover = accessorOrValue instanceof Function ? null : accessorOrValue;
32 |
33 | popover = popover || accessorOrValue && accessorOrValue(d) || d.popover;
34 |
35 | if(popover) {
36 | $(this).popover({
37 | title: popover.title,
38 | content: popover.content,
39 | container: 'body',
40 | placement: popover.placement ? popover.placement : 'auto',
41 | offset: 10,
42 | trigger: 'manual',
43 | html: true,
44 | template: '
'
45 | }).mouseenter(function(e) {
46 | $(this).popover('show');
47 | }).mouseleave(function(e) {
48 | var ref = $(this);
49 | timeoutObj = setTimeout(function(){
50 | ref.popover('hide');
51 | }, 100);
52 | });
53 | }
54 | });
55 |
56 | return this;
57 | };
58 | })();
--------------------------------------------------------------------------------
/appengine/js/d3.selection.tooltip.js:
--------------------------------------------------------------------------------
1 | // adapted from: https://gist.github.com/mrfr0g/5968059
2 |
3 | (function () {
4 | // Bootstrap provided getPosition uses offsetWidth and offsetHeight to calculate
5 | // the positioning of the tooltip. SVG Elements do not have this property because
6 | // SVG does not layout elements, it assumes elements are always positioned.
7 | // This replaces their implementation for SVG elements, and utilizes getBoundingClientRect.
8 | var getPosition = $.fn.tooltip.Constructor.prototype.getPosition;
9 | $.fn.tooltip.Constructor.prototype.getPosition = function (inside) {
10 | var svgParent = this.$element.parents('svg');
11 | // Only apply to SVG children
12 | // Test for iOS 3/BlackBerry
13 | if(svgParent.length && Element.prototype.getBoundingClientRect) {
14 | // Get initial offset
15 | var offset = this.$element.offset(),
16 | // Get rect (with width/height values)
17 | rect = this.$element[0].getBoundingClientRect();
18 |
19 | offset.width = rect.width;
20 | offset.height = rect.height;
21 |
22 | // Return the completed object
23 | return offset;
24 | }
25 | return getPosition.call(this, inside);
26 | };
27 |
28 | // Attach the tooltip method to d3's selection object
29 | d3.selection.prototype.tooltip = function (/* Accepts value, or function */ accessorOrValue) {
30 | this.each(function (d) {
31 | var tooltip = accessorOrValue instanceof Function ? null : accessorOrValue;
32 |
33 | tooltip = tooltip || accessorOrValue && accessorOrValue(d) || d.tooltip;
34 |
35 | if(tooltip) {
36 | $(this).tooltip({
37 | title: tooltip,
38 | container: 'body',
39 | html: true
40 | });
41 | }
42 | });
43 |
44 | return this;
45 | };
46 | })();
--------------------------------------------------------------------------------
/appengine/js/prolog.js:
--------------------------------------------------------------------------------
1 | CodeMirror.defineMode("prolog", function() {
2 | return {
3 | startState: function() {
4 | return { in_comment:0 };
5 | },
6 | token: function(stream,state) {
7 | var token_name;
8 | if (state.in_comment) {
9 | token_name = 'comment';
10 | if (stream.match("*/"))
11 | state.in_comment--;
12 | else if (stream.match("/*"))
13 | state.in_comment++;
14 | else
15 | stream.next();
16 | } else if (stream.match("/*")) {
17 | token_name = 'comment';
18 | state.in_comment++;
19 | } else if (stream.match(/[a-z][A-Za-z0-9_]*/))
20 | token_name = 'atom';
21 | else if (stream.match(/\'(\\\'|[^\'])*\'/))
22 | token_name = 'atom';
23 | else if (stream.match(/\"(\\\"|[^\"])*\"/))
24 | token_name = 'string';
25 | else if (stream.match(/0'./))
26 | token_name = 'string-2';
27 | else if (stream.match(/[A-Z_][A-Za-z0-9_]*/))
28 | token_name = 'variable-2';
29 | else if (stream.match(/[0-9]+(\.[0-9]+)?/))
30 | token_name = 'number';
31 | else if (stream.match(/[\+\-\*\/\=\^<>~:\.\?@#$\\&{}`]+/))
32 | token_name = 'operator';
33 | else
34 | if (stream.next() === '%') {
35 | stream.skipToEnd();
36 | token_name = 'comment';
37 | }
38 | return token_name;
39 | }
40 | };
41 | });
--------------------------------------------------------------------------------
/appengine/js/queries.js:
--------------------------------------------------------------------------------
1 | $(document).ready(function() {
2 | $('.query-row[data-status="RUNNING"]').each(function(i, e) {
3 | var qid = $(this).attr('data-id');
4 | window.setInterval(function() {
5 | $.getJSON('/execute', { 'queryId': qid }, function(data) {
6 | if (data.status != 'RUNNING') {
7 | location.reload();
8 | }
9 | });
10 | }, 10*1000);
11 | });
12 |
13 | $('.kill-query').click(function() {
14 | $.ajax({
15 | url: $(this).attr('href'),
16 | type: 'DELETE',
17 | success: function(result) {
18 | location.reload();
19 | }
20 | });
21 | return false;
22 | });
23 | });
--------------------------------------------------------------------------------
/appengine/js/querystats.js:
--------------------------------------------------------------------------------
1 | var updateQueryStats = function(element, queryStatus) {
2 | var shuffleUrl = templates.urls.aggregatedSentData({
3 | myria: myriaConnection,
4 | query: queryStatus.queryId,
5 | subquery: queryStatus.subqueryId
6 | });
7 |
8 | d3.csv(shuffleUrl, function(d) {
9 | d.numTuples = +d.numTuples;
10 | return d;
11 | }, function (data) {
12 | $(element.node()).empty();
13 | var div = element.append("div")
14 | .attr("class", "query-stats");
15 | var h = div.append("h4")
16 | .text("Query stats:");
17 | var totalTuple = data.reduce(function(a,b){
18 | return a + b.numTuples;
19 | }, 0);
20 | var items = "";
21 | items += templates.defItem({key: "Running time:", value: customFullTimeFormat(queryStatus.elapsedNanos, false)});
22 | items += templates.defItem({key: "# shuffled tuples:", value: Intl.NumberFormat().format(totalTuple)});
23 | var dl = templates.defList({items: items});
24 | $(".query-stats").append(dl);
25 | });
26 | };
--------------------------------------------------------------------------------
/appengine/js/runmode.js:
--------------------------------------------------------------------------------
1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 | // Distributed under an MIT license: http://codemirror.net/LICENSE
3 |
4 | (function(mod) {
5 | if (typeof exports == "object" && typeof module == "object") // CommonJS
6 | mod(require("../../lib/codemirror"));
7 | else if (typeof define == "function" && define.amd) // AMD
8 | define(["../../lib/codemirror"], mod);
9 | else // Plain browser env
10 | mod(CodeMirror);
11 | })(function(CodeMirror) {
12 | "use strict";
13 |
14 | CodeMirror.runMode = function(string, modespec, callback, options) {
15 | var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
16 | var ie = /MSIE \d/.test(navigator.userAgent);
17 | var ie_lt9 = ie && (document.documentMode == null || document.documentMode < 9);
18 |
19 | if (callback.nodeType == 1) {
20 | var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
21 | var node = callback, col = 0;
22 | node.innerHTML = "";
23 | callback = function(text, style) {
24 | if (text == "\n") {
25 | // Emitting LF or CRLF on IE8 or earlier results in an incorrect display.
26 | // Emitting a carriage return makes everything ok.
27 | node.appendChild(document.createTextNode(ie_lt9 ? '\r' : text));
28 | col = 0;
29 | return;
30 | }
31 | var content = "";
32 | // replace tabs
33 | for (var pos = 0;;) {
34 | var idx = text.indexOf("\t", pos);
35 | if (idx == -1) {
36 | content += text.slice(pos);
37 | col += text.length - pos;
38 | break;
39 | } else {
40 | col += idx - pos;
41 | content += text.slice(pos, idx);
42 | var size = tabSize - col % tabSize;
43 | col += size;
44 | for (var i = 0; i < size; ++i) content += " ";
45 | pos = idx + 1;
46 | }
47 | }
48 |
49 | if (style) {
50 | var sp = node.appendChild(document.createElement("span"));
51 | sp.className = "cm-" + style.replace(/ +/g, " cm-");
52 | sp.appendChild(document.createTextNode(content));
53 | } else {
54 | node.appendChild(document.createTextNode(content));
55 | }
56 | };
57 | }
58 |
59 | var lines = CodeMirror.splitLines(string), state = (options && options.state) || CodeMirror.startState(mode);
60 | for (var i = 0, e = lines.length; i < e; ++i) {
61 | if (i) callback("\n");
62 | var stream = new CodeMirror.StringStream(lines[i]);
63 | if (!stream.string && mode.blankLine) mode.blankLine(state);
64 | while (!stream.eol()) {
65 | var style = mode.token(stream, state);
66 | callback(stream.current(), style, i, stream.start, state);
67 | stream.start = stream.pos;
68 | }
69 | }
70 | };
71 |
72 | });
73 |
--------------------------------------------------------------------------------
/appengine/jupyter_not_found.txt:
--------------------------------------------------------------------------------
1 | Jupyter Notebook not found, please check that the service is running and set up on port 8888.
--------------------------------------------------------------------------------
/appengine/myria:
--------------------------------------------------------------------------------
1 | ../submodules/myria-python/myria
--------------------------------------------------------------------------------
/appengine/networkx/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | NetworkX
3 | ========
4 |
5 | NetworkX (NX) is a Python package for the creation, manipulation, and
6 | study of the structure, dynamics, and functions of complex networks.
7 |
8 | https://networkx.lanl.gov/
9 |
10 | Using
11 | -----
12 |
13 | Just write in Python
14 |
15 | >>> import networkx as nx
16 | >>> G=nx.Graph()
17 | >>> G.add_edge(1,2)
18 | >>> G.add_node("spam")
19 | >>> print(G.nodes())
20 | [1, 2, 'spam']
21 | >>> print(G.edges())
22 | [(1, 2)]
23 | """
24 | # Copyright (C) 2004-2010 by
25 | # Aric Hagberg
26 | # Dan Schult
27 | # Pieter Swart
28 | # All rights reserved.
29 | # BSD license.
30 | #
31 | # Add platform dependent shared library path to sys.path
32 | #
33 |
34 | from __future__ import absolute_import
35 |
36 | import sys
37 | if sys.version_info[:2] < (2, 6):
38 | m = "Python version 2.6 or later is required for NetworkX (%d.%d detected)."
39 | raise ImportError(m % sys.version_info[:2])
40 | del sys
41 |
42 | # Release data
43 | from networkx import release
44 |
45 | __author__ = '%s <%s>\n%s <%s>\n%s <%s>' % \
46 | ( release.authors['Hagberg'] + release.authors['Schult'] + \
47 | release.authors['Swart'] )
48 | __license__ = release.license
49 |
50 | __date__ = release.date
51 | __version__ = release.version
52 |
53 | #These are import orderwise
54 | from networkx.exception import *
55 | import networkx.external
56 | import networkx.utils
57 | # these packages work with Python >= 2.6
58 |
59 | import networkx.classes
60 | from networkx.classes import *
61 |
62 |
63 | import networkx.convert
64 | from networkx.convert import *
65 |
66 | import networkx.relabel
67 | from networkx.relabel import *
68 |
69 | import networkx.generators
70 | from networkx.generators import *
71 |
72 | import networkx.readwrite
73 | from networkx.readwrite import *
74 |
75 | #Need to test with SciPy, when available
76 | import networkx.algorithms
77 | from networkx.algorithms import *
78 | import networkx.linalg
79 |
80 | from networkx.linalg import *
81 | from networkx.tests.test import run as test
82 |
83 | import networkx.drawing
84 | from networkx.drawing import *
85 |
86 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/__init__.py:
--------------------------------------------------------------------------------
1 | from networkx.algorithms.assortativity import *
2 | from networkx.algorithms.block import *
3 | from networkx.algorithms.boundary import *
4 | from networkx.algorithms.centrality import *
5 | from networkx.algorithms.cluster import *
6 | from networkx.algorithms.clique import *
7 | from networkx.algorithms.community import *
8 | from networkx.algorithms.components import *
9 | from networkx.algorithms.core import *
10 | from networkx.algorithms.cycles import *
11 | from networkx.algorithms.dag import *
12 | from networkx.algorithms.distance_measures import *
13 | from networkx.algorithms.flow import *
14 | from networkx.algorithms.matching import *
15 | from networkx.algorithms.mis import *
16 | from networkx.algorithms.mst import *
17 | from networkx.algorithms.link_analysis import *
18 | from networkx.algorithms.operators import *
19 | from networkx.algorithms.product import *
20 | from networkx.algorithms.shortest_paths import *
21 | from networkx.algorithms.smetric import *
22 | from networkx.algorithms.traversal import *
23 | from networkx.algorithms.isolate import *
24 | from networkx.algorithms.euler import *
25 | from networkx.algorithms.vitality import *
26 | from networkx.algorithms.chordal import *
27 | from networkx.algorithms.richclub import *
28 | from networkx.algorithms.distance_regular import *
29 | from networkx.algorithms.swap import *
30 | from networkx.algorithms.graphical import *
31 |
32 | import networkx.algorithms.assortativity
33 | import networkx.algorithms.bipartite
34 | import networkx.algorithms.centrality
35 | import networkx.algorithms.cluster
36 | import networkx.algorithms.clique
37 | import networkx.algorithms.components
38 | import networkx.algorithms.flow
39 | import networkx.algorithms.isomorphism
40 | import networkx.algorithms.link_analysis
41 | import networkx.algorithms.shortest_paths
42 | import networkx.algorithms.traversal
43 | import networkx.algorithms.chordal
44 |
45 | from networkx.algorithms.bipartite import projected_graph,project,is_bipartite
46 | from networkx.algorithms.isomorphism import is_isomorphic,could_be_isomorphic,\
47 | fast_could_be_isomorphic,faster_could_be_isomorphic
48 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/assortativity/__init__.py:
--------------------------------------------------------------------------------
1 | from networkx.algorithms.assortativity.connectivity import *
2 | from networkx.algorithms.assortativity.correlation import *
3 | from networkx.algorithms.assortativity.mixing import *
4 | from networkx.algorithms.assortativity.neighbor_degree import *
5 | from networkx.algorithms.assortativity.pairs import *
6 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/assortativity/tests/base_test.py:
--------------------------------------------------------------------------------
1 | import networkx as nx
2 |
3 | class BaseTestAttributeMixing(object):
4 |
5 | def setUp(self):
6 | G=nx.Graph()
7 | G.add_nodes_from([0,1],fish='one')
8 | G.add_nodes_from([2,3],fish='two')
9 | G.add_nodes_from([4],fish='red')
10 | G.add_nodes_from([5],fish='blue')
11 | G.add_edges_from([(0,1),(2,3),(0,4),(2,5)])
12 | self.G=G
13 |
14 | D=nx.DiGraph()
15 | D.add_nodes_from([0,1],fish='one')
16 | D.add_nodes_from([2,3],fish='two')
17 | D.add_nodes_from([4],fish='red')
18 | D.add_nodes_from([5],fish='blue')
19 | D.add_edges_from([(0,1),(2,3),(0,4),(2,5)])
20 | self.D=D
21 |
22 | M=nx.MultiGraph()
23 | M.add_nodes_from([0,1],fish='one')
24 | M.add_nodes_from([2,3],fish='two')
25 | M.add_nodes_from([4],fish='red')
26 | M.add_nodes_from([5],fish='blue')
27 | M.add_edges_from([(0,1),(0,1),(2,3)])
28 | self.M=M
29 |
30 | S=nx.Graph()
31 | S.add_nodes_from([0,1],fish='one')
32 | S.add_nodes_from([2,3],fish='two')
33 | S.add_nodes_from([4],fish='red')
34 | S.add_nodes_from([5],fish='blue')
35 | S.add_edge(0,0)
36 | S.add_edge(2,2)
37 | self.S=S
38 |
39 | class BaseTestDegreeMixing(object):
40 |
41 | def setUp(self):
42 | self.P4=nx.path_graph(4)
43 | self.D=nx.DiGraph()
44 | self.D.add_edges_from([(0, 2), (0, 3), (1, 3), (2, 3)])
45 | self.M=nx.MultiGraph()
46 | self.M.add_path(list(range(4)))
47 | self.M.add_edge(0,1)
48 | self.S=nx.Graph()
49 | self.S.add_edges_from([(0,0),(1,1)])
50 |
51 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/assortativity/tests/test_neighbor_degree.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from nose.tools import *
3 | import networkx as nx
4 |
5 | class TestAverageNeighbor(object):
6 |
7 | def test_degree_p4(self):
8 | G=nx.path_graph(4)
9 | answer={0:2,1:1.5,2:1.5,3:2}
10 | nd = nx.average_neighbor_degree(G)
11 | assert_equal(nd,answer)
12 |
13 | D=G.to_directed()
14 | nd = nx.average_neighbor_degree(D)
15 | assert_equal(nd,answer)
16 |
17 | D=G.to_directed()
18 | nd = nx.average_neighbor_degree(D)
19 | assert_equal(nd,answer)
20 |
21 | D=G.to_directed()
22 | nd = nx.average_neighbor_degree(D, source='in', target='in')
23 | assert_equal(nd,answer)
24 |
25 | def test_degree_p4_weighted(self):
26 | G=nx.path_graph(4)
27 | G[1][2]['weight']=4
28 | answer={0:2,1:1.8,2:1.8,3:2}
29 | nd = nx.average_neighbor_degree(G,weight='weight')
30 | assert_equal(nd,answer)
31 |
32 | D=G.to_directed()
33 | nd = nx.average_neighbor_degree(D,weight='weight')
34 | assert_equal(nd,answer)
35 |
36 | D=G.to_directed()
37 | nd = nx.average_neighbor_degree(D,weight='weight')
38 | assert_equal(nd,answer)
39 | nd = nx.average_neighbor_degree(D,source='out',target='out',
40 | weight='weight')
41 | assert_equal(nd,answer)
42 |
43 | D=G.to_directed()
44 | nd = nx.average_neighbor_degree(D,source='in',target='in',
45 | weight='weight')
46 | assert_equal(nd,answer)
47 |
48 |
49 | def test_degree_k4(self):
50 | G=nx.complete_graph(4)
51 | answer={0:3,1:3,2:3,3:3}
52 | nd = nx.average_neighbor_degree(G)
53 | assert_equal(nd,answer)
54 |
55 | D=G.to_directed()
56 | nd = nx.average_neighbor_degree(D)
57 | assert_equal(nd,answer)
58 |
59 | D=G.to_directed()
60 | nd = nx.average_neighbor_degree(D)
61 | assert_equal(nd,answer)
62 |
63 | D=G.to_directed()
64 | nd = nx.average_neighbor_degree(D,source='in',target='in')
65 | assert_equal(nd,answer)
66 |
67 | def test_degree_k4_nodes(self):
68 | G=nx.complete_graph(4)
69 | answer={1:3.0,2:3.0}
70 | nd = nx.average_neighbor_degree(G,nodes=[1,2])
71 | assert_equal(nd,answer)
72 |
73 | def test_degree_barrat(self):
74 | G=nx.star_graph(5)
75 | G.add_edges_from([(5,6),(5,7),(5,8),(5,9)])
76 | G[0][5]['weight']=5
77 | nd = nx.average_neighbor_degree(G)[5]
78 | assert_equal(nd,1.8)
79 | nd = nx.average_neighbor_degree(G,weight='weight')[5]
80 | assert_almost_equal(nd,3.222222,places=5)
81 |
82 |
83 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/bipartite/__init__.py:
--------------------------------------------------------------------------------
1 | """ This module provides functions and operations for bipartite
2 | graphs. Bipartite graphs G(X,Y,E) have two node sets X,Y and edges in
3 | E that only connect nodes from opposite sets.
4 |
5 | NetworkX does not have a custom bipartite graph class but the Graph()
6 | or DiGraph() classes can be used to represent bipartite graphs.
7 |
8 | For example:
9 |
10 | >>> import networkx as nx
11 | >>> top_nodes=[1,1,2,3,3]
12 | >>> bottom_nodes=['a','b','b','b','c']
13 | >>> edges=zip(top_nodes,bottom_nodes) # create 2-tuples of edges
14 | >>> B=nx.Graph(edges)
15 |
16 |
17 | The bipartite algorithms are not imported into the networkx namespace
18 | at the top level so the easiest way to use them is with:
19 |
20 | >>> from networkx.algorithms import bipartite
21 |
22 | Some of the functions such as bipartite_density and projected_graph take
23 | a node set as an argument in addition to the graph B.
24 |
25 | >>> print(bipartite.density(B,top_nodes))
26 | 1.0
27 | >>> G=bipartite.projected_graph(B,bottom_nodes)
28 | >>> G.edges()
29 | [('a', 'b'), ('c', 'b')]
30 |
31 | You can find the bipartite node sets using
32 |
33 | >>> X,Y=bipartite.sets(B)
34 | >>> print(list(X))
35 | ['a', 'c', 'b']
36 | >>> print(list(Y))
37 | [1, 2, 3]
38 |
39 | """
40 | from networkx.algorithms.bipartite.basic import *
41 | from networkx.algorithms.bipartite.centrality import *
42 | from networkx.algorithms.bipartite.cluster import *
43 | from networkx.algorithms.bipartite.projection import *
44 | from networkx.algorithms.bipartite.redundancy import *
45 | from networkx.algorithms.bipartite.spectral import *
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/bipartite/redundancy.py:
--------------------------------------------------------------------------------
1 | #-*- coding: utf-8 -*-
2 | """Node redundancy for bipartite graphs."""
3 | # Copyright (C) 2011 by
4 | # Jordi Torrents
5 | # Aric Hagberg
6 | # All rights reserved.
7 | # BSD license.
8 | from itertools import combinations
9 | import networkx as nx
10 |
11 | __author__ = """\n""".join(['Jordi Torrents ',
12 | 'Aric Hagberg (hagberg@lanl.gov)'])
13 | __all__ = ['node_redundancy']
14 |
15 | def node_redundancy(G, nodes=None):
16 | r"""Compute bipartite node redundancy coefficient.
17 |
18 | The redundancy coefficient of a node `v` is the fraction of pairs of
19 | neighbors of `v` that are both linked to other nodes. In a one-mode
20 | projection these nodes would be linked together even if `v` were
21 | not there.
22 |
23 | .. math::
24 |
25 | rc(v) = \frac{|\{\{u,w\} \subseteq N(v),
26 | \: \exists v' \neq v,\: (v',u) \in E\:
27 | \mathrm{and}\: (v',w) \in E\}|}{ \frac{|N(v)|(|N(v)|-1)}{2}}
28 |
29 | where `N(v)` are the neighbors of `v` in `G`.
30 |
31 | Parameters
32 | ----------
33 | G : graph
34 | A bipartite graph
35 |
36 | nodes : list or iterable (optional)
37 | Compute redundancy for these nodes. The default is all nodes in G.
38 |
39 | Returns
40 | -------
41 | redundancy : dictionary
42 | A dictionary keyed by node with the node redundancy value.
43 |
44 | Examples
45 | --------
46 | >>> from networkx.algorithms import bipartite
47 | >>> G = nx.cycle_graph(4)
48 | >>> rc = bipartite.node_redundancy(G)
49 | >>> rc[0]
50 | 1.0
51 |
52 | Compute the average redundancy for the graph:
53 |
54 | >>> sum(rc.values())/len(G)
55 | 1.0
56 |
57 | Compute the average redundancy for a set of nodes:
58 |
59 | >>> nodes = [0, 2]
60 | >>> sum(rc[n] for n in nodes)/len(nodes)
61 | 1.0
62 |
63 | References
64 | ----------
65 | .. [1] Latapy, Matthieu, Clémence Magnien, and Nathalie Del Vecchio (2008).
66 | Basic notions for the analysis of large two-mode networks.
67 | Social Networks 30(1), 31--48.
68 | """
69 | if nodes is None:
70 | nodes = G
71 | rc = {}
72 | for v in nodes:
73 | overlap = 0.0
74 | for u, w in combinations(G[v], 2):
75 | if len((set(G[u]) & set(G[w])) - set([v])) > 0:
76 | overlap += 1
77 | if overlap > 0:
78 | n = len(G[v])
79 | norm = 2.0/(n*(n-1))
80 | else:
81 | norm = 1.0
82 | rc[v] = overlap*norm
83 | return rc
84 |
85 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/bipartite/spectral.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Spectral bipartivity measure.
4 | """
5 | import networkx as nx
6 | __author__ = """Aric Hagberg (hagberg@lanl.gov)"""
7 | # Copyright (C) 2011 by
8 | # Aric Hagberg
9 | # Dan Schult
10 | # Pieter Swart
11 | # All rights reserved.
12 | # BSD license.
13 | __all__ = ['spectral_bipartivity']
14 |
15 | def spectral_bipartivity(G, nodes=None, weight='weight'):
16 | """Returns the spectral bipartivity.
17 |
18 | Parameters
19 | ----------
20 | G : NetworkX graph
21 |
22 | nodes : list or container optional(default is all nodes)
23 | Nodes to return value of spectral bipartivity contribution.
24 |
25 | weight : string or None optional (default = 'weight')
26 | Edge data key to use for edge weights. If None, weights set to 1.
27 |
28 | Returns
29 | -------
30 | sb : float or dict
31 | A single number if the keyword nodes is not specified, or
32 | a dictionary keyed by node with the spectral bipartivity contribution
33 | of that node as the value.
34 |
35 | Examples
36 | --------
37 | >>> from networkx.algorithms import bipartite
38 | >>> G = nx.path_graph(4)
39 | >>> bipartite.spectral_bipartivity(G)
40 | 1.0
41 |
42 | Notes
43 | -----
44 | This implementation uses Numpy (dense) matrices which are not efficient
45 | for storing large sparse graphs.
46 |
47 | See Also
48 | --------
49 | color
50 |
51 | References
52 | ----------
53 | .. [1] E. Estrada and J. A. Rodríguez-Velázquez, "Spectral measures of
54 | bipartivity in complex networks", PhysRev E 72, 046105 (2005)
55 | """
56 | try:
57 | import scipy.linalg
58 | except ImportError:
59 | raise ImportError('spectral_bipartivity() requires SciPy: ',
60 | 'http://scipy.org/')
61 | nodelist = G.nodes() # ordering of nodes in matrix
62 | A = nx.to_numpy_matrix(G, nodelist, weight=weight)
63 | expA = scipy.linalg.expm(A)
64 | expmA = scipy.linalg.expm(-A)
65 | coshA = 0.5 * (expA + expmA)
66 | if nodes is None:
67 | # return single number for entire graph
68 | return coshA.diagonal().sum() / expA.diagonal().sum()
69 | else:
70 | # contribution for individual nodes
71 | index = dict(zip(nodelist, range(len(nodelist))))
72 | sb = {}
73 | for n in nodes:
74 | i = index[n]
75 | sb[n] = coshA[i, i] / expA[i, i]
76 | return sb
77 |
78 | def setup_module(module):
79 | """Fixture for nose tests."""
80 | from nose import SkipTest
81 | try:
82 | import numpy
83 | except:
84 | raise SkipTest("NumPy not available")
85 | try:
86 | import scipy
87 | except:
88 | raise SkipTest("SciPy not available")
89 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/bipartite/tests/test_basic.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from nose.tools import *
3 | import networkx as nx
4 | from networkx.algorithms import bipartite
5 | class TestBipartiteBasic:
6 |
7 | def test_is_bipartite(self):
8 | G=nx.path_graph(4)
9 | assert_true(bipartite.is_bipartite(G))
10 | G=nx.DiGraph([(1,0)])
11 | assert_true(bipartite.is_bipartite(G))
12 |
13 | def test_bipartite_color(self):
14 | G=nx.path_graph(4)
15 | c=bipartite.color(G)
16 | assert_equal(c,{0: 1, 1: 0, 2: 1, 3: 0})
17 |
18 | def test_bipartite_directed(self):
19 | G = nx.bipartite_random_graph(10, 10, 0.1, directed=True)
20 | assert_true(bipartite.is_bipartite(G))
21 |
22 | def test_bipartite_sets(self):
23 | G=nx.path_graph(4)
24 | X,Y=bipartite.sets(G)
25 | assert_equal(X,set([0,2]))
26 | assert_equal(Y,set([1,3]))
27 |
28 | def test_is_bipartite_node_set(self):
29 | G=nx.path_graph(4)
30 | assert_true(bipartite.is_bipartite_node_set(G,[0,2]))
31 | assert_true(bipartite.is_bipartite_node_set(G,[1,3]))
32 | G.add_path([10,20])
33 | assert_true(bipartite.is_bipartite_node_set(G,[0,2,10]))
34 | assert_true(bipartite.is_bipartite_node_set(G,[0,2,20]))
35 | assert_true(bipartite.is_bipartite_node_set(G,[1,3,10]))
36 | assert_true(bipartite.is_bipartite_node_set(G,[1,3,20]))
37 |
38 | def test_bipartite_density(self):
39 | G=nx.path_graph(5)
40 | X,Y=bipartite.sets(G)
41 | density=float(len(G.edges()))/(len(X)*len(Y))
42 | assert_equal(bipartite.density(G,X),density)
43 |
44 | def test_bipartite_degrees(self):
45 | G=nx.path_graph(5)
46 | X=set([1,3])
47 | Y=set([0,2,4])
48 | u,d=bipartite.degrees(G,Y)
49 | assert_equal(u,{1:2,3:2})
50 | assert_equal(d,{0:1,2:2,4:1})
51 |
52 | def test_bipartite_weighted_degrees(self):
53 | G=nx.path_graph(5)
54 | G.add_edge(0,1,weight=0.1,other=0.2)
55 | X=set([1,3])
56 | Y=set([0,2,4])
57 | u,d=bipartite.degrees(G,Y,weight='weight')
58 | assert_equal(u,{1:1.1,3:2})
59 | assert_equal(d,{0:0.1,2:2,4:1})
60 | u,d=bipartite.degrees(G,Y,weight='other')
61 | assert_equal(u,{1:1.2,3:2})
62 | assert_equal(d,{0:0.2,2:2,4:1})
63 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/bipartite/tests/test_cluster.py:
--------------------------------------------------------------------------------
1 | import networkx as nx
2 | from nose.tools import *
3 | from networkx.algorithms.bipartite.cluster import cc_dot,cc_min,cc_max
4 | import networkx.algorithms.bipartite as bipartite
5 |
6 | def test_pairwise_bipartite_cc_functions():
7 | # Test functions for different kinds of bipartite clustering coefficients
8 | # between pairs of nodes using 3 example graphs from figure 5 p. 40
9 | # Latapy et al (2008)
10 | G1 = nx.Graph([(0,2),(0,3),(0,4),(0,5),(0,6),(1,5),(1,6),(1,7)])
11 | G2 = nx.Graph([(0,2),(0,3),(0,4),(1,3),(1,4),(1,5)])
12 | G3 = nx.Graph([(0,2),(0,3),(0,4),(0,5),(0,6),(1,5),(1,6),(1,7),(1,8),(1,9)])
13 | result = {0:[1/3.0, 2/3.0, 2/5.0], 1:[1/2.0, 2/3.0, 2/3.0], 2:[2/8.0, 2/5.0, 2/5.0]}
14 | for i, G in enumerate([G1, G2, G3]):
15 | assert(bipartite.is_bipartite(G))
16 | assert(cc_dot(set(G[0]), set(G[1])) == result[i][0])
17 | assert(cc_min(set(G[0]), set(G[1])) == result[i][1])
18 | assert(cc_max(set(G[0]), set(G[1])) == result[i][2])
19 |
20 | def test_star_graph():
21 | G=nx.star_graph(3)
22 | # all modes are the same
23 | answer={0:0,1:1,2:1,3:1}
24 | assert_equal(bipartite.clustering(G,mode='dot'),answer)
25 | assert_equal(bipartite.clustering(G,mode='min'),answer)
26 | assert_equal(bipartite.clustering(G,mode='max'),answer)
27 |
28 | def test_path_graph():
29 | G=nx.path_graph(4)
30 | answer={0:0.5,1:0.5,2:0.5,3:0.5}
31 | assert_equal(bipartite.clustering(G,mode='dot'),answer)
32 | assert_equal(bipartite.clustering(G,mode='max'),answer)
33 | answer={0:1,1:1,2:1,3:1}
34 | assert_equal(bipartite.clustering(G,mode='min'),answer)
35 |
36 |
37 | def test_average_path_graph():
38 | G=nx.path_graph(4)
39 | assert_equal(bipartite.average_clustering(G,mode='dot'),0.5)
40 | assert_equal(bipartite.average_clustering(G,mode='max'),0.5)
41 | assert_equal(bipartite.average_clustering(G,mode='min'),1)
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | from nose import SkipTest
3 | from nose.tools import *
4 | import networkx as nx
5 | from networkx.algorithms.bipartite import spectral_bipartivity as sb
6 |
7 | # Examples from Figure 1
8 | # E. Estrada and J. A. Rodríguez-Velázquez, "Spectral measures of
9 | # bipartivity in complex networks", PhysRev E 72, 046105 (2005)
10 |
11 | class TestSpectralBipartivity(object):
12 | @classmethod
13 | def setupClass(cls):
14 | global scipy
15 | global assert_equal
16 | global assert_almost_equal
17 | try:
18 | import scipy.linalg
19 | except ImportError:
20 | raise SkipTest('SciPy not available.')
21 |
22 |
23 | def test_star_like(self):
24 | # star-like
25 |
26 | G=nx.star_graph(2)
27 | G.add_edge(1,2)
28 | assert_almost_equal(sb(G),0.843,places=3)
29 |
30 | G=nx.star_graph(3)
31 | G.add_edge(1,2)
32 | assert_almost_equal(sb(G),0.871,places=3)
33 |
34 | G=nx.star_graph(4)
35 | G.add_edge(1,2)
36 | assert_almost_equal(sb(G),0.890,places=3)
37 |
38 |
39 | def k23_like(self):
40 | # K2,3-like
41 | G=nx.complete_bipartite_graph(2,3)
42 | G.add_edge(0,1)
43 | assert_almost_equal(sb(G),0.769,places=3)
44 |
45 | G=nx.complete_bipartite_graph(2,3)
46 | G.add_edge(2,4)
47 | assert_almost_equal(sb(G),0.829,places=3)
48 |
49 | G=nx.complete_bipartite_graph(2,3)
50 | G.add_edge(2,4)
51 | G.add_edge(3,4)
52 | assert_almost_equal(sb(G),0.731,places=3)
53 |
54 |
55 | G=nx.complete_bipartite_graph(2,3)
56 | G.add_edge(0,1)
57 | G.add_edge(2,4)
58 | assert_almost_equal(sb(G),0.692,places=3)
59 |
60 | G=nx.complete_bipartite_graph(2,3)
61 | G.add_edge(2,4)
62 | G.add_edge(3,4)
63 | G.add_edge(0,1)
64 | assert_almost_equal(sb(G),0.645,places=3)
65 |
66 | G=nx.complete_bipartite_graph(2,3)
67 | G.add_edge(2,4)
68 | G.add_edge(3,4)
69 | G.add_edge(2,3)
70 | assert_almost_equal(sb(G),0.645,places=3)
71 |
72 | G=nx.complete_bipartite_graph(2,3)
73 | G.add_edge(2,4)
74 | G.add_edge(3,4)
75 | G.add_edge(2,3)
76 | G.add_edge(0,1)
77 | assert_almost_equal(sb(G),0.597,places=3)
78 |
79 | def test_single_nodes(self):
80 |
81 | # single nodes
82 | G=nx.complete_bipartite_graph(2,3)
83 | G.add_edge(2,4)
84 | sbn=sb(G,nodes=[1,2])
85 | assert_almost_equal(sbn[1],0.85,places=2)
86 | assert_almost_equal(sbn[2],0.77,places=2)
87 |
88 | G=nx.complete_bipartite_graph(2,3)
89 | G.add_edge(0,1)
90 | sbn=sb(G,nodes=[1,2])
91 | assert_almost_equal(sbn[1],0.73,places=2)
92 | assert_almost_equal(sbn[2],0.82,places=2)
93 |
94 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/boundary.py:
--------------------------------------------------------------------------------
1 | """
2 | Routines to find the boundary of a set of nodes.
3 |
4 | Edge boundaries are edges that have only one end
5 | in the set of nodes.
6 |
7 | Node boundaries are nodes outside the set of nodes
8 | that have an edge to a node in the set.
9 |
10 | """
11 | __author__ = """Aric Hagberg (hagberg@lanl.gov)\nPieter Swart (swart@lanl.gov)\nDan Schult (dschult@colgate.edu)"""
12 | # Copyright (C) 2004-2008 by
13 | # Aric Hagberg
14 | # Dan Schult
15 | # Pieter Swart
16 | # All rights reserved.
17 | # BSD license.
18 |
19 | __all__=['edge_boundary','node_boundary']
20 |
21 | def edge_boundary(G, nbunch1, nbunch2=None):
22 | """Return the edge boundary.
23 |
24 | Edge boundaries are edges that have only one end
25 | in the given set of nodes.
26 |
27 | Parameters
28 | -----------
29 | G : graph
30 | A networkx graph
31 |
32 | nbunch1 : list, container
33 | Interior node set
34 |
35 | nbunch2 : list, container
36 | Exterior node set. If None then it is set to all of the
37 | nodes in G not in nbunch1.
38 |
39 | Returns
40 | -------
41 | elist : list
42 | List of edges
43 |
44 | Notes
45 | ------
46 | Nodes in nbunch1 and nbunch2 that are not in G are ignored.
47 |
48 | nbunch1 and nbunch2 are usually meant to be disjoint,
49 | but in the interest of speed and generality, that is
50 | not required here.
51 |
52 | """
53 | if nbunch2 is None: # Then nbunch2 is complement of nbunch1
54 | nset1=set((n for n in nbunch1 if n in G))
55 | return [(n1,n2) for n1 in nset1 for n2 in G[n1] \
56 | if n2 not in nset1]
57 |
58 | nset2=set(nbunch2)
59 | return [(n1,n2) for n1 in nbunch1 if n1 in G for n2 in G[n1] \
60 | if n2 in nset2]
61 |
62 | def node_boundary(G, nbunch1, nbunch2=None):
63 | """Return the node boundary.
64 |
65 | The node boundary is all nodes in the edge boundary of a given
66 | set of nodes that are in the set.
67 |
68 | Parameters
69 | -----------
70 | G : graph
71 | A networkx graph
72 |
73 | nbunch1 : list, container
74 | Interior node set
75 |
76 | nbunch2 : list, container
77 | Exterior node set. If None then it is set to all of the
78 | nodes in G not in nbunch1.
79 |
80 | Returns
81 | -------
82 | nlist : list
83 | List of nodes.
84 |
85 | Notes
86 | ------
87 | Nodes in nbunch1 and nbunch2 that are not in G are ignored.
88 |
89 | nbunch1 and nbunch2 are usually meant to be disjoint,
90 | but in the interest of speed and generality, that is
91 | not required here.
92 |
93 | """
94 | nset1=set(n for n in nbunch1 if n in G)
95 | bdy=set()
96 | for n1 in nset1:
97 | bdy.update(G[n1])
98 | bdy -= nset1
99 | if nbunch2 is not None: # else nbunch2 is complement of nbunch1
100 | bdy &= set(nbunch2)
101 | return list(bdy)
102 |
103 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/centrality/__init__.py:
--------------------------------------------------------------------------------
1 | from networkx.algorithms.centrality.betweenness import *
2 | from networkx.algorithms.centrality.betweenness_subset import *
3 | from networkx.algorithms.centrality.closeness import *
4 | from networkx.algorithms.centrality.current_flow_closeness import *
5 | from networkx.algorithms.centrality.current_flow_betweenness import *
6 | from networkx.algorithms.centrality.current_flow_betweenness_subset import *
7 | from networkx.algorithms.centrality.degree_alg import *
8 | from networkx.algorithms.centrality.eigenvector import *
9 | from networkx.algorithms.centrality.load import *
10 | from networkx.algorithms.centrality.communicability_alg import *
11 | import networkx.algorithms.centrality.betweenness
12 | import networkx.algorithms.centrality.closeness
13 | import networkx.algorithms.centrality.current_flow_betweenness
14 | import networkx.algorithms.centrality.current_flow_closeness
15 | import networkx.algorithms.centrality.degree_alg
16 | import networkx.algorithms.centrality.eigenvector
17 | import networkx.algorithms.centrality.load
18 | import networkx.algorithms.centrality.communicability_alg
19 |
20 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/centrality/closeness.py:
--------------------------------------------------------------------------------
1 | """
2 | Closeness centrality measures.
3 |
4 | """
5 | # Copyright (C) 2004-2010 by
6 | # Aric Hagberg
7 | # Dan Schult
8 | # Pieter Swart
9 | # All rights reserved.
10 | # BSD license.
11 | import functools
12 | import networkx as nx
13 | __author__ = "\n".join(['Aric Hagberg (hagberg@lanl.gov)',
14 | 'Pieter Swart (swart@lanl.gov)',
15 | 'Sasha Gutfraind (ag362@cornell.edu)'])
16 | __all__ = ['closeness_centrality']
17 |
18 |
19 | def closeness_centrality(G, v=None, distance=None, normalized=True):
20 | """Compute closeness centrality for nodes.
21 |
22 | Closeness centrality at a node is 1/average distance to all other nodes.
23 |
24 | Parameters
25 | ----------
26 | G : graph
27 | A networkx graph
28 | v : node, optional
29 | Return only the value for node v
30 | distance : string key, optional (default=None)
31 | Use specified edge key as edge distance.
32 | If True, use 'weight' as the edge key.
33 | normalized : bool, optional
34 | If True (default) normalize by the graph size.
35 |
36 | Returns
37 | -------
38 | nodes : dictionary
39 | Dictionary of nodes with closeness centrality as the value.
40 |
41 | See Also
42 | --------
43 | betweenness_centrality, load_centrality, eigenvector_centrality,
44 | degree_centrality
45 |
46 | Notes
47 | -----
48 | The closeness centrality is normalized to to n-1 / size(G)-1 where
49 | n is the number of nodes in the connected part of graph containing
50 | the node. If the graph is not completely connected, this
51 | algorithm computes the closeness centrality for each connected
52 | part separately.
53 | """
54 | if distance is not None:
55 | if distance is True: distance='weight'
56 | path_length=functools.partial(nx.single_source_dijkstra_path_length,
57 | weight=distance)
58 | else:
59 | path_length=nx.single_source_shortest_path_length
60 |
61 | if v is None:
62 | nodes=G.nodes()
63 | else:
64 | nodes=[v]
65 | closeness_centrality={}
66 |
67 | for n in nodes:
68 | sp=path_length(G,n)
69 | totsp=sum(sp.values())
70 | if totsp > 0.0 and len(G) > 1:
71 | closeness_centrality[n]= (len(sp)-1.0) / totsp
72 | # normalize to number of nodes-1 in connected part
73 | if normalized:
74 | s=(len(sp)-1.0) / ( len(G) - 1 )
75 | closeness_centrality[n] *= s
76 | else:
77 | closeness_centrality[n]=0.0
78 | if v is not None:
79 | return closeness_centrality[v]
80 | else:
81 | return closeness_centrality
82 |
83 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/centrality/tests/test_closeness_centrality.py:
--------------------------------------------------------------------------------
1 | """
2 | Tests for degree centrality.
3 | """
4 | from nose.tools import *
5 | import networkx as nx
6 |
7 | class TestClosenessCentrality:
8 | def setUp(self):
9 |
10 | self.K = nx.krackhardt_kite_graph()
11 | self.P3 = nx.path_graph(3)
12 | self.P4 = nx.path_graph(4)
13 | self.K5 = nx.complete_graph(5)
14 |
15 | self.C4=nx.cycle_graph(4)
16 | self.T=nx.balanced_tree(r=2, h=2)
17 | self.Gb = nx.Graph()
18 | self.Gb.add_edges_from([(0,1), (0,2), (1,3), (2,3),
19 | (2,4), (4,5), (3,5)])
20 |
21 |
22 | F = nx.florentine_families_graph()
23 | self.F = F
24 |
25 |
26 | def test_k5_closeness(self):
27 | c=nx.closeness_centrality(self.K5)
28 | d={0: 1.000,
29 | 1: 1.000,
30 | 2: 1.000,
31 | 3: 1.000,
32 | 4: 1.000}
33 | for n in sorted(self.K5):
34 | assert_almost_equal(c[n],d[n],places=3)
35 |
36 | def test_p3_closeness(self):
37 | c=nx.closeness_centrality(self.P3)
38 | d={0: 0.667,
39 | 1: 1.000,
40 | 2: 0.667}
41 | for n in sorted(self.P3):
42 | assert_almost_equal(c[n],d[n],places=3)
43 |
44 | def test_krackhardt_closeness(self):
45 | c=nx.closeness_centrality(self.K)
46 | d={0: 0.529,
47 | 1: 0.529,
48 | 2: 0.500,
49 | 3: 0.600,
50 | 4: 0.500,
51 | 5: 0.643,
52 | 6: 0.643,
53 | 7: 0.600,
54 | 8: 0.429,
55 | 9: 0.310}
56 | for n in sorted(self.K):
57 | assert_almost_equal(c[n],d[n],places=3)
58 |
59 | def test_florentine_families_closeness(self):
60 | c=nx.closeness_centrality(self.F)
61 | d={'Acciaiuoli': 0.368,
62 | 'Albizzi': 0.483,
63 | 'Barbadori': 0.4375,
64 | 'Bischeri': 0.400,
65 | 'Castellani': 0.389,
66 | 'Ginori': 0.333,
67 | 'Guadagni': 0.467,
68 | 'Lamberteschi': 0.326,
69 | 'Medici': 0.560,
70 | 'Pazzi': 0.286,
71 | 'Peruzzi': 0.368,
72 | 'Ridolfi': 0.500,
73 | 'Salviati': 0.389,
74 | 'Strozzi': 0.4375,
75 | 'Tornabuoni': 0.483}
76 | for n in sorted(self.F):
77 | assert_almost_equal(c[n],d[n],places=3)
78 |
79 | def test_weighted_closeness(self):
80 | XG=nx.Graph()
81 | XG.add_weighted_edges_from([('s','u',10), ('s','x',5), ('u','v',1),
82 | ('u','x',2), ('v','y',1), ('x','u',3),
83 | ('x','v',5), ('x','y',2), ('y','s',7),
84 | ('y','v',6)])
85 | c=nx.closeness_centrality(XG,distance=True)
86 | d={'y': 0.200,
87 | 'x': 0.286,
88 | 's': 0.138,
89 | 'u': 0.235,
90 | 'v': 0.200}
91 | for n in sorted(XG):
92 | assert_almost_equal(c[n],d[n],places=3)
93 |
94 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/centrality/tests/test_current_flow_closeness.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from nose.tools import *
3 | from nose import SkipTest
4 | import networkx
5 |
6 | class TestFlowClosenessCentrality(object):
7 | numpy=1 # nosetests attribute, use nosetests -a 'not numpy' to skip test
8 | @classmethod
9 | def setupClass(cls):
10 | global np
11 | try:
12 | import numpy as np
13 | import scipy
14 | except ImportError:
15 | raise SkipTest('NumPy not available.')
16 |
17 |
18 | def test_K4(self):
19 | """Closeness centrality: K4"""
20 | G=networkx.complete_graph(4)
21 | b=networkx.current_flow_closeness_centrality(G,normalized=True)
22 | b_answer={0: 2.0, 1: 2.0, 2: 2.0, 3: 2.0}
23 | for n in sorted(G):
24 | assert_almost_equal(b[n],b_answer[n])
25 |
26 |
27 | def test_P4_normalized(self):
28 | """Closeness centrality: P4 normalized"""
29 | G=networkx.path_graph(4)
30 | b=networkx.current_flow_closeness_centrality(G,normalized=True)
31 | b_answer={0: 1./2, 1: 3./4, 2: 3./4, 3:1./2}
32 | for n in sorted(G):
33 | assert_almost_equal(b[n],b_answer[n])
34 |
35 |
36 | def test_P4(self):
37 | """Closeness centrality: P4"""
38 | G=networkx.path_graph(4)
39 | b=networkx.current_flow_closeness_centrality(G,normalized=False)
40 | b_answer={0: 1.0/6, 1: 1.0/4, 2: 1.0/4, 3:1.0/6}
41 | for n in sorted(G):
42 | assert_almost_equal(b[n],b_answer[n])
43 |
44 | def test_star(self):
45 | """Closeness centrality: star """
46 | G=networkx.Graph()
47 | G.add_star(['a','b','c','d'])
48 | b=networkx.current_flow_closeness_centrality(G,normalized=True)
49 | b_answer={'a': 1.0, 'b': 0.6, 'c': 0.6, 'd':0.6}
50 | for n in sorted(G):
51 | assert_almost_equal(b[n],b_answer[n])
52 |
53 |
54 |
55 | class TestWeightedFlowClosenessCentrality(object):
56 | pass
57 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import math
3 | from nose import SkipTest
4 | from nose.tools import *
5 | import networkx
6 |
7 | class TestEigenvectorCentrality(object):
8 | numpy=1 # nosetests attribute, use nosetests -a 'not numpy' to skip test
9 | @classmethod
10 | def setupClass(cls):
11 | global np
12 | try:
13 | import numpy as np
14 | except ImportError:
15 | raise SkipTest('NumPy not available.')
16 |
17 | def test_K5(self):
18 | """Eigenvector centrality: K5"""
19 | G=networkx.complete_graph(5)
20 | b=networkx.eigenvector_centrality(G)
21 | v=math.sqrt(1/5.0)
22 | b_answer=dict.fromkeys(G,v)
23 | for n in sorted(G):
24 | assert_almost_equal(b[n],b_answer[n])
25 | b=networkx.eigenvector_centrality_numpy(G)
26 | for n in sorted(G):
27 | assert_almost_equal(b[n],b_answer[n],places=3)
28 |
29 | def test_P3(self):
30 | """Eigenvector centrality: P3"""
31 | G=networkx.path_graph(3)
32 | b_answer={0: 0.5, 1: 0.7071, 2: 0.5}
33 | b=networkx.eigenvector_centrality_numpy(G)
34 | for n in sorted(G):
35 | assert_almost_equal(b[n],b_answer[n],places=4)
36 |
37 |
38 | class TestEigenvectorCentralityDirected(object):
39 | numpy=1 # nosetests attribute, use nosetests -a 'not numpy' to skip test
40 | @classmethod
41 | def setupClass(cls):
42 | global np
43 | try:
44 | import numpy as np
45 | except ImportError:
46 | raise SkipTest('NumPy not available.')
47 |
48 | def setUp(self):
49 |
50 | G=networkx.DiGraph()
51 |
52 | edges=[(1,2),(1,3),(2,4),(3,2),(3,5),(4,2),(4,5),(4,6),\
53 | (5,6),(5,7),(5,8),(6,8),(7,1),(7,5),\
54 | (7,8),(8,6),(8,7)]
55 |
56 | G.add_edges_from(edges,weight=2.0)
57 | self.G=G
58 | self.G.evc=[0.25368793, 0.19576478, 0.32817092, 0.40430835,
59 | 0.48199885, 0.15724483, 0.51346196, 0.32475403]
60 |
61 | H=networkx.DiGraph()
62 |
63 | edges=[(1,2),(1,3),(2,4),(3,2),(3,5),(4,2),(4,5),(4,6),\
64 | (5,6),(5,7),(5,8),(6,8),(7,1),(7,5),\
65 | (7,8),(8,6),(8,7)]
66 |
67 | G.add_edges_from(edges)
68 | self.H=G
69 | self.H.evc=[0.25368793, 0.19576478, 0.32817092, 0.40430835,
70 | 0.48199885, 0.15724483, 0.51346196, 0.32475403]
71 |
72 |
73 | def test_eigenvector_centrality_weighted(self):
74 | G=self.G
75 | p=networkx.eigenvector_centrality_numpy(G)
76 | for (a,b) in zip(list(p.values()),self.G.evc):
77 | assert_almost_equal(a,b)
78 |
79 | def test_eigenvector_centrality_unweighted(self):
80 | G=self.H
81 | p=networkx.eigenvector_centrality_numpy(G)
82 | for (a,b) in zip(list(p.values()),self.G.evc):
83 | assert_almost_equal(a,b)
84 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/chordal/__init__.py:
--------------------------------------------------------------------------------
1 | from networkx.algorithms.chordal.chordal_alg import *
2 |
3 |
4 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/chordal/tests/test_chordal.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from nose.tools import *
3 | import networkx as nx
4 |
5 | class TestMCS:
6 |
7 | def setUp(self):
8 | # simple graph
9 | connected_chordal_G=nx.Graph()
10 | connected_chordal_G.add_edges_from([(1,2),(1,3),(2,3),(2,4),(3,4),
11 | (3,5),(3,6),(4,5),(4,6),(5,6)])
12 | self.connected_chordal_G=connected_chordal_G
13 |
14 | chordal_G = nx.Graph()
15 | chordal_G.add_edges_from([(1,2),(1,3),(2,3),(2,4),(3,4),
16 | (3,5),(3,6),(4,5),(4,6),(5,6),(7,8)])
17 | chordal_G.add_node(9)
18 | self.chordal_G=chordal_G
19 |
20 | non_chordal_G = nx.Graph()
21 | non_chordal_G.add_edges_from([(1,2),(1,3),(2,4),(2,5),(3,4),(3,5)])
22 | self.non_chordal_G = non_chordal_G
23 |
24 | def test_is_chordal(self):
25 | assert_false(nx.is_chordal(self.non_chordal_G))
26 | assert_true(nx.is_chordal(self.chordal_G))
27 | assert_true(nx.is_chordal(self.connected_chordal_G))
28 | assert_true(nx.is_chordal(nx.complete_graph(3)))
29 | assert_true(nx.is_chordal(nx.cycle_graph(3)))
30 | assert_false(nx.is_chordal(nx.cycle_graph(5)))
31 |
32 | def test_induced_nodes(self):
33 | G = nx.generators.classic.path_graph(10)
34 | I = nx.find_induced_nodes(G,1,9,2)
35 | assert_equal(I,set([1,2,3,4,5,6,7,8,9]))
36 | assert_raises(nx.NetworkXTreewidthBoundExceeded,
37 | nx.find_induced_nodes,G,1,9,1)
38 | I = nx.find_induced_nodes(self.chordal_G,1,6)
39 | assert_equal(I,set([1,2,4,6]))
40 | assert_raises(nx.NetworkXError,
41 | nx.find_induced_nodes,self.non_chordal_G,1,5)
42 |
43 | def test_chordal_find_cliques(self):
44 | cliques = set([frozenset([9]),frozenset([7,8]),frozenset([1,2,3]),
45 | frozenset([2,3,4]),frozenset([3,4,5,6])])
46 | assert_equal(nx.chordal_graph_cliques(self.chordal_G),cliques)
47 |
48 | def test_chordal_find_cliques_path(self):
49 | G = nx.path_graph(10)
50 | cliqueset = nx.chordal_graph_cliques(G)
51 | for (u,v) in G.edges_iter():
52 | assert_true(frozenset([u,v]) in cliqueset
53 | or frozenset([v,u]) in cliqueset)
54 |
55 | def test_chordal_find_cliquesCC(self):
56 | cliques = set([frozenset([1,2,3]),frozenset([2,3,4]),
57 | frozenset([3,4,5,6])])
58 | assert_equal(nx.chordal_graph_cliques(self.connected_chordal_G),cliques)
59 |
60 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/community/__init__.py:
--------------------------------------------------------------------------------
1 | from networkx.algorithms.community.kclique import *
2 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/community/kclique.py:
--------------------------------------------------------------------------------
1 | #-*- coding: utf-8 -*-
2 | # Copyright (C) 2011 by
3 | # Conrad Lee
4 | # Aric Hagberg
5 | # All rights reserved.
6 | # BSD license.
7 | from collections import defaultdict
8 | import networkx as nx
9 | __author__ = """\n""".join(['Conrad Lee ',
10 | 'Aric Hagberg '])
11 | __all__ = ['k_clique_communities']
12 |
13 | def k_clique_communities(G, k, cliques=None):
14 | """Find k-clique communities in graph using percolation method.
15 |
16 | A k-clique community is the union of all cliques of size k that
17 | can be reached through adjacent (sharing k-1 nodes) k-cliques.
18 |
19 | Parameters
20 | ----------
21 | G : NetworkX graph
22 |
23 | k : int
24 | Size of smallest clique
25 |
26 | cliques: list or generator
27 | Precomputed cliques (use networkx.find_cliques(G))
28 |
29 | Returns
30 | -------
31 | Yields sets of nodes, one for each k-clique community.
32 |
33 | Examples
34 | --------
35 | >>> G = nx.complete_graph(5)
36 | >>> K5 = nx.convert_node_labels_to_integers(G,first_label=2)
37 | >>> G.add_edges_from(K5.edges())
38 | >>> c = list(nx.k_clique_communities(G, 4))
39 | >>> list(c[0])
40 | [0, 1, 2, 3, 4, 5, 6]
41 | >>> list(nx.k_clique_communities(G, 5))
42 | []
43 |
44 | References
45 | ----------
46 | .. [1] Gergely Palla, Imre Derényi, Illés Farkas1, and Tamás Vicsek,
47 | Uncovering the overlapping community structure of complex networks
48 | in nature and society Nature 435, 814-818, 2005,
49 | doi:10.1038/nature03607
50 | """
51 | if cliques is None:
52 | cliques = nx.find_cliques(G)
53 | cliques = [frozenset(c) for c in cliques if len(c) >= k]
54 |
55 | # First index which nodes are in which cliques
56 | membership_dict = defaultdict(list)
57 | for clique in cliques:
58 | for node in clique:
59 | membership_dict[node].append(clique)
60 |
61 | # For each clique, see which adjacent cliques percolate
62 | perc_graph = nx.Graph()
63 | for clique in cliques:
64 | for adj_clique in _get_adjacent_cliques(clique, membership_dict):
65 | if len(clique.intersection(adj_clique)) >= (k - 1):
66 | perc_graph.add_edge(clique, adj_clique)
67 |
68 | # Connected components of clique graph with perc edges
69 | # are the percolated cliques
70 | for component in nx.connected_components(perc_graph):
71 | yield(frozenset.union(*component))
72 |
73 | def _get_adjacent_cliques(clique, membership_dict):
74 | adjacent_cliques = set()
75 | for n in clique:
76 | for adj_clique in membership_dict[n]:
77 | if clique != adj_clique:
78 | adjacent_cliques.add(adj_clique)
79 | return adjacent_cliques
80 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/community/tests/test_kclique.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from nose.tools import *
3 | import networkx as nx
4 | from itertools import combinations
5 |
6 | def test_overlaping_K5():
7 | G = nx.Graph()
8 | G.add_edges_from(combinations(range(5), 2)) # Add a five clique
9 | G.add_edges_from(combinations(range(2,7), 2)) # Add another five clique
10 | c = list(nx.k_clique_communities(G, 4))
11 | assert_equal(c,[frozenset([0, 1, 2, 3, 4, 5, 6])])
12 | c= list(nx.k_clique_communities(G, 5))
13 | assert_equal(c,[])
14 |
15 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/components/__init__.py:
--------------------------------------------------------------------------------
1 | from networkx.algorithms.components.connected import *
2 | from networkx.algorithms.components.strongly_connected import *
3 | from networkx.algorithms.components.weakly_connected import *
4 | from networkx.algorithms.components.attracting import *
5 | from networkx.algorithms.components.biconnected import *
6 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/components/tests/test_attracting.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from nose.tools import *
3 | import networkx as nx
4 |
5 |
6 | class TestAttractingComponents(object):
7 | def setUp(self):
8 | self.G1 = nx.DiGraph()
9 | self.G1.add_edges_from([(5,11),(11,2),(11,9),(11,10),
10 | (7,11),(7,8),(8,9),(3,8),(3,10)])
11 | self.G2 = nx.DiGraph()
12 | self.G2.add_edges_from([(0,1),(0,2),(1,1),(1,2),(2,1)])
13 |
14 | self.G3 = nx.DiGraph()
15 | self.G3.add_edges_from([(0,1),(1,2),(2,1),(0,3),(3,4),(4,3)])
16 |
17 | def test_attracting_components(self):
18 | ac = nx.attracting_components(self.G1)
19 | assert_true([2] in ac)
20 | assert_true([9] in ac)
21 | assert_true([10] in ac)
22 |
23 | ac = nx.attracting_components(self.G2)
24 | ac = [tuple(sorted(x)) for x in ac]
25 | assert_true(ac == [(1,2)])
26 |
27 | ac = nx.attracting_components(self.G3)
28 | ac = [tuple(sorted(x)) for x in ac]
29 | assert_true((1,2) in ac)
30 | assert_true((3,4) in ac)
31 | assert_equal(len(ac), 2)
32 |
33 | def test_number_attacting_components(self):
34 | assert_equal(len(nx.attracting_components(self.G1)), 3)
35 | assert_equal(len(nx.attracting_components(self.G2)), 1)
36 | assert_equal(len(nx.attracting_components(self.G3)), 2)
37 |
38 | def test_is_attracting_component(self):
39 | assert_false(nx.is_attracting_component(self.G1))
40 | assert_false(nx.is_attracting_component(self.G2))
41 | assert_false(nx.is_attracting_component(self.G3))
42 | g2 = self.G3.subgraph([1,2])
43 | assert_true(nx.is_attracting_component(g2))
44 |
45 | def test_attracting_component_subgraphs(self):
46 | subgraphs = nx.attracting_component_subgraphs(self.G1)
47 | for subgraph in subgraphs:
48 | assert_equal(len(subgraph), 1)
49 |
50 | self.G2.add_edge(1,2,eattr='red') # test attrs copied to subgraphs
51 | self.G2.node[2]['nattr']='blue'
52 | self.G2.graph['gattr']='green'
53 | subgraphs = nx.attracting_component_subgraphs(self.G2)
54 | assert_equal(len(subgraphs), 1)
55 | SG2=subgraphs[0]
56 | assert_true(1 in SG2)
57 | assert_true(2 in SG2)
58 | assert_equal(SG2[1][2]['eattr'],'red')
59 | assert_equal(SG2.node[2]['nattr'],'blue')
60 | assert_equal(SG2.graph['gattr'],'green')
61 | SG2.add_edge(1,2,eattr='blue')
62 | assert_equal(SG2[1][2]['eattr'],'blue')
63 | assert_equal(self.G2[1][2]['eattr'],'red')
64 |
65 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/components/tests/test_connected.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from nose.tools import *
3 | import networkx as nx
4 | from networkx import convert_node_labels_to_integers as cnlti
5 | from networkx import NetworkXError
6 |
7 | class TestConnected:
8 |
9 | def setUp(self):
10 | G1=cnlti(nx.grid_2d_graph(2,2),first_label=0,ordering="sorted")
11 | G2=cnlti(nx.lollipop_graph(3,3),first_label=4,ordering="sorted")
12 | G3=cnlti(nx.house_graph(),first_label=10,ordering="sorted")
13 | self.G=nx.union(G1,G2)
14 | self.G=nx.union(self.G,G3)
15 | self.DG=nx.DiGraph([(1,2),(1,3),(2,3)])
16 | self.grid=cnlti(nx.grid_2d_graph(4,4),first_label=1)
17 |
18 | def test_connected_components(self):
19 | cc=nx.connected_components
20 | G=self.G
21 | C=[[0, 1, 2, 3], [4, 5, 6, 7, 8, 9], [10, 11, 12, 13, 14]]
22 | assert_equal(sorted([sorted(g) for g in cc(G)]),sorted(C))
23 |
24 | def test_number_connected_components(self):
25 | ncc=nx.number_connected_components
26 | assert_equal(ncc(self.G),3)
27 |
28 | def test_number_connected_components2(self):
29 | ncc=nx.number_connected_components
30 | assert_equal(ncc(self.grid),1)
31 |
32 | def test_connected_components2(self):
33 | cc=nx.connected_components
34 | G=self.grid
35 | C=[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]]
36 | assert_equal(sorted([sorted(g) for g in cc(G)]),sorted(C))
37 |
38 | def test_node_connected_components(self):
39 | ncc=nx.node_connected_component
40 | G=self.grid
41 | C=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
42 | assert_equal(sorted(ncc(G,1)),sorted(C))
43 |
44 | def test_connected_component_subgraphs(self):
45 | G=self.grid
46 | G.add_edge(1,2,eattr='red') # test attributes copied to subgraphs
47 | G.node[1]['nattr']='blue'
48 | G.graph['gattr']='green'
49 | ccs=nx.connected_component_subgraphs(G)
50 | assert_equal(len(ccs),1)
51 | sg=ccs[0]
52 | assert_equal(sorted(sg.nodes()),list(range(1,17)))
53 | assert_equal(sg[1][2]['eattr'],'red')
54 | assert_equal(sg.node[1]['nattr'],'blue')
55 | assert_equal(sg.graph['gattr'],'green')
56 | sg[1][2]['eattr']='blue'
57 | assert_equal(G[1][2]['eattr'],'red')
58 | assert_equal(sg[1][2]['eattr'],'blue')
59 |
60 |
61 | def test_is_connected(self):
62 | assert_true(nx.is_connected(self.grid))
63 | G=nx.Graph()
64 | G.add_nodes_from([1,2])
65 | assert_false(nx.is_connected(G))
66 |
67 | def test_connected_raise(self):
68 | assert_raises(NetworkXError,nx.connected_components,self.DG)
69 | assert_raises(NetworkXError,nx.number_connected_components,self.DG)
70 | assert_raises(NetworkXError,nx.connected_component_subgraphs,self.DG)
71 | assert_raises(NetworkXError,nx.node_connected_component,self.DG,1)
72 | assert_raises(NetworkXError,nx.is_connected,self.DG)
73 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/components/tests/test_weakly_connected.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from nose.tools import *
3 | import networkx as nx
4 | from networkx import NetworkXError
5 |
6 | class TestWeaklyConnected:
7 |
8 | def setUp(self):
9 | self.gc=[]
10 | G=nx.DiGraph()
11 | G.add_edges_from([(1,2),(2,3),(2,8),(3,4),(3,7),
12 | (4,5),(5,3),(5,6),(7,4),(7,6),(8,1),(8,7)])
13 | C=[[3, 4, 5, 7], [1, 2, 8], [6]]
14 | self.gc.append((G,C))
15 |
16 | G= nx.DiGraph()
17 | G.add_edges_from([(1,2),(1,3),(1,4),(4,2),(3,4),(2,3)])
18 | C = [[2, 3, 4],[1]]
19 | self.gc.append((G,C))
20 |
21 | G = nx.DiGraph()
22 | G.add_edges_from([(1,2),(2,3),(3,2),(2,1)])
23 | C = [[1, 2, 3]]
24 | self.gc.append((G,C))
25 |
26 | # Eppstein's tests
27 | G = nx.DiGraph({ 0:[1],1:[2,3],2:[4,5],3:[4,5],4:[6],5:[],6:[]})
28 | C = [[0],[1],[2],[3],[4],[5],[6]]
29 | self.gc.append((G,C))
30 |
31 | G = nx.DiGraph({0:[1],1:[2,3,4],2:[0,3],3:[4],4:[3]})
32 | C = [[0,1,2],[3,4]]
33 | self.gc.append((G,C))
34 |
35 |
36 | def test_weakly_connected_components(self):
37 | wcc=nx.weakly_connected_components
38 | cc=nx.connected_components
39 | for G,C in self.gc:
40 | U=G.to_undirected()
41 | w=sorted([sorted(g) for g in wcc(G)])
42 | c=sorted([sorted(g) for g in cc(U)])
43 | assert_equal(w,c)
44 |
45 | def test_number_weakly_connected_components(self):
46 | wcc=nx.number_weakly_connected_components
47 | cc=nx.number_connected_components
48 | for G,C in self.gc:
49 | U=G.to_undirected()
50 | w=wcc(G)
51 | c=cc(U)
52 | assert_equal(w,c)
53 |
54 | def test_weakly_connected_component_subgraphs(self):
55 | wcc=nx.weakly_connected_component_subgraphs
56 | cc=nx.connected_component_subgraphs
57 | for G,C in self.gc:
58 | U=G.to_undirected()
59 | w=sorted([sorted(g.nodes()) for g in wcc(G)])
60 | c=sorted([sorted(g.nodes()) for g in cc(U)])
61 | assert_equal(w,c)
62 | G,C=self.gc[0]
63 | G.add_edge(1,2,eattr='red')
64 | G.node[1]['nattr']='blue'
65 | G.graph['gattr']='green'
66 | sgs=wcc(G)[0]
67 | assert_equal(sgs[1][2]['eattr'],'red')
68 | assert_equal(sgs.node[1]['nattr'],'blue')
69 | assert_equal(sgs.graph['gattr'],'green')
70 | sgs[1][2]['eattr']='blue'
71 | assert_equal(G[1][2]['eattr'],'red')
72 | assert_equal(sgs[1][2]['eattr'],'blue')
73 |
74 | def test_is_weakly_connected(self):
75 | wcc=nx.is_weakly_connected
76 | cc=nx.is_connected
77 | for G,C in self.gc:
78 | U=G.to_undirected()
79 | assert_equal(wcc(G),cc(U))
80 |
81 |
82 | def test_connected_raise(self):
83 | G=nx.Graph()
84 | assert_raises(NetworkXError,nx.weakly_connected_components,G)
85 | assert_raises(NetworkXError,nx.number_weakly_connected_components,G)
86 | assert_raises(NetworkXError,nx.weakly_connected_component_subgraphs,G)
87 | assert_raises(NetworkXError,nx.is_weakly_connected,G)
88 |
89 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/flow/__init__.py:
--------------------------------------------------------------------------------
1 | from networkx.algorithms.flow.maxflow import *
2 | from networkx.algorithms.flow.mincost import *
3 |
4 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/flow/tests/test_maxflow_large_graph.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """Max flow algorithm test suite on large graphs.
3 |
4 | Run with nose: nosetests -v test_max_flow.py
5 | """
6 |
7 | __author__ = """Loïc Séguin-C. """
8 | # Copyright (C) 2010 Loïc Séguin-C.
9 | # All rights reserved.
10 | # BSD license.
11 |
12 |
13 | import networkx as nx
14 | from nose.tools import *
15 |
16 | def gen_pyramid(N):
17 | # This graph admits a flow of value 1 for which every arc is at
18 | # capacity (except the arcs incident to the sink which have
19 | # infinite capacity).
20 | G = nx.DiGraph()
21 |
22 | for i in range(N - 1):
23 | cap = 1. / (i + 2)
24 | for j in range(i + 1):
25 | G.add_edge((i, j), (i + 1, j),
26 | capacity = cap)
27 | cap = 1. / (i + 1) - cap
28 | G.add_edge((i, j), (i + 1, j + 1),
29 | capacity = cap)
30 | cap = 1. / (i + 2) - cap
31 |
32 | for j in range(N):
33 | G.add_edge((N - 1, j), 't')
34 |
35 | return G
36 |
37 |
38 | class TestMaxflowLargeGraph:
39 | def test_complete_graph(self):
40 | N = 50
41 | G = nx.complete_graph(N)
42 | for (u, v) in G.edges():
43 | G[u][v]['capacity'] = 5
44 | assert_equal(nx.ford_fulkerson(G, 1, 2)[0], 5 * (N - 1))
45 |
46 | def test_pyramid(self):
47 | N = 10
48 | # N = 100 # this gives a graph with 5051 nodes
49 | G = gen_pyramid(N)
50 | assert_almost_equal(nx.ford_fulkerson(G, (0, 0), 't')[0], 1.)
51 |
52 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/isolate.py:
--------------------------------------------------------------------------------
1 | # encoding: utf-8
2 | """
3 | Functions for identifying isolate (degree zero) nodes.
4 | """
5 | # Copyright (C) 2004-2011 by
6 | # Aric Hagberg
7 | # Dan Schult
8 | # Pieter Swart
9 | # All rights reserved.
10 | # BSD license.
11 | import networkx as nx
12 | __author__ = """\n""".join(['Drew Conway ',
13 | 'Aric Hagberg '])
14 | __all__=['is_isolate','isolates']
15 |
16 | def is_isolate(G,n):
17 | """Determine of node n is an isolate (degree zero).
18 |
19 | Parameters
20 | ----------
21 | G : graph
22 | A networkx graph
23 | n : node
24 | A node in G
25 |
26 | Returns
27 | -------
28 | isolate : bool
29 | True if n has no neighbors, False otherwise.
30 |
31 | Examples
32 | --------
33 | >>> G=nx.Graph()
34 | >>> G.add_edge(1,2)
35 | >>> G.add_node(3)
36 | >>> nx.is_isolate(G,2)
37 | False
38 | >>> nx.is_isolate(G,3)
39 | True
40 | """
41 | return G.degree(n)==0
42 |
43 | def isolates(G):
44 | """Return list of isolates in the graph.
45 |
46 | Isolates are nodes with no neighbors (degree zero).
47 |
48 | Parameters
49 | ----------
50 | G : graph
51 | A networkx graph
52 |
53 | Returns
54 | -------
55 | isolates : list
56 | List of isolate nodes.
57 |
58 | Examples
59 | --------
60 | >>> G = nx.Graph()
61 | >>> G.add_edge(1,2)
62 | >>> G.add_node(3)
63 | >>> nx.isolates(G)
64 | [3]
65 |
66 | To remove all isolates in the graph use
67 | >>> G.remove_nodes_from(nx.isolates(G))
68 | >>> G.nodes()
69 | [1, 2]
70 |
71 | For digraphs isolates have zero in-degree and zero out_degre
72 | >>> G = nx.DiGraph([(0,1),(1,2)])
73 | >>> G.add_node(3)
74 | >>> nx.isolates(G)
75 | [3]
76 | """
77 | return [n for (n,d) in G.degree_iter() if d==0]
78 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/isomorphism/__init__.py:
--------------------------------------------------------------------------------
1 | from networkx.algorithms.isomorphism.isomorph import *
2 | from networkx.algorithms.isomorphism.vf2userfunc import *
3 | from networkx.algorithms.isomorphism.matchhelpers import *
4 |
5 |
--------------------------------------------------------------------------------
/appengine/networkx/algorithms/isomorphism/tests/iso_r01_s80.A99:
--------------------------------------------------------------------------------
1 | P % 6 : C G , - . 9 : G % 0 1 4 ! $ + 0 2 : B J
! * 5 6 7 <