├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── TODO ├── autogen.sh ├── configure.ac ├── doc ├── .static │ ├── graph-icon.ico │ └── graph-icon.png ├── .templates │ └── layout.html ├── Makefile ├── centrality.rst ├── clustering.rst ├── collection.rst ├── community.rst ├── community.xml ├── conf.py ├── correlations.rst ├── demos │ ├── animation.rst │ ├── animation_dancing.py │ ├── animation_sirs.py │ ├── animation_zombies.py │ ├── face-grin.png │ ├── face-surprise.png │ ├── index.rst │ ├── interactive_bst.py │ └── zombie.png ├── draw.rst ├── faq.rst ├── flow.rst ├── generation.rst ├── graph_tool.rst ├── gt_format.rst ├── gt_theme │ ├── static │ │ ├── flasky.css │ │ ├── font-awesome-4.2.0 │ │ │ ├── css │ │ │ │ ├── font-awesome.css │ │ │ │ └── font-awesome.min.css │ │ │ ├── fonts │ │ │ │ ├── FontAwesome.otf │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ ├── fontawesome-webfont.svg │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ └── fontawesome-webfont.woff │ │ │ ├── less │ │ │ │ ├── bordered-pulled.less │ │ │ │ ├── core.less │ │ │ │ ├── fixed-width.less │ │ │ │ ├── font-awesome.less │ │ │ │ ├── icons.less │ │ │ │ ├── larger.less │ │ │ │ ├── list.less │ │ │ │ ├── mixins.less │ │ │ │ ├── path.less │ │ │ │ ├── rotated-flipped.less │ │ │ │ ├── spinning.less │ │ │ │ ├── stacked.less │ │ │ │ └── variables.less │ │ │ └── scss │ │ │ │ ├── _bordered-pulled.scss │ │ │ │ ├── _core.scss │ │ │ │ ├── _fixed-width.scss │ │ │ │ ├── _icons.scss │ │ │ │ ├── _larger.scss │ │ │ │ ├── _list.scss │ │ │ │ ├── _mixins.scss │ │ │ │ ├── _path.scss │ │ │ │ ├── _rotated-flipped.scss │ │ │ │ ├── _spinning.scss │ │ │ │ ├── _stacked.scss │ │ │ │ ├── _variables.scss │ │ │ │ └── font-awesome.scss │ │ └── gt_style.css │ └── theme.conf ├── index.rst ├── mathjax.py ├── mincut-example.xml.gz ├── modules.rst ├── price.py ├── pyenv.py ├── quickstart.rst ├── run_action.rst ├── search_example.xml ├── search_module.rst ├── spectral.rst ├── sphinxext │ ├── LICENSE.txt │ ├── MANIFEST.in │ ├── README.txt │ ├── __init__.py │ ├── comment_eater.py │ ├── compiler_unparse.py │ ├── docscrape.py │ ├── docscrape_sphinx.py │ ├── linkcode.py │ ├── numpydoc.py │ ├── phantom_import.py │ ├── plot_directive.py │ ├── setup.py │ ├── tests │ │ └── test_docscrape.py │ └── traitsdoc.py ├── stats.rst ├── topology.rst └── util.rst ├── m4 ├── ax_boost_base.m4 ├── ax_boost_graph.m4 ├── ax_boost_iostreams.m4 ├── ax_boost_python.m4 ├── ax_boost_regex.m4 ├── ax_python_devel.m4 └── ax_python_module.m4 └── src ├── Makefile.am ├── boost-workaround ├── LICENSE_1_0.txt └── boost │ └── graph │ ├── betweenness_centrality.hpp │ ├── copy_alt.hpp │ ├── detail │ └── read_graphviz_new.hpp │ ├── graphml.hpp │ ├── graphviz.hpp │ ├── isomorphism.hpp │ ├── kamada_kawai_spring_layout.hpp │ ├── metric_tsp_approx.hpp │ ├── named_function_params-alt.hpp │ ├── overloading.hpp │ ├── push_relabel_max_flow.hpp │ ├── reverse_graph_alt.hpp │ └── stoer_wagner_min_cut.hpp ├── graph ├── Makefile.am ├── base64.cc ├── base64.hh ├── centrality │ ├── Makefile.am │ ├── graph_betweenness.cc │ ├── graph_centrality_bind.cc │ ├── graph_closeness.cc │ ├── graph_closeness.hh │ ├── graph_eigentrust.cc │ ├── graph_eigentrust.hh │ ├── graph_eigenvector.cc │ ├── graph_eigenvector.hh │ ├── graph_hits.cc │ ├── graph_hits.hh │ ├── graph_katz.cc │ ├── graph_katz.hh │ ├── graph_pagerank.cc │ ├── graph_pagerank.hh │ ├── graph_trust_transitivity.cc │ ├── graph_trust_transitivity.hh │ └── minmax.hh ├── clustering │ ├── Makefile.am │ ├── graph_clustering.cc │ ├── graph_clustering.hh │ ├── graph_extended_clustering.cc │ ├── graph_extended_clustering.hh │ ├── graph_motifs.cc │ └── graph_motifs.hh ├── community │ ├── Makefile.am │ ├── graph_blockmodel.cc │ ├── graph_blockmodel.hh │ ├── graph_blockmodel_covariates.cc │ ├── graph_blockmodel_covariates.hh │ ├── graph_blockmodel_overlap.cc │ ├── graph_blockmodel_overlap.hh │ ├── graph_community.cc │ ├── graph_community.hh │ ├── graph_community_network.cc │ ├── graph_community_network.hh │ ├── graph_community_network_eavg.cc │ ├── graph_community_network_eavg_imp1.cc │ ├── graph_community_network_edges.cc │ ├── graph_community_network_vavg.cc │ └── spence.cc ├── correlations │ ├── Makefile.am │ ├── graph_assortativity.cc │ ├── graph_assortativity.hh │ ├── graph_avg_correlations.cc │ ├── graph_avg_correlations.hh │ ├── graph_avg_correlations_combined.cc │ ├── graph_avg_correlations_imp1.cc │ ├── graph_corr_hist.hh │ ├── graph_correlations.cc │ ├── graph_correlations.hh │ ├── graph_correlations_bind.cc │ ├── graph_correlations_combined.cc │ └── graph_correlations_imp1.cc ├── draw │ ├── Makefile.am │ ├── graph_cairo_draw.cc │ └── graph_tree_cts.cc ├── fast_vector_property_map.hh ├── flow │ ├── Makefile.am │ ├── graph_augment.hh │ ├── graph_edmonds_karp.cc │ ├── graph_flow_bind.cc │ ├── graph_kolmogorov.cc │ ├── graph_maximum_cardinality_matching.cc │ ├── graph_minimum_cut.cc │ └── graph_push_relabel.cc ├── generation │ ├── Makefile.am │ ├── dynamic_sampler.hh │ ├── graph_complete.cc │ ├── graph_complete.hh │ ├── graph_generation.cc │ ├── graph_generation.hh │ ├── graph_geometric.cc │ ├── graph_geometric.hh │ ├── graph_lattice.cc │ ├── graph_lattice.hh │ ├── graph_line_graph.cc │ ├── graph_predecessor.cc │ ├── graph_predecessor.hh │ ├── graph_price.cc │ ├── graph_price.hh │ ├── graph_rewiring.cc │ ├── graph_rewiring.hh │ ├── graph_triangulation.cc │ ├── graph_triangulation.hh │ ├── graph_union.cc │ ├── graph_union.hh │ ├── graph_union_eprop.cc │ ├── graph_union_vprop.cc │ └── sampler.hh ├── gml.hh ├── graph.cc ├── graph.hh ├── graph_adaptor.hh ├── graph_adjacency.hh ├── graph_bind.cc ├── graph_copy.cc ├── graph_exceptions.cc ├── graph_exceptions.hh ├── graph_filtering.cc ├── graph_filtering.hh ├── graph_io.cc ├── graph_io_binary.hh ├── graph_openmp.cc ├── graph_properties.cc ├── graph_properties.hh ├── graph_properties_copy.cc ├── graph_properties_group.cc ├── graph_properties_group.hh ├── graph_properties_imp1.cc ├── graph_properties_imp2.cc ├── graph_properties_ungroup.cc ├── graph_python_interface.cc ├── graph_python_interface.hh ├── graph_python_interface_export.cc ├── graph_selectors.cc ├── graph_selectors.hh ├── graph_util.hh ├── graphml.cpp ├── histogram.hh ├── layout │ ├── Makefile.am │ ├── graph_arf.cc │ ├── graph_arf.hh │ ├── graph_bind_layout.cc │ ├── graph_fruchterman_reingold.cc │ ├── graph_radial.cc │ ├── graph_sfdp.cc │ └── graph_sfdp.hh ├── mpl_nested_loop.hh ├── numpy_bind.hh ├── numpy_bind_old.hh ├── random.cc ├── random.hh ├── read_graphviz_new.cpp ├── search │ ├── Makefile.am │ ├── graph_astar.cc │ ├── graph_astar.hh │ ├── graph_astar_implicit.cc │ ├── graph_bellman_ford.cc │ ├── graph_bfs.cc │ ├── graph_dfs.cc │ ├── graph_dijkstra.cc │ └── graph_search_bind.cc ├── shared_map.hh ├── spectral │ ├── Makefile.am │ ├── graph_adjacency.cc │ ├── graph_adjacency.hh │ ├── graph_incidence.cc │ ├── graph_incidence.hh │ ├── graph_laplacian.cc │ ├── graph_laplacian.hh │ ├── graph_matrix.cc │ ├── graph_norm_laplacian.cc │ ├── graph_transition.cc │ └── graph_transition.hh ├── stats │ ├── Makefile.am │ ├── graph_average.cc │ ├── graph_average.hh │ ├── graph_distance.cc │ ├── graph_distance.hh │ ├── graph_distance_sampled.cc │ ├── graph_distance_sampled.hh │ ├── graph_histograms.cc │ ├── graph_histograms.hh │ ├── graph_parallel.cc │ ├── graph_parallel.hh │ └── graph_stats_bind.cc ├── str_repr.hh ├── topology │ ├── Makefile.am │ ├── graph_all_distances.cc │ ├── graph_bipartite.cc │ ├── graph_components.cc │ ├── graph_components.hh │ ├── graph_diameter.cc │ ├── graph_distance.cc │ ├── graph_dominator_tree.cc │ ├── graph_isomorphism.cc │ ├── graph_kcore.cc │ ├── graph_kcore.hh │ ├── graph_maximal_planar.cc │ ├── graph_maximal_vertex_set.cc │ ├── graph_minimum_spanning_tree.cc │ ├── graph_planar.cc │ ├── graph_random_matching.cc │ ├── graph_random_spanning_tree.cc │ ├── graph_reciprocity.cc │ ├── graph_sequential_color.cc │ ├── graph_similarity.cc │ ├── graph_similarity.hh │ ├── graph_subgraph_isomorphism.cc │ ├── graph_topological_sort.cc │ ├── graph_topology.cc │ ├── graph_transitive_closure.cc │ └── graph_tsp.cc ├── transform_iterator.hh └── util │ ├── Makefile.am │ ├── graph_search.cc │ ├── graph_search.hh │ └── graph_util_bind.cc └── graph_tool ├── Makefile.am ├── __init__.py ├── all.py ├── centrality └── __init__.py ├── clustering └── __init__.py ├── collection ├── __init__.py ├── adjnoun.gt.gz ├── as-22july06.gt.gz ├── astro-ph.gt.gz ├── celegansneural.gt.gz ├── cond-mat-2003.gt.gz ├── cond-mat-2005.gt.gz ├── cond-mat.gt.gz ├── dolphins.gt.gz ├── email-Enron.gt.gz ├── football.gt.gz ├── hep-th.gt.gz ├── karate.gt.gz ├── lesmis.gt.gz ├── netscience.gt.gz ├── pgp-strong-2009.gt.gz ├── polblogs.gt.gz ├── polbooks.gt.gz ├── power.gt.gz └── serengeti-foodweb.gt.gz ├── community ├── __init__.py ├── blockmodel.py ├── covariate_blockmodel.py ├── nested_blockmodel.py └── overlap_blockmodel.py ├── correlations └── __init__.py ├── decorators.py ├── dl_import.py ├── draw ├── __init__.py ├── cairo_draw.py ├── graph-tool-logo.svg ├── graphviz_draw.py └── gtk_draw.py ├── flow └── __init__.py ├── generation └── __init__.py ├── io.py ├── run_action ├── __init__.py ├── inline.py ├── run_action_support.hh └── run_action_template.hh ├── search └── __init__.py ├── spectral └── __init__.py ├── stats └── __init__.py ├── topology └── __init__.py └── util └── __init__.py /AUTHORS: -------------------------------------------------------------------------------- 1 | Tiago de Paula Peixoto - pretty much everything so far 2 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | To see the full detailed changelog, see the git repository 2 | at git://git.skewed.de/graph-tool or http://git.skewed.de/?p=graph-tool 3 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | SUBDIRS = src 4 | 5 | graphtooldocdir = ${PACKAGE_DOC_DIR} 6 | nobase_dist_graphtooldoc_DATA = \ 7 | README\ 8 | COPYING\ 9 | AUTHORS\ 10 | INSTALL\ 11 | NEWS\ 12 | TODO\ 13 | src/boost-workaround/LICENSE_1_0.txt\ 14 | doc/centrality.rst \ 15 | doc/correlations.rst \ 16 | doc/price.py \ 17 | doc/search_module.rst \ 18 | doc/util.rst \ 19 | doc/clustering.rst \ 20 | doc/draw.rst \ 21 | doc/index.rst \ 22 | doc/spectral.rst \ 23 | doc/community.rst \ 24 | doc/flow.rst \ 25 | doc/Makefile \ 26 | doc/quickstart.rst \ 27 | doc/generation.rst \ 28 | doc/mathjax.py \ 29 | doc/run_action.rst \ 30 | doc/stats.rst \ 31 | doc/graph_tool.rst \ 32 | doc/modules.rst \ 33 | doc/topology.rst \ 34 | doc/conf.py \ 35 | doc/pyenv.py \ 36 | doc/community.xml \ 37 | doc/search_example.xml \ 38 | doc/sphinxext/README.txt \ 39 | doc/sphinxext/LICENSE.txt \ 40 | doc/sphinxext/__init__.py \ 41 | doc/sphinxext/setup.py \ 42 | doc/sphinxext/comment_eater.py \ 43 | doc/sphinxext/docscrape.py \ 44 | doc/sphinxext/MANIFEST.in \ 45 | doc/sphinxext/phantom_import.py \ 46 | doc/sphinxext/compiler_unparse.py \ 47 | doc/sphinxext/docscrape_sphinx.py \ 48 | doc/sphinxext/numpydoc.py \ 49 | doc/sphinxext/traitsdoc.py \ 50 | doc/sphinxext/tests/test_docscrape.py \ 51 | doc/gt_theme/static/flasky.css \ 52 | doc/gt_theme/static/gt_style.css \ 53 | doc/gt_theme/theme.conf \ 54 | doc/.static/graph-icon.png \ 55 | doc/.static/graph-icon.ico 56 | 57 | 58 | EXTRA_DIST = $(graphtooldoc_DATA) autogen.sh 59 | 60 | # Copy all the spec files. Of cource, only one is actually used. 61 | dist-hook: 62 | for specfile in *.spec; do \ 63 | if test -f $$specfile; then \ 64 | cp -p $$specfile $(distdir); \ 65 | fi \ 66 | done -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | See the website for details: http://graph-tool.skewed.de -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | graph-tool -- an efficient python module for analysis of graphs 2 | =============================================================== 3 | 4 | graph-tool is an efficient python module for manipulation and 5 | statistical analysis of graphs. It contains several general graph 6 | measurements data structures and algorithms, such as degree or 7 | properties distributions, degree or properties correlations, 8 | clustering, graph filtering, graph layout, and more, as well as a 9 | random graph generation routine. For more information and 10 | documentation, please take a look at the website 11 | http://graph-tool.skewed.de. 12 | 13 | graph-tool is free software, you can redistribute it and/or modify it 14 | under the terms of the GNU General Public License, version 3 or 15 | above. See COPYING for details. 16 | 17 | This program is distributed in the hope that it will be useful, but 18 | WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20 | 21 | Availability 22 | ============ 23 | 24 | The current stable version of graph-tool is always available from the 25 | project's website: http://graph-tool.skewed.de 26 | 27 | Installation 28 | ============ 29 | 30 | graph-tool follows the standard GNU installation procedure. Please 31 | consult the INSTALL file in this distribution for more detailed 32 | instructions. 33 | 34 | Note that recent versions of GCC (4.4 or above) are required for 35 | compilation, and due to the usage of template metaprogramming 36 | techniques in the program, relatively large amounts of RAM are 37 | required during compilation. You have been warned! For this reason, 38 | pre-compiled packages are available in the website. 39 | 40 | More information about graph-tool 41 | ================================== 42 | 43 | The project homepage is http://graph-tool.skewed.de. It contains 44 | documentation, info on mailing lists, a wiki, as well as a 45 | bug-tracking function. You should be reading it, instead of this. :-) 46 | 47 | See the NEWS file for recent changes to the program. 48 | 49 | Reporting Bugs 50 | ============== 51 | 52 | A list of known bugs can be found in the website: 53 | 54 | http://graph-tool.skewed.de/tickets 55 | 56 | If you found a bug in the program which is not included in this list, 57 | please submit a ticket through the provided interface. 58 | 59 | -- 60 | Tiago de Paula Peixoto -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | see website for details: http://graph-tool.skewed.de -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Run this to generate all the initial makefiles, etc. 3 | 4 | srcdir=`dirname $0` 5 | test -z "$srcdir" && srcdir=. 6 | 7 | PROJECT="graph-tool" 8 | 9 | (test -f $srcdir/configure.ac) || { 10 | echo -n "**Error**: Directory \"\'$srcdir\'\" does not look like the" 11 | echo " top-level package directory" 12 | exit 1 13 | } 14 | 15 | AUTOGEN_SUBDIR_MODE="foo" 16 | 17 | if test -z "$AUTOGEN_SUBDIR_MODE"; then 18 | if test -z "$*"; then 19 | echo "I am going to run ./configure with no arguments - if you wish " 20 | echo "to pass any to it, please specify them on the $0 command line." 21 | fi 22 | fi 23 | 24 | aclocal -I m4 || exit $? 25 | autoheader || exit $? 26 | if [ `type -P libtoolize` ]; then 27 | libtoolize -f || exit $? 28 | else 29 | glibtoolize -f || exit $? 30 | fi 31 | automake --add-missing --copy || exit $? 32 | autoconf || exit $? 33 | 34 | if test -z "$AUTOGEN_SUBDIR_MODE"; then 35 | $srcdir/configure --enable-maintainer-mode $AUTOGEN_CONFIGURE_ARGS "$@" || exit $? 36 | 37 | echo 38 | echo "Now type 'make' to compile $PROJECT." 39 | fi 40 | -------------------------------------------------------------------------------- /doc/.static/graph-icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/doc/.static/graph-icon.ico -------------------------------------------------------------------------------- /doc/.static/graph-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/doc/.static/graph-icon.png -------------------------------------------------------------------------------- /doc/.templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html" %} 2 | {% block rootrellink %} 3 |
  • logoProject Homepage »
  • 4 | {{ super() }} 5 | {% endblock %} 6 | 7 | {% block extrahead %} 8 | 22 | {{ super() }} 23 | {% endblock %} 24 | 25 | {% block sidebarsearch %} 26 | {{ super() }} 27 | 28 | 29 |

    30 | Latest development version docs are also available. 31 | {% endblock %} 32 | 33 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | sphinx-build -E -b html . build 3 | 4 | latex: 5 | sphinx-build -E -b latex . build 6 | 7 | test: 8 | OMP_NUM_THREADS=1 sphinx-build -b doctest . build 9 | 10 | clean: 11 | rm -rf build 12 | 13 | -------------------------------------------------------------------------------- /doc/centrality.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.centrality 2 | :members: 3 | :undoc-members: 4 | -------------------------------------------------------------------------------- /doc/clustering.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.clustering 2 | :members: 3 | :undoc-members: 4 | -------------------------------------------------------------------------------- /doc/collection.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.collection 2 | :members: 3 | :undoc-members: 4 | -------------------------------------------------------------------------------- /doc/community.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.community 2 | :no-members: 3 | :no-undoc-members: 4 | 5 | .. autofunction:: minimize_blockmodel_dl 6 | .. autoclass:: BlockState 7 | .. autoclass:: OverlapBlockState 8 | .. autoclass:: CovariateBlockState 9 | .. autofunction:: mcmc_sweep 10 | .. autoclass:: MinimizeState 11 | .. autofunction:: multilevel_minimize 12 | .. autofunction:: collect_edge_marginals 13 | .. autofunction:: collect_vertex_marginals 14 | .. autofunction:: mf_entropy 15 | .. autofunction:: bethe_entropy 16 | .. autofunction:: model_entropy 17 | .. autofunction:: get_max_B 18 | .. autofunction:: get_akc 19 | .. autofunction:: condensation_graph 20 | .. autofunction:: minimize_nested_blockmodel_dl 21 | .. autoclass:: NestedBlockState 22 | .. autoclass:: NestedMinimizeState 23 | .. autofunction:: init_nested_state 24 | .. autofunction:: nested_mcmc_sweep 25 | .. autofunction:: nested_tree_sweep 26 | .. autofunction:: get_hierarchy_tree 27 | .. autofunction:: get_block_edge_gradient 28 | .. autofunction:: community_structure 29 | .. autofunction:: modularity 30 | -------------------------------------------------------------------------------- /doc/correlations.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.correlations 2 | :members: 3 | :undoc-members: 4 | -------------------------------------------------------------------------------- /doc/demos/face-grin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/doc/demos/face-grin.png -------------------------------------------------------------------------------- /doc/demos/face-surprise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/doc/demos/face-surprise.png -------------------------------------------------------------------------------- /doc/demos/index.rst: -------------------------------------------------------------------------------- 1 | Cookbook 2 | ======== 3 | 4 | Contents: 5 | 6 | .. toctree:: 7 | :maxdepth: 3 8 | :glob: 9 | 10 | animation -------------------------------------------------------------------------------- /doc/demos/interactive_bst.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | # This simple example on how to interactive animations using graph-tool. Here we 5 | # show the BFS tree of length 3 for the currently selected vertex. 6 | 7 | from graph_tool.all import * 8 | 9 | # We need some Gtk functions 10 | from gi.repository import Gtk, Gdk 11 | import sys 12 | 13 | offscreen = sys.argv[1] == "offscreen" if len(sys.argv) > 1 else False 14 | 15 | # We will use the network of network scientists, and filter out the largest 16 | # component 17 | g = collection.data["netscience"] 18 | g = GraphView(g, vfilt=label_largest_component(g), directed=False) 19 | g = Graph(g, prune=True) 20 | 21 | pos = g.vp["pos"] # layout positions 22 | 23 | ecolor = g.new_edge_property("vector") 24 | for e in g.edges(): 25 | ecolor[e] = [0.6, 0.6, 0.6, 1] 26 | vcolor = g.new_vertex_property("vector") 27 | for v in g.vertices(): 28 | vcolor[v] = [0.6, 0.6, 0.6, 1] 29 | 30 | win = GraphWindow(g, pos, geometry=(500, 400), 31 | edge_color=ecolor, 32 | vertex_fill_color=vcolor) 33 | 34 | orange = [0.807843137254902, 0.3607843137254902, 0.0, 1.0] 35 | old_src = None 36 | count = 0 37 | def update_bfs(widget, event): 38 | global old_src, g, count, win 39 | src = widget.picked 40 | if src is None: 41 | return True 42 | if isinstance(src, PropertyMap): 43 | src = [v for v in g.vertices() if src[v]] 44 | if len(src) == 0: 45 | return True 46 | src = src[0] 47 | if src == old_src: 48 | return True 49 | old_src = src 50 | pred = shortest_distance(g, src, max_dist=3, pred_map=True)[1] 51 | for e in g.edges(): 52 | ecolor[e] = [0.6, 0.6, 0.6, 1] 53 | for v in g.vertices(): 54 | vcolor[v] = [0.6, 0.6, 0.6, 1] 55 | for v in g.vertices(): 56 | w = g.vertex(pred[v]) 57 | if w < g.num_vertices(): 58 | e = g.edge(w, v) 59 | if e is not None: 60 | ecolor[e] = orange 61 | vcolor[v] = vcolor[w] = orange 62 | widget.regenerate_surface(lazy=False) 63 | widget.queue_draw() 64 | 65 | if offscreen: 66 | window = widget.get_window() 67 | pixbuf = Gdk.pixbuf_get_from_window(window, 0, 0, 500, 400) 68 | pixbuf.savev(r'./frames/bfs%06d.png' % count, 'png', [], []) 69 | count += 1 70 | 71 | # Bind the function above as a montion notify handler 72 | win.graph.connect("motion_notify_event", update_bfs) 73 | 74 | # We will give the user the ability to stop the program by closing the window. 75 | win.connect("delete_event", Gtk.main_quit) 76 | 77 | # Actually show the window, and start the main loop. 78 | win.show_all() 79 | Gtk.main() 80 | -------------------------------------------------------------------------------- /doc/demos/zombie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/doc/demos/zombie.png -------------------------------------------------------------------------------- /doc/draw.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.draw 2 | :no-members: 3 | 4 | .. container:: sec_title 5 | 6 | Layout algorithms 7 | 8 | .. autofunction:: sfdp_layout 9 | .. autofunction:: fruchterman_reingold_layout 10 | .. autofunction:: arf_layout 11 | .. autofunction:: radial_tree_layout 12 | .. autofunction:: random_layout 13 | 14 | 15 | .. container:: sec_title 16 | 17 | Graph drawing 18 | 19 | .. autofunction:: graph_draw 20 | .. autofunction:: draw_hierarchy 21 | .. autofunction:: graphviz_draw 22 | .. autofunction:: prop_to_size 23 | .. autofunction:: get_hierarchy_control_points 24 | 25 | 26 | .. container:: sec_title 27 | 28 | Low-level graph drawing 29 | 30 | .. autofunction:: cairo_draw 31 | .. autofunction:: interactive_window 32 | .. autoclass:: GraphWidget 33 | :show-inheritance: 34 | :members: 35 | :undoc-members: 36 | .. autoclass:: GraphWindow 37 | :show-inheritance: 38 | :members: 39 | :undoc-members: 40 | -------------------------------------------------------------------------------- /doc/faq.rst: -------------------------------------------------------------------------------- 1 | .. _sec_faq: 2 | 3 | Frequently Asked Questions (FAQ) 4 | ================================ 5 | 6 | How do I cite graph-tool? 7 | ------------------------- 8 | 9 | You can cite graph-tool in your publications as follows: 10 | 11 | Tiago P. Peixoto, "The graph-tool python library", figshare. (2014) 12 | :doi:`10.6084/m9.figshare.1164194` 13 | 14 | Here is a more convenient `BibTeX `_ entry: 15 | 16 | .. code-block:: none 17 | 18 | @article{peixoto_graph-tool_2014, 19 | title = {The graph-tool python library}, 20 | url = {http://figshare.com/articles/graph_tool/1164194}, 21 | doi = {10.6084/m9.figshare.1164194}, 22 | urldate = {2014-09-10}, 23 | journal = {figshare}, 24 | author = {Peixoto, Tiago P.}, 25 | year = {2014}, 26 | keywords = {all, complex networks, graph, network, other}} 27 | 28 | More information can be found at the `figshare site 29 | `_. 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /doc/flow.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.flow 2 | :members: 3 | :undoc-members: 4 | -------------------------------------------------------------------------------- /doc/generation.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.generation 2 | :members: 3 | :undoc-members: 4 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/doc/gt_theme/static/font-awesome-4.2.0/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/doc/gt_theme/static/font-awesome-4.2.0/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/doc/gt_theme/static/font-awesome-4.2.0/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/doc/gt_theme/static/font-awesome-4.2.0/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/less/bordered-pulled.less: -------------------------------------------------------------------------------- 1 | // Bordered & Pulled 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix}-border { 5 | padding: .2em .25em .15em; 6 | border: solid .08em @fa-border-color; 7 | border-radius: .1em; 8 | } 9 | 10 | .pull-right { float: right; } 11 | .pull-left { float: left; } 12 | 13 | .@{fa-css-prefix} { 14 | &.pull-left { margin-right: .3em; } 15 | &.pull-right { margin-left: .3em; } 16 | } 17 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/less/core.less: -------------------------------------------------------------------------------- 1 | // Base Class Definition 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix} { 5 | display: inline-block; 6 | font: normal normal normal 14px/1 FontAwesome; // shortening font declaration 7 | font-size: inherit; // can't have font-size inherit on line above, so need to override 8 | text-rendering: auto; // optimizelegibility throws things off #1094 9 | -webkit-font-smoothing: antialiased; 10 | -moz-osx-font-smoothing: grayscale; 11 | } 12 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/less/fixed-width.less: -------------------------------------------------------------------------------- 1 | // Fixed Width Icons 2 | // ------------------------- 3 | .@{fa-css-prefix}-fw { 4 | width: (18em / 14); 5 | text-align: center; 6 | } 7 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/less/font-awesome.less: -------------------------------------------------------------------------------- 1 | /*! 2 | * Font Awesome 4.2.0 by @davegandy - http://fontawesome.io - @fontawesome 3 | * License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License) 4 | */ 5 | 6 | @import "variables.less"; 7 | @import "mixins.less"; 8 | @import "path.less"; 9 | @import "core.less"; 10 | @import "larger.less"; 11 | @import "fixed-width.less"; 12 | @import "list.less"; 13 | @import "bordered-pulled.less"; 14 | @import "spinning.less"; 15 | @import "rotated-flipped.less"; 16 | @import "stacked.less"; 17 | @import "icons.less"; 18 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/less/larger.less: -------------------------------------------------------------------------------- 1 | // Icon Sizes 2 | // ------------------------- 3 | 4 | /* makes the font 33% larger relative to the icon container */ 5 | .@{fa-css-prefix}-lg { 6 | font-size: (4em / 3); 7 | line-height: (3em / 4); 8 | vertical-align: -15%; 9 | } 10 | .@{fa-css-prefix}-2x { font-size: 2em; } 11 | .@{fa-css-prefix}-3x { font-size: 3em; } 12 | .@{fa-css-prefix}-4x { font-size: 4em; } 13 | .@{fa-css-prefix}-5x { font-size: 5em; } 14 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/less/list.less: -------------------------------------------------------------------------------- 1 | // List Icons 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix}-ul { 5 | padding-left: 0; 6 | margin-left: @fa-li-width; 7 | list-style-type: none; 8 | > li { position: relative; } 9 | } 10 | .@{fa-css-prefix}-li { 11 | position: absolute; 12 | left: -@fa-li-width; 13 | width: @fa-li-width; 14 | top: (2em / 14); 15 | text-align: center; 16 | &.@{fa-css-prefix}-lg { 17 | left: (-@fa-li-width + (4em / 14)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/less/mixins.less: -------------------------------------------------------------------------------- 1 | // Mixins 2 | // -------------------------- 3 | 4 | .fa-icon() { 5 | display: inline-block; 6 | font: normal normal normal 14px/1 FontAwesome; // shortening font declaration 7 | font-size: inherit; // can't have font-size inherit on line above, so need to override 8 | text-rendering: auto; // optimizelegibility throws things off #1094 9 | -webkit-font-smoothing: antialiased; 10 | -moz-osx-font-smoothing: grayscale; 11 | } 12 | 13 | .fa-icon-rotate(@degrees, @rotation) { 14 | filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=@rotation); 15 | -webkit-transform: rotate(@degrees); 16 | -ms-transform: rotate(@degrees); 17 | transform: rotate(@degrees); 18 | } 19 | 20 | .fa-icon-flip(@horiz, @vert, @rotation) { 21 | filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=@rotation, mirror=1); 22 | -webkit-transform: scale(@horiz, @vert); 23 | -ms-transform: scale(@horiz, @vert); 24 | transform: scale(@horiz, @vert); 25 | } 26 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/less/path.less: -------------------------------------------------------------------------------- 1 | /* FONT PATH 2 | * -------------------------- */ 3 | 4 | @font-face { 5 | font-family: 'FontAwesome'; 6 | src: url('@{fa-font-path}/fontawesome-webfont.eot?v=@{fa-version}'); 7 | src: url('@{fa-font-path}/fontawesome-webfont.eot?#iefix&v=@{fa-version}') format('embedded-opentype'), 8 | url('@{fa-font-path}/fontawesome-webfont.woff?v=@{fa-version}') format('woff'), 9 | url('@{fa-font-path}/fontawesome-webfont.ttf?v=@{fa-version}') format('truetype'), 10 | url('@{fa-font-path}/fontawesome-webfont.svg?v=@{fa-version}#fontawesomeregular') format('svg'); 11 | // src: url('@{fa-font-path}/FontAwesome.otf') format('opentype'); // used when developing fonts 12 | font-weight: normal; 13 | font-style: normal; 14 | } 15 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/less/rotated-flipped.less: -------------------------------------------------------------------------------- 1 | // Rotated & Flipped Icons 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix}-rotate-90 { .fa-icon-rotate(90deg, 1); } 5 | .@{fa-css-prefix}-rotate-180 { .fa-icon-rotate(180deg, 2); } 6 | .@{fa-css-prefix}-rotate-270 { .fa-icon-rotate(270deg, 3); } 7 | 8 | .@{fa-css-prefix}-flip-horizontal { .fa-icon-flip(-1, 1, 0); } 9 | .@{fa-css-prefix}-flip-vertical { .fa-icon-flip(1, -1, 2); } 10 | 11 | // Hook for IE8-9 12 | // ------------------------- 13 | 14 | :root .@{fa-css-prefix}-rotate-90, 15 | :root .@{fa-css-prefix}-rotate-180, 16 | :root .@{fa-css-prefix}-rotate-270, 17 | :root .@{fa-css-prefix}-flip-horizontal, 18 | :root .@{fa-css-prefix}-flip-vertical { 19 | filter: none; 20 | } 21 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/less/spinning.less: -------------------------------------------------------------------------------- 1 | // Spinning Icons 2 | // -------------------------- 3 | 4 | .@{fa-css-prefix}-spin { 5 | -webkit-animation: fa-spin 2s infinite linear; 6 | animation: fa-spin 2s infinite linear; 7 | } 8 | 9 | @-webkit-keyframes fa-spin { 10 | 0% { 11 | -webkit-transform: rotate(0deg); 12 | transform: rotate(0deg); 13 | } 14 | 100% { 15 | -webkit-transform: rotate(359deg); 16 | transform: rotate(359deg); 17 | } 18 | } 19 | 20 | @keyframes fa-spin { 21 | 0% { 22 | -webkit-transform: rotate(0deg); 23 | transform: rotate(0deg); 24 | } 25 | 100% { 26 | -webkit-transform: rotate(359deg); 27 | transform: rotate(359deg); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/less/stacked.less: -------------------------------------------------------------------------------- 1 | // Stacked Icons 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix}-stack { 5 | position: relative; 6 | display: inline-block; 7 | width: 2em; 8 | height: 2em; 9 | line-height: 2em; 10 | vertical-align: middle; 11 | } 12 | .@{fa-css-prefix}-stack-1x, .@{fa-css-prefix}-stack-2x { 13 | position: absolute; 14 | left: 0; 15 | width: 100%; 16 | text-align: center; 17 | } 18 | .@{fa-css-prefix}-stack-1x { line-height: inherit; } 19 | .@{fa-css-prefix}-stack-2x { font-size: 2em; } 20 | .@{fa-css-prefix}-inverse { color: @fa-inverse; } 21 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/scss/_bordered-pulled.scss: -------------------------------------------------------------------------------- 1 | // Bordered & Pulled 2 | // ------------------------- 3 | 4 | .#{$fa-css-prefix}-border { 5 | padding: .2em .25em .15em; 6 | border: solid .08em $fa-border-color; 7 | border-radius: .1em; 8 | } 9 | 10 | .pull-right { float: right; } 11 | .pull-left { float: left; } 12 | 13 | .#{$fa-css-prefix} { 14 | &.pull-left { margin-right: .3em; } 15 | &.pull-right { margin-left: .3em; } 16 | } 17 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/scss/_core.scss: -------------------------------------------------------------------------------- 1 | // Base Class Definition 2 | // ------------------------- 3 | 4 | .#{$fa-css-prefix} { 5 | display: inline-block; 6 | font: normal normal normal 14px/1 FontAwesome; // shortening font declaration 7 | font-size: inherit; // can't have font-size inherit on line above, so need to override 8 | text-rendering: auto; // optimizelegibility throws things off #1094 9 | -webkit-font-smoothing: antialiased; 10 | -moz-osx-font-smoothing: grayscale; 11 | } 12 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/scss/_fixed-width.scss: -------------------------------------------------------------------------------- 1 | // Fixed Width Icons 2 | // ------------------------- 3 | .#{$fa-css-prefix}-fw { 4 | width: (18em / 14); 5 | text-align: center; 6 | } 7 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/scss/_larger.scss: -------------------------------------------------------------------------------- 1 | // Icon Sizes 2 | // ------------------------- 3 | 4 | /* makes the font 33% larger relative to the icon container */ 5 | .#{$fa-css-prefix}-lg { 6 | font-size: (4em / 3); 7 | line-height: (3em / 4); 8 | vertical-align: -15%; 9 | } 10 | .#{$fa-css-prefix}-2x { font-size: 2em; } 11 | .#{$fa-css-prefix}-3x { font-size: 3em; } 12 | .#{$fa-css-prefix}-4x { font-size: 4em; } 13 | .#{$fa-css-prefix}-5x { font-size: 5em; } 14 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/scss/_list.scss: -------------------------------------------------------------------------------- 1 | // List Icons 2 | // ------------------------- 3 | 4 | .#{$fa-css-prefix}-ul { 5 | padding-left: 0; 6 | margin-left: $fa-li-width; 7 | list-style-type: none; 8 | > li { position: relative; } 9 | } 10 | .#{$fa-css-prefix}-li { 11 | position: absolute; 12 | left: -$fa-li-width; 13 | width: $fa-li-width; 14 | top: (2em / 14); 15 | text-align: center; 16 | &.#{$fa-css-prefix}-lg { 17 | left: -$fa-li-width + (4em / 14); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/scss/_mixins.scss: -------------------------------------------------------------------------------- 1 | // Mixins 2 | // -------------------------- 3 | 4 | @mixin fa-icon() { 5 | display: inline-block; 6 | font: normal normal normal 14px/1 FontAwesome; // shortening font declaration 7 | font-size: inherit; // can't have font-size inherit on line above, so need to override 8 | text-rendering: auto; // optimizelegibility throws things off #1094 9 | -webkit-font-smoothing: antialiased; 10 | -moz-osx-font-smoothing: grayscale; 11 | } 12 | 13 | @mixin fa-icon-rotate($degrees, $rotation) { 14 | filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=#{$rotation}); 15 | -webkit-transform: rotate($degrees); 16 | -ms-transform: rotate($degrees); 17 | transform: rotate($degrees); 18 | } 19 | 20 | @mixin fa-icon-flip($horiz, $vert, $rotation) { 21 | filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=#{$rotation}); 22 | -webkit-transform: scale($horiz, $vert); 23 | -ms-transform: scale($horiz, $vert); 24 | transform: scale($horiz, $vert); 25 | } 26 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/scss/_path.scss: -------------------------------------------------------------------------------- 1 | /* FONT PATH 2 | * -------------------------- */ 3 | 4 | @font-face { 5 | font-family: 'FontAwesome'; 6 | src: url('#{$fa-font-path}/fontawesome-webfont.eot?v=#{$fa-version}'); 7 | src: url('#{$fa-font-path}/fontawesome-webfont.eot?#iefix&v=#{$fa-version}') format('embedded-opentype'), 8 | url('#{$fa-font-path}/fontawesome-webfont.woff?v=#{$fa-version}') format('woff'), 9 | url('#{$fa-font-path}/fontawesome-webfont.ttf?v=#{$fa-version}') format('truetype'), 10 | url('#{$fa-font-path}/fontawesome-webfont.svg?v=#{$fa-version}#fontawesomeregular') format('svg'); 11 | //src: url('#{$fa-font-path}/FontAwesome.otf') format('opentype'); // used when developing fonts 12 | font-weight: normal; 13 | font-style: normal; 14 | } 15 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/scss/_rotated-flipped.scss: -------------------------------------------------------------------------------- 1 | // Rotated & Flipped Icons 2 | // ------------------------- 3 | 4 | .#{$fa-css-prefix}-rotate-90 { @include fa-icon-rotate(90deg, 1); } 5 | .#{$fa-css-prefix}-rotate-180 { @include fa-icon-rotate(180deg, 2); } 6 | .#{$fa-css-prefix}-rotate-270 { @include fa-icon-rotate(270deg, 3); } 7 | 8 | .#{$fa-css-prefix}-flip-horizontal { @include fa-icon-flip(-1, 1, 0); } 9 | .#{$fa-css-prefix}-flip-vertical { @include fa-icon-flip(1, -1, 2); } 10 | 11 | // Hook for IE8-9 12 | // ------------------------- 13 | 14 | :root .#{$fa-css-prefix}-rotate-90, 15 | :root .#{$fa-css-prefix}-rotate-180, 16 | :root .#{$fa-css-prefix}-rotate-270, 17 | :root .#{$fa-css-prefix}-flip-horizontal, 18 | :root .#{$fa-css-prefix}-flip-vertical { 19 | filter: none; 20 | } 21 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/scss/_spinning.scss: -------------------------------------------------------------------------------- 1 | // Spinning Icons 2 | // -------------------------- 3 | 4 | .#{$fa-css-prefix}-spin { 5 | -webkit-animation: fa-spin 2s infinite linear; 6 | animation: fa-spin 2s infinite linear; 7 | } 8 | 9 | @-webkit-keyframes fa-spin { 10 | 0% { 11 | -webkit-transform: rotate(0deg); 12 | transform: rotate(0deg); 13 | } 14 | 100% { 15 | -webkit-transform: rotate(359deg); 16 | transform: rotate(359deg); 17 | } 18 | } 19 | 20 | @keyframes fa-spin { 21 | 0% { 22 | -webkit-transform: rotate(0deg); 23 | transform: rotate(0deg); 24 | } 25 | 100% { 26 | -webkit-transform: rotate(359deg); 27 | transform: rotate(359deg); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/scss/_stacked.scss: -------------------------------------------------------------------------------- 1 | // Stacked Icons 2 | // ------------------------- 3 | 4 | .#{$fa-css-prefix}-stack { 5 | position: relative; 6 | display: inline-block; 7 | width: 2em; 8 | height: 2em; 9 | line-height: 2em; 10 | vertical-align: middle; 11 | } 12 | .#{$fa-css-prefix}-stack-1x, .#{$fa-css-prefix}-stack-2x { 13 | position: absolute; 14 | left: 0; 15 | width: 100%; 16 | text-align: center; 17 | } 18 | .#{$fa-css-prefix}-stack-1x { line-height: inherit; } 19 | .#{$fa-css-prefix}-stack-2x { font-size: 2em; } 20 | .#{$fa-css-prefix}-inverse { color: $fa-inverse; } 21 | -------------------------------------------------------------------------------- /doc/gt_theme/static/font-awesome-4.2.0/scss/font-awesome.scss: -------------------------------------------------------------------------------- 1 | /*! 2 | * Font Awesome 4.2.0 by @davegandy - http://fontawesome.io - @fontawesome 3 | * License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License) 4 | */ 5 | 6 | @import "variables"; 7 | @import "mixins"; 8 | @import "path"; 9 | @import "core"; 10 | @import "larger"; 11 | @import "fixed-width"; 12 | @import "list"; 13 | @import "bordered-pulled"; 14 | @import "spinning"; 15 | @import "rotated-flipped"; 16 | @import "stacked"; 17 | @import "icons"; 18 | -------------------------------------------------------------------------------- /doc/gt_theme/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = nature 3 | stylesheet = gt_style.css 4 | pygments_style = tango 5 | -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to graph-tool's documentation! 2 | ====================================== 3 | 4 | Contents: 5 | 6 | .. toctree:: 7 | :maxdepth: 3 8 | :glob: 9 | 10 | quickstart 11 | gt_format 12 | demos/index 13 | modules 14 | faq 15 | 16 | Indexes and tables 17 | ================== 18 | 19 | * :ref:`genindex` 20 | * :ref:`modindex` 21 | * :ref:`search` 22 | -------------------------------------------------------------------------------- /doc/mathjax.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | sphinx.ext.mathjax 4 | ~~~~~~~~~~~~~~~~~~ 5 | 6 | Set up everything for use of MathJax (http://www.mathjax.org/) 7 | to display math in HTML via JavaScript. 8 | 9 | (c) Kevin Dunn, http://connectmv.com 10 | :license: BSD, see LICENSE for details. 11 | """ 12 | 13 | from docutils import nodes 14 | 15 | from sphinx.application import ExtensionError 16 | from sphinx.ext.mathbase import setup_math as mathbase_setup 17 | 18 | def html_visit_math(self, node): 19 | self.body.append(self.starttag(node, 'span', '', CLASS='math')) 20 | self.body.append(self.builder.config.mathjax_inline[0] + \ 21 | self.encode(node['latex']) +\ 22 | self.builder.config.mathjax_inline[1] + '') 23 | raise nodes.SkipNode 24 | 25 | def html_visit_displaymath(self, node): 26 | self.body.append(self.starttag(node, 'div', CLASS='math')) 27 | if node['nowrap']: 28 | self.body.append(self.builder.config.mathjax_display[0] + \ 29 | node['latex'] +\ 30 | self.builder.config.mathjax_display[1]) 31 | self.body.append('') 32 | raise nodes.SkipNode 33 | 34 | parts = [prt for prt in node['latex'].split('\n\n') if prt.strip() != ''] 35 | for i, part in enumerate(parts): 36 | part = self.encode(part) 37 | if i == 0: 38 | # necessary to e.g. set the id property correctly 39 | if node['number']: 40 | self.body.append('(%s)' % 41 | node['number']) 42 | if '&' in part or '\\\\' in part: 43 | self.body.append(self.builder.config.mathjax_display[0] + \ 44 | '\\begin{split}' + part + '\\end{split}' + \ 45 | self.builder.config.mathjax_display[1]) 46 | else: 47 | self.body.append(self.builder.config.mathjax_display[0] + part + \ 48 | self.builder.config.mathjax_display[1]) 49 | self.body.append('\n') 50 | raise nodes.SkipNode 51 | 52 | def builder_inited(app): 53 | if not app.config.mathjax_path: 54 | raise ExtensionError('mathjax_path config value must be set for the ' 55 | 'mathjax extension to work') 56 | app.add_javascript(app.config.mathjax_path) 57 | 58 | 59 | def setup(app): 60 | mathbase_setup(app, (html_visit_math, None), (html_visit_displaymath, None)) 61 | app.add_config_value('mathjax_path', '', False) 62 | app.add_config_value('mathjax_inline', [r'\(', r'\)'], 'html') 63 | app.add_config_value('mathjax_display', [r'\[', r'\]'], 'html') 64 | app.connect('builder-inited', builder_inited) 65 | -------------------------------------------------------------------------------- /doc/mincut-example.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/doc/mincut-example.xml.gz -------------------------------------------------------------------------------- /doc/modules.rst: -------------------------------------------------------------------------------- 1 | Module documentation 2 | ==================== 3 | 4 | .. toctree:: 5 | 6 | graph_tool 7 | -------------------------------------------------------------------------------- /doc/pyenv.py: -------------------------------------------------------------------------------- 1 | from matplotlib import rc 2 | from matplotlib import rcParams 3 | 4 | font_size=14 5 | rcParams["backend"] = "PDF" 6 | rcParams["figure.figsize"] = (4, 3) 7 | rcParams["font.family"] = "Serif" 8 | rcParams["font.serif"] = ["Palatino"] 9 | rcParams["font.size"] = font_size 10 | rcParams["axes.labelsize"] = font_size 11 | rcParams["xtick.labelsize"] = font_size - 2 12 | rcParams["ytick.labelsize"] = font_size - 2 13 | rcParams["legend.numpoints"] = 1 14 | rcParams["legend.fontsize"] = "small" 15 | rcParams["lines.markersize"] = 4 16 | rcParams["figure.subplot.right"] = 0.95 17 | rcParams["figure.subplot.top"] = 0.95 18 | rcParams["figure.subplot.right"] = 0.95 19 | rcParams["figure.subplot.top"] = 0.95 20 | rcParams["figure.subplot.left"] = 0.2 21 | rcParams["figure.subplot.bottom"] = 0.2 22 | 23 | rcParams["image.cmap"] = "hot" 24 | 25 | rcParams["text.usetex"] = True 26 | 27 | rcParams["ps.usedistiller"] = "xpdf" 28 | rcParams["pdf.compression"] = 9 29 | rcParams["ps.useafm"] = True 30 | rcParams["path.simplify"] = True 31 | rcParams["text.latex.preamble"] = [#"\usepackage{times}", 32 | #"\usepackage{euler}", 33 | r"\usepackage{amssymb}", 34 | r"\usepackage{amsmath}"] 35 | 36 | from numpy import * 37 | import scipy 38 | import scipy.stats 39 | from math import * 40 | import numpy as np 41 | import graph_tool.all as gt 42 | -------------------------------------------------------------------------------- /doc/run_action.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.run_action 2 | :members: 3 | :undoc-members: 4 | -------------------------------------------------------------------------------- /doc/search_module.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.search 2 | :members: 3 | :undoc-members: 4 | -------------------------------------------------------------------------------- /doc/spectral.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.spectral 2 | :members: 3 | :undoc-members: 4 | -------------------------------------------------------------------------------- /doc/sphinxext/MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include tests *.py 2 | include *.txt 3 | -------------------------------------------------------------------------------- /doc/sphinxext/README.txt: -------------------------------------------------------------------------------- 1 | ===================================== 2 | numpydoc -- Numpy's Sphinx extensions 3 | ===================================== 4 | 5 | Numpy's documentation uses several custom extensions to Sphinx. These 6 | are shipped in this ``numpydoc`` package, in case you want to make use 7 | of them in third-party projects. 8 | 9 | The following extensions are available: 10 | 11 | - ``numpydoc``: support for the Numpy docstring format in Sphinx, and add 12 | the code description directives ``np:function``, ``np-c:function``, etc. 13 | that support the Numpy docstring syntax. 14 | 15 | - ``numpydoc.traitsdoc``: For gathering documentation about Traits attributes. 16 | 17 | - ``numpydoc.plot_directive``: Adaptation of Matplotlib's ``plot::`` 18 | directive. Note that this implementation may still undergo severe 19 | changes or eventually be deprecated. 20 | 21 | 22 | numpydoc 23 | ======== 24 | 25 | Numpydoc inserts a hook into Sphinx's autodoc that converts docstrings 26 | following the Numpy/Scipy format to a form palatable to Sphinx. 27 | 28 | Options 29 | ------- 30 | 31 | The following options can be set in conf.py: 32 | 33 | - numpydoc_use_plots: bool 34 | 35 | Whether to produce ``plot::`` directives for Examples sections that 36 | contain ``import matplotlib``. 37 | 38 | - numpydoc_show_class_members: bool 39 | 40 | Whether to show all members of a class in the Methods and Attributes 41 | sections automatically. 42 | 43 | - numpydoc_edit_link: bool (DEPRECATED -- edit your HTML template instead) 44 | 45 | Whether to insert an edit link after docstrings. 46 | -------------------------------------------------------------------------------- /doc/sphinxext/__init__.py: -------------------------------------------------------------------------------- 1 | from .numpydoc import setup 2 | -------------------------------------------------------------------------------- /doc/sphinxext/linkcode.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | linkcode 4 | ~~~~~~~~ 5 | 6 | Add external links to module code in Python object descriptions. 7 | 8 | :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. 9 | :license: BSD, see LICENSE for details. 10 | """ 11 | 12 | import warnings 13 | import collections 14 | warnings.warn("This extension has been submitted to Sphinx upstream. " 15 | "Use the version from there if it is accepted " 16 | "https://bitbucket.org/birkenfeld/sphinx/pull-request/47/sphinxextlinkcode", 17 | FutureWarning, stacklevel=1) 18 | 19 | 20 | from docutils import nodes 21 | 22 | from sphinx import addnodes 23 | from sphinx.locale import _ 24 | from sphinx.errors import SphinxError 25 | 26 | class LinkcodeError(SphinxError): 27 | category = "linkcode error" 28 | 29 | def doctree_read(app, doctree): 30 | env = app.builder.env 31 | 32 | resolve_target = getattr(env.config, 'linkcode_resolve', None) 33 | if not isinstance(env.config.linkcode_resolve, collections.Callable): 34 | raise LinkcodeError( 35 | "Function `linkcode_resolve` is not given in conf.py") 36 | 37 | domain_keys = dict( 38 | py=['module', 'fullname'], 39 | c=['names'], 40 | cpp=['names'], 41 | js=['object', 'fullname'], 42 | ) 43 | 44 | for objnode in doctree.traverse(addnodes.desc): 45 | domain = objnode.get('domain') 46 | uris = set() 47 | for signode in objnode: 48 | if not isinstance(signode, addnodes.desc_signature): 49 | continue 50 | 51 | # Convert signode to a specified format 52 | info = {} 53 | for key in domain_keys.get(domain, []): 54 | value = signode.get(key) 55 | if not value: 56 | value = '' 57 | info[key] = value 58 | if not info: 59 | continue 60 | 61 | # Call user code to resolve the link 62 | uri = resolve_target(domain, info) 63 | if not uri: 64 | # no source 65 | continue 66 | 67 | if uri in uris or not uri: 68 | # only one link per name, please 69 | continue 70 | uris.add(uri) 71 | 72 | onlynode = addnodes.only(expr='html') 73 | onlynode += nodes.reference('', '', internal=False, refuri=uri) 74 | onlynode[0] += nodes.inline('', _('[source]'), 75 | classes=['viewcode-link']) 76 | signode += onlynode 77 | 78 | def setup(app): 79 | app.connect('doctree-read', doctree_read) 80 | app.add_config_value('linkcode_resolve', None, 'env') 81 | -------------------------------------------------------------------------------- /doc/sphinxext/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | 3 | version = "0.4" 4 | 5 | setup( 6 | name="numpydoc", 7 | packages=["numpydoc"], 8 | package_dir={"numpydoc": "."}, 9 | version=version, 10 | description="Sphinx extension to support docstrings in Numpy format", 11 | # classifiers from http://pypi.python.org/pypi?%3Aaction=list_classifiers 12 | classifiers=["Development Status :: 3 - Alpha", 13 | "Environment :: Plugins", 14 | "License :: OSI Approved :: BSD License", 15 | "Topic :: Documentation"], 16 | keywords="sphinx numpy", 17 | author="Pauli Virtanen and others", 18 | author_email="pav@iki.fi", 19 | url="http://github.com/numpy/numpy/tree/master/doc/sphinxext", 20 | license="BSD", 21 | requires=["sphinx (>= 1.0.1)"], 22 | package_data={'numpydoc': ['tests/test_*.py']}, 23 | ) 24 | -------------------------------------------------------------------------------- /doc/stats.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.stats 2 | :members: 3 | :undoc-members: 4 | -------------------------------------------------------------------------------- /doc/topology.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.topology 2 | :members: 3 | :undoc-members: 4 | -------------------------------------------------------------------------------- /doc/util.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: graph_tool.util 2 | :members: 3 | :undoc-members: 4 | -------------------------------------------------------------------------------- /m4/ax_python_module.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_python_module.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_PYTHON_MODULE(modname[, fatal]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Checks for Python module. 12 | # 13 | # If fatal is non-empty then absence of a module will trigger an error. 14 | # 15 | # LICENSE 16 | # 17 | # Copyright (c) 2008 Andrew Collier 18 | # 19 | # Copying and distribution of this file, with or without modification, are 20 | # permitted in any medium without royalty provided the copyright notice 21 | # and this notice are preserved. This file is offered as-is, without any 22 | # warranty. 23 | 24 | #serial 5 25 | 26 | AU_ALIAS([AC_PYTHON_MODULE], [AX_PYTHON_MODULE]) 27 | AC_DEFUN([AX_PYTHON_MODULE],[ 28 | if test -z $PYTHON; 29 | then 30 | PYTHON="python" 31 | fi 32 | PYTHON_NAME=`basename $PYTHON` 33 | AC_MSG_CHECKING($PYTHON_NAME module: $1) 34 | $PYTHON -c "import $1" 2>/dev/null 35 | if test $? -eq 0; 36 | then 37 | AC_MSG_RESULT(yes) 38 | eval AS_TR_CPP(HAVE_PYMOD_$1)=yes 39 | else 40 | AC_MSG_RESULT(no) 41 | eval AS_TR_CPP(HAVE_PYMOD_$1)=no 42 | # 43 | if test -n "$2" 44 | then 45 | AC_MSG_ERROR(failed to find required module $1) 46 | exit 1 47 | fi 48 | fi 49 | ]) 50 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AUTOMAKE_OPTIONS = subdir-objects 4 | 5 | SUBDIRS = graph graph_tool . 6 | 7 | -------------------------------------------------------------------------------- /src/boost-workaround/LICENSE_1_0.txt: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /src/boost-workaround/boost/graph/overloading.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2004 The Trustees of Indiana University. 2 | 3 | // Use, modification and distribution is subject to the Boost Software 4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | // Authors: Douglas Gregor 8 | // Andrew Lumsdaine 9 | 10 | // 11 | // This file contains helps that enable concept-based overloading 12 | // within the Boost Graph Library. 13 | // 14 | #ifndef BOOST_GRAPH_OVERLOADING_HPP 15 | #define BOOST_GRAPH_OVERLOADING_HPP 16 | 17 | #include 18 | #include 19 | 20 | namespace boost { namespace graph { namespace detail { 21 | 22 | struct no_parameter {}; 23 | 24 | } } } // end namespace boost::graph::detail 25 | 26 | #ifndef BOOST_NO_SFINAE 27 | 28 | #define BOOST_GRAPH_ENABLE_IF_MODELS(Graph, Tag, Type) \ 29 | typename enable_if_c<(is_base_and_derived< \ 30 | Tag, \ 31 | typename graph_traits::traversal_category>::value), \ 32 | Type>::type 33 | 34 | #define BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph, Tag) \ 35 | , BOOST_GRAPH_ENABLE_IF_MODELS(Graph, Tag, \ 36 | ::boost::graph::detail::no_parameter) \ 37 | = ::boost::graph::detail::no_parameter() 38 | 39 | #else 40 | 41 | #define BOOST_GRAPH_ENABLE_IF_MODELS(Graph, Tag, Type) Type 42 | #define BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph, Tag) 43 | 44 | #endif // no SFINAE support 45 | 46 | #endif // BOOST_GRAPH_OVERLOADING_HPP 47 | -------------------------------------------------------------------------------- /src/graph/base64.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | 19 | #include "base64.hh" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | std::string base64_encode(const std::string& s) 28 | { 29 | static const std::string base64_padding[] = {"", "==","="}; 30 | namespace bai = boost::archive::iterators; 31 | std::stringstream os; 32 | typedef bai::base64_from_binary > 33 | base64_enc; 34 | std::copy(base64_enc(s.c_str()), base64_enc(s.c_str() + s.size()), 35 | std::ostream_iterator(os)); 36 | os << base64_padding[s.size() % 3]; 37 | return os.str(); 38 | } 39 | 40 | std::string base64_decode(const std::string& s) 41 | { 42 | namespace bai = boost::archive::iterators; 43 | std::stringstream os; 44 | 45 | typedef bai::transform_width, 8, 6> base64_dec; 46 | 47 | unsigned int size = s.size(); 48 | 49 | // Remove the padding characters, cf. https://svn.boost.org/trac/boost/ticket/5629 50 | if (size && s[size - 1] == '=') 51 | { 52 | --size; 53 | if (size && s[size - 1] == '=') 54 | --size; 55 | } 56 | if (size == 0) 57 | return std::string(); 58 | 59 | std::copy(base64_dec(s.data()), base64_dec(s.data() + size), 60 | std::ostream_iterator(os)); 61 | 62 | return os.str(); 63 | } 64 | -------------------------------------------------------------------------------- /src/graph/base64.hh: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #ifndef BASE64_HH 19 | #define BASE64_HH 20 | 21 | #include 22 | 23 | std::string base64_encode(const std::string& s); 24 | std::string base64_decode(const std::string& s); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/graph/centrality/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) 4 | 5 | AM_CFLAGS=$(AM_CXXFLAGS) 6 | 7 | libgraph_tool_centralitydir = $(MOD_DIR)/centrality 8 | 9 | libgraph_tool_centrality_LTLIBRARIES = libgraph_tool_centrality.la 10 | 11 | libgraph_tool_centrality_la_includedir = $(MOD_DIR)/include/centrality 12 | 13 | libgraph_tool_centrality_la_LIBADD = $(MOD_LIBADD) 14 | 15 | libgraph_tool_centrality_la_LDFLAGS = $(MOD_LDFLAGS) 16 | 17 | libgraph_tool_centrality_la_SOURCES = \ 18 | graph_betweenness.cc \ 19 | graph_centrality_bind.cc \ 20 | graph_closeness.cc \ 21 | graph_eigentrust.cc \ 22 | graph_eigenvector.cc \ 23 | graph_hits.cc \ 24 | graph_katz.cc \ 25 | graph_pagerank.cc \ 26 | graph_trust_transitivity.cc 27 | 28 | libgraph_tool_centrality_la_include_HEADERS = \ 29 | graph_closeness.hh \ 30 | graph_eigentrust.hh \ 31 | graph_eigenvector.hh \ 32 | graph_pagerank.hh \ 33 | graph_hits.hh \ 34 | graph_katz.hh \ 35 | graph_trust_transitivity.hh \ 36 | minmax.hh 37 | -------------------------------------------------------------------------------- /src/graph/centrality/graph_centrality_bind.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | 20 | using namespace boost; 21 | 22 | void export_betweenness(); 23 | void export_closeness(); 24 | void export_eigentrust(); 25 | void export_eigenvector(); 26 | void export_hits(); 27 | void export_katz(); 28 | void export_trust_transitivity(); 29 | void export_pagerank(); 30 | 31 | BOOST_PYTHON_MODULE(libgraph_tool_centrality) 32 | { 33 | export_betweenness(); 34 | export_closeness(); 35 | export_eigentrust(); 36 | export_eigenvector(); 37 | export_hits(); 38 | export_katz(); 39 | export_trust_transitivity(); 40 | export_pagerank(); 41 | } 42 | -------------------------------------------------------------------------------- /src/graph/centrality/graph_closeness.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | #include "graph.hh" 20 | #include "graph_selectors.hh" 21 | #include "graph_properties.hh" 22 | 23 | #include "graph_closeness.hh" 24 | 25 | #include 26 | 27 | using namespace std; 28 | using namespace graph_tool; 29 | 30 | void do_get_closeness(GraphInterface& gi, boost::any weight, 31 | boost::any closeness, bool harmonic, bool norm) 32 | { 33 | if (weight.empty()) 34 | { 35 | run_action<>()(gi, 36 | std::bind(get_closeness(), placeholders::_1, 37 | gi.GetVertexIndex(), no_weightS(), 38 | placeholders::_2, harmonic, norm), 39 | writable_vertex_scalar_properties())(closeness); 40 | } 41 | else 42 | { 43 | run_action<>()(gi, 44 | std::bind(get_closeness(), placeholders::_1, 45 | gi.GetVertexIndex(), placeholders::_2, 46 | placeholders::_3, harmonic, norm), 47 | edge_scalar_properties(), 48 | writable_vertex_scalar_properties())(weight, closeness); 49 | } 50 | } 51 | 52 | void export_closeness() 53 | { 54 | boost::python::def("closeness", &do_get_closeness); 55 | } 56 | -------------------------------------------------------------------------------- /src/graph/centrality/graph_eigentrust.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | 20 | #include 21 | 22 | #include "graph.hh" 23 | #include "graph_selectors.hh" 24 | #include "graph_eigentrust.hh" 25 | 26 | using namespace std; 27 | using namespace graph_tool; 28 | 29 | size_t eigentrust(GraphInterface& g, boost::any c, boost::any t, 30 | double epslon, size_t max_iter) 31 | { 32 | if (!belongs()(c)) 33 | throw ValueException("edge property must be writable"); 34 | if (!belongs()(t)) 35 | throw ValueException("vertex property must be of floating point" 36 | " value type"); 37 | 38 | size_t iter = 0; 39 | run_action<>() 40 | (g, bind(get_eigentrust(), 41 | _1, g.GetVertexIndex(), g.GetEdgeIndex(), _2, 42 | _3, epslon, max_iter, ref(iter)), 43 | writable_edge_scalar_properties(), 44 | vertex_floating_properties())(c,t); 45 | return iter; 46 | } 47 | 48 | void export_eigentrust() 49 | { 50 | using namespace boost::python; 51 | def("get_eigentrust", &eigentrust); 52 | } 53 | -------------------------------------------------------------------------------- /src/graph/centrality/graph_eigenvector.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | 20 | #include "graph.hh" 21 | #include "graph_selectors.hh" 22 | #include "graph_eigenvector.hh" 23 | 24 | using namespace std; 25 | using namespace graph_tool; 26 | 27 | long double eigenvector(GraphInterface& g, boost::any w, boost::any c, 28 | double epsilon, size_t max_iter) 29 | { 30 | if (!w.empty() && !belongs()(w)) 31 | throw ValueException("edge property must be writable"); 32 | if (!belongs()(c)) 33 | throw ValueException("vertex property must be of floating point" 34 | " value type"); 35 | 36 | typedef ConstantPropertyMap weight_map_t; 37 | typedef boost::mpl::push_back::type 38 | weight_props_t; 39 | 40 | if(w.empty()) 41 | w = weight_map_t(1); 42 | 43 | long double eig = 0; 44 | run_action<>() 45 | (g, std::bind(get_eigenvector(), placeholders::_1, g.GetVertexIndex(), 46 | placeholders::_2, placeholders::_3, epsilon, max_iter, 47 | std::ref(eig)), 48 | weight_props_t(), 49 | vertex_floating_properties())(w, c); 50 | return eig; 51 | } 52 | 53 | #include 54 | 55 | void export_eigenvector() 56 | { 57 | using namespace boost::python; 58 | def("get_eigenvector", &eigenvector); 59 | } 60 | -------------------------------------------------------------------------------- /src/graph/centrality/graph_katz.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | 20 | #include 21 | 22 | #include "graph.hh" 23 | #include "graph_selectors.hh" 24 | #include "graph_katz.hh" 25 | 26 | using namespace std; 27 | using namespace boost; 28 | using namespace graph_tool; 29 | 30 | void katz(GraphInterface& g, boost::any w, boost::any c, boost::any beta, 31 | long double alpha, double epsilon, size_t max_iter) 32 | { 33 | if (!w.empty() && !belongs()(w)) 34 | throw ValueException("edge property must be writable"); 35 | if (!belongs()(c)) 36 | throw ValueException("centrality vertex property must be of floating point" 37 | " value type"); 38 | if (!beta.empty() && !belongs()(beta)) 39 | throw ValueException("personalization vertex property must be of floating point" 40 | " value type"); 41 | 42 | typedef ConstantPropertyMap weight_map_t; 43 | typedef boost::mpl::push_back::type 44 | weight_props_t; 45 | 46 | if(w.empty()) 47 | w = weight_map_t(1.); 48 | 49 | typedef ConstantPropertyMap beta_map_t; 50 | typedef boost::mpl::push_back::type 51 | beta_props_t; 52 | 53 | if(beta.empty()) 54 | beta = beta_map_t(1.); 55 | 56 | run_action<>()(g, std::bind(get_katz(), placeholders::_1, g.GetVertexIndex(), 57 | placeholders::_2, placeholders::_3, 58 | placeholders::_4, alpha, epsilon, max_iter), 59 | weight_props_t(), 60 | vertex_floating_properties(), 61 | beta_props_t())(w, c, beta); 62 | } 63 | 64 | void export_katz() 65 | { 66 | using namespace boost::python; 67 | def("get_katz", &katz); 68 | } 69 | -------------------------------------------------------------------------------- /src/graph/centrality/graph_pagerank.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | 20 | #include 21 | #include 22 | 23 | #include "graph.hh" 24 | #include "graph_selectors.hh" 25 | #include "graph_pagerank.hh" 26 | 27 | using namespace std; 28 | using namespace boost; 29 | using namespace graph_tool; 30 | 31 | size_t pagerank(GraphInterface& g, boost::any rank, boost::any pers, 32 | boost::any weight, double d, double epsilon, size_t max_iter) 33 | { 34 | if (!belongs()(rank)) 35 | throw ValueException("rank vertex property must have a floating-point value type"); 36 | 37 | if (!pers.empty() && !belongs()(pers)) 38 | throw ValueException("personalization vertex property must have a scalar value type"); 39 | 40 | typedef ConstantPropertyMap pers_map_t; 41 | typedef boost::mpl::push_back::type 42 | pers_props_t; 43 | 44 | if(pers.empty()) 45 | pers = pers_map_t(1.0 / g.GetNumberOfVertices()); 46 | 47 | typedef ConstantPropertyMap weight_map_t; 48 | typedef boost::mpl::push_back::type 49 | weight_props_t; 50 | 51 | if (!weight.empty() && !belongs()(weight)) 52 | throw ValueException("weight edge property must have a scalar value type"); 53 | 54 | if(weight.empty()) 55 | weight = weight_map_t(1.0); 56 | 57 | size_t iter; 58 | run_action<>() 59 | (g, std::bind(get_pagerank(), 60 | placeholders::_1, g.GetVertexIndex(), placeholders::_2, 61 | placeholders::_3, placeholders::_4, d, 62 | epsilon, max_iter, std::ref(iter)), 63 | vertex_floating_properties(), 64 | pers_props_t(), weight_props_t())(rank, pers, weight); 65 | return iter; 66 | } 67 | 68 | 69 | void export_pagerank() 70 | { 71 | using namespace boost::python; 72 | def("get_pagerank", &pagerank); 73 | } 74 | -------------------------------------------------------------------------------- /src/graph/centrality/graph_trust_transitivity.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | 20 | #include 21 | 22 | #include "graph.hh" 23 | #include "graph_selectors.hh" 24 | 25 | #include "graph_trust_transitivity.hh" 26 | 27 | using namespace std; 28 | using namespace boost; 29 | using namespace graph_tool; 30 | 31 | void trust_transitivity(GraphInterface& g, int64_t source, int64_t target, 32 | boost::any c, boost::any t) 33 | { 34 | if (!belongs()(c)) 35 | throw ValueException("edge property must be of floating point value type"); 36 | if (!belongs()(t)) 37 | throw ValueException("vertex property must be of floating point valued vector type"); 38 | 39 | run_action<>()(g, 40 | bind(get_trust_transitivity(), _1, g.GetVertexIndex(), 41 | source, target, _2, _3), 42 | edge_floating_properties(), 43 | vertex_floating_vector_properties())(c,t); 44 | } 45 | 46 | void export_trust_transitivity() 47 | { 48 | using namespace boost::python; 49 | def("get_trust_transitivity", &trust_transitivity); 50 | } 51 | -------------------------------------------------------------------------------- /src/graph/clustering/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) 4 | 5 | AM_CFLAGS = $(AM_CXXFLAGS) 6 | 7 | libgraph_tool_clusteringdir = $(MOD_DIR)/clustering 8 | 9 | libgraph_tool_clustering_LTLIBRARIES = libgraph_tool_clustering.la 10 | 11 | libgraph_tool_clustering_la_includedir = $(MOD_DIR)/include/clustering 12 | 13 | libgraph_tool_clustering_la_LIBADD = $(MOD_LIBADD) 14 | 15 | libgraph_tool_clustering_la_LDFLAGS = $(MOD_LDFLAGS) 16 | 17 | libgraph_tool_clustering_la_SOURCES = \ 18 | graph_clustering.cc \ 19 | graph_extended_clustering.cc \ 20 | graph_motifs.cc 21 | 22 | libgraph_tool_clustering_la_include_HEADERS = \ 23 | graph_clustering.hh \ 24 | graph_extended_clustering.hh \ 25 | graph_motifs.hh 26 | 27 | -------------------------------------------------------------------------------- /src/graph/clustering/graph_clustering.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | 20 | #include "graph.hh" 21 | #include "graph_selectors.hh" 22 | #include "graph_properties.hh" 23 | 24 | #include "graph_clustering.hh" 25 | 26 | #include "random.hh" 27 | 28 | #include 29 | 30 | using namespace std; 31 | using namespace boost; 32 | using namespace graph_tool; 33 | 34 | boost::python::tuple global_clustering(GraphInterface& g) 35 | { 36 | double c, c_err; 37 | bool directed = g.GetDirected(); 38 | g.SetDirected(false); 39 | run_action() 40 | (g, std::bind(get_global_clustering(), std::placeholders::_1, 41 | std::ref(c), std::ref(c_err)))(); 42 | g.SetDirected(directed); 43 | return boost::python::make_tuple(c, c_err); 44 | } 45 | 46 | void local_clustering(GraphInterface& g, boost::any prop) 47 | { 48 | bool directed = g.GetDirected(); 49 | g.SetDirected(false); 50 | run_action() 51 | (g, std::bind(set_clustering_to_property(), 52 | std::placeholders::_1, 53 | std::placeholders::_2), 54 | writable_vertex_scalar_properties())(prop); 55 | g.SetDirected(directed); 56 | } 57 | 58 | using namespace boost::python; 59 | 60 | void extended_clustering(GraphInterface& g, boost::python::list props); 61 | void get_motifs(GraphInterface& g, size_t k, boost::python::list subgraph_list, 62 | boost::python::list hist, boost::python::list pvmaps, bool collect_vmaps, 63 | boost::python::list p, bool comp_iso, bool fill_list, rng_t& rng); 64 | 65 | BOOST_PYTHON_MODULE(libgraph_tool_clustering) 66 | { 67 | def("global_clustering", &global_clustering); 68 | def("local_clustering", &local_clustering); 69 | def("extended_clustering", &extended_clustering); 70 | def("get_motifs", &get_motifs); 71 | } 72 | -------------------------------------------------------------------------------- /src/graph/community/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) 4 | 5 | AM_CFLAGS=$(AM_CXXFLAGS) 6 | 7 | libgraph_tool_communitydir = $(MOD_DIR)/community 8 | 9 | libgraph_tool_community_LTLIBRARIES = libgraph_tool_community.la 10 | 11 | libgraph_tool_community_la_includedir = $(MOD_DIR)/include/community 12 | 13 | libgraph_tool_community_la_LIBADD = $(MOD_LIBADD) 14 | 15 | libgraph_tool_community_la_LDFLAGS = $(MOD_LDFLAGS) 16 | 17 | libgraph_tool_community_la_SOURCES = \ 18 | graph_blockmodel.cc \ 19 | graph_blockmodel_covariates.cc \ 20 | graph_blockmodel_overlap.cc \ 21 | graph_community.cc \ 22 | graph_community_network.cc \ 23 | graph_community_network_edges.cc \ 24 | graph_community_network_vavg.cc \ 25 | graph_community_network_eavg.cc \ 26 | graph_community_network_eavg_imp1.cc \ 27 | spence.cc 28 | 29 | libgraph_tool_community_la_include_HEADERS = \ 30 | graph_blockmodel.hh \ 31 | graph_blockmodel_covariates.hh \ 32 | graph_blockmodel_overlap.hh \ 33 | graph_community.hh \ 34 | graph_community_network.hh 35 | -------------------------------------------------------------------------------- /src/graph/correlations/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) 4 | AM_CFLAGS = $(AM_CXXFLAGS) 5 | 6 | libgraph_tool_correlationsdir = $(MOD_DIR)/correlations 7 | 8 | libgraph_tool_correlations_LTLIBRARIES = libgraph_tool_correlations.la 9 | 10 | libgraph_tool_correlations_la_includedir = $(MOD_DIR)/include/correlations 11 | 12 | libgraph_tool_correlations_la_LIBADD = $(MOD_LIBADD) 13 | 14 | libgraph_tool_correlations_la_LDFLAGS = $(MOD_LDFLAGS) 15 | 16 | libgraph_tool_correlations_la_SOURCES = \ 17 | graph_assortativity.cc \ 18 | graph_correlations.cc \ 19 | graph_correlations_imp1.cc \ 20 | graph_avg_correlations.cc \ 21 | graph_avg_correlations_imp1.cc \ 22 | graph_avg_correlations_combined.cc \ 23 | graph_correlations_combined.cc \ 24 | graph_correlations_bind.cc 25 | 26 | libgraph_tool_correlations_la_include_HEADERS = \ 27 | graph_assortativity.hh \ 28 | graph_correlations.hh \ 29 | graph_corr_hist.hh \ 30 | graph_avg_correlations.hh 31 | 32 | -------------------------------------------------------------------------------- /src/graph/correlations/graph_assortativity.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | #include "graph_selectors.hh" 20 | #include "graph_properties.hh" 21 | #include "graph.hh" 22 | 23 | #include "graph_assortativity.hh" 24 | 25 | using namespace std; 26 | using namespace graph_tool; 27 | 28 | pair 29 | assortativity_coefficient(GraphInterface& gi, 30 | GraphInterface::deg_t deg) 31 | { 32 | double a, a_err; 33 | run_action<>()(gi,std::bind(get_assortativity_coefficient(), 34 | placeholders::_1, placeholders::_2, 35 | std::ref(a), std::ref(a_err)), 36 | scalar_selectors()) 37 | (degree_selector(deg)); 38 | return make_pair(a, a_err); 39 | } 40 | 41 | pair 42 | scalar_assortativity_coefficient(GraphInterface& gi, 43 | GraphInterface::deg_t deg) 44 | { 45 | double a, a_err; 46 | run_action<>()(gi, std::bind(get_scalar_assortativity_coefficient(), 47 | placeholders::_1, placeholders::_2, 48 | std::ref(a), std::ref(a_err)), 49 | scalar_selectors()) 50 | (degree_selector(deg)); 51 | return make_pair(a, a_err); 52 | } 53 | 54 | #include 55 | 56 | using namespace boost::python; 57 | 58 | void export_assortativity() 59 | { 60 | def("assortativity_coefficient", &assortativity_coefficient); 61 | def("scalar_assortativity_coefficient", &scalar_assortativity_coefficient); 62 | } 63 | -------------------------------------------------------------------------------- /src/graph/correlations/graph_avg_correlations_combined.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | 20 | #include 21 | 22 | #include "graph.hh" 23 | #include "graph_selectors.hh" 24 | #include "graph_properties.hh" 25 | 26 | #include "graph_avg_correlations.hh" 27 | 28 | #include 29 | 30 | using namespace std; 31 | using namespace boost; 32 | using namespace graph_tool; 33 | 34 | typedef ConstantPropertyMap dummy_weight; 35 | 36 | boost::python::object 37 | get_vertex_avg_combined_correlation(GraphInterface& gi, 38 | GraphInterface::deg_t deg1, 39 | GraphInterface::deg_t deg2, 40 | const vector& bins) 41 | { 42 | boost::python::object avg, dev; 43 | boost::python::object ret_bins; 44 | 45 | run_action<>()(gi, get_avg_correlation 46 | (avg, dev, bins, ret_bins), 47 | scalar_selectors(), scalar_selectors(), 48 | boost::mpl::vector()) 49 | (any(degree_selector(deg1)), any(degree_selector(deg2)), 50 | any(dummy_weight())); 51 | return boost::python::make_tuple(avg, dev, ret_bins); 52 | } 53 | 54 | using namespace boost::python; 55 | 56 | void export_avg_combined_correlations() 57 | { 58 | def("vertex_avg_combined_correlation", 59 | &get_vertex_avg_combined_correlation); 60 | } 61 | -------------------------------------------------------------------------------- /src/graph/correlations/graph_avg_correlations_imp1.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | 20 | #include "graph.hh" 21 | #include "histogram.hh" 22 | #include "graph_selectors.hh" 23 | #include "graph_properties.hh" 24 | 25 | #include "graph_avg_correlations.hh" 26 | 27 | using namespace std; 28 | using namespace boost; 29 | using namespace graph_tool; 30 | 31 | void graph_avg_corr_imp1(GraphInterface& g, boost::python::object& avg, 32 | boost::python::object& dev, boost::python::object& ret_bins, 33 | boost::any deg1, boost::any deg2, 34 | boost::any weight, 35 | const vector& bins) 36 | { 37 | typedef DynamicPropertyMapWrap 38 | wrapped_weight_t; 39 | run_action<>()(g, get_avg_correlation 40 | (avg, dev, bins, ret_bins), 41 | scalar_selectors(), scalar_selectors(), 42 | boost::mpl::vector()) 43 | (deg1, deg2, weight); 44 | } 45 | -------------------------------------------------------------------------------- /src/graph/correlations/graph_correlations_bind.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | 20 | using namespace boost; 21 | 22 | void export_assortativity(); 23 | void export_vertex_correlations(); 24 | void export_combined_vertex_correlations(); 25 | void export_avg_correlations(); 26 | void export_avg_combined_correlations(); 27 | 28 | BOOST_PYTHON_MODULE(libgraph_tool_correlations) 29 | { 30 | export_assortativity(); 31 | export_vertex_correlations(); 32 | export_combined_vertex_correlations(); 33 | export_avg_correlations(); 34 | export_avg_combined_correlations(); 35 | } 36 | -------------------------------------------------------------------------------- /src/graph/correlations/graph_correlations_combined.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | 20 | #include 21 | 22 | #include "graph.hh" 23 | #include "histogram.hh" 24 | #include "graph_selectors.hh" 25 | #include "graph_properties.hh" 26 | 27 | #include "graph_corr_hist.hh" 28 | 29 | using namespace std; 30 | using namespace boost; 31 | using namespace graph_tool; 32 | 33 | typedef ConstantPropertyMap dummy_weight; 34 | 35 | boost::python::object 36 | get_vertex_combined_correlation_histogram(GraphInterface& gi, 37 | GraphInterface::deg_t deg1, 38 | GraphInterface::deg_t deg2, 39 | const vector& xbin, 40 | const vector& ybin) 41 | { 42 | boost::python::object hist; 43 | boost::python::object ret_bins; 44 | 45 | std::array,2> bins; 46 | bins[0] = xbin; 47 | bins[1] = ybin; 48 | 49 | run_action<>()(gi, get_correlation_histogram(hist, bins, 50 | ret_bins), 51 | scalar_selectors(), scalar_selectors(), 52 | boost::mpl::vector()) 53 | (any(degree_selector(deg1)), any(degree_selector(deg2)), 54 | boost::any(dummy_weight())); 55 | 56 | return boost::python::make_tuple(hist, ret_bins); 57 | } 58 | 59 | using namespace boost::python; 60 | 61 | void export_combined_vertex_correlations() 62 | { 63 | def("vertex_combined_correlation_histogram", 64 | &get_vertex_combined_correlation_histogram); 65 | } 66 | -------------------------------------------------------------------------------- /src/graph/correlations/graph_correlations_imp1.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | 20 | #include "graph.hh" 21 | #include "histogram.hh" 22 | #include "graph_selectors.hh" 23 | #include "graph_properties.hh" 24 | 25 | #include "graph_corr_hist.hh" 26 | 27 | using namespace std; 28 | using namespace boost; 29 | using namespace graph_tool; 30 | 31 | 32 | void graph_correlations_imp1(GraphInterface& g, boost::python::object& hist, 33 | boost::python::object& ret_bins, 34 | boost::any deg1, boost::any deg2, 35 | boost::any weight, 36 | const std::array,2>& bins) 37 | { 38 | typedef DynamicPropertyMapWrap 39 | wrapped_weight_t; 40 | run_action<>()(g, get_correlation_histogram 41 | (hist, bins, ret_bins), 42 | scalar_selectors(), scalar_selectors(), 43 | boost::mpl::vector()) 44 | (deg1, deg2, weight); 45 | } 46 | -------------------------------------------------------------------------------- /src/graph/draw/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) $(CAIROMM_CFLAGS) 4 | 5 | AM_CFLAGS = $(AM_CXXFLAGS) 6 | 7 | libgraph_tool_drawdir = $(MOD_DIR)/draw 8 | 9 | libgraph_tool_draw_LTLIBRARIES = libgraph_tool_draw.la 10 | 11 | libgraph_tool_draw_la_includedir = $(MOD_DIR)/include/draw 12 | 13 | libgraph_tool_draw_la_LIBADD = $(MOD_LIBADD) 14 | 15 | libgraph_tool_draw_la_LDFLAGS = $(MOD_LDFLAGS) $(CAIROMM_LIBS) 16 | 17 | libgraph_tool_draw_la_SOURCES = \ 18 | graph_cairo_draw.cc \ 19 | graph_tree_cts.cc 20 | 21 | libgraph_tool_draw_la_include_HEADERS = 22 | -------------------------------------------------------------------------------- /src/graph/flow/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) 4 | 5 | AM_CFLAGS = $(AM_CXXFLAGS) 6 | 7 | libgraph_tool_flowdir = $(MOD_DIR)/flow 8 | 9 | libgraph_tool_flow_LTLIBRARIES = libgraph_tool_flow.la 10 | 11 | libgraph_tool_flow_la_includedir = $(MOD_DIR)/include/flow 12 | 13 | libgraph_tool_flow_la_LIBADD = $(MOD_LIBADD) 14 | 15 | libgraph_tool_flow_la_LDFLAGS = $(MOD_LDFLAGS) 16 | 17 | libgraph_tool_flow_la_SOURCES = \ 18 | graph_edmonds_karp.cc \ 19 | graph_push_relabel.cc \ 20 | graph_kolmogorov.cc \ 21 | graph_maximum_cardinality_matching.cc \ 22 | graph_minimum_cut.cc \ 23 | graph_flow_bind.cc 24 | 25 | libgraph_tool_flow_la_include_HEADERS = \ 26 | graph_augment.hh 27 | -------------------------------------------------------------------------------- /src/graph/flow/graph_flow_bind.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | 20 | using namespace graph_tool; 21 | using namespace boost; 22 | 23 | void edmonds_karp_max_flow(GraphInterface& gi, size_t src, size_t sink, 24 | boost::any capacity, boost::any res); 25 | void push_relabel_max_flow(GraphInterface& gi, size_t src, size_t sink, 26 | boost::any capacity, boost::any res); 27 | void kolmogorov_max_flow(GraphInterface& gi, size_t src, size_t sink, 28 | boost::any capacity, boost::any res); 29 | bool max_cardinality_matching(GraphInterface& gi, boost::any match); 30 | double min_cut(GraphInterface& gi, boost::any weight, boost::any part_map); 31 | void get_residual_graph(GraphInterface& gi, boost::any capacity, boost::any res, 32 | boost::any oaugment); 33 | 34 | #include 35 | using namespace boost::python; 36 | 37 | BOOST_PYTHON_MODULE(libgraph_tool_flow) 38 | { 39 | def("edmonds_karp_max_flow", &edmonds_karp_max_flow); 40 | def("push_relabel_max_flow", &push_relabel_max_flow); 41 | def("kolmogorov_max_flow", &kolmogorov_max_flow); 42 | def("max_cardinality_matching", &max_cardinality_matching); 43 | def("min_cut", &min_cut); 44 | def("residual_graph", &get_residual_graph); 45 | } 46 | -------------------------------------------------------------------------------- /src/graph/generation/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) 4 | 5 | AM_CXXFLAGS = $(CXXFLAGS) $(CGAL_FLAGS) 6 | 7 | libgraph_tool_generationdir = $(MOD_DIR)/generation 8 | 9 | libgraph_tool_generation_LTLIBRARIES = libgraph_tool_generation.la 10 | 11 | libgraph_tool_generation_la_includedir = $(MOD_DIR)/include/generation 12 | 13 | libgraph_tool_generation_la_LIBADD = $(MOD_LIBADD) $(CGAL_LIBADD) 14 | 15 | libgraph_tool_generation_la_LDFLAGS = $(MOD_LDFLAGS) 16 | 17 | libgraph_tool_generation_la_SOURCES = \ 18 | graph_generation.cc \ 19 | graph_rewiring.cc \ 20 | graph_predecessor.cc \ 21 | graph_line_graph.cc \ 22 | graph_union.cc \ 23 | graph_union_vprop.cc \ 24 | graph_union_eprop.cc \ 25 | graph_triangulation.cc \ 26 | graph_lattice.cc \ 27 | graph_geometric.cc \ 28 | graph_complete.cc \ 29 | graph_price.cc 30 | 31 | 32 | libgraph_tool_generation_la_include_HEADERS = \ 33 | graph_generation.hh \ 34 | graph_rewiring.hh \ 35 | graph_predecessor.hh \ 36 | graph_union.hh \ 37 | graph_triangulation.hh \ 38 | graph_lattice.hh \ 39 | graph_geometric.hh \ 40 | graph_complete.hh \ 41 | graph_price.hh \ 42 | dynamic_sampler.hh \ 43 | sampler.hh 44 | -------------------------------------------------------------------------------- /src/graph/generation/graph_complete.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_filtering.hh" 20 | 21 | #include "graph_complete.hh" 22 | 23 | #include 24 | 25 | using namespace std; 26 | using namespace boost; 27 | using namespace graph_tool; 28 | 29 | void complete(GraphInterface& gi, size_t N, bool directed, 30 | bool self_loops) 31 | { 32 | get_complete()(gi.GetGraph(), N, directed, self_loops); 33 | } 34 | 35 | void circular(GraphInterface& gi, size_t N, size_t k, bool directed, 36 | bool self_loops) 37 | { 38 | get_circular()(gi.GetGraph(), N, k, directed, self_loops); 39 | } 40 | -------------------------------------------------------------------------------- /src/graph/generation/graph_complete.hh: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #ifndef GRAPH_COMPLETE_HH 19 | #define GRAPH_COMPLETE_HH 20 | 21 | #include 22 | #include "graph_util.hh" 23 | 24 | namespace graph_tool 25 | { 26 | using namespace std; 27 | using namespace boost; 28 | 29 | struct get_complete 30 | { 31 | template 32 | void operator()(Graph& g, size_t N, bool directed, bool self_loops) const 33 | { 34 | for (size_t i = 0; i < N; ++i) 35 | add_vertex(g); 36 | 37 | for (size_t i = 0; i < N; ++i) 38 | { 39 | for (size_t j = directed ? 0 : i; j < N; ++j) 40 | { 41 | if (!self_loops && j == i) 42 | continue; 43 | add_edge(vertex(i, g), 44 | vertex(j, g), g); 45 | } 46 | } 47 | } 48 | }; 49 | 50 | struct get_circular 51 | { 52 | template 53 | void operator()(Graph& g, size_t N, size_t k, bool directed, 54 | bool self_loops) const 55 | { 56 | for (size_t i = 0; i < N; ++i) 57 | add_vertex(g); 58 | 59 | for (size_t i = 0; i < N; ++i) 60 | { 61 | for (size_t j = i; j < i + k + 1; ++j) 62 | { 63 | if (!self_loops && j == i) 64 | continue; 65 | add_edge(vertex(i, g), 66 | vertex(j % N, g), g); 67 | if (directed && j != i) 68 | add_edge(vertex(j % N, g), 69 | vertex(i, g), g); 70 | } 71 | } 72 | } 73 | }; 74 | 75 | } // namespace graph_tool 76 | 77 | #endif // GRAPH_COMPLETE_HH 78 | -------------------------------------------------------------------------------- /src/graph/generation/graph_geometric.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_filtering.hh" 20 | 21 | #include "graph_geometric.hh" 22 | 23 | #include 24 | 25 | using namespace std; 26 | using namespace boost; 27 | using namespace graph_tool; 28 | 29 | 30 | typedef graph_tool::detail::get_all_graph_views 31 | ::apply, 32 | mpl::bool_,mpl::bool_, 33 | mpl::bool_,mpl::bool_ >::type graph_views; 34 | 35 | typedef property_map_types::apply >, 36 | GraphInterface::vertex_index_map_t, 37 | mpl::bool_ >::type prop_types; 38 | 39 | 40 | void geometric(GraphInterface& gi, python::object opoints, double r, 41 | python::object orange, bool periodic, boost::any pos) 42 | { 43 | python::object shape = opoints.attr("shape"); 44 | size_t size = python::extract(shape[0]); 45 | vector > points(size); 46 | vector > range(python::len(orange)); 47 | 48 | size = python::extract(shape[1]); 49 | for(size_t i = 0; i < points.size(); ++i) 50 | { 51 | points[i].resize(size); 52 | for (size_t j = 0; j < points[i].size(); ++j) 53 | points[i][j] = python::extract(opoints[i][j]); 54 | } 55 | 56 | for(size_t i = 0; i < range.size(); ++i) 57 | { 58 | range[i].first = python::extract(orange[i][0]); 59 | range[i].second = python::extract(orange[i][1]); 60 | } 61 | 62 | run_action()(gi, std::bind(get_geometric(), placeholders::_1, 63 | placeholders::_2, std::ref(points), 64 | std::ref(range), r, 65 | periodic), 66 | prop_types())(pos); 67 | } 68 | -------------------------------------------------------------------------------- /src/graph/generation/graph_lattice.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_filtering.hh" 20 | 21 | #include "graph_lattice.hh" 22 | 23 | #include 24 | 25 | using namespace std; 26 | using namespace boost; 27 | using namespace graph_tool; 28 | 29 | void lattice(GraphInterface& gi, boost::python::object oshape, bool periodic) 30 | { 31 | vector shape(boost::python::len(oshape)); 32 | for(size_t i = 0; i < shape.size(); ++i) 33 | shape[i] = python::extract(oshape[i]); 34 | get_lattice()(gi.GetGraph(), shape, periodic); 35 | } 36 | -------------------------------------------------------------------------------- /src/graph/generation/graph_predecessor.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_filtering.hh" 20 | 21 | #include "graph_predecessor.hh" 22 | 23 | using namespace graph_tool; 24 | using namespace boost; 25 | 26 | void predecessor_graph(GraphInterface& gi, GraphInterface& gpi, 27 | boost::any pred_map) 28 | { 29 | run_action<>()(gi, std::bind(get_predecessor_graph(), placeholders::_1, 30 | gi.GetVertexIndex(), std::ref(gpi.GetGraph()), 31 | placeholders::_2), 32 | vertex_scalar_properties())(pred_map); 33 | } 34 | -------------------------------------------------------------------------------- /src/graph/generation/graph_predecessor.hh: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #ifndef GRAPH_PREDECESSOR_HH 19 | #define GRAPH_PREDECESSOR_HH 20 | 21 | #include "graph.hh" 22 | #include "graph_filtering.hh" 23 | #include "graph_util.hh" 24 | 25 | namespace graph_tool 26 | { 27 | using namespace std; 28 | using namespace boost; 29 | 30 | struct get_predecessor_graph 31 | { 32 | template 33 | void operator()(Graph& g, IndexMap vertex_index, PredGraph& pg, 34 | PredMap pred_map) const 35 | { 36 | unchecked_vector_property_map 37 | index_map(vertex_index, num_vertices(g)); 38 | 39 | size_t count = 0; 40 | typename graph_traits::vertex_iterator v,v_end; 41 | for (tie(v,v_end) = vertices(g); v != v_end; ++v) 42 | { 43 | index_map[*v] = count++; 44 | add_vertex(pg); 45 | } 46 | 47 | for (tie(v,v_end) = vertices(g); v != v_end; ++v) 48 | { 49 | size_t pred_i = get(pred_map, *v); 50 | if (pred_i >= num_vertices(g)) 51 | continue; 52 | 53 | typename graph_traits::vertex_descriptor pred = 54 | vertex(pred_i, g); 55 | if (pred == graph_traits::null_vertex()) 56 | continue; 57 | 58 | if (pred != *v) 59 | { 60 | typename graph_traits::vertex_descriptor s, t; 61 | s = vertex(index_map[pred], pg); 62 | t = vertex(index_map[*v], pg); 63 | add_edge(s, t, pg); 64 | } 65 | } 66 | } 67 | }; 68 | 69 | } // graph_tool namespace 70 | 71 | #endif // GRAPH_PREDECESSOR_HH 72 | -------------------------------------------------------------------------------- /src/graph/generation/graph_price.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_filtering.hh" 20 | 21 | #include "graph_price.hh" 22 | 23 | using namespace std; 24 | using namespace boost; 25 | using namespace graph_tool; 26 | 27 | 28 | void price(GraphInterface& gi, size_t N, double gamma, double c, size_t m, 29 | rng_t& rng) 30 | { 31 | run_action<>()(gi, std::bind(get_price(), placeholders::_1, N, gamma, c, m, 32 | std::ref(rng)))(); 33 | } 34 | -------------------------------------------------------------------------------- /src/graph/generation/graph_union.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_filtering.hh" 20 | 21 | #include "graph_union.hh" 22 | 23 | #include 24 | 25 | #include 26 | 27 | using namespace graph_tool; 28 | using namespace boost; 29 | 30 | typedef property_map_type::apply::type 32 | vprop_t; 33 | 34 | typedef property_map_type::apply::type 36 | eprop_t; 37 | 38 | struct get_pointers 39 | { 40 | template 41 | struct apply 42 | { 43 | typedef typename boost::mpl::transform >::type type; 45 | }; 46 | }; 47 | 48 | boost::python::tuple graph_union(GraphInterface& ugi, GraphInterface& gi, 49 | boost::any avprop) 50 | { 51 | vprop_t vprop = boost::any_cast(avprop); 52 | eprop_t eprop(gi.GetEdgeIndex()); 53 | run_action() 54 | (ugi, std::bind(graph_tool::graph_union(), 55 | placeholders::_1, placeholders::_2, vprop, eprop), 56 | get_pointers::apply::type()) 57 | (gi.GetGraphView()); 58 | return boost::python::make_tuple(avprop, boost::any(eprop)); 59 | } 60 | -------------------------------------------------------------------------------- /src/graph/generation/graph_union_eprop.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_filtering.hh" 20 | 21 | #include "graph_union.hh" 22 | 23 | #include 24 | 25 | #include 26 | 27 | 28 | using namespace graph_tool; 29 | using namespace boost; 30 | 31 | 32 | typedef property_map_type::apply::type 34 | vprop_t; 35 | 36 | typedef property_map_type::apply::type 38 | eprop_t; 39 | 40 | struct get_pointers 41 | { 42 | template 43 | struct apply 44 | { 45 | typedef typename boost::mpl::transform >::type type; 47 | }; 48 | }; 49 | 50 | void edge_property_union(GraphInterface& ugi, GraphInterface& gi, 51 | boost::any p_vprop, boost::any p_eprop, 52 | boost::any uprop, boost::any prop) 53 | { 54 | vprop_t vprop = any_cast(p_vprop); 55 | eprop_t eprop = any_cast(p_eprop); 56 | 57 | run_action() 58 | (ugi, std::bind(graph_tool::property_union(), 59 | placeholders::_1, placeholders::_2, vprop, eprop, 60 | placeholders::_3, prop), 61 | get_pointers::apply::type(), 62 | writable_edge_properties()) 63 | (gi.GetGraphView(), uprop); 64 | } 65 | -------------------------------------------------------------------------------- /src/graph/generation/graph_union_vprop.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_filtering.hh" 20 | 21 | #include "graph_union.hh" 22 | 23 | #include 24 | 25 | #include 26 | 27 | using namespace graph_tool; 28 | using namespace boost; 29 | 30 | typedef property_map_type::apply::type 32 | vprop_t; 33 | 34 | typedef property_map_type::apply::type 36 | eprop_t; 37 | 38 | struct get_pointers 39 | { 40 | template 41 | struct apply 42 | { 43 | typedef typename boost::mpl::transform >::type type; 45 | }; 46 | }; 47 | 48 | void vertex_property_union(GraphInterface& ugi, GraphInterface& gi, 49 | boost::any p_vprop, boost::any p_eprop, 50 | boost::any uprop, boost::any prop) 51 | { 52 | vprop_t vprop = any_cast(p_vprop); 53 | eprop_t eprop = any_cast(p_eprop); 54 | 55 | run_action() 56 | (ugi, std::bind(graph_tool::property_union(), 57 | placeholders::_1, placeholders::_2, vprop, eprop, 58 | placeholders::_3, prop), 59 | get_pointers::apply::type(), 60 | writable_vertex_properties()) 61 | (gi.GetGraphView(), uprop); 62 | } 63 | -------------------------------------------------------------------------------- /src/graph/graph_exceptions.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_exceptions.hh" 19 | 20 | using namespace std; 21 | using namespace graph_tool; 22 | 23 | GraphException::GraphException(const string& error) {_error = error;} 24 | GraphException::~GraphException() throw () {} 25 | const char * GraphException::what () const throw () {return _error.c_str();} 26 | void GraphException::SetError(const string& error) {_error = error;} 27 | 28 | IOException::IOException(const string& error): GraphException(error) {} 29 | IOException::~IOException() throw () {} 30 | 31 | ValueException::ValueException(const string& error): GraphException(error) {} 32 | ValueException::~ValueException() throw () {} 33 | -------------------------------------------------------------------------------- /src/graph/graph_exceptions.hh: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #ifndef GRAPH_EXCEPTIONS_HH 19 | #define GRAPH_EXCEPTIONS_HH 20 | #include "config.h" 21 | #include 22 | 23 | // Exceptions 24 | // ========== 25 | // 26 | // This is the main exception which will be thrown the outside world, when 27 | // things go wrong 28 | 29 | namespace graph_tool{ 30 | using namespace std; 31 | 32 | class GraphException : public std::exception 33 | { 34 | public: 35 | GraphException(const string& error); 36 | virtual ~GraphException() throw (); 37 | virtual const char * what () const throw (); 38 | protected: 39 | virtual void SetError(const string& error); 40 | private: 41 | string _error; 42 | }; 43 | 44 | class IOException : public GraphException 45 | { 46 | public: 47 | IOException(const string& error); 48 | virtual ~IOException() throw (); 49 | }; 50 | 51 | class ValueException : public GraphException 52 | { 53 | public: 54 | ValueException(const string& error); 55 | virtual ~ValueException() throw (); 56 | }; 57 | 58 | } // namespace std 59 | 60 | #endif // GRAPH_EXCEPTIONS_HH 61 | -------------------------------------------------------------------------------- /src/graph/graph_properties_group.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_properties.hh" 20 | #include "graph_filtering.hh" 21 | #include "graph_selectors.hh" 22 | 23 | #include "graph_properties_group.hh" 24 | 25 | #include 26 | 27 | using namespace std; 28 | using namespace boost; 29 | using namespace graph_tool; 30 | 31 | 32 | typedef boost::mpl::transform::type vector_types; 33 | typedef property_map_types::apply >::type 36 | vertex_vector_properties; 37 | 38 | typedef property_map_types::apply >::type 41 | edge_vector_properties; 42 | 43 | void group_vector_property(GraphInterface& g, boost::any vector_prop, 44 | boost::any prop, size_t pos, bool edge) 45 | { 46 | if (edge) 47 | run_action() 48 | (g, bind(do_group_vector_property(), 49 | placeholders::_1, placeholders::_2, placeholders::_3, pos), 50 | edge_vector_properties(), edge_properties()) 51 | (vector_prop, prop); 52 | else 53 | run_action() 54 | (g, bind(do_group_vector_property(), 55 | placeholders::_1, placeholders::_2, placeholders::_3, pos), 56 | vertex_vector_properties(), vertex_properties()) 57 | (vector_prop, prop); 58 | } 59 | -------------------------------------------------------------------------------- /src/graph/graph_properties_ungroup.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_properties.hh" 20 | #include "graph_filtering.hh" 21 | #include "graph_selectors.hh" 22 | 23 | #include "graph_properties_group.hh" 24 | 25 | #include 26 | 27 | using namespace std; 28 | using namespace boost; 29 | using namespace graph_tool; 30 | 31 | typedef boost::mpl::transform::type vector_types; 32 | typedef property_map_types::apply >::type 35 | vertex_vector_properties; 36 | 37 | typedef property_map_types::apply >::type 40 | edge_vector_properties; 41 | 42 | void ungroup_vector_property(GraphInterface& g, boost::any vector_prop, 43 | boost::any prop, size_t pos, bool edge) 44 | { 45 | if (edge) 46 | run_action() 47 | (g, bind(do_group_vector_property(), 48 | placeholders::_1, placeholders::_2, placeholders::_3, pos), 49 | edge_vector_properties(), writable_edge_properties()) 50 | (vector_prop, prop); 51 | else 52 | run_action() 53 | (g, bind(do_group_vector_property(), 54 | placeholders::_1, placeholders::_2, placeholders::_3, pos), 55 | vertex_vector_properties(), writable_vertex_properties()) 56 | (vector_prop, prop); 57 | } 58 | -------------------------------------------------------------------------------- /src/graph/graph_selectors.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | #include "graph.hh" 20 | #include "graph_selectors.hh" 21 | #include 22 | 23 | using namespace graph_tool; 24 | using namespace boost; 25 | 26 | // retrieves the appropriate degree selector 27 | boost::any graph_tool::degree_selector(GraphInterface::deg_t deg) 28 | { 29 | boost::any sel; 30 | 31 | GraphInterface::degree_t* d = boost::get(°); 32 | 33 | if (d != 0) 34 | { 35 | mpl::for_each 36 | (std::bind(get_degree_selector(), std::placeholders::_1, *d, 37 | std::ref(sel))); 38 | } 39 | else 40 | { 41 | boost::any* d = boost::get(°); 42 | bool found = false; 43 | mpl::for_each 44 | (std::bind(get_scalar_selector(), std::placeholders::_1, *d, 45 | std::ref(sel), std::ref(found))); 46 | if (!found) 47 | throw ValueException("invalid degree selector"); 48 | } 49 | return sel; 50 | } 51 | -------------------------------------------------------------------------------- /src/graph/layout/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) 4 | 5 | AM_CFLAGS = $(AM_CXXFLAGS) 6 | 7 | libgraph_tool_layoutdir = $(MOD_DIR)/draw 8 | 9 | libgraph_tool_layout_LTLIBRARIES = libgraph_tool_layout.la 10 | 11 | libgraph_tool_layout_la_includedir = $(MOD_DIR)/include/layout 12 | 13 | libgraph_tool_layout_la_LIBADD = $(MOD_LIBADD) 14 | 15 | libgraph_tool_layout_la_LDFLAGS = $(MOD_LDFLAGS) 16 | 17 | libgraph_tool_layout_la_SOURCES = \ 18 | graph_arf.cc \ 19 | graph_fruchterman_reingold.cc \ 20 | graph_sfdp.cc \ 21 | graph_radial.cc \ 22 | graph_bind_layout.cc 23 | 24 | libgraph_tool_layout_la_include_HEADERS = \ 25 | graph_arf.hh \ 26 | graph_sfdp.hh 27 | -------------------------------------------------------------------------------- /src/graph/layout/graph_arf.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | #include "graph.hh" 20 | #include "graph_properties.hh" 21 | 22 | #include 23 | 24 | #include "graph_arf.hh" 25 | 26 | using namespace std; 27 | using namespace boost; 28 | using namespace graph_tool; 29 | 30 | void arf_layout(GraphInterface& g, boost::any pos, boost::any weight, double d, 31 | double a, double dt, size_t max_iter, double epsilon, 32 | size_t dim) 33 | { 34 | typedef ConstantPropertyMap weight_map_t; 35 | typedef boost::mpl::push_back::type 36 | edge_props_t; 37 | 38 | if(weight.empty()) 39 | weight = weight_map_t(1); 40 | run_action() 41 | (g, std::bind(get_arf_layout(), placeholders::_1, placeholders::_2, 42 | placeholders::_3, a, d, dt, epsilon, max_iter, dim), 43 | vertex_floating_vector_properties(), edge_props_t())(pos, weight); 44 | } 45 | 46 | #include 47 | 48 | void export_arf() 49 | { 50 | boost::python::def("arf_layout", &arf_layout); 51 | } 52 | -------------------------------------------------------------------------------- /src/graph/layout/graph_bind_layout.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | 20 | using namespace boost::python; 21 | void export_arf(); 22 | void export_fruchterman_reingold(); 23 | void export_sfdp(); 24 | void export_radial(); 25 | 26 | BOOST_PYTHON_MODULE(libgraph_tool_layout) 27 | { 28 | export_arf(); 29 | export_fruchterman_reingold(); 30 | export_sfdp(); 31 | export_radial(); 32 | } 33 | -------------------------------------------------------------------------------- /src/graph/random.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "random.hh" 19 | 20 | rng_t get_rng(size_t seed) 21 | { 22 | std::seed_seq seq{seed, seed + 1, seed + 2, seed + 3, seed + 4}; 23 | return rng_t(seq); 24 | } 25 | -------------------------------------------------------------------------------- /src/graph/random.hh: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #ifndef RANDOM_HH 19 | #define RANDOM_HH 20 | 21 | #include 22 | 23 | typedef std::mt19937 rng_t; 24 | 25 | rng_t get_rng(size_t seed); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/graph/search/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) 4 | 5 | AM_CFLAGS=$(AM_CXXFLAGS) 6 | 7 | libgraph_tool_searchdir = $(MOD_DIR)/search 8 | 9 | libgraph_tool_search_LTLIBRARIES = libgraph_tool_search.la 10 | 11 | libgraph_tool_search_la_includedir = $(MOD_DIR)/include/search 12 | 13 | libgraph_tool_search_la_LIBADD = $(MOD_LIBADD) 14 | 15 | libgraph_tool_search_la_LDFLAGS = $(MOD_LDFLAGS) 16 | 17 | libgraph_tool_search_la_SOURCES = \ 18 | graph_bfs.cc\ 19 | graph_dfs.cc\ 20 | graph_dijkstra.cc\ 21 | graph_bellman_ford.cc\ 22 | graph_astar.hh\ 23 | graph_astar.cc\ 24 | graph_astar_implicit.cc\ 25 | graph_search_bind.cc 26 | 27 | libgraph_tool_search_la_include_HEADERS = 28 | -------------------------------------------------------------------------------- /src/graph/search/graph_search_bind.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | 20 | using namespace boost; 21 | 22 | void export_bfs(); 23 | void export_dfs(); 24 | void export_dijkstra(); 25 | void export_bellman_ford(); 26 | void export_astar(); 27 | void export_astar_implicit(); 28 | 29 | BOOST_PYTHON_MODULE(libgraph_tool_search) 30 | { 31 | export_bfs(); 32 | export_dfs(); 33 | export_dijkstra(); 34 | export_bellman_ford(); 35 | export_astar(); 36 | export_astar_implicit(); 37 | } 38 | -------------------------------------------------------------------------------- /src/graph/shared_map.hh: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #ifndef SHARED_MAP_HH 19 | #define SHARED_MAP_HH 20 | 21 | // This class will encapsulate a map, and atomically sum it to a given resulting 22 | // map (which is shared among all copies) after it is destructed, or when the 23 | // Gather() member function is called. This enables, for instance, a histogram 24 | // to built in parallel. 25 | 26 | template 27 | class SharedMap: public Map 28 | { 29 | public: 30 | SharedMap(Map &map):_sum(&map) {} 31 | ~SharedMap() 32 | { 33 | Gather(); 34 | } 35 | 36 | void Gather() 37 | { 38 | if (_sum != 0) 39 | { 40 | for (typeof(this->begin()) iter = this->begin(); 41 | iter != this->end(); ++iter) 42 | { 43 | #pragma omp critical 44 | { 45 | (*_sum)[iter->first] += iter->second; 46 | } 47 | } 48 | _sum = 0; 49 | } 50 | } 51 | private: 52 | Map* _sum; 53 | }; 54 | 55 | // This class will encapsulate a generic container, such as a vector or list, 56 | // and atomically concatenate it to a given resulting container (which is shared 57 | // among all copies) after it is destructed, or when the Gather() member 58 | // function is called. 59 | 60 | template 61 | class SharedContainer: public Container 62 | { 63 | public: 64 | SharedContainer(Container &cont): _sum(&cont) {} 65 | ~SharedContainer() 66 | { 67 | Gather(); 68 | } 69 | 70 | void Gather() 71 | { 72 | if (_sum != 0) 73 | { 74 | for (typeof(this->begin()) iter = this->begin(); 75 | iter != this->end(); ++iter) 76 | { 77 | #pragma omp critical 78 | { 79 | _sum->push_back(*iter); 80 | } 81 | } 82 | _sum = 0; 83 | } 84 | } 85 | private: 86 | Container* _sum; 87 | }; 88 | 89 | 90 | #endif //SHARED_MAP_HH 91 | -------------------------------------------------------------------------------- /src/graph/spectral/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) $(CAIROMM_CFLAGS) 4 | 5 | AM_CFLAGS = $(AM_CXXFLAGS) 6 | 7 | libgraph_tool_spectraldir = $(MOD_DIR)/spectral 8 | 9 | libgraph_tool_spectral_LTLIBRARIES = libgraph_tool_spectral.la 10 | 11 | libgraph_tool_spectral_la_includedir = $(MOD_DIR)/include/spectral 12 | 13 | libgraph_tool_spectral_la_LIBADD = $(MOD_LIBADD) 14 | 15 | libgraph_tool_spectral_la_LDFLAGS = $(MOD_LDFLAGS) 16 | 17 | libgraph_tool_spectral_la_SOURCES = \ 18 | graph_adjacency.cc \ 19 | graph_incidence.cc \ 20 | graph_laplacian.cc \ 21 | graph_norm_laplacian.cc \ 22 | graph_matrix.cc \ 23 | graph_transition.cc 24 | 25 | libgraph_tool_spectral_la_include_HEADERS = \ 26 | graph_adjacency.hh \ 27 | graph_incidence.hh \ 28 | graph_laplacian.hh \ 29 | graph_transition.hh 30 | -------------------------------------------------------------------------------- /src/graph/spectral/graph_adjacency.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | #include "graph.hh" 20 | #include "graph_filtering.hh" 21 | #include "graph_util.hh" 22 | #include "numpy_bind.hh" 23 | 24 | #include "graph_selectors.hh" 25 | #include "graph_properties.hh" 26 | 27 | #include "graph_adjacency.hh" 28 | 29 | using namespace std; 30 | using namespace boost; 31 | using namespace graph_tool; 32 | 33 | void adjacency(GraphInterface& g, boost::any index, boost::any weight, 34 | python::object odata, python::object oi, 35 | python::object oj) 36 | { 37 | if (!belongs()(index)) 38 | throw ValueException("index vertex property must have a scalar value type"); 39 | 40 | typedef ConstantPropertyMap weight_map_t; 41 | typedef mpl::push_back::type 42 | weight_props_t; 43 | 44 | if (!weight.empty() && !belongs()(weight)) 45 | throw ValueException("weight edge property must have a scalar value type"); 46 | 47 | if(weight.empty()) 48 | weight = weight_map_t(1.0); 49 | 50 | multi_array_ref data = get_array(odata); 51 | multi_array_ref i = get_array(oi); 52 | multi_array_ref j = get_array(oj); 53 | run_action<>() 54 | (g, std::bind(get_adjacency(), 55 | placeholders::_1, placeholders::_2, placeholders::_3, 56 | std::ref(data), std::ref(i), std::ref(j)), 57 | vertex_scalar_properties(), 58 | weight_props_t())(index, weight); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/graph/spectral/graph_adjacency.hh: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #ifndef GRAPH_ADJACENCY_MATRIX_HH 19 | #define GRAPH_ADJACENCY_MATRIX_HH 20 | 21 | #include "graph.hh" 22 | #include "graph_filtering.hh" 23 | #include "graph_util.hh" 24 | 25 | namespace graph_tool 26 | { 27 | using namespace boost; 28 | 29 | struct get_adjacency 30 | { 31 | template 32 | void operator()(Graph& g, Index index, Weight weight, 33 | multi_array_ref& data, 34 | multi_array_ref& i, 35 | multi_array_ref& j) const 36 | { 37 | int pos = 0; 38 | for (const auto& e : edges_range(g)) 39 | { 40 | data[pos] = get(weight, e); 41 | i[pos] = get(index, target(e, g)); 42 | j[pos] = get(index, source(e, g)); 43 | 44 | ++pos; 45 | if (!is_directed::apply::type::value) 46 | { 47 | data[pos] = get(weight, e); 48 | i[pos] = get(index, source(e, g)); 49 | j[pos] = get(index, target(e, g)); 50 | ++pos; 51 | } 52 | } 53 | } 54 | }; 55 | 56 | } // namespace graph_tool 57 | 58 | #endif // GRAPH_ADJACENCY_MATRIX_HH 59 | -------------------------------------------------------------------------------- /src/graph/spectral/graph_incidence.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | #include "graph.hh" 20 | #include "graph_filtering.hh" 21 | #include "graph_util.hh" 22 | #include "numpy_bind.hh" 23 | 24 | #include "graph_selectors.hh" 25 | #include "graph_properties.hh" 26 | 27 | #include "graph_incidence.hh" 28 | 29 | using namespace std; 30 | using namespace boost; 31 | using namespace graph_tool; 32 | 33 | void incidence(GraphInterface& g, boost::any vindex, boost::any eindex, 34 | python::object odata, python::object oi, 35 | python::object oj) 36 | { 37 | if (!belongs()(vindex)) 38 | throw ValueException("index vertex property must have a scalar value type"); 39 | if (!belongs()(eindex)) 40 | throw ValueException("index edge property must have a scalar value type"); 41 | 42 | multi_array_ref data = get_array(odata); 43 | multi_array_ref i = get_array(oi); 44 | multi_array_ref j = get_array(oj); 45 | run_action<>() 46 | (g, std::bind(get_incidence(), 47 | placeholders::_1, placeholders::_2, placeholders::_3, 48 | std::ref(data), std::ref(i), std::ref(j)), 49 | vertex_scalar_properties(), 50 | edge_scalar_properties())(vindex, eindex); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/graph/spectral/graph_incidence.hh: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #ifndef GRAPH_INCIDENCE_HH 19 | #define GRAPH_INCIDENCE_HH 20 | 21 | #include "graph.hh" 22 | #include "graph_filtering.hh" 23 | #include "graph_util.hh" 24 | 25 | namespace graph_tool 26 | { 27 | using namespace boost; 28 | 29 | struct get_incidence 30 | { 31 | template 32 | void operator()(Graph& g, VIndex vindex, EIndex eindex, 33 | multi_array_ref& data, 34 | multi_array_ref& i, 35 | multi_array_ref& j) const 36 | { 37 | int pos = 0; 38 | for (auto v : vertices_range(g)) 39 | { 40 | for (const auto& e : out_edges_range(v, g)) 41 | { 42 | if (is_directed::apply::type::value) 43 | data[pos] = -1; 44 | else 45 | data[pos] = 1; 46 | i[pos] = get(vindex, v); 47 | j[pos] = get(eindex, e); 48 | ++pos; 49 | } 50 | 51 | for (const auto& e : in_edges_range(v, g)) 52 | { 53 | data[pos] = 1; 54 | i[pos] = get(vindex, v); 55 | j[pos] = get(eindex, e); 56 | ++pos; 57 | } 58 | } 59 | } 60 | }; 61 | 62 | } // namespace graph_tool 63 | 64 | #endif // GRAPH_INCIDENCE_HH 65 | -------------------------------------------------------------------------------- /src/graph/spectral/graph_laplacian.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | #include "graph.hh" 20 | #include "graph_filtering.hh" 21 | #include "graph_util.hh" 22 | #include "numpy_bind.hh" 23 | 24 | #include "graph_selectors.hh" 25 | #include "graph_properties.hh" 26 | 27 | #include "graph_laplacian.hh" 28 | 29 | using namespace std; 30 | using namespace boost; 31 | using namespace graph_tool; 32 | 33 | void laplacian(GraphInterface& g, boost::any index, boost::any weight, 34 | string sdeg, 35 | python::object odata, python::object oi, 36 | python::object oj) 37 | { 38 | if (!belongs()(index)) 39 | throw ValueException("index vertex property must have a scalar value type"); 40 | 41 | typedef ConstantPropertyMap weight_map_t; 42 | typedef mpl::push_back::type 43 | weight_props_t; 44 | 45 | if (!weight.empty() && !belongs()(weight)) 46 | throw ValueException("weight edge property must have a scalar value type"); 47 | 48 | if(weight.empty()) 49 | weight = weight_map_t(1.0); 50 | 51 | deg_t deg; 52 | if (sdeg == "in") 53 | deg = IN_DEG; 54 | if (sdeg == "out") 55 | deg = OUT_DEG; 56 | if (sdeg == "total") 57 | deg = TOTAL_DEG; 58 | 59 | multi_array_ref data = get_array(odata); 60 | multi_array_ref i = get_array(oi); 61 | multi_array_ref j = get_array(oj); 62 | run_action<>() 63 | (g, std::bind(get_laplacian(), 64 | placeholders::_1, placeholders::_2, placeholders::_3, 65 | deg, std::ref(data), std::ref(i), std::ref(j)), 66 | vertex_scalar_properties(), 67 | weight_props_t())(index, weight); 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/graph/spectral/graph_matrix.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | #include "graph.hh" 20 | 21 | using namespace std; 22 | using namespace boost; 23 | using namespace graph_tool; 24 | 25 | void adjacency(GraphInterface& g, boost::any index, boost::any weight, 26 | python::object odata, python::object oi, 27 | python::object oj); 28 | 29 | 30 | void laplacian(GraphInterface& g, boost::any index, boost::any weight, 31 | string sdeg, 32 | python::object odata, python::object oi, 33 | python::object oj); 34 | 35 | 36 | void norm_laplacian(GraphInterface& g, boost::any index, boost::any weight, 37 | string sdeg, 38 | python::object odata, python::object oi, 39 | python::object oj); 40 | 41 | void incidence(GraphInterface& g, boost::any vindex, boost::any eindex, 42 | python::object odata, python::object oi, 43 | python::object oj); 44 | 45 | void transition(GraphInterface& g, boost::any index, boost::any weight, 46 | python::object odata, python::object oi, 47 | python::object oj); 48 | 49 | BOOST_PYTHON_MODULE(libgraph_tool_spectral) 50 | { 51 | using namespace boost::python; 52 | def("adjacency", &adjacency); 53 | def("laplacian", &laplacian); 54 | def("norm_laplacian", &norm_laplacian); 55 | def("incidence", &incidence); 56 | def("transition", &transition); 57 | } 58 | -------------------------------------------------------------------------------- /src/graph/spectral/graph_norm_laplacian.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | #include "graph.hh" 20 | #include "graph_filtering.hh" 21 | #include "graph_util.hh" 22 | #include "numpy_bind.hh" 23 | 24 | #include "graph_selectors.hh" 25 | #include "graph_properties.hh" 26 | 27 | #include "graph_laplacian.hh" 28 | 29 | using namespace std; 30 | using namespace boost; 31 | using namespace graph_tool; 32 | 33 | void norm_laplacian(GraphInterface& g, boost::any index, boost::any weight, 34 | string sdeg, 35 | python::object odata, python::object oi, 36 | python::object oj) 37 | { 38 | if (!belongs()(index)) 39 | throw ValueException("index vertex property must have a scalar value type"); 40 | 41 | typedef ConstantPropertyMap weight_map_t; 42 | typedef mpl::push_back::type 43 | weight_props_t; 44 | 45 | if (!weight.empty() && !belongs()(weight)) 46 | throw ValueException("weight edge property must have a scalar value type"); 47 | 48 | if(weight.empty()) 49 | weight = weight_map_t(1.0); 50 | 51 | deg_t deg; 52 | if (sdeg == "in") 53 | deg = IN_DEG; 54 | if (sdeg == "out") 55 | deg = OUT_DEG; 56 | if (sdeg == "total") 57 | deg = TOTAL_DEG; 58 | 59 | multi_array_ref data = get_array(odata); 60 | multi_array_ref i = get_array(oi); 61 | multi_array_ref j = get_array(oj); 62 | run_action<>() 63 | (g, std::bind(get_norm_laplacian(), 64 | placeholders::_1, placeholders::_2, placeholders::_3, 65 | deg, std::ref(data), std::ref(i), std::ref(j)), 66 | vertex_scalar_properties(), 67 | weight_props_t())(index, weight); 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/graph/spectral/graph_transition.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | #include "graph.hh" 20 | #include "graph_filtering.hh" 21 | #include "graph_util.hh" 22 | #include "numpy_bind.hh" 23 | 24 | #include "graph_selectors.hh" 25 | #include "graph_properties.hh" 26 | 27 | #include "graph_transition.hh" 28 | 29 | using namespace std; 30 | using namespace boost; 31 | using namespace graph_tool; 32 | 33 | void transition(GraphInterface& g, boost::any index, boost::any weight, 34 | python::object odata, python::object oi, 35 | python::object oj) 36 | { 37 | if (!belongs()(index)) 38 | throw ValueException("index vertex property must have a scalar value type"); 39 | 40 | typedef ConstantPropertyMap weight_map_t; 41 | typedef mpl::push_back::type 42 | weight_props_t; 43 | 44 | if (!weight.empty() && !belongs()(weight)) 45 | throw ValueException("weight edge property must have a scalar value type"); 46 | 47 | if(weight.empty()) 48 | weight = weight_map_t(1.0); 49 | 50 | multi_array_ref data = get_array(odata); 51 | multi_array_ref i = get_array(oi); 52 | multi_array_ref j = get_array(oj); 53 | run_action<>() 54 | (g, std::bind(get_transition(), 55 | placeholders::_1, placeholders::_2, placeholders::_3, 56 | std::ref(data), std::ref(i), std::ref(j)), 57 | vertex_scalar_properties(), 58 | weight_props_t())(index, weight); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/graph/spectral/graph_transition.hh: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #ifndef GRAPH_TRANSITION_HH 19 | #define GRAPH_TRANSITION_HH 20 | 21 | #include "graph.hh" 22 | #include "graph_filtering.hh" 23 | #include "graph_util.hh" 24 | 25 | namespace graph_tool 26 | { 27 | 28 | using namespace boost; 29 | 30 | template 31 | typename property_traits::value_type 32 | sum_degree(Graph& g, typename graph_traits::vertex_descriptor v, 33 | Weight w, EdgeSelector) 34 | { 35 | typename property_traits::value_type sum = 0; 36 | typename EdgeSelector::type e, e_end; 37 | for(tie(e, e_end) = EdgeSelector::get_edges(v, g); e != e_end; ++e) 38 | sum += get(w, *e); 39 | return sum; 40 | } 41 | 42 | template 43 | double 44 | sum_degree(Graph& g, typename graph_traits::vertex_descriptor v, 45 | ConstantPropertyMap w, out_edge_iteratorS) 46 | { 47 | return out_degreeS()(v, g); 48 | } 49 | 50 | struct get_transition 51 | { 52 | template 53 | void operator()(const Graph& g, Index index, Weight weight, 54 | multi_array_ref& data, 55 | multi_array_ref& i, 56 | multi_array_ref& j) const 57 | { 58 | int pos = 0; 59 | for (auto v: vertices_range(g)) 60 | { 61 | double k = sum_degree(g, v, weight, out_edge_iteratorS()); 62 | for (const auto& e: out_edges_range(v, g)) 63 | { 64 | data[pos] = weight[e] / k; 65 | i[pos] = get(index, source(e, g)); 66 | j[pos] = get(index, target(e, g)); 67 | ++pos; 68 | } 69 | } 70 | } 71 | }; 72 | 73 | } // namespace graph_tool 74 | 75 | #endif // GRAPH_TRANSITION_HH 76 | -------------------------------------------------------------------------------- /src/graph/stats/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) 4 | 5 | AM_CXXFLAGS = $(CXXFLAGS) 6 | 7 | libgraph_tool_statsdir = $(MOD_DIR)/stats 8 | 9 | libgraph_tool_stats_LTLIBRARIES = libgraph_tool_stats.la 10 | 11 | libgraph_tool_stats_la_includedir = $(MOD_DIR)/include/stats 12 | 13 | libgraph_tool_stats_la_SOURCES = \ 14 | graph_histograms.cc \ 15 | graph_average.cc \ 16 | graph_parallel.cc \ 17 | graph_distance.cc \ 18 | graph_distance_sampled.cc \ 19 | graph_stats_bind.cc 20 | 21 | 22 | libgraph_tool_stats_la_include_HEADERS = \ 23 | graph_parallel.hh \ 24 | graph_histograms.hh \ 25 | graph_average.hh \ 26 | graph_distance_sampled.hh \ 27 | graph_distance.hh 28 | 29 | libgraph_tool_stats_la_LIBADD = $(MOD_LIBADD) 30 | 31 | libgraph_tool_stats_la_LDFLAGS = $(MOD_LDFLAGS) 32 | -------------------------------------------------------------------------------- /src/graph/stats/graph_distance.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | #include "graph.hh" 20 | #include "graph_selectors.hh" 21 | #include "graph_properties.hh" 22 | 23 | #include "graph_distance.hh" 24 | 25 | using namespace std; 26 | using namespace boost; 27 | using namespace graph_tool; 28 | 29 | typedef Histogram hist_t; 30 | 31 | python::object distance_histogram(GraphInterface& gi, boost::any weight, 32 | const vector& bins) 33 | { 34 | python::object ret; 35 | 36 | if (weight.empty()) 37 | { 38 | run_action<>()(gi, 39 | std::bind(get_distance_histogram(), placeholders::_1, 40 | gi.GetVertexIndex(), no_weightS(), 41 | std::ref(bins), std::ref(ret)))(); 42 | } 43 | else 44 | { 45 | run_action<>()(gi, 46 | std::bind(get_distance_histogram(), placeholders::_1, 47 | gi.GetVertexIndex(), placeholders::_2, 48 | std::ref(bins), std::ref(ret)), 49 | edge_scalar_properties())(weight); 50 | } 51 | return ret; 52 | } 53 | 54 | void export_distance() 55 | { 56 | python::def("distance_histogram", &distance_histogram); 57 | } 58 | -------------------------------------------------------------------------------- /src/graph/stats/graph_distance_sampled.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | #include "graph.hh" 20 | #include "graph_selectors.hh" 21 | #include "graph_properties.hh" 22 | 23 | #include "graph_distance_sampled.hh" 24 | 25 | #include "random.hh" 26 | 27 | using namespace std; 28 | using namespace boost; 29 | using namespace graph_tool; 30 | 31 | typedef Histogram hist_t; 32 | 33 | python::object sampled_distance_histogram(GraphInterface& gi, boost::any weight, 34 | const vector& bins, 35 | size_t n_samples, rng_t& rng) 36 | { 37 | python::object ret; 38 | 39 | if (weight.empty()) 40 | { 41 | run_action<>()(gi, 42 | std::bind(get_sampled_distance_histogram(), 43 | placeholders::_1, 44 | gi.GetVertexIndex(), no_weightS(), 45 | n_samples, std::ref(bins), 46 | std::ref(ret), std::ref(rng)))(); 47 | } 48 | else 49 | { 50 | run_action<>()(gi, 51 | std::bind(get_sampled_distance_histogram(), 52 | placeholders::_1, 53 | gi.GetVertexIndex(), placeholders::_2, 54 | n_samples, 55 | std::ref(bins), std::ref(ret), 56 | std::ref(rng)), 57 | edge_scalar_properties())(weight); 58 | } 59 | return ret; 60 | } 61 | 62 | void export_sampled_distance() 63 | { 64 | python::def("sampled_distance_histogram", &sampled_distance_histogram); 65 | } 66 | -------------------------------------------------------------------------------- /src/graph/stats/graph_parallel.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_filtering.hh" 20 | #include "graph_properties.hh" 21 | 22 | #include "graph_parallel.hh" 23 | 24 | #include 25 | 26 | #include 27 | 28 | using namespace std; 29 | using namespace boost; 30 | using namespace graph_tool; 31 | 32 | void do_label_parallel_edges(GraphInterface& gi, boost::any property, 33 | bool mark_only) 34 | { 35 | run_action<>()(gi, std::bind(label_parallel_edges(), placeholders::_1, 36 | placeholders::_2, mark_only), 37 | writable_edge_scalar_properties())(property); 38 | } 39 | 40 | void do_label_self_loops(GraphInterface& gi, boost::any property, 41 | bool mark_only) 42 | { 43 | run_action<>()(gi, std::bind(label_self_loops(), 44 | placeholders::_1, placeholders::_2, mark_only), 45 | writable_edge_scalar_properties())(property); 46 | } 47 | 48 | void do_remove_labeled_edges(GraphInterface& gi, boost::any property) 49 | { 50 | run_action() 51 | (gi, std::bind(remove_labeled_edges(), placeholders::_1, 52 | placeholders::_2), 53 | edge_scalar_properties())(property); 54 | } 55 | 56 | using namespace boost::python; 57 | 58 | void export_parallel() 59 | { 60 | def("label_parallel_edges", &do_label_parallel_edges); 61 | def("label_self_loops", &do_label_self_loops); 62 | def("remove_labeled_edges", &do_remove_labeled_edges); 63 | } 64 | -------------------------------------------------------------------------------- /src/graph/stats/graph_stats_bind.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | 20 | using namespace boost; 21 | 22 | void export_parallel(); 23 | void export_histograms(); 24 | void export_average(); 25 | void export_distance(); 26 | void export_sampled_distance(); 27 | 28 | BOOST_PYTHON_MODULE(libgraph_tool_stats) 29 | { 30 | export_parallel(); 31 | export_histograms(); 32 | export_average(); 33 | export_distance(); 34 | export_sampled_distance(); 35 | } 36 | -------------------------------------------------------------------------------- /src/graph/topology/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) 4 | 5 | AM_CFLAGS=$(AM_CXXFLAGS) 6 | 7 | libgraph_tool_topologydir = $(MOD_DIR)/topology 8 | 9 | libgraph_tool_topology_LTLIBRARIES = libgraph_tool_topology.la 10 | 11 | libgraph_tool_topology_la_includedir = $(MOD_DIR)/include/topology 12 | 13 | libgraph_tool_topology_la_LIBADD = $(MOD_LIBADD) 14 | 15 | libgraph_tool_topology_la_LDFLAGS = $(MOD_LDFLAGS) 16 | 17 | libgraph_tool_topology_la_SOURCES = \ 18 | graph_all_distances.cc \ 19 | graph_bipartite.cc \ 20 | graph_components.cc \ 21 | graph_distance.cc \ 22 | graph_diameter.cc \ 23 | graph_dominator_tree.cc \ 24 | graph_isomorphism.cc \ 25 | graph_kcore.cc \ 26 | graph_maximal_planar.cc \ 27 | graph_maximal_vertex_set.cc \ 28 | graph_minimum_spanning_tree.cc \ 29 | graph_planar.cc \ 30 | graph_random_matching.cc \ 31 | graph_random_spanning_tree.cc \ 32 | graph_reciprocity.cc \ 33 | graph_sequential_color.cc \ 34 | graph_similarity.cc \ 35 | graph_subgraph_isomorphism.cc \ 36 | graph_topological_sort.cc \ 37 | graph_topology.cc \ 38 | graph_tsp.cc \ 39 | graph_transitive_closure.cc 40 | 41 | 42 | libgraph_tool_topology_la_include_HEADERS = \ 43 | graph_components.hh \ 44 | graph_kcore.hh \ 45 | graph_similarity.hh -------------------------------------------------------------------------------- /src/graph/topology/graph_bipartite.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | #include "graph.hh" 20 | #include "graph_properties.hh" 21 | 22 | #include 23 | 24 | using namespace std; 25 | using namespace boost; 26 | using namespace graph_tool; 27 | 28 | struct get_bipartite 29 | { 30 | template 31 | void operator()(Graph& g, VertexIndex vertex_index, PartMap part_map, 32 | bool& is_bip) const 33 | { 34 | unchecked_vector_property_map 35 | part(vertex_index, num_vertices(g)); 36 | 37 | is_bip = is_bipartite(g, vertex_index, part); 38 | 39 | int i, N = num_vertices(g); 40 | #pragma omp parallel for default(shared) private(i) schedule(runtime) if (N > 100) 41 | for (i = 0; i < N; ++i) 42 | { 43 | typename graph_traits::vertex_descriptor v = vertex(i, g); 44 | if (v == graph_traits::null_vertex()) 45 | continue; 46 | part_map[v] = (part[v] == color_traits::white()); 47 | } 48 | } 49 | 50 | template 51 | void operator()(Graph& g, VertexIndex vertex_index, 52 | dummy_property_map, bool& is_bip) const 53 | { 54 | is_bip = is_bipartite(g, vertex_index); 55 | } 56 | }; 57 | 58 | bool is_bipartite(GraphInterface& gi, boost::any part_map) 59 | { 60 | bool is_bip; 61 | 62 | if (part_map.empty()) 63 | part_map = dummy_property_map(); 64 | 65 | typedef mpl::push_back::type vertex_map_types; 67 | 68 | run_action() 69 | (gi, std::bind(get_bipartite(), placeholders::_1, gi.GetVertexIndex(), 70 | placeholders::_2, std::ref(is_bip)), 71 | vertex_map_types())(part_map); 72 | return is_bip; 73 | } 74 | -------------------------------------------------------------------------------- /src/graph/topology/graph_dominator_tree.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | #include "graph.hh" 20 | #include "graph_properties.hh" 21 | 22 | #include 23 | 24 | using namespace std; 25 | using namespace boost; 26 | using namespace graph_tool; 27 | 28 | struct get_dominator_tree 29 | { 30 | template 31 | void operator()(const Graph& g, size_t entry, PredMap pred_map) const 32 | { 33 | lengauer_tarjan_dominator_tree(g, vertex(entry,g), pred_map); 34 | } 35 | }; 36 | 37 | typedef property_map_types::apply, 38 | GraphInterface::vertex_index_map_t, 39 | mpl::bool_ >::type 40 | pred_properties; 41 | 42 | void dominator_tree(GraphInterface& gi, size_t entry, boost::any pred_map) 43 | { 44 | run_action() 45 | (gi, std::bind(get_dominator_tree(), placeholders::_1, entry, 46 | placeholders::_2), 47 | pred_properties())(pred_map); 48 | } 49 | -------------------------------------------------------------------------------- /src/graph/topology/graph_kcore.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_filtering.hh" 20 | #include "graph_properties.hh" 21 | #include "graph_selectors.hh" 22 | 23 | #include "graph_kcore.hh" 24 | 25 | #include 26 | 27 | using namespace std; 28 | using namespace boost; 29 | using namespace graph_tool; 30 | 31 | void do_kcore_decomposition(GraphInterface& gi, boost::any prop, 32 | GraphInterface::deg_t deg) 33 | { 34 | run_action<>()(gi, std::bind(kcore_decomposition(), placeholders::_1, 35 | gi.GetVertexIndex(), placeholders::_2, 36 | placeholders::_3), 37 | writable_vertex_scalar_properties(), 38 | degree_selectors())(prop, degree_selector(deg)); 39 | } 40 | 41 | void export_kcore() 42 | { 43 | python::def("kcore_decomposition", &do_kcore_decomposition); 44 | }; 45 | -------------------------------------------------------------------------------- /src/graph/topology/graph_maximal_planar.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | #include "graph.hh" 20 | #include "graph_properties.hh" 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | using namespace boost; 28 | using namespace graph_tool; 29 | 30 | struct mark_planar_edge 31 | { 32 | template 33 | void visit_vertex_pair(Vertex u, Vertex v, Graph& g) 34 | { 35 | if (!is_adjacent(u, v, g)) 36 | add_edge(u, v, g); 37 | } 38 | }; 39 | 40 | struct do_maximal_planar 41 | { 42 | template 43 | void operator()(Graph& g, VertexIndex vertex_index, EdgeIndex edge_index) const 44 | { 45 | 46 | unchecked_vector_property_map 47 | ::edge_descriptor>, VertexIndex> 48 | embedding(vertex_index, num_vertices(g)); 49 | bool is_planar = boyer_myrvold_planarity_test 50 | (boyer_myrvold_params::graph = g, 51 | boyer_myrvold_params::edge_index_map = edge_index, 52 | boyer_myrvold_params::embedding = embedding); 53 | 54 | if (!is_planar) 55 | throw GraphException("Graph is not planar!"); 56 | 57 | mark_planar_edge vis; 58 | make_biconnected_planar(g, embedding, edge_index, vis); 59 | boyer_myrvold_planarity_test 60 | (boyer_myrvold_params::graph = g, 61 | boyer_myrvold_params::edge_index_map = edge_index, 62 | boyer_myrvold_params::embedding = embedding); 63 | make_maximal_planar(g, embedding, vertex_index, edge_index, vis); 64 | } 65 | 66 | }; 67 | 68 | 69 | void maximal_planar(GraphInterface& gi) 70 | { 71 | run_action() 72 | (gi, std::bind(do_maximal_planar(), placeholders::_1, gi.GetVertexIndex(), 73 | gi.GetEdgeIndex()))(); 74 | } 75 | -------------------------------------------------------------------------------- /src/graph/topology/graph_reciprocity.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | 19 | #include "graph.hh" 20 | #include "graph_filtering.hh" 21 | #include "graph_selectors.hh" 22 | #include "graph_properties.hh" 23 | 24 | using namespace std; 25 | using namespace boost; 26 | using namespace graph_tool; 27 | 28 | struct get_reciprocity 29 | { 30 | template 31 | void operator()(const Graph& g, double& reciprocity) const 32 | { 33 | size_t L = 0, Lbd = 0; 34 | 35 | int i, NV = num_vertices(g); 36 | #pragma omp parallel for default(shared) private(i) reduction(+:L,Lbd) \ 37 | schedule(runtime) if (NV > 100) 38 | for (i = 0; i < NV; ++i) 39 | { 40 | typename graph_traits::vertex_descriptor v = vertex(i, g); 41 | if (v == graph_traits::null_vertex()) 42 | continue; 43 | 44 | typename graph_traits::out_edge_iterator e, e_begin, e_end; 45 | tie(e_begin,e_end) = out_edges(v,g); 46 | for(e = e_begin; e != e_end; ++e) 47 | { 48 | typename graph_traits::vertex_descriptor t; 49 | t = target(*e, g); 50 | 51 | typename graph_traits::adjacency_iterator a, a_end; 52 | for (tie(a, a_end) = adjacent_vertices(t, g); a != a_end; ++a) 53 | if (*a == v) 54 | { 55 | Lbd += 1; 56 | break; 57 | } 58 | L++; 59 | } 60 | } 61 | 62 | reciprocity = Lbd / double(L); 63 | } 64 | }; 65 | 66 | double reciprocity(GraphInterface& gi) 67 | { 68 | double reciprocity; 69 | run_action<>()(gi, std::bind(get_reciprocity(), placeholders::_1, 70 | std::ref(reciprocity)))(); 71 | return reciprocity; 72 | } 73 | -------------------------------------------------------------------------------- /src/graph/topology/graph_sequential_color.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | #include "graph.hh" 20 | #include "graph_properties.hh" 21 | 22 | #include 23 | 24 | using namespace std; 25 | using namespace boost; 26 | using namespace graph_tool; 27 | 28 | struct get_coloring 29 | { 30 | template 31 | void operator()(Graph& g, OrderMap order, ColorMap color, size_t& nc) const 32 | { 33 | nc = sequential_vertex_coloring(g, order, color); 34 | } 35 | }; 36 | 37 | typedef property_map_types::apply, 38 | GraphInterface::vertex_index_map_t, 39 | mpl::bool_ >::type 40 | int_properties; 41 | 42 | size_t sequential_coloring(GraphInterface& gi, boost::any order, 43 | boost::any color) 44 | { 45 | size_t nc = 0; 46 | run_action<>() 47 | (gi, std::bind(get_coloring(), placeholders::_1, placeholders::_2, 48 | placeholders::_3, std::ref(nc)), 49 | vertex_integer_properties(), int_properties())(order, color); 50 | return nc; 51 | } 52 | -------------------------------------------------------------------------------- /src/graph/topology/graph_similarity.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | 19 | #include "graph_python_interface.hh" 20 | 21 | #include "graph.hh" 22 | #include "graph_filtering.hh" 23 | #include "graph_properties.hh" 24 | #include "graph_selectors.hh" 25 | 26 | #include "graph_similarity.hh" 27 | 28 | using namespace std; 29 | using namespace boost; 30 | using namespace graph_tool; 31 | 32 | struct get_pointers 33 | { 34 | template 35 | struct apply 36 | { 37 | typedef typename mpl::transform >::type type; 39 | }; 40 | }; 41 | 42 | 43 | size_t similarity(GraphInterface& gi1, GraphInterface& gi2, boost::any label1, 44 | boost::any label2) 45 | { 46 | size_t s = 0; 47 | run_action<>() 48 | (gi1, std::bind(get_similarity(), placeholders::_1, placeholders::_2, 49 | placeholders::_3, label2, std::ref(s)), 50 | get_pointers::apply::type(), 51 | writable_vertex_properties()) 52 | (gi2.GetGraphView(), label1); 53 | return s; 54 | } 55 | 56 | size_t similarity_fast(GraphInterface& gi1, GraphInterface& gi2, boost::any label1, 57 | boost::any label2) 58 | { 59 | size_t s = 0; 60 | run_action() 61 | (gi1, std::bind(get_similarity_fast(), placeholders::_1, placeholders::_2, 62 | placeholders::_3, label2, std::ref(s)), 63 | get_pointers::apply::type(), 64 | vertex_integer_properties()) 65 | (gi2.GetGraphView(), label1); 66 | return s; 67 | } 68 | 69 | void export_similarity() 70 | { 71 | python::def("similarity", &similarity); 72 | python::def("similarity_fast", &similarity_fast); 73 | }; 74 | -------------------------------------------------------------------------------- /src/graph/topology/graph_topological_sort.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | #include "graph.hh" 20 | #include "graph_properties.hh" 21 | 22 | #include 23 | 24 | using namespace std; 25 | using namespace boost; 26 | using namespace graph_tool; 27 | 28 | struct get_topological_sort 29 | { 30 | template 31 | void operator()(const Graph& g, vector& sort) const 32 | { 33 | sort.clear(); 34 | topological_sort(g, std::back_inserter(sort)); 35 | } 36 | }; 37 | 38 | bool topological_sort(GraphInterface& gi, vector& sort) 39 | { 40 | try 41 | { 42 | run_action<>() 43 | (gi, std::bind(get_topological_sort(), placeholders::_1, 44 | std::ref(sort)))(); 45 | return true; 46 | } 47 | catch (not_a_dag& e) 48 | { 49 | return false; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/graph/topology/graph_transitive_closure.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | #include 20 | 21 | #include "graph.hh" 22 | #include "graph_filtering.hh" 23 | #include "graph_properties.hh" 24 | 25 | 26 | 27 | using namespace graph_tool; 28 | using namespace boost; 29 | 30 | struct get_transitive_closure 31 | { 32 | template 33 | void operator()(Graph& g, TCGraph& tcg) const 34 | { 35 | boost::transitive_closure(g, tcg); 36 | } 37 | }; 38 | 39 | 40 | void transitive_closure(GraphInterface& gi, GraphInterface& tcgi) 41 | { 42 | run_action() 43 | (gi, std::bind(get_transitive_closure(), placeholders::_1, 44 | std::ref(tcgi.GetGraph())))(); 45 | } 46 | -------------------------------------------------------------------------------- /src/graph/topology/graph_tsp.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph_filtering.hh" 19 | #include "graph.hh" 20 | #include "graph_properties.hh" 21 | 22 | #include 23 | 24 | using namespace std; 25 | using namespace boost; 26 | using namespace graph_tool; 27 | 28 | struct get_tsp_approx 29 | { 30 | template 31 | void operator()(Graph& g, size_t src, WeightMap weights, 32 | vector& tour) const 33 | { 34 | back_insert_iterator > back_it(tour); 35 | metric_tsp_approx_tour_from_vertex(g, vertex(src, g), weights, 36 | back_it); 37 | } 38 | }; 39 | 40 | vector get_tsp(GraphInterface& gi, size_t src, boost::any weight_map) 41 | { 42 | vector tour; 43 | 44 | typedef ConstantPropertyMap cweight_t; 45 | 46 | if (weight_map.empty()) 47 | weight_map = cweight_t(1); 48 | 49 | typedef mpl::push_back::type 50 | weight_maps; 51 | 52 | run_action() 53 | (gi, std::bind(get_tsp_approx(), placeholders::_1, src, 54 | placeholders::_2, std::ref(tour)), 55 | weight_maps())(weight_map); 56 | 57 | return tour; 58 | } 59 | -------------------------------------------------------------------------------- /src/graph/transform_iterator.hh: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #ifndef TRANSFORM_ITERATOR_HH 19 | #define TRANSFORM_ITERATOR_HH 20 | 21 | #include 22 | #include 23 | 24 | template 25 | class transform_random_access_iterator: 26 | public boost::transform_iterator 27 | { 28 | public: 29 | typedef Iterator iter_t; 30 | typedef boost::transform_iterator base_t; 31 | transform_random_access_iterator() {} 32 | transform_random_access_iterator(const base_t& iter) :base_t(iter) {} 33 | transform_random_access_iterator(const Iterator& iter, const Predicate& pred = Predicate()) 34 | : base_t(iter, pred) {} 35 | }; 36 | 37 | namespace std 38 | { 39 | template 40 | struct iterator_traits > 41 | { 42 | typedef transform_random_access_iterator titer_t; 43 | typedef typename titer_t::base_t base_t; 44 | typedef typename iterator_traits::difference_type difference_type; 45 | typedef typename iterator_traits::value_type value_type; 46 | typedef typename iterator_traits::value_type reference; 47 | typedef typename iterator_traits::pointer pointer; 48 | typedef typename iterator_traits::iterator_category iterator_category; 49 | }; 50 | } 51 | 52 | #endif // TRANSFORM_ITERATOR_HH 53 | -------------------------------------------------------------------------------- /src/graph/util/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AM_CPPFLAGS = $(MOD_CPPFLAGS) 4 | 5 | AM_CFLAGS = $(AM_CXXFLAGS) 6 | 7 | libgraph_tool_utildir = $(MOD_DIR)/util 8 | 9 | libgraph_tool_util_LTLIBRARIES = libgraph_tool_util.la 10 | 11 | libgraph_tool_util_la_includedir = $(MOD_DIR)/include/util 12 | 13 | libgraph_tool_util_la_LIBADD = $(MOD_LIBADD) 14 | 15 | libgraph_tool_util_la_LDFLAGS = $(MOD_LDFLAGS) 16 | 17 | libgraph_tool_util_la_SOURCES = \ 18 | graph_search.cc \ 19 | graph_util_bind.cc 20 | 21 | libgraph_tool_util_la_include_HEADERS = \ 22 | graph_search.hh 23 | -------------------------------------------------------------------------------- /src/graph/util/graph_search.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include "graph.hh" 19 | #include "graph_filtering.hh" 20 | #include "graph_properties.hh" 21 | 22 | #include "graph_search.hh" 23 | 24 | #include 25 | 26 | using namespace std; 27 | using namespace boost; 28 | using namespace graph_tool; 29 | 30 | // find vertices which match a certain (inclusive) property range 31 | python::list 32 | find_vertex_range(python::object g, GraphInterface::deg_t deg, 33 | python::tuple range) 34 | { 35 | GraphInterface& gi = python::extract(g().attr("_Graph__graph")); 36 | python::list ret; 37 | run_action<>()(gi, std::bind(find_vertices(), placeholders::_1, std::ref(g), 38 | placeholders::_2, std::ref(range), 39 | std::ref(ret)), 40 | all_selectors())(degree_selector(deg)); 41 | return ret; 42 | } 43 | 44 | // find edges which match a certain (inclusive) property range 45 | python::list 46 | find_edge_range(python::object g, boost::any eprop, 47 | python::tuple range) 48 | { 49 | GraphInterface& gi = python::extract(g().attr("_Graph__graph")); 50 | python::list ret; 51 | typedef property_map_types::apply >::type 54 | all_edge_props; 55 | 56 | GraphInterface::edge_index_map_t eindex = 57 | any_cast(gi.GetEdgeIndex()); 58 | run_action<>()(gi, std::bind(find_edges(), placeholders::_1, std::ref(g), eindex, 59 | placeholders::_2, std::ref(range), std::ref(ret)), 60 | all_edge_props())(eprop); 61 | return ret; 62 | } 63 | 64 | 65 | using namespace boost::python; 66 | 67 | void export_search() 68 | { 69 | def("find_vertex_range", &find_vertex_range); 70 | def("find_edge_range", &find_edge_range); 71 | } 72 | -------------------------------------------------------------------------------- /src/graph/util/graph_util_bind.cc: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | 20 | using namespace boost; 21 | 22 | void export_search(); 23 | 24 | BOOST_PYTHON_MODULE(libgraph_tool_util) 25 | { 26 | export_search(); 27 | } 28 | -------------------------------------------------------------------------------- /src/graph_tool/all.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # graph_tool -- a general graph manipulation python module 5 | # 6 | # Copyright (C) 2006-2015 Tiago de Paula Peixoto 7 | # 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | 21 | """ 22 | Utility module which includes all the sub-modules in graph_tool 23 | """ 24 | 25 | from __future__ import division, absolute_import, print_function 26 | import warnings 27 | 28 | from graph_tool import * 29 | import graph_tool 30 | from graph_tool.correlations import * 31 | import graph_tool.correlations 32 | from graph_tool.centrality import * 33 | import graph_tool.centrality 34 | try: 35 | from graph_tool.draw import * 36 | import graph_tool.draw 37 | except ImportError as e: 38 | # Proceed despite errors with cairo, matplotlib, etc. 39 | msg = "Error importing draw module, proceeding nevertheless: " + str(e) 40 | warnings.warn(msg, RuntimeWarning) 41 | pass 42 | from graph_tool.stats import * 43 | import graph_tool.stats 44 | from graph_tool.generation import * 45 | import graph_tool.generation 46 | from graph_tool.stats import * 47 | import graph_tool.stats 48 | from graph_tool.clustering import * 49 | import graph_tool.clustering 50 | from graph_tool.community import * 51 | import graph_tool.community 52 | from graph_tool.run_action import * 53 | import graph_tool.run_action 54 | from graph_tool.topology import * 55 | import graph_tool.topology 56 | from graph_tool.flow import * 57 | import graph_tool.flow 58 | from graph_tool.spectral import * 59 | import graph_tool.spectral 60 | from graph_tool.search import * 61 | import graph_tool.search 62 | from graph_tool.util import * 63 | import graph_tool.util 64 | import graph_tool.collection 65 | import graph_tool.collection as collection 66 | -------------------------------------------------------------------------------- /src/graph_tool/collection/adjnoun.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/adjnoun.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/as-22july06.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/as-22july06.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/astro-ph.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/astro-ph.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/celegansneural.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/celegansneural.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/cond-mat-2003.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/cond-mat-2003.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/cond-mat-2005.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/cond-mat-2005.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/cond-mat.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/cond-mat.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/dolphins.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/dolphins.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/email-Enron.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/email-Enron.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/football.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/football.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/hep-th.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/hep-th.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/karate.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/karate.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/lesmis.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/lesmis.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/netscience.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/netscience.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/pgp-strong-2009.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/pgp-strong-2009.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/polblogs.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/polblogs.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/polbooks.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/polbooks.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/power.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/power.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/collection/serengeti-foodweb.gt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/antmd/graph-tool/85f11ae869fe318532e60554963b16eca6367eab/src/graph_tool/collection/serengeti-foodweb.gt.gz -------------------------------------------------------------------------------- /src/graph_tool/dl_import.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # graph_tool -- a general graph manipulation python module 5 | # 6 | # Copyright (C) 2006-2015 Tiago de Paula Peixoto 7 | # 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | 21 | from __future__ import division, absolute_import, print_function 22 | 23 | import sys 24 | import os.path 25 | 26 | try: 27 | from DLFCN import RTLD_LAZY, RTLD_GLOBAL 28 | dl_flags = RTLD_LAZY | RTLD_GLOBAL 29 | except ImportError: 30 | # handle strange python installations, by importing from the deprecated dl 31 | # module, otherwise from ctypes 32 | try: 33 | from dl import RTLD_LAZY, RTLD_GLOBAL 34 | dl_flags = RTLD_LAZY | RTLD_GLOBAL 35 | except ImportError: 36 | from ctypes import RTLD_GLOBAL 37 | dl_flags = RTLD_GLOBAL 38 | 39 | __all__ = ["dl_import"] 40 | 41 | 42 | def dl_import(import_expr): 43 | """Import module according to import_expr, but with RTLD_GLOBAL enabled.""" 44 | # we need to get the locals and globals of the _calling_ function. Thus, we 45 | # need to go deeper into the call stack 46 | call_frame = sys._getframe(1) 47 | local_dict = call_frame.f_locals 48 | global_dict = call_frame.f_globals 49 | 50 | # RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and friends to 51 | # work properly across DSO boundaries. See http://gcc.gnu.org/faq.html#dso 52 | 53 | orig_dlopen_flags = sys.getdlopenflags() 54 | sys.setdlopenflags(dl_flags) 55 | 56 | try: 57 | exec(import_expr, local_dict, global_dict) 58 | finally: 59 | sys.setdlopenflags(orig_dlopen_flags) # reset it to normal case to 60 | # avoid unnecessary symbol 61 | # collision 62 | -------------------------------------------------------------------------------- /src/graph_tool/io.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # graph_tool -- a general graph manipulation python module 5 | # 6 | # Copyright (C) 2006-2015 Tiago de Paula Peixoto 7 | # 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | 21 | from __future__ import division, absolute_import, print_function 22 | 23 | import pickle 24 | import base64 25 | import atexit 26 | import sys 27 | from io import BytesIO 28 | from . import libgraph_tool_core 29 | 30 | # IStream and OStream need to be tweaked a little to become a real file-like 31 | # object... 32 | 33 | 34 | def IStream_read(self, n=None, buflen=1048576): 35 | if n is None: 36 | data = b"" 37 | while True: 38 | buf = self.Read(buflen) 39 | data += buf 40 | if len(buf) < buflen: 41 | break 42 | return data 43 | else: 44 | return self.Read(n) 45 | 46 | 47 | def IStream_readline(self, n=None): 48 | c = None 49 | line = b"" 50 | while c != "" and c != "\n" and len(line) < n: 51 | c = self.Read(1) 52 | line += c 53 | return line 54 | 55 | 56 | def OStream_write(self, s): 57 | data = s 58 | self.Write(data, len(s)) 59 | 60 | libgraph_tool_core.IStream.read = IStream_read 61 | libgraph_tool_core.IStream.readline = IStream_readline 62 | libgraph_tool_core.OStream.write = OStream_write 63 | 64 | 65 | # define and set the pickler/unpickler functions 66 | def pickler(stream, obj): 67 | sstream = BytesIO() 68 | pickle.dump(obj, sstream, -1) 69 | stream.write(sstream.getvalue()) 70 | 71 | def unpickler(stream): 72 | data = stream.read() 73 | sstream = BytesIO(data) 74 | if sys.version_info < (3,): 75 | return pickle.load(sstream) 76 | return pickle.load(sstream, encoding="bytes") 77 | 78 | libgraph_tool_core.set_pickler(pickler) 79 | libgraph_tool_core.set_unpickler(unpickler) 80 | 81 | def clean_picklers(): 82 | libgraph_tool_core.set_pickler(None) 83 | libgraph_tool_core.set_unpickler(None) 84 | 85 | atexit.register(clean_picklers) 86 | -------------------------------------------------------------------------------- /src/graph_tool/run_action/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # graph_tool -- a general graph manipulation python module 5 | # 6 | # Copyright (C) 2006-2015 Tiago de Paula Peixoto 7 | # 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | 21 | """ 22 | ``graph_tool.run_action`` - Inline C++ code embedding 23 | ----------------------------------------------------- 24 | 25 | This module implements support for automatic ad-hoc code embedding into 26 | graph-tool. 27 | 28 | Summary 29 | +++++++ 30 | 31 | .. autosummary:: 32 | :nosignatures: 33 | 34 | inline 35 | 36 | Contents 37 | ++++++++ 38 | """ 39 | 40 | from __future__ import division, absolute_import, print_function 41 | 42 | __all__ = ["inline"] 43 | 44 | from .inline import inline 45 | -------------------------------------------------------------------------------- /src/graph_tool/run_action/run_action_support.hh: -------------------------------------------------------------------------------- 1 | // graph-tool -- a general graph modification and manipulation thingy 2 | // 3 | // Copyright (C) 2006-2015 Tiago de Paula Peixoto 4 | // 5 | // This program is free software; you can redistribute it and/or 6 | // modify it under the terms of the GNU General Public License 7 | // as published by the Free Software Foundation; either version 3 8 | // of the License, or (at your option) any later version. 9 | // 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | // 15 | // You should have received a copy of the GNU General Public License 16 | // along with this program. If not, see . 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "graph.hh" 25 | #include "graph_filtering.hh" 26 | #include "graph_properties.hh" 27 | #include "histogram.hh" 28 | #include 29 | #include 30 | 31 | using namespace boost; 32 | using namespace std; 33 | using namespace graph_tool; 34 | 35 | namespace graph_tool 36 | { 37 | 38 | // metafunction to get the correct property map 39 | template 40 | struct prop_bind_t 41 | { 42 | template 43 | struct as 44 | { 45 | typedef typename mpl::if_, 46 | uint8_t, Value>::type val_t; 47 | typedef typename property_map_type::apply::type type; 48 | }; 49 | }; 50 | 51 | // utility template function to extract the correct property map 52 | template 53 | PropertyMap get_prop(py::object& map) 54 | { 55 | try 56 | { 57 | python::object pmap(python::handle<> 58 | (python::borrowed((PyObject*)(map)))); 59 | 60 | python::object opmap = pmap.attr("_PropertyMap__map").attr("get_map")(); 61 | return any_cast(python::extract(opmap)()); 62 | } 63 | catch (bad_any_cast&) 64 | { 65 | throw GraphException("could not convert property map as requested"); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/graph_tool/run_action/run_action_template.hh: -------------------------------------------------------------------------------- 1 | bool __exception_thrown = false; 2 | string __exception_error; 3 | 4 | //variable definitions 5 | ${var_defs} 6 | 7 | try 8 | { 9 | //variable extraction 10 | ${var_extract} 11 | 12 | // where the actual code is included 13 | ${code} 14 | } 15 | catch (const GraphException& e) 16 | { 17 | __exception_error = e.what(); 18 | __exception_thrown = true; 19 | } 20 | catch (const bad_any_cast& e) 21 | { 22 | __exception_error = e.what(); 23 | __exception_error += " (wrong property map type?)"; 24 | __exception_thrown = true; 25 | } 26 | catch (const std::exception& e) 27 | { 28 | __exception_error = "unknown exception thrown: "; 29 | __exception_error += e.what(); 30 | __exception_thrown = true; 31 | } 32 | 33 | python::dict return_vals; 34 | return_vals["__exception_error"] = __exception_error; 35 | return_vals["__exception_thrown"] = __exception_thrown; 36 | 37 | // updated values will be inserted in return_vals below 38 | ${return_vals} 39 | 40 | return_val = py::object(return_vals.ptr()); 41 | --------------------------------------------------------------------------------