├── BrainConnectivity ├── 00 readme.txt ├── assortativity.m ├── betweenness_bin.m ├── betweenness_wei.m ├── breadth.m ├── breadthdist.m ├── cat.mat ├── charpath.m ├── clustering_coef_bd.m ├── clustering_coef_bu.m ├── clustering_coef_wd.m ├── clustering_coef_wu.m ├── cycprob.m ├── degrees_dir.m ├── degrees_und.m ├── density_dir.m ├── density_und.m ├── distance_bin.m ├── distance_wei.m ├── edge_betweenness_bin.m ├── edge_betweenness_wei.m ├── efficiency.m ├── erange.m ├── find_motif34.m ├── findpaths.m ├── findwalks.m ├── fve30.mat ├── fve32.mat ├── jdegree.m ├── latmio_dir.m ├── latmio_dir_connected.m ├── latmio_und.m ├── latmio_und_connected.m ├── macaque47.mat ├── macaque71.mat ├── make_motif34lib.m ├── makeevenCIJ.m ├── makefractalCIJ.m ├── makelatticeCIJ.m ├── makerandCIJ_dir.m ├── makerandCIJ_und.m ├── makerandCIJdegreesfixed.m ├── makeringlatticeCIJ.m ├── maketoeplitzCIJ.m ├── matching_ind.m ├── modularity_dir.m ├── modularity_louvain_und.m ├── modularity_und.m ├── module_degree_zscore.m ├── motif34lib.mat ├── motif3funct_bin.m ├── motif3funct_wei.m ├── motif3struct_bin.m ├── motif3struct_wei.m ├── motif4funct_bin.m ├── motif4funct_wei.m ├── motif4struct_bin.m ├── motif4struct_wei.m ├── participation_coef.m ├── randmio_dir.m ├── randmio_dir_connected.m ├── randmio_und.m ├── randmio_und_connected.m ├── randomizer_bin_und.m ├── reachdist.m ├── reorderMAT.m ├── strengths_dir.m ├── strengths_und.m ├── threshold_absolute.m ├── threshold_proportional.m ├── transitivity_bd.m ├── transitivity_bu.m ├── transitivity_wd.m ├── transitivity_wu.m └── writetoPAJ.m ├── Louvain ├── cluster_jl.m ├── cluster_jl_cpp.m ├── cluster_jl_orient.m ├── cluster_jl_orientT.m ├── cluster_jl_orientT_cpp.m ├── cluster_jl_orient_cpp.m ├── jl_clust.cpp ├── jl_clust.mexa64 ├── jl_clust.mexglx ├── jl_clust_orient.cpp ├── jl_clust_orient.mexa64 ├── jl_clust_orient.mexglx ├── jl_mnew.cpp ├── jl_mnew.mexa64 ├── jl_mnew.mexglx ├── nwstats_1000prof.mat ├── readme.txt └── test_Louvain.m ├── README ├── contest ├── CONTEST Manual.pdf ├── Contents.m ├── a26-taylor.pdf ├── baitsample.m ├── curvature.m ├── erdrey.m ├── geo.m ├── gilbert.m ├── kleinberg.m ├── lap.m ├── lockandkey.m ├── mht.m ├── pagerank.m ├── pathlength.m ├── pref.m ├── renga.m ├── rewire.m ├── short.m ├── smallw.m ├── sticky.m └── unisample.m ├── elapsed.m ├── getMiddle.m ├── getTimeXAxis.m ├── laplacian.m ├── matlab_bgl ├── .project ├── @inplace │ ├── assign.m │ ├── display.m │ ├── double.m │ ├── end.m │ ├── inplace.m │ ├── size.m │ ├── subsasgn.m │ └── subsref.m ├── @ipdouble │ └── ipdouble.m ├── @ipint32 │ └── ipint32.m ├── Contents.m ├── all_shortest_paths.m ├── astar_search.m ├── bellman_ford_sp.m ├── betweenness_centrality.m ├── bfs.m ├── biconnected_components.m ├── boyer_myrvold_planarity_test.m ├── breadth_first_search.m ├── chrobak_payne_straight_line_drawing.m ├── circle_graph_layout.m ├── clique_graph.m ├── clustering_coefficients.m ├── combine_visitors.m ├── components.m ├── core_numbers.m ├── custom │ ├── dijkstra_all_sp.m │ └── path_histogram.m ├── cycle_graph.m ├── dag_sp.m ├── depth_first_search.m ├── dfs.m ├── dijkstra_sp.m ├── doc │ ├── changed.txt │ ├── html │ │ ├── changes.html │ │ ├── core_numbers_example │ │ │ ├── core_numbers_example.html │ │ │ ├── core_numbers_example.png │ │ │ ├── core_numbers_example_01.png │ │ │ └── core_numbers_example_02.png │ │ ├── faq.html │ │ ├── images │ │ │ └── matlab-bgl-header.png │ │ ├── index.html │ │ ├── new_in_3 │ │ │ ├── new_in_3_0.html │ │ │ ├── new_in_3_0.png │ │ │ ├── new_in_3_0_01.png │ │ │ ├── new_in_3_0_02.png │ │ │ └── new_in_3_0_03.png │ │ ├── new_in_4 │ │ │ ├── new_in_4_0.html │ │ │ ├── new_in_4_0.png │ │ │ ├── new_in_4_0_01.png │ │ │ ├── new_in_4_0_02.png │ │ │ ├── new_in_4_0_03.png │ │ │ └── new_in_4_0_04.png │ │ ├── old.html │ │ ├── planar_graphs │ │ │ ├── planar_graphs.html │ │ │ ├── planar_graphs.png │ │ │ ├── planar_graphs_01.png │ │ │ ├── planar_graphs_02.png │ │ │ ├── planar_graphs_03.png │ │ │ ├── planar_graphs_04.png │ │ │ ├── planar_graphs_05.png │ │ │ ├── planar_graphs_06.png │ │ │ ├── planar_graphs_07.png │ │ │ └── planar_graphs_08.png │ │ ├── record_alg │ │ │ └── record_alg.html │ │ ├── red_black │ │ │ ├── red_black.html │ │ │ ├── red_black.png │ │ │ ├── red_black_01.png │ │ │ ├── red_black_02.png │ │ │ ├── red_black_03.png │ │ │ └── red_black_04.png │ │ ├── reweighted_graphs │ │ │ └── reweighted_graphs.html │ │ ├── site.css │ │ └── style.css │ ├── mxdom2mbgl-html.xsl │ └── write_examples_html.m ├── edge_weight_index.m ├── edge_weight_vector.m ├── edmonds_maximum_cardinality_matching.m ├── edmunds_karp_max_flow.m ├── erdos_reyni.m ├── examples │ ├── approx_multiway_cut.m │ ├── bacon_numbers.m │ ├── bfs_example.m │ ├── bfs_in_mbgl.m │ ├── bfs_in_mbgl_efficient.m │ ├── core_numbers_example.m │ ├── dfs_example.m │ ├── edge_index_example.m │ ├── max_flow_example.m │ ├── multiway_example.m │ ├── new_in_3_0.m │ ├── new_in_4_0.m │ ├── planar_graphs.m │ ├── record_alg.m │ ├── red_black.m │ └── reweighted_graphs.m ├── floyd_warshall_all_sp.m ├── fruchterman_reingold_force_directed_layout.m ├── graphs │ ├── all_shortest_paths_example.mat │ ├── bfs_example.mat │ ├── bgl_cities.mat │ ├── clique-10.mat │ ├── clr-24-1.mat │ ├── clr-25-2.mat │ ├── clr-26-1.mat │ ├── clr-27-1.mat │ ├── cores_example.mat │ ├── cs-stanford.mat │ ├── dfs_example.mat │ ├── dominator_tree_example.mat │ ├── kt-3-2.mat │ ├── kt-3-7.mat │ ├── kt-6-23.mat │ ├── kt-7-2.mat │ ├── line-7.mat │ ├── matching_example.mat │ ├── max_flow_example.mat │ ├── minnesota.mat │ ├── padgett-florentine.mat │ ├── tapir.mat │ └── tarjan-biconn.mat ├── grid_graph.m ├── gursoy_atun_layout.m ├── indexed_sparse.m ├── is_kuratowski_graph.m ├── is_straight_line_drawing.m ├── johnson_all_sp.m ├── kamada_kawai_spring_layout.m ├── kolmogorov_max_flow.m ├── kruskal_mst.m ├── kuratowski_subgraph.m ├── lengauer_tarjan_dominator_tree.m ├── libmbgl │ ├── ccfiles.sh │ ├── compile-linux-32.sh │ ├── compile-linux-64-large.sh │ ├── compile-linux-64.sh │ ├── compile-macosx-intel-32.sh │ ├── compile-macosx-ppc-32.sh │ ├── compile-win32.bat │ ├── compile-win64.bat │ ├── components.cc │ ├── crm_graph.hpp │ ├── include │ │ ├── matlab_bgl.h │ │ └── matlab_bgl_types.h │ ├── layouts.cc │ ├── libmbgl.sln │ ├── libmbgl.vcproj │ ├── libmbgl_test │ │ ├── Makefile │ │ ├── fr_layout_test.cc │ │ ├── layout_funcs_test.cc │ │ ├── libmbgl_funcs_test.cc │ │ ├── libmbgl_funcs_test.h │ │ ├── libmbgl_test.cc │ │ ├── libmbgl_test.vcproj │ │ ├── planar_funcs_test.cc │ │ ├── planar_is_straight_line_test.cc │ │ ├── planar_ksubgraph_test.cc │ │ ├── property_map_test.cc │ │ ├── simple_prop_map_test.cc │ │ ├── simple_prop_map_test_2.cc │ │ ├── simple_prop_map_test_3.cc │ │ └── simple_prop_map_test_4.cc │ ├── libmbgl_util.hpp │ ├── max_flow.cc │ ├── orderings.cc │ ├── planar.cc │ ├── searches.cc │ ├── shortest_path.cc │ ├── spanning_trees.cc │ ├── statistics.cc │ ├── stop_visitors.hpp │ ├── visitor_macros.hpp │ └── yasmic │ │ ├── .sconsign │ │ ├── bgl_kcore.hpp │ │ ├── binary_ifstream_graph.hpp │ │ ├── binary_ifstream_matrix.hpp │ │ ├── bind_utility.hpp │ │ ├── boost_mod │ │ ├── .sconsign │ │ ├── bellman_ford_shortest_paths.hpp │ │ ├── betweenness_centrality.hpp │ │ ├── chrobak_payne_drawing.hpp │ │ ├── core_numbers.hpp │ │ ├── floyd_warshall_shortest.hpp │ │ ├── fruchterman_reingold.hpp │ │ ├── gzip.hpp │ │ ├── integer_extra.hpp │ │ ├── is_straight_line_drawing.hpp │ │ ├── johnson_all_pairs_shortest.hpp │ │ ├── kolmogorov_max_flow.hpp │ │ ├── kruskal_min_spanning_tree.hpp │ │ └── zlib.cpp │ │ ├── bvgraph_matrix.hpp │ │ ├── cluto_ifstream_matrix.hpp │ │ ├── compressed_row_matrix.hpp │ │ ├── compressed_row_matrix_graph.hpp │ │ ├── generic_matrix_operations.hpp │ │ ├── graph_ifstream_matrix.hpp │ │ ├── ifstream_as_matrix.hpp │ │ ├── ifstream_matrix.hpp │ │ ├── indexed_list.hpp │ │ ├── indexed_list.old.hpp │ │ ├── indexed_list_as_graph.hpp │ │ ├── istream_as_matrix.hpp │ │ ├── iterator_utility.hpp │ │ ├── matrix_row_col_graph.hpp │ │ ├── nonzero_union.hpp │ │ ├── simple_csr_matrix.hpp │ │ ├── simple_csr_matrix_as_graph.hpp │ │ ├── simple_row_and_column_matrix.hpp │ │ ├── simple_row_and_column_matrix_as_graph.hpp │ │ ├── smatrix_traits.hpp │ │ ├── transpose_matrix.hpp │ │ ├── tuple_utility.hpp │ │ ├── undir_simple_csr_matrix.hpp │ │ ├── undir_simple_csr_matrix_as_graph.hpp │ │ ├── util │ │ ├── .sconsign │ │ ├── crm_matrix.hpp │ │ ├── filtered_matrix.hpp │ │ ├── load_crm_graph.hpp │ │ ├── load_crm_matrix.hpp │ │ ├── write_matrix.hpp │ │ └── write_petsc_matrix.hpp │ │ ├── verbose_util.hpp │ │ ├── yasmic.cbp │ │ ├── yasmic.layout │ │ ├── yasmic.vcproj │ │ ├── yasmic.vcproj.DUALCORE.mithandor.user │ │ └── yasmic.vcproj.MITHANDOR.mithandor.user ├── make_biconnected_planar.m ├── make_connected.m ├── make_maximal_planar.m ├── matching.m ├── max_flow.m ├── maximal_matching.m ├── mst.m ├── num_edges.m ├── num_vertices.m ├── path_from_pred.m ├── planar_canonical_ordering.m ├── prim_mst.m ├── private │ ├── astar_search_mex.c │ ├── astar_search_mex.mexa64 │ ├── astar_search_mex.mexglx │ ├── astar_search_mex.mexmac │ ├── astar_search_mex.mexmaci │ ├── astar_search_mex.mexw32 │ ├── astar_search_mex.mexw64 │ ├── betweenness_centrality_mex.c │ ├── betweenness_centrality_mex.mexa64 │ ├── betweenness_centrality_mex.mexglx │ ├── betweenness_centrality_mex.mexmac │ ├── betweenness_centrality_mex.mexmaci │ ├── betweenness_centrality_mex.mexw32 │ ├── betweenness_centrality_mex.mexw64 │ ├── bfs_dfs_vis_mex.c │ ├── bfs_dfs_vis_mex.mexa64 │ ├── bfs_dfs_vis_mex.mexglx │ ├── bfs_dfs_vis_mex.mexmac │ ├── bfs_dfs_vis_mex.mexmaci │ ├── bfs_dfs_vis_mex.mexw32 │ ├── bfs_dfs_vis_mex.mexw64 │ ├── bfs_mex.c │ ├── bfs_mex.mexa64 │ ├── bfs_mex.mexglx │ ├── bfs_mex.mexmac │ ├── bfs_mex.mexmaci │ ├── bfs_mex.mexw32 │ ├── bfs_mex.mexw64 │ ├── biconnected_components_mex.c │ ├── biconnected_components_mex.mexa64 │ ├── biconnected_components_mex.mexglx │ ├── biconnected_components_mex.mexmac │ ├── biconnected_components_mex.mexmaci │ ├── biconnected_components_mex.mexw32 │ ├── biconnected_components_mex.mexw64 │ ├── check_matlab_bgl.m │ ├── clustering_coefficients_mex.c │ ├── clustering_coefficients_mex.mexa64 │ ├── clustering_coefficients_mex.mexglx │ ├── clustering_coefficients_mex.mexmac │ ├── clustering_coefficients_mex.mexmaci │ ├── clustering_coefficients_mex.mexw32 │ ├── clustering_coefficients_mex.mexw64 │ ├── common_functions.h │ ├── common_macros.h │ ├── compile.m │ ├── components_mex.c │ ├── components_mex.mexa64 │ ├── components_mex.mexglx │ ├── components_mex.mexmac │ ├── components_mex.mexmaci │ ├── components_mex.mexw32 │ ├── components_mex.mexw64 │ ├── core_numbers_mex.c │ ├── core_numbers_mex.mexa64 │ ├── core_numbers_mex.mexglx │ ├── core_numbers_mex.mexmac │ ├── core_numbers_mex.mexmaci │ ├── core_numbers_mex.mexw32 │ ├── core_numbers_mex.mexw64 │ ├── dfs_mex.c │ ├── dfs_mex.mexa64 │ ├── dfs_mex.mexglx │ ├── dfs_mex.mexmac │ ├── dfs_mex.mexmaci │ ├── dfs_mex.mexw32 │ ├── dfs_mex.mexw64 │ ├── dominator_tree_mex.c │ ├── dominator_tree_mex.mexa64 │ ├── dominator_tree_mex.mexglx │ ├── dominator_tree_mex.mexmac │ ├── dominator_tree_mex.mexmaci │ ├── dominator_tree_mex.mexw32 │ ├── dominator_tree_mex.mexw64 │ ├── expand_macros.h │ ├── fruchterman_reingold_mex.c │ ├── fruchterman_reingold_mex.mexa64 │ ├── fruchterman_reingold_mex.mexglx │ ├── fruchterman_reingold_mex.mexmac │ ├── fruchterman_reingold_mex.mexmaci │ ├── fruchterman_reingold_mex.mexw32 │ ├── fruchterman_reingold_mex.mexw64 │ ├── get_matlab_bgl_options.m │ ├── gursoy_atun_mex.c │ ├── gursoy_atun_mex.mexa64 │ ├── gursoy_atun_mex.mexglx │ ├── gursoy_atun_mex.mexmac │ ├── gursoy_atun_mex.mexmaci │ ├── gursoy_atun_mex.mexw32 │ ├── gursoy_atun_mex.mexw64 │ ├── kamada_kawai_spring_layout_mex.c │ ├── kamada_kawai_spring_layout_mex.mexa64 │ ├── kamada_kawai_spring_layout_mex.mexglx │ ├── kamada_kawai_spring_layout_mex.mexmac │ ├── kamada_kawai_spring_layout_mex.mexmaci │ ├── kamada_kawai_spring_layout_mex.mexw32 │ ├── kamada_kawai_spring_layout_mex.mexw64 │ ├── matching_mex.c │ ├── matching_mex.mexa64 │ ├── matching_mex.mexglx │ ├── matching_mex.mexmac │ ├── matching_mex.mexmaci │ ├── matching_mex.mexw32 │ ├── matching_mex.mexw64 │ ├── matlab_bgl_all_sp_mex.c │ ├── matlab_bgl_all_sp_mex.mexa64 │ ├── matlab_bgl_all_sp_mex.mexglx │ ├── matlab_bgl_all_sp_mex.mexmac │ ├── matlab_bgl_all_sp_mex.mexmaci │ ├── matlab_bgl_all_sp_mex.mexw32 │ ├── matlab_bgl_all_sp_mex.mexw64 │ ├── matlab_bgl_sp_mex.c │ ├── matlab_bgl_sp_mex.mexa64 │ ├── matlab_bgl_sp_mex.mexglx │ ├── matlab_bgl_sp_mex.mexmac │ ├── matlab_bgl_sp_mex.mexmaci │ ├── matlab_bgl_sp_mex.mexw32 │ ├── matlab_bgl_sp_mex.mexw64 │ ├── max_flow_mex.c │ ├── max_flow_mex.mexa64 │ ├── max_flow_mex.mexglx │ ├── max_flow_mex.mexmac │ ├── max_flow_mex.mexmaci │ ├── max_flow_mex.mexw32 │ ├── max_flow_mex.mexw64 │ ├── merge_options.m │ ├── merge_structs.m │ ├── mst_mex.c │ ├── mst_mex.mexa64 │ ├── mst_mex.mexglx │ ├── mst_mex.mexmac │ ├── mst_mex.mexmaci │ ├── mst_mex.mexw32 │ ├── mst_mex.mexw64 │ ├── path_from_pred_mex.c │ ├── path_from_pred_mex.mexa64 │ ├── path_from_pred_mex.mexglx │ ├── path_from_pred_mex.mexmac │ ├── path_from_pred_mex.mexmaci │ ├── path_from_pred_mex.mexw32 │ ├── path_from_pred_mex.mexw64 │ ├── planar_drawing_mex.c │ ├── planar_drawing_mex.mexa64 │ ├── planar_drawing_mex.mexglx │ ├── planar_drawing_mex.mexmac │ ├── planar_drawing_mex.mexmaci │ ├── planar_drawing_mex.mexw32 │ ├── planar_drawing_mex.mexw64 │ ├── planar_edges_mex.c │ ├── planar_edges_mex.mexa64 │ ├── planar_edges_mex.mexglx │ ├── planar_edges_mex.mexmac │ ├── planar_edges_mex.mexmaci │ ├── planar_edges_mex.mexw32 │ ├── planar_edges_mex.mexw64 │ ├── planar_test_mex.c │ ├── planar_test_mex.mexa64 │ ├── planar_test_mex.mexglx │ ├── planar_test_mex.mexmac │ ├── planar_test_mex.mexmaci │ ├── planar_test_mex.mexw32 │ ├── planar_test_mex.mexw64 │ ├── test_matching_mex.c │ ├── test_matching_mex.mexa64 │ ├── test_matching_mex.mexglx │ ├── test_matching_mex.mexmac │ ├── test_matching_mex.mexmaci │ ├── test_matching_mex.mexw32 │ ├── test_matching_mex.mexw64 │ ├── todo.m │ ├── todo_3_0_release.m │ ├── topological_order_mex.c │ ├── topological_order_mex.mexa64 │ ├── topological_order_mex.mexglx │ ├── topological_order_mex.mexmac │ ├── topological_order_mex.mexmaci │ ├── topological_order_mex.mexw32 │ ├── topological_order_mex.mexw64 │ └── visitor_macros.h ├── push_relabel_max_flow.m ├── random_graph_layout.m ├── set_matlab_bgl_default.m ├── shortest_paths.m ├── star_graph.m ├── test │ ├── assert.m │ ├── rtest_1.m │ ├── rtest_2.m │ ├── rtest_3_cojocaru.m │ ├── rtest_5_henderson.m │ ├── rtest_6.m │ ├── rtest_7_karsi.m │ ├── rtest_all.m │ ├── test_all.m │ ├── test_benchmark.m │ ├── test_breadth_first_search.m │ ├── test_components.m │ ├── test_depth_first_search.m │ ├── test_examples.m │ ├── test_layouts.m │ ├── test_main.m │ ├── test_planar.m │ ├── test_searches.m │ ├── test_shortest_paths.m │ ├── test_spanning_trees.m │ ├── test_statistics.m │ └── test_trivial.m ├── test_dag.m ├── test_matching.m ├── test_planar_graph.m ├── topological_order.m ├── tree_from_pred.m └── wheel_graph.m ├── mit_matlab_functions ├── BFS.m ├── BounovaPhDThesis2009.pdf ├── DFS.m ├── PriceModel.m ├── add_edges.m ├── adj2adjL.m ├── adj2edgeL.m ├── adj2inc.m ├── adj2pajek.m ├── adj2simple.m ├── adj2str.m ├── adjL2adj.m ├── adjL2edgeL.m ├── algebraic_connectivity.m ├── alt │ ├── ave_path_length.m │ ├── diameter.m │ └── test_dijkstra.m ├── ave_neighbor_deg.m ├── ave_path_length.m ├── average_degree.m ├── bike_data.mat ├── closeness.m ├── clust_coeff.m ├── degrees.m ├── diagnose_powerlaw.m ├── diameter.m ├── distance_distribution.m ├── downloads.html ├── draw_circ_graph.m ├── draw_dot_matrix.m ├── edgeL2adj.m ├── edgeL2adjL.m ├── edgeL2pajek.m ├── edgeL2simple.m ├── edge_betweenness_slow.m ├── eigencentrality.m ├── el2geom.m ├── fiedler_vector.m ├── find_conn_comp.m ├── giant_component.m ├── graph_complement.m ├── graph_dual.m ├── graph_spectrum.m ├── ij2ind.m ├── inc2adj.m ├── ind2ij.m ├── iscomplete.m ├── isconnected.m ├── isdirected.m ├── iseulerian.m ├── isregular.m ├── issimple.m ├── issymmetric.m ├── istree.m ├── isweighted.m ├── kneighbors.m ├── laplacian_matrix.m ├── link_density.m ├── loops3.m ├── min_span_tree.m ├── multiedges.m ├── node_betweenness_slow.m ├── num_conn_comp.m ├── num_conn_triples.m ├── numedges.m ├── numnodes.m ├── pajek2adj.m ├── pajek2edgeL.m ├── pajek2xyz.m ├── pdf_cdf_rank.m ├── pearson.m ├── preferential_attachment.m ├── purge.m ├── random_graph.m ├── random_modular_graph.m ├── random_number.m ├── rich_club_metric.m ├── s_metric.m ├── selfloops.m ├── shortest_pathDP.m ├── simple_dijkstra.m ├── str2adj.m ├── subgraph.m ├── symmetrize.m └── symmetrize_edgeL.m ├── network ├── apl_diam_fast.m ├── betweenness_fast.m ├── betweenness_fastDC.m ├── betweenness_fastPF.m ├── btwn_test.mat ├── closeness_fast.m ├── dijkstra.m ├── findNode.m ├── getAllBetweenness.m ├── getAllCloseness.m ├── getAvgPathLength.m ├── getBetweenness.m ├── getDiameter.m ├── getGiantComponent.m ├── removeDiagonal.m └── removeInf.m ├── nlaplacian.m ├── padcat.m ├── powerlaw ├── plfit.m ├── plplot.m ├── plpva.m ├── plvar.m └── randht.m ├── processMemory.m ├── quickCorr.m └── seconds2human.m /BrainConnectivity/00 readme.txt: -------------------------------------------------------------------------------- 1 | Date of Package: 2010-08-07 -------------------------------------------------------------------------------- /BrainConnectivity/breadthdist.m: -------------------------------------------------------------------------------- 1 | function [R,D] = breadthdist(CIJ) 2 | %BREADTHDIST Reachability and distance matrices 3 | % 4 | % [R,D] = breadthdist(CIJ); 5 | % 6 | % The binary reachability matrix describes reachability between all pairs 7 | % of nodes. An entry (u,v)=1 means that there exists a path from node u 8 | % to node v; alternatively (u,v)=0. 9 | % 10 | % The distance matrix contains lengths of shortest paths between all 11 | % pairs of nodes. An entry (u,v) represents the length of shortest path 12 | % from node u to node v. The average shortest path length is the 13 | % characteristic path length of the network. 14 | % 15 | % Input: CIJ, binary (directed/undirected) connection matrix 16 | % 17 | % Outputs: R, reachability matrix 18 | % D, distance matrix 19 | % 20 | % Note: slower but less memory intensive than "reachdist.m". 21 | % 22 | % Algorithm: Breadth-first search. 23 | % 24 | % 25 | % Olaf Sporns, Indiana University, 2002/2007/2008 26 | 27 | N = size(CIJ,1); 28 | 29 | D = zeros(N); 30 | for i=1:N 31 | D(i,:) = breadth(CIJ,i); 32 | end; 33 | 34 | % replace zeros with 'Inf's 35 | D(D==0) = Inf; 36 | 37 | % construct R 38 | R = double(D~=Inf); 39 | 40 | -------------------------------------------------------------------------------- /BrainConnectivity/cat.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/BrainConnectivity/cat.mat -------------------------------------------------------------------------------- /BrainConnectivity/charpath.m: -------------------------------------------------------------------------------- 1 | function [lambda,ecc,radius,diameter] = charpath(D) 2 | %CHARPATH Characteristic path length and related statistics 3 | % 4 | % lambda = charpath(D); 5 | % [lambda,ecc,radius,diameter] = charpath(D); 6 | % 7 | % The characteristic path length is the average shortest path length in 8 | % the network. 9 | % 10 | % Input: D, distance matrix 11 | % 12 | % Outputs: lambda, characteristic path length 13 | % ecc, eccentricity (for each vertex) 14 | % radius, radius of graph 15 | % diameter, diameter of graph 16 | % 17 | % Note: Characteristic path length is calculated as the global mean of 18 | % the distance matrix D, excludings any 'Infs' but including distances on 19 | % the main diagonal. 20 | % 21 | % 22 | % Olaf Sporns, Indiana University, 2002/2007/2008 23 | 24 | % Mean of finite entries of D(G) 25 | lambda = sum(sum(D(D~=Inf)))/length(nonzeros(D~=Inf)); 26 | 27 | % Eccentricity for each vertex (note: ignore 'Inf') 28 | ecc = max(D.*(D~=Inf),[],2); 29 | 30 | % Radius of graph 31 | radius = min(ecc); % but what about zeros? 32 | 33 | % Diameter of graph 34 | diameter = max(ecc); 35 | -------------------------------------------------------------------------------- /BrainConnectivity/clustering_coef_bd.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/BrainConnectivity/clustering_coef_bd.m -------------------------------------------------------------------------------- /BrainConnectivity/clustering_coef_bu.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/BrainConnectivity/clustering_coef_bu.m -------------------------------------------------------------------------------- /BrainConnectivity/clustering_coef_wu.m: -------------------------------------------------------------------------------- 1 | function C=clustering_coef_wu(W) 2 | %CLUSTERING_COEF_WU Clustering coefficient 3 | % 4 | % C = clustering_coef_wu(W); 5 | % 6 | % The weighted clustering coefficient is the average "intensity" of 7 | % triangles around a node. 8 | % 9 | % Input: W, weighted undirected connection matrix 10 | % 11 | % Output: C, clustering coefficient vector 12 | % 13 | % Reference: Onnela et al. (2005) Phys Rev E 71:065103 14 | % 15 | % 16 | % Mika Rubinov, UNSW, 2007-2010 17 | 18 | K=sum(W~=0,2); 19 | cyc3=diag((W.^(1/3))^3); 20 | K(cyc3==0)=inf; %if no 3-cycles exist, make C=0 (via K=inf) 21 | C=cyc3./(K.*(K-1)); %clustering coefficient 22 | -------------------------------------------------------------------------------- /BrainConnectivity/degrees_dir.m: -------------------------------------------------------------------------------- 1 | function [id,od,deg] = degrees_dir(CIJ) 2 | %DEGREES_DIR Indegree and outdegree 3 | % 4 | % [id,od,deg] = degrees_dir(CIJ); 5 | % 6 | % Node degree is the number of links connected to the node. The indegree 7 | % is the number of inward links and the outdegree is the number of 8 | % outward links. 9 | % 10 | % Input: CIJ, directed (binary/weighted) connection matrix 11 | % 12 | % Output: id, node indegree 13 | % od, node outdegree 14 | % deg, node degree (indegree + outdegree) 15 | % 16 | % Notes: Inputs are assumed to be on the columns of the CIJ matrix. 17 | % Weight information is discarded. 18 | % 19 | % 20 | % Olaf Sporns, Indiana University, 2002/2006/2008 21 | 22 | 23 | % ensure CIJ is binary... 24 | CIJ = double(CIJ~=0); 25 | 26 | % compute degrees 27 | id = sum(CIJ,1); % indegree = column sum of CIJ 28 | od = sum(CIJ,2)'; % outdegree = row sum of CIJ 29 | deg = id+od; % degree = indegree+outdegree 30 | 31 | 32 | -------------------------------------------------------------------------------- /BrainConnectivity/degrees_und.m: -------------------------------------------------------------------------------- 1 | function [deg] = degrees_und(CIJ) 2 | %DEGREES_UND Degree 3 | % 4 | % deg = degrees_und(CIJ); 5 | % 6 | % Node degree is the number of links connected to the node. 7 | % 8 | % Input: CIJ, undirected (binary/weighted) connection matrix 9 | % 10 | % Output: deg, node degree 11 | % 12 | % Note: Weight information is discarded. 13 | % 14 | % 15 | % Olaf Sporns, Indiana University, 2002/2006/2008 16 | 17 | 18 | % ensure CIJ is binary... 19 | CIJ = double(CIJ~=0); 20 | 21 | deg = sum(CIJ); 22 | 23 | -------------------------------------------------------------------------------- /BrainConnectivity/density_dir.m: -------------------------------------------------------------------------------- 1 | function [kden,N,K] = density_dir(CIJ) 2 | %DENSITY Density 3 | % 4 | % kden = density_dir(CIJ); 5 | % [kden,N,K] = density_dir(CIJ); 6 | % 7 | % Density is the fraction of present connections to possible connections. 8 | % 9 | % Input: CIJ, directed (weighted/binary) connection matrix 10 | % 11 | % Output: kden, density 12 | % N, number of vertices 13 | % K, number of edges 14 | % 15 | % Notes: Assumes CIJ is directed and has no self-connections. 16 | % Weight information is discarded. 17 | % 18 | % 19 | % Olaf Sporns, Indiana University, 2002/2007/2008 20 | 21 | N = size(CIJ,1); 22 | K = nnz(CIJ); 23 | kden = K/(N^2-N); 24 | 25 | -------------------------------------------------------------------------------- /BrainConnectivity/density_und.m: -------------------------------------------------------------------------------- 1 | function [kden,N,K] = density_und(CIJ) 2 | %DENSITY Density 3 | % 4 | % kden = density_und(CIJ); 5 | % [kden,N,K] = density_und(CIJ); 6 | % 7 | % Density is the fraction of present connections to possible connections. 8 | % 9 | % Input: CIJ, undirected (weighted/binary) connection matrix 10 | % 11 | % Output: kden, density 12 | % N, number of vertices 13 | % K, number of edges 14 | % 15 | % Notes: Assumes CIJ is undirected and has no self-connections. 16 | % Weight information is discarded. 17 | % 18 | % 19 | % Olaf Sporns, Indiana University, 2002/2007/2008 20 | 21 | 22 | % Modification history: 23 | % 2009-10: K fixed to sum over one half of CIJ [Tony Herdman, SFU] 24 | 25 | N = size(CIJ,1); 26 | K = nnz(triu(CIJ)); 27 | kden = K/((N^2-N)/2); 28 | 29 | -------------------------------------------------------------------------------- /BrainConnectivity/distance_bin.m: -------------------------------------------------------------------------------- 1 | function D=distance_bin(G) 2 | %DISTANCE_BIN Distance matrix 3 | % 4 | % D = distance_bin(A); 5 | % 6 | % The distance matrix contains lengths of shortest paths between all 7 | % pairs of nodes. An entry (u,v) represents the length of shortest path 8 | % from node u to node v. The average shortest path length is the 9 | % characteristic path length of the network. 10 | % 11 | % Input: A, binary directed/undirected connection matrix 12 | % 13 | % Output: D, distance matrix 14 | % 15 | % Notes: 16 | % Lengths between disconnected nodes are set to Inf. 17 | % Lengths on the main diagonal are set to 0. 18 | % 19 | % Algorithm: Algebraic shortest paths. 20 | % 21 | % 22 | % Mika Rubinov, UNSW, 2007-2010. 23 | 24 | 25 | D=eye(length(G)); 26 | n=1; 27 | nPATH=G; %n-path matrix 28 | L=(nPATH~=0); %shortest n-path matrix 29 | 30 | while find(L,1); 31 | D=D+n.*L; 32 | n=n+1; 33 | nPATH=nPATH*G; 34 | L=(nPATH~=0).*(D==0); 35 | end 36 | 37 | D(~D)=inf; %disconnected nodes are assigned d=inf; 38 | D=D-eye(length(G)); -------------------------------------------------------------------------------- /BrainConnectivity/findwalks.m: -------------------------------------------------------------------------------- 1 | function [Wq,twalk,wlq] = findwalks(CIJ) 2 | %FINDWALKS Network walks 3 | % 4 | % [Wq,twalk,wlq] = findwalks(CIJ); 5 | % 6 | % Walks are sequences of linked nodes, that may visit a single node more 7 | % than once. This function finds the number of walks of a given length, 8 | % between any two nodes. 9 | % 10 | % Input: CIJ binary (directed/undirected) connection matrix 11 | % 12 | % Outputs: Wq 3D matrix, Wq(i,j,q) is the number of walks 13 | % from 'i' to 'j' of length 'q'. 14 | % twalk total number of walks found 15 | % wlq walk length distribution as function of 'q' 16 | % 17 | % Notes: Wq grows very quickly for larger N,K,q. Weights are discarded. 18 | % 19 | % Algorithm: algebraic path count 20 | % 21 | % 22 | % Olaf Sporns, Indiana University, 2002/2007/2008 23 | 24 | % ensure CIJ is binary... 25 | CIJ = double(CIJ~=0); 26 | 27 | N = size(CIJ,1); 28 | Wq = zeros(N,N,N); 29 | CIJpwr = CIJ; 30 | Wq(:,:,1) = CIJ; 31 | for q=2:N 32 | CIJpwr = CIJpwr*CIJ; 33 | Wq(:,:,q) = CIJpwr; 34 | end; 35 | 36 | % total number of walks 37 | twalk = sum(sum(sum(Wq))); 38 | 39 | % walk length distribution 40 | wlq = reshape(sum(sum(Wq)),1,N); 41 | 42 | -------------------------------------------------------------------------------- /BrainConnectivity/fve30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/BrainConnectivity/fve30.mat -------------------------------------------------------------------------------- /BrainConnectivity/fve32.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/BrainConnectivity/fve32.mat -------------------------------------------------------------------------------- /BrainConnectivity/macaque47.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/BrainConnectivity/macaque47.mat -------------------------------------------------------------------------------- /BrainConnectivity/macaque71.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/BrainConnectivity/macaque71.mat -------------------------------------------------------------------------------- /BrainConnectivity/makelatticeCIJ.m: -------------------------------------------------------------------------------- 1 | function [CIJ] = makelatticeCIJ(N,K) 2 | %MAKELATTICECIJ Synthetic lattice network 3 | % 4 | % CIJ = makelatticeCIJ(N,K); 5 | % 6 | % This function generates a directed lattice network without toroidal 7 | % boundary counditions (i.e. no ring-like "wrapping around"). 8 | % 9 | % Inputs: N, number of vertices 10 | % K, number of edges 11 | % 12 | % Outputs: CIJ, connection matrix 13 | % 14 | % Note: The lattice is made by placing connections as close as possible 15 | % to the main diagonal, without wrapping around. No connections are made 16 | % on the main diagonal. In/Outdegree is kept approx. constant at K/N. 17 | % 18 | % 19 | % Olaf Sporns, Indiana University, 2005/2007 20 | 21 | % initialize 22 | CIJ = zeros(N); 23 | CIJ1 = ones(N); 24 | KK = 0; 25 | cnt = 0; 26 | seq = 1:N-1; 27 | 28 | % fill in 29 | while (KK0) 40 | [i j] = find(dCIJ); 41 | rp = randperm(length(i)); 42 | for ii=1:overby 43 | CIJ(i(rp(ii)),j(rp(ii))) = 0; 44 | end; 45 | end; 46 | -------------------------------------------------------------------------------- /BrainConnectivity/makerandCIJ_dir.m: -------------------------------------------------------------------------------- 1 | function [CIJ] = makerandCIJ_dir(N,K) 2 | %MAKERANDCIJ_DIR Synthetic directed random network 3 | % 4 | % CIJ = makerandCIJ_dir(N,K); 5 | % 6 | % This function generates a directed random network 7 | % 8 | % Inputs: N, number of vertices 9 | % K, number of edges 10 | % 11 | % Output: CIJ, directed random connection matrix 12 | % 13 | % Note: no connections are placed on the main diagonal. 14 | % 15 | % 16 | % Olaf Sporns, Indiana University, 2007/2008 17 | 18 | ind = ~eye(N); 19 | i = find(ind); 20 | rp = randperm(length(i)); 21 | irp = i(rp); 22 | 23 | CIJ = zeros(N); 24 | CIJ(irp(1:K)) = 1; 25 | -------------------------------------------------------------------------------- /BrainConnectivity/makerandCIJ_und.m: -------------------------------------------------------------------------------- 1 | function [CIJ] = makerandCIJ_und(N,K) 2 | %MAKERANDCIJ_UND Synthetic directed random network 3 | % 4 | % CIJ = makerandCIJ_und(N,K); 5 | % 6 | % This function generates an undirected random network 7 | % 8 | % Inputs: N, number of vertices 9 | % K, number of edges 10 | % 11 | % Output: CIJ, undirected random connection matrix 12 | % 13 | % Note: no connections are placed on the main diagonal. 14 | % 15 | % 16 | % Olaf Sporns, Indiana University, 2007/2008 17 | 18 | ind = triu(~eye(N)); 19 | i = find(ind); 20 | rp = randperm(length(i)); 21 | irp = i(rp); 22 | 23 | CIJ = zeros(N); 24 | CIJ(irp(1:K)) = 1; 25 | CIJ = CIJ+CIJ'; % symmetrize 26 | -------------------------------------------------------------------------------- /BrainConnectivity/maketoeplitzCIJ.m: -------------------------------------------------------------------------------- 1 | function [CIJ] = maketoeplitzCIJ(N,K,s) 2 | %MAKETOEPLITZCIJ A synthetic directed network with Gaussian drop-off of 3 | % connectivity with distance 4 | % 5 | % CIJ = maketoeprandCIJ(N,K,s) 6 | % 7 | % This function generates a directed network with a Gaussian drop-off in 8 | % edge density with increasing distance from the main diagonal. There are 9 | % toroidal boundary counditions (i.e. no ring-like "wrapping around"). 10 | % 11 | % Inputs: N, number of vertices 12 | % K, number of edges 13 | % s, standard deviation of toeplitz 14 | % 15 | % Output: CIJ, connection matrix 16 | % 17 | % Note: no connections are placed on the main diagonal. 18 | % 19 | % 20 | % Olaf Sporns, Indiana University, 2005/2007 21 | 22 | profile = normpdf([1:N-1],0.5,s); 23 | template = toeplitz([0 profile],[0 profile]); 24 | template = template.*(K./sum(sum(template))); 25 | CIJ = zeros(N); 26 | 27 | while ((sum(sum(CIJ)) ~= K)) 28 | CIJ = (rand(N) 0) )*power; 28 | end 29 | 30 | pzero = find(Plength == 0); 31 | Plength(pzero) = inf; % reset zeros to inf 32 | 33 | Plength = Plength - diag(diag(Plength)); % reset diagonal to zero -------------------------------------------------------------------------------- /contest/short.m: -------------------------------------------------------------------------------- 1 | function S = short(A,p) 2 | 3 | %SHORT Randomly add entries (shortcuts) to a matrix 4 | % 5 | % Input A: n by n adjacency matrix 6 | % p: probability that an entry is added to a given row 7 | % 8 | % Output S: n by n adjacency matrix with the attribute sparse. 9 | % 10 | % Description: A symmetric matrix of shortcuts is created which has 11 | % an entry in each row with independent probability p. 12 | % This is added to the matrix A. 13 | % 14 | % Example: S = short(A,0.3); 15 | 16 | n = length(A); 17 | 18 | if nargin == 1 19 | p = log(n)/n; 20 | end 21 | 22 | Ihat = find(rand(n,1)<=p); 23 | Jhat = ceil(n*rand(size(Ihat))); 24 | Ehat = ones(size(Ihat)); 25 | 26 | self = find(Ihat==Jhat); 27 | Ihat(self) = []; 28 | Jhat(self) = []; 29 | Ehat(self) = []; 30 | 31 | 32 | [I,J,E] = find(A); 33 | 34 | S = sparse([I;Ihat;Jhat],[J;Jhat;Ihat],[E;Ehat;Ehat],n,n); -------------------------------------------------------------------------------- /contest/unisample.m: -------------------------------------------------------------------------------- 1 | function U = unisample(A,p) 2 | 3 | %UNISAMPLE subsampling a graph 4 | % 5 | % Input A: n by n adjacency matrix 6 | % p: probability of retaining each node. Defaults to 0.5. 7 | % 8 | % Output U: adjacency matrix with the attribute sparse. 9 | % Dimension of U cannot be predicted. 10 | % 11 | % Description: Nodes in a graph are retained with independent 12 | % probability p. Nodes that are "discarded" are removed 13 | % from the adjacency matrix. 14 | % 15 | % Example: U = unisample(A,0.25); 16 | 17 | if nargin == 1 18 | p = 0.5; 19 | end 20 | 21 | U=A; 22 | remove = find(rand(length(A),1) > p); % remove these rows/columns 23 | U(remove,:) = []; 24 | U(:,remove) = []; -------------------------------------------------------------------------------- /elapsed.m: -------------------------------------------------------------------------------- 1 | function str_elapsed = elapsed(t) 2 | %takes a time t and converts it into hours, minutes, seconds. 3 | % param t is in seconds 4 | % return str_elapsed says "Time Elapsed is 6 seconds, 4 minutes, ..." 5 | if t > 1 6 | str_elapsed = ['Time Elapsed is ', seconds2human(t)]; 7 | else 8 | str_elapsed = ['Time Elapsed is ', num2str(t), ' seconds']; 9 | end; -------------------------------------------------------------------------------- /getMiddle.m: -------------------------------------------------------------------------------- 1 | function middle = getMiddle(vector) 2 | %Returns just the middle of a vector from position 2 to end-1. 3 | % param vector can be of any length 4 | % return middle is a vector of length(vector)-2 5 | middle = vector(2:end-1); -------------------------------------------------------------------------------- /getTimeXAxis.m: -------------------------------------------------------------------------------- 1 | function yearq = getTimeXAxis(startYr,Nyr) 2 | % getTimeXAxis returns a vector of X Axis labels with time/qtr pairs 3 | % 4 | % Parameters: 5 | % start is the start year 6 | % N is the number of quarters desired starting 1Q1980 7 | % 8 | % Returns: 9 | % CellArray of labels of length N 10 | 11 | yr = startYr:startYr+ceil(Nyr/4); 12 | qtr = [3 6 9 12]; 13 | 14 | yrlist = repmat(yr,1,4); 15 | sorted_yrlist = sort(yrlist); 16 | qtrlist = repmat(qtr,1,length(yr)); 17 | datev = [sorted_yrlist' qtrlist' ones(length(qtrlist),4)]; 18 | dates = datestr(datev); 19 | 20 | yearq = cellstr(dates(1:Nyr,:)); -------------------------------------------------------------------------------- /laplacian.m: -------------------------------------------------------------------------------- 1 | function L = laplacian(A) 2 | % LAPLACIAN Compute the Laplacian matrix for a graph. 3 | % 4 | % L = laplacian(A) computes the weighted Laplacian matrix for a symmetric 5 | % adjenceny matrix A. 6 | % 7 | % If A has unit weights, then the Laplacian is unweighted. 8 | % 9 | 10 | % 11 | % David Gleich 12 | % October 29th, 2005 13 | % 14 | 15 | L = diag(sum(A,2)) - A; -------------------------------------------------------------------------------- /matlab_bgl/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | matlab-bgl-work 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /matlab_bgl/@inplace/assign.m: -------------------------------------------------------------------------------- 1 | function ipa = assign(ipa,y,varargin) 2 | % INPLACE/ASSIGN Assign an entire inplace array. 3 | % 4 | % assign(ipa,y) overwrites the contents of ipa with y. 5 | % 6 | % Example: 7 | % ipa = inplace(ones(5,1)); 8 | % assign(ipa,pi*ones(5,1)); 9 | 10 | ipd.assign(y); -------------------------------------------------------------------------------- /matlab_bgl/@inplace/display.m: -------------------------------------------------------------------------------- 1 | function display(ipa) 2 | % INPLACE/DISPLAY Display an inplace array from the command line. 3 | % 4 | % Example: 5 | % ipa = inplace(ones(5)); 6 | % ipa 7 | 8 | disp([inputname(1), ' = ']); 9 | disp(ipa.get_a()); -------------------------------------------------------------------------------- /matlab_bgl/@inplace/double.m: -------------------------------------------------------------------------------- 1 | function d = double(ipa) 2 | % INPLACE/DOUBLE Return the data as a Matlab double type. 3 | % d = double(ipa) returns a double array. Changing d will not change the 4 | % ipa data. 5 | % 6 | % Example: 7 | % ipa = inplace(cumsum(ones(5,1))); 8 | % d = double(ipa); 9 | % d(2) = 10: % Doesn't change ipa 10 | % ipa 11 | 12 | d = ipa.get_a(); -------------------------------------------------------------------------------- /matlab_bgl/@inplace/end.m: -------------------------------------------------------------------------------- 1 | function n=end(ipa,a,n) 2 | % INPLACE/END Allow inline "end" indices to work. 3 | % 4 | % n=end(ipa,a,n) Returns the ending index along dimension a. 5 | % 6 | % Example: 7 | % ipa = inplace(cumsum(ones(5,1))); 8 | % ipa(3:end) 9 | 10 | n = size(ipa.get_a(),a); -------------------------------------------------------------------------------- /matlab_bgl/@inplace/inplace.m: -------------------------------------------------------------------------------- 1 | function ip = inplace(a) 2 | % INPLACE Convert to a type that supports inplace modification 3 | % ipa = inplace(v) creates an inplace double object from any matrix v. 4 | % 5 | % Example: 6 | % ipa = inplace(ones(5)); 7 | 8 | if nargin == 0 9 | error('inplace:invalidParameter', ['ipdouble must be created with an initial .']); 10 | elseif isa(a,'ipdouble') 11 | % make a copy 12 | ipd = inplace(a.a); 13 | 14 | return; 15 | 16 | end 17 | 18 | function out = ip_get_a() 19 | out = a; 20 | end 21 | 22 | function ip_assign(in) 23 | a = in; 24 | end 25 | 26 | function ip_subsasgn(S,B) 27 | subsasgn(a,S,B); 28 | end 29 | 30 | ip.get_a = @ip_get_a; 31 | ip.assign = @ip_assign; 32 | ip.subsasgn = @ip_subsasgn; 33 | 34 | ip = class(ip,'inplace'); 35 | 36 | % ***** end inplace ***** 37 | end 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /matlab_bgl/@inplace/size.m: -------------------------------------------------------------------------------- 1 | function [varargout] = size(ipa) 2 | % INPLACE/SIZE Size of array 3 | % 4 | % [m,n] = size(ipa) Juse like SIZE for matrices and vectors. 5 | % 6 | % Example: 7 | % ipa = inplace(ones(10,3)); 8 | % size(ipa) 9 | 10 | varargout{:} = size(ipd.get_a()); -------------------------------------------------------------------------------- /matlab_bgl/@inplace/subsasgn.m: -------------------------------------------------------------------------------- 1 | function ip=subsasgn(ip,S,B) 2 | % INPLACE/SUBSASGN Support Matlab subscript assignment 3 | % 4 | % This function supports subscript assignment just like Matlab matrices. 5 | % 6 | % Example: 7 | % ipa = inplace(cumsum(ones(5,1))); 8 | % ipa([2 4]) = 1; 9 | % ipa 10 | 11 | ip.subsasgn(S,B); -------------------------------------------------------------------------------- /matlab_bgl/@inplace/subsref.m: -------------------------------------------------------------------------------- 1 | function b = subsref(ipd,index) 2 | % INPLACE/SUBSREF Support Matlab subscript references. 3 | % 4 | % This function supports subscript references just like Matlab matrices. 5 | % 6 | % Example: 7 | % ipa = inplace(cumsum(ones(5,1))); 8 | % ipa([2 4]) 9 | % ipa(3:end) 10 | 11 | if (length(index) > 1) 12 | error('Indexing operation not supported'); 13 | end; 14 | if (strcmp(index.type,'()')) 15 | b = subsref(ipd.get_a(),index); 16 | elseif (strcmp(index.type,'.')) 17 | try 18 | a = 1; 19 | a.a; 20 | catch 21 | rethrow(lasterr); 22 | end; 23 | elseif (strcmp(index.type,'{}')) 24 | try 25 | a = 1; 26 | a{1}; 27 | catch 28 | rethrow(lasterr); 29 | end; 30 | else 31 | error('Unsupported'); 32 | end; 33 | -------------------------------------------------------------------------------- /matlab_bgl/@ipdouble/ipdouble.m: -------------------------------------------------------------------------------- 1 | function ipd = ipdouble(a) 2 | % IPDOUBLE Create a double type that supports inplace modification 3 | % ipd = ipdouble(v) creates an inplace double object from any double 4 | % matrix v. 5 | % 6 | % Example: 7 | % ipd = ipdouble(ones(5)); 8 | 9 | ip = inplace(a); 10 | ipd = class(struct([]),'ipdouble',ip); 11 | 12 | -------------------------------------------------------------------------------- /matlab_bgl/@ipint32/ipint32.m: -------------------------------------------------------------------------------- 1 | function ipi = ipint32(a) 2 | % IPDOUBLE Create a int32 type that supports inplace modification 3 | % ipi = ipint32(v) creates an inplace int32 object from any int32 4 | % matrix v. 5 | % 6 | % Example: 7 | % ipd = ipint32(ones(5)); 8 | 9 | ip = inplace(a); 10 | ipi = class(struct([]),'ipint32',ip); 11 | 12 | -------------------------------------------------------------------------------- /matlab_bgl/circle_graph_layout.m: -------------------------------------------------------------------------------- 1 | function X = circle_graph_layout(G,radius) 2 | % CIRCLE_LAYOUT Layout the vertices of a graph on a circle 3 | % 4 | % X = circle_layout(G) generates a layout of graph with vertices uniformly 5 | % placed on the circle. This function does no interesting layout and just 6 | % places the vertices around the circle in order. 7 | % 8 | % X = circle_layout(G,radius) places the vertices with a radius other than 9 | % 1.0. 10 | % 11 | % Example: 12 | % G = cycle_graph(6); 13 | % X = circle_graph_layout(G); 14 | % gplot(G,X); 15 | 16 | % David F. Gleich 17 | % Copyright, Stanford University, 2008 18 | 19 | %% History 20 | % 2008-09-25: Initial coding 21 | %% 22 | 23 | if ~exist('radius','var') || isempty(radius), radius = 1.0; end; 24 | pi = 3.14159; 25 | n = num_vertices(G); 26 | X = zeros(n,2); 27 | X(:,1) = radius*cos( (0:n-1)'*2*pi/n ); 28 | X(:,2) = radius*sin( (0:n-1)'*2*pi/n ); 29 | -------------------------------------------------------------------------------- /matlab_bgl/doc/html/core_numbers_example/core_numbers_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/core_numbers_example/core_numbers_example.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/core_numbers_example/core_numbers_example_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/core_numbers_example/core_numbers_example_01.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/core_numbers_example/core_numbers_example_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/core_numbers_example/core_numbers_example_02.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/images/matlab-bgl-header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/images/matlab-bgl-header.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/new_in_3/new_in_3_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/new_in_3/new_in_3_0.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/new_in_3/new_in_3_0_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/new_in_3/new_in_3_0_01.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/new_in_3/new_in_3_0_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/new_in_3/new_in_3_0_02.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/new_in_3/new_in_3_0_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/new_in_3/new_in_3_0_03.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/new_in_4/new_in_4_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/new_in_4/new_in_4_0.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/new_in_4/new_in_4_0_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/new_in_4/new_in_4_0_01.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/new_in_4/new_in_4_0_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/new_in_4/new_in_4_0_02.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/new_in_4/new_in_4_0_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/new_in_4/new_in_4_0_03.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/new_in_4/new_in_4_0_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/new_in_4/new_in_4_0_04.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/planar_graphs/planar_graphs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/planar_graphs/planar_graphs.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/planar_graphs/planar_graphs_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/planar_graphs/planar_graphs_01.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/planar_graphs/planar_graphs_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/planar_graphs/planar_graphs_02.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/planar_graphs/planar_graphs_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/planar_graphs/planar_graphs_03.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/planar_graphs/planar_graphs_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/planar_graphs/planar_graphs_04.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/planar_graphs/planar_graphs_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/planar_graphs/planar_graphs_05.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/planar_graphs/planar_graphs_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/planar_graphs/planar_graphs_06.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/planar_graphs/planar_graphs_07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/planar_graphs/planar_graphs_07.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/planar_graphs/planar_graphs_08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/planar_graphs/planar_graphs_08.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/red_black/red_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/red_black/red_black.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/red_black/red_black_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/red_black/red_black_01.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/red_black/red_black_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/red_black/red_black_02.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/red_black/red_black_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/red_black/red_black_03.png -------------------------------------------------------------------------------- /matlab_bgl/doc/html/red_black/red_black_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/doc/html/red_black/red_black_04.png -------------------------------------------------------------------------------- /matlab_bgl/doc/write_examples_html.m: -------------------------------------------------------------------------------- 1 | opts = @(outputDir) struct(... 2 | 'format','html',... 3 | 'stylesheet',fullfile(pwd,'../doc/','mxdom2mbgl-html.xsl'),... 4 | 'outputDir', fullfile(pwd,['../doc/html/' outputDir '/'])); 5 | 6 | try 7 | cd ('../examples'); 8 | publish('red_black.m', opts('red_black')); 9 | publish('record_alg.m', opts('record_alg')); 10 | cnopts = opts('core_numbers_example'); cnopts.figureSnapMethod='getframe'; 11 | publish('core_numbers_example.m', cnopts); 12 | publish('reweighted_graphs.m', opts('reweighted_graphs')); 13 | publish('new_in_3_0.m', opts('new_in_3')); 14 | publish('new_in_4_0.m', opts('new_in_4')); 15 | publish('planar_graphs.m', opts('planar_graphs')); 16 | catch 17 | cd ('../doc'); 18 | end 19 | -------------------------------------------------------------------------------- /matlab_bgl/edmunds_karp_max_flow.m: -------------------------------------------------------------------------------- 1 | function [varargout]=edmunds_karp_max_flow(A,u,v,varargin) 2 | % EDMUNDS_KARP_MAX_FLOW Edmunds-Karp max flow algorithm 3 | % 4 | % The Edmunds-Karp algorithm implements the augmenting path idea 5 | % to compute a maximum flow or minimum cut in a network. 6 | % 7 | % See the max_flow function for calling information and return parameters. 8 | % This function just calls max_flow(...,struct('algname','edmunds_karp')); 9 | % The complexity is O(VE^2) or O(VEU) where U is the maximum capacity. 10 | % 11 | % Example: 12 | % load('graphs/max_flow_example.mat'); 13 | % edmunds_karp_max_flow(A,1,8) 14 | 15 | % David Gleich 16 | % Copyright, Stanford University, 2007-2008 17 | 18 | %% History 19 | % 2007-07-07: Initial version 20 | % 2008-10-07: Changed options parsing 21 | %% 22 | 23 | algname = 'edmunds_karp'; 24 | 25 | if ~isempty(varargin), 26 | options = merge_options(struct(),varargin{:}); 27 | options.algname= algname; 28 | else options = struct('algname',algname); 29 | end 30 | 31 | varargout = cell(1,max(nargout,1)); 32 | 33 | [varargout{:}] = max_flow(A,u,v,options); 34 | -------------------------------------------------------------------------------- /matlab_bgl/erdos_reyni.m: -------------------------------------------------------------------------------- 1 | function A=erdos_reyni(n,p) 2 | % ERDOS_REYNI Generates a random Erdos-Reyni (Gnp) graph 3 | % 4 | % A=erdos_reyni(n,p) generates a random Gnp graph with n vertices and where 5 | % the probability of each edge is p. The resulting graph is symmetric. 6 | % 7 | % This function is different from the Boost Graph library version, it was 8 | % reimplemented natively in Matlab. 9 | % 10 | % Example: 11 | % A = erdos_reyni(100,0.05); 12 | 13 | % David Gleich 14 | % Copyright, Stanford University, 2006-2008 15 | 16 | %% History 17 | % 2006-05-21: Initial version 18 | % 2007-04-05: Fixed the function so it returns correct output. 19 | %% 20 | 21 | A = triu(rand(n) 27 | typedef size_t mbglIndex; 28 | typedef mbglIndex mbglDegreeType; 29 | #else 30 | typedef int mbglIndex; 31 | typedef unsigned int mbglDegreeType; 32 | #endif /* MATLAB_BGL_LARGE_ARRAYS */ 33 | 34 | #endif /* MATLAB_BGL_TYPES_H */ 35 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/libmbgl_test/fr_layout_test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char **argv) { 6 | mbglIndex rp[] = {0, 3, 7, 11, 15, 19, 22, 26, 31, 36, 41, 46, 50, 54, 59, 64, 69, 74, 78, 82, 87, 92, 97, 102, 106, 109, 113, 117, 121, 125, 128}; 7 | mbglIndex ci[] = {0, 1, 6, 0, 1, 2, 7, 1, 2, 3, 8, 2, 3, 4, 9, 3, 4, 5, 10, 4, 5, 11, 0, 6, 7, 12, 1, 6, 7, 8, 13, 2, 7, 8, 9, 14, 3, 8, 9, 10, 15, 4, 9, 10, 11, 16, 5, 10, 11, 17, 6, 12, 13, 18, 7, 12, 13, 14, 19, 8, 13, 14, 15, 20, 9, 14, 15, 16, 21, 10, 15, 16, 17, 22, 11, 16, 17, 23, 12, 18, 19, 24, 13, 18, 19, 20, 25, 14, 19, 20, 21, 26, 15, 20, 21, 22, 27, 16, 21, 22, 23, 28, 17, 22, 23, 29, 18, 24, 25, 19, 24, 25, 26, 20, 25, 26, 27, 21, 26, 27, 28, 22, 27, 28, 29, 23, 28, 29}; 8 | double positions[60]; 9 | 10 | fruchterman_reingold_force_directed_layout( 11 | 30, ci, rp, 12 | 100, 10.0, 1, 13 | 50.0, 50.0, 0, positions); 14 | for (int i = 0; i < 30; i++) { 15 | std::cout << positions[i] << " " << positions[i+30] << std::endl; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/libmbgl_test/layout_funcs_test.cc: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include "libmbgl_funcs_test.h" 6 | 7 | int test_layout_1() { 8 | const mbglIndex n = 9; 9 | mbglIndex rp[] = {0,3,7,10,14,19,23,26,30,33}; 10 | mbglIndex ci[] = {0,1,3,0,1,2,4,1,2,5,0,3,4,6,1,3,4,5,7,2,4,5,8,3,6,7,4,6,7,8,5,7,8}; 11 | double w[33], X[2*n], dists[n*n], springs[n*n]; 12 | int rval; 13 | for (int i=0; i<33; i++) { w[i]= 1.0; } 14 | rval= kamada_kawai_spring_layout(n, ci, rp, w, 0.0001, 100, 1.0, 0, 1.0, 15 | X, dists, springs); 16 | if (rval!=0) { 17 | errstr = "function error"; 18 | return -1; 19 | } 20 | return 0; 21 | } 22 | 23 | int layout_funcs_test() 24 | { 25 | int nfail= 0, ntotal= 0, rval; 26 | const char* name; 27 | 28 | name= "kamada_kawai 3-grid"; 29 | rval= test_layout_1(); ntotal++; 30 | if (rval!= 0) { nfail++; printf("%20s %50s\n", name, errstr); } 31 | else { printf("%20s success\n", name); } 32 | 33 | printf("\n"); 34 | printf("Total tests : %3i\n", ntotal); 35 | printf("Total failed : %3i\n", nfail); 36 | 37 | return nfail!=0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/libmbgl_test/libmbgl_funcs_test.cc: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include "libmbgl_funcs_test.h" 6 | 7 | const char* errstr = ""; 8 | 9 | 10 | int main(int argc, char **argv) { 11 | layout_funcs_test(); 12 | planar_funcs_test(); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/libmbgl_test/libmbgl_funcs_test.h: -------------------------------------------------------------------------------- 1 | extern const char* errstr; 2 | int planar_funcs_test(); 3 | int layout_funcs_test(); 4 | 5 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/libmbgl_test/libmbgl_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * David Gleich 3 | * Copyright, Stanford University, 2006-2007 4 | */ 5 | 6 | /** 7 | * @file libmbgl_test.cc 8 | * Implement a unit test for libmbgl 9 | */ 10 | 11 | /**History 12 | 13 | * 31 July 2007 14 | * Initial version 15 | */ 16 | 17 | #include "matlab_bgl.h" 18 | 19 | int main(int argc, char **argv) 20 | { 21 | mbglIndex ai[] = {0}; 22 | mbglIndex aj[] = {0}; 23 | mbglIndex ei[6], ej[6]; 24 | mbglIndex nedges = 0; 25 | 26 | triangulate_graph(0, aj, ai, 1, 1, 0, ei, ej, &nedges); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/libmbgl_test/planar_is_straight_line_test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char **argv) { 6 | mbglIndex n = 4; 7 | mbglIndex rp[] = {0,3,6,9,12}; 8 | mbglIndex ci[] = {1,2,3,0,2,3,0,1,3,0,1,2}; 9 | double X[] = { 1,2,1,0,2,1,0,1 }; 10 | int is_sldraw = 0; 11 | is_straight_line_drawing(n, ci, rp, X, &is_sldraw); 12 | std::cout << "is_sldraw = " << is_sldraw << std::endl; 13 | } 14 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/libmbgl_test/planar_ksubgraph_test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char **argv) { 6 | mbglIndex n = 5; 7 | mbglIndex rp[] = {0,4,8,12,16,20}; 8 | mbglIndex ci[] = {1,2,3,4,0,2,3,4,0,1,3,4,0,1,2,4,0,1,2,3}; 9 | mbglIndex ki[20]; 10 | mbglIndex kj[20]; 11 | int is_planar = 0; 12 | mbglIndex nedges = 0; 13 | boyer_myrvold_planarity_test(n, ci, rp, &is_planar, ki, kj, &nedges, 14 | NULL, NULL); 15 | std::cout << "is_planar = " << is_planar << std::endl; 16 | std::cout << "nedges = " << nedges << std::endl; 17 | if (nedges != 10) { 18 | return -1; 19 | } 20 | if (is_planar != 0) { 21 | return -1; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/libmbgl_util.hpp: -------------------------------------------------------------------------------- 1 | /** @file libmbgl_util.hpp 2 | * @author David F. Gleich 3 | * @date 2008-09-25 4 | * @copyright Stanford University, 2008 5 | * Misc utility functions 6 | */ 7 | 8 | /** History 9 | * 2008-09-25: Initial coding 10 | */ 11 | 12 | /** Wrapper class to turn a row-storage matrix into a boost BasicMatrix 13 | */ 14 | template 15 | struct row_matrix { 16 | value_type* head; 17 | std::size_t nrows; 18 | std::size_t ncols; 19 | const value_type* operator[](std::size_t i) const { 20 | return (head+ncols*i); 21 | } 22 | 23 | value_type* operator[](std::size_t i) { 24 | return (head+ncols*i); 25 | } 26 | 27 | row_matrix(value_type* _head, std::size_t _nrows, std::size_t _ncols) 28 | : head(_head), nrows(_nrows), ncols(_ncols) {} 29 | }; 30 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/orderings.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * @file orderings.cc 3 | * 4 | * Implement the BGL matrix orderings wrappers. 5 | */ 6 | 7 | /* 8 | * David Gleich 9 | * 21 April 2006 10 | */ 11 | 12 | #include "include/matlab_bgl.h" 13 | 14 | #include 15 | #include 16 | 17 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/stop_visitors.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MATLAB_BGL_STOP_VISITORS_HPP 2 | #define MATLAB_BGL_STOP_VISITORS_HPP 3 | 4 | /* 5 | * David Gleich 6 | * Copyright, Stanford University, 2007 7 | * 18 April 2007 8 | */ 9 | 10 | /** 11 | * @file stop_visitors.hpp 12 | * A few custom visitors that will stop a search (bfs,dfs,dijkstra,etc.) 13 | */ 14 | 15 | template 16 | struct vertex_search_stopper 17 | : public boost::base_visitor > 18 | { 19 | typedef Tag event_filter; 20 | vertex_search_stopper(Vertex v) 21 | : m_v(v) { } 22 | Vertex m_v; 23 | template 24 | void operator()(Vertex u, const Graph&) { 25 | if (m_v == u) { Exception e; throw e; } 26 | } 27 | }; 28 | 29 | template 30 | vertex_search_stopper 31 | stop_search_on_vertex_target(Vertex v, Exception, Tag) { 32 | return vertex_search_stopper(v); 33 | } 34 | 35 | #endif /* MATLAB_BGL_STOP_VISITORS_HPP */ 36 | 37 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/visitor_macros.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MATLAB_BGL_VISITOR_MACROS_HPP 2 | #define MATLAB_BGL_VISITOR_MACROS_HPP 3 | 4 | /* 5 | * David Gleich 6 | * Copyright, Stanford University, 2006-2007 7 | */ 8 | 9 | /* 10 | * 8 July 2007 11 | * Switched to get(edge_index,g,e) instead of get(get(edge_index,g),e) 12 | */ 13 | 14 | #define VISITOR_VERTEX_FUNC(NAME,EXCEPT) \ 15 | void NAME (typename boost::graph_traits::vertex_descriptor v, const Graph& g) \ 16 | { \ 17 | if (vis->NAME != NULL) \ 18 | { \ 19 | if (vis->NAME (vis->pdata, (int)v) == 0) \ 20 | throw EXCEPT (); \ 21 | } \ 22 | } 23 | 24 | #define VISITOR_EDGE_FUNC(NAME,EXCEPT) \ 25 | void NAME (typename boost::graph_traits::edge_descriptor e, const Graph& g) \ 26 | { \ 27 | if (vis->NAME != NULL) \ 28 | { \ 29 | int src=(int)boost::source(e,g), dst=(int)boost::target(e,g); \ 30 | if (vis->NAME (vis->pdata, (int)get(boost::edge_index, g, e), src, dst) == 0) \ 31 | throw EXCEPT (); \ 32 | } \ 33 | } 34 | 35 | 36 | #endif // MATLAB_BGL_VISITOR_MACROS_HPP 37 | 38 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/yasmic/.sconsign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/libmbgl/yasmic/.sconsign -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/yasmic/boost_mod/.sconsign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/libmbgl/yasmic/boost_mod/.sconsign -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/yasmic/boost_mod/integer_extra.hpp: -------------------------------------------------------------------------------- 1 | #ifndef YASMIC_BOOST_MOD_INTEGER_EXTRA_HPP 2 | #define YASMIC_BOOST_MOD_INTEGER_EXTRA_HPP 3 | 4 | /** 5 | * @file integer_extra.hpp 6 | * This file fixes some problems with the boost::int_t type 7 | * and 64-bit compiles under Windows. 8 | */ 9 | 10 | #ifdef BOOST_MSVC 11 | // this code is only for MSVC 12 | namespace boost { 13 | template <> 14 | struct int_t<64> { 15 | typedef __int64 least; 16 | typedef __int64 fast; 17 | }; 18 | } 19 | #endif // BOOST_MSVC 20 | 21 | #endif // YASMIC_BOOST_MOD_INTEGER_EXTRA_HPP 22 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/yasmic/indexed_list_as_graph.hpp: -------------------------------------------------------------------------------- 1 | #ifndef YASMIC_INDEXED_LIST_AS_GRAPH 2 | #define YASMIC_INDEXED_LIST_AS_GRAPH 3 | 4 | /** 5 | * @file indexed_list_as_graph.hpp 6 | * Provide the necessary types to view an IndexedList as an EdgeListGraph 7 | * for use with the Boost graph library. 8 | * 9 | * We also provide very inefficient routines to access the vertices and 10 | * edges; but don't use these. 11 | */ 12 | 13 | 14 | 15 | 16 | #endif //YASMIC_INDEXED_LIST_AS_GRAPH -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/yasmic/tuple_utility.hpp: -------------------------------------------------------------------------------- 1 | #ifndef YASMIC_TUPLE_UTILITY 2 | #define YASMIC_TUPLE_UTILITY 3 | 4 | #include 5 | 6 | namespace yasmic 7 | { 8 | template 9 | boost::tuple< 10 | typename boost::tuples::element::type, 11 | typename boost::tuples::element::type > 12 | tuple_get_2(const Tuple& t) 13 | { 14 | return ( boost::make_tuple(boost::tuples::get(t), 15 | boost::tuples::get(t)) ); 16 | } 17 | 18 | template 19 | struct tuple_get_2_fn 20 | { 21 | typedef boost::tuple< 22 | typename boost::tuples::element::type, 23 | typename boost::tuples::element::type > result_type; 24 | typedef const Tuple argument_type; 25 | 26 | result_type operator() (argument_type arg) const 27 | { 28 | return tuple_get_2(arg); 29 | } 30 | }; 31 | 32 | template 33 | struct tuple_get_fn 34 | { 35 | typedef 36 | typename boost::tuples::element::type result_type; 37 | typedef const Tuple argument_type; 38 | 39 | result_type operator() (argument_type arg) const 40 | { 41 | return boost::tuples::get(arg); 42 | } 43 | }; 44 | } 45 | 46 | #endif // YASMIC_TUPLE_UTILITY 47 | 48 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/yasmic/util/.sconsign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/libmbgl/yasmic/util/.sconsign -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/yasmic/verbose_util.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * verbose_util.hpp 3 | * David Gleich 4 | * Stanford University 5 | * 17 March 2006 6 | */ 7 | 8 | /** 9 | * @file verbose_util.hpp 10 | * Add defines to control verbose statement in the code. 11 | */ 12 | 13 | // 14 | // this file is somewhat strange. There are two sections; the first section 15 | // simple makes a few define statements 16 | // 17 | #ifdef YASMIC_VERBOSE_UTIL_DEFINE 18 | namespace yasmic 19 | { 20 | int yasmic_verbose; 21 | } // namespace yasmic 22 | #else 23 | namespace yasmic 24 | { 25 | extern int yasmic_verbose; 26 | } 27 | #endif // YASMIC_VERBOSE_UTIL_DEFINE 28 | 29 | #ifndef YASMIC_VERBOSE_UTIL 30 | #define YASMIC_VERBOSE_UTIL 31 | 32 | #ifdef YASMIC_USE_VERBOSE 33 | 34 | #define YASMIC_VERBOSE(a) \ 35 | if (yasmic::yasmic_verbose) \ 36 | { \ 37 | a; \ 38 | } 39 | 40 | #else 41 | 42 | #define YASMIC_VERBOSE(a) \ 43 | 44 | #endif 45 | 46 | 47 | 48 | 49 | #endif // YASMIC_VERBOSE_UTIL 50 | 51 | -------------------------------------------------------------------------------- /matlab_bgl/libmbgl/yasmic/yasmic.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /matlab_bgl/num_edges.m: -------------------------------------------------------------------------------- 1 | function n=num_edges(A) 2 | % NUM_EDGES The number of edges in a graph. 3 | % 4 | % n = num_edges(A) returns the number of edges in graph A. 5 | % 6 | % For symmetric/undirected graphs, the number of edges returned is twice 7 | % the number of undirected edges. 8 | % 9 | % Example: 10 | % load graphs/dfs_example.mat 11 | % n = num_edges(A) 12 | % 13 | % See also NUM_VERTICES 14 | 15 | % David Gleich 16 | % Copyright, Stanford University, 2006-2008 17 | 18 | n = nnz(A); 19 | -------------------------------------------------------------------------------- /matlab_bgl/num_vertices.m: -------------------------------------------------------------------------------- 1 | function n=num_vertices(A) 2 | % NUM_VERTICES The number of vertices in a graph. 3 | % 4 | % n = num_vertices(A) returns the number of vertices in graph A. 5 | % 6 | % Example: 7 | % A = sparse(ones(5)); 8 | % n = num_vertices(A); 9 | % 10 | % See also NUM_EDGES 11 | 12 | % David Gleich 13 | % Copyright, Stanford University, 2006-2008 14 | 15 | n = size(A,1); 16 | -------------------------------------------------------------------------------- /matlab_bgl/private/astar_search_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/astar_search_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/astar_search_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/astar_search_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/astar_search_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/astar_search_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/astar_search_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/astar_search_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/astar_search_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/astar_search_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/astar_search_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/astar_search_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/betweenness_centrality_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/betweenness_centrality_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/betweenness_centrality_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/betweenness_centrality_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/betweenness_centrality_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/betweenness_centrality_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/betweenness_centrality_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/betweenness_centrality_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/betweenness_centrality_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/betweenness_centrality_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/betweenness_centrality_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/betweenness_centrality_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/bfs_dfs_vis_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/bfs_dfs_vis_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/bfs_dfs_vis_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/bfs_dfs_vis_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/bfs_dfs_vis_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/bfs_dfs_vis_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/bfs_dfs_vis_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/bfs_dfs_vis_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/bfs_dfs_vis_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/bfs_dfs_vis_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/bfs_dfs_vis_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/bfs_dfs_vis_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/bfs_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/bfs_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/bfs_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/bfs_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/bfs_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/bfs_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/bfs_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/bfs_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/bfs_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/bfs_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/bfs_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/bfs_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/biconnected_components_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/biconnected_components_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/biconnected_components_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/biconnected_components_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/biconnected_components_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/biconnected_components_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/biconnected_components_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/biconnected_components_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/biconnected_components_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/biconnected_components_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/biconnected_components_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/biconnected_components_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/clustering_coefficients_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/clustering_coefficients_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/clustering_coefficients_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/clustering_coefficients_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/clustering_coefficients_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/clustering_coefficients_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/clustering_coefficients_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/clustering_coefficients_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/clustering_coefficients_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/clustering_coefficients_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/clustering_coefficients_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/clustering_coefficients_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/common_macros.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/common_macros.h -------------------------------------------------------------------------------- /matlab_bgl/private/components_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/components_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/components_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/components_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/components_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/components_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/components_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/components_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/components_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/components_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/components_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/components_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/core_numbers_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/core_numbers_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/core_numbers_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/core_numbers_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/core_numbers_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/core_numbers_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/core_numbers_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/core_numbers_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/core_numbers_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/core_numbers_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/core_numbers_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/core_numbers_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/dfs_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/dfs_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/dfs_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/dfs_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/dfs_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/dfs_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/dfs_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/dfs_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/dfs_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/dfs_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/dfs_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/dfs_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/dominator_tree_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/dominator_tree_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/dominator_tree_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/dominator_tree_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/dominator_tree_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/dominator_tree_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/dominator_tree_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/dominator_tree_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/dominator_tree_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/dominator_tree_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/dominator_tree_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/dominator_tree_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/fruchterman_reingold_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/fruchterman_reingold_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/fruchterman_reingold_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/fruchterman_reingold_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/fruchterman_reingold_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/fruchterman_reingold_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/fruchterman_reingold_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/fruchterman_reingold_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/fruchterman_reingold_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/fruchterman_reingold_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/fruchterman_reingold_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/fruchterman_reingold_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/get_matlab_bgl_options.m: -------------------------------------------------------------------------------- 1 | function [trans check full2sparse] = get_matlab_bgl_options(varargin) 2 | % 3 | % Internal private function. 4 | % 5 | % Example: 6 | % Don't use this function! 7 | % 8 | 9 | %% History 10 | % 2008-09-26: Changed to use merge_options instead 11 | %% 12 | 13 | doptions = set_matlab_bgl_default(); 14 | if nargin>0 15 | options = merge_options(doptions,varargin{:}); 16 | else 17 | options = doptions; 18 | end 19 | 20 | trans = ~options.istrans; 21 | check = ~options.nocheck; 22 | full2sparse = options.full2sparse; 23 | 24 | -------------------------------------------------------------------------------- /matlab_bgl/private/gursoy_atun_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/gursoy_atun_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/gursoy_atun_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/gursoy_atun_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/gursoy_atun_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/gursoy_atun_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/gursoy_atun_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/gursoy_atun_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/gursoy_atun_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/gursoy_atun_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/gursoy_atun_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/gursoy_atun_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/kamada_kawai_spring_layout_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/kamada_kawai_spring_layout_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/kamada_kawai_spring_layout_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/kamada_kawai_spring_layout_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/kamada_kawai_spring_layout_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/kamada_kawai_spring_layout_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/kamada_kawai_spring_layout_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/kamada_kawai_spring_layout_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/kamada_kawai_spring_layout_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/kamada_kawai_spring_layout_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/kamada_kawai_spring_layout_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/kamada_kawai_spring_layout_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/matching_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matching_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/matching_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matching_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/matching_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matching_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/matching_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matching_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/matching_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matching_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/matching_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matching_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/matlab_bgl_all_sp_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matlab_bgl_all_sp_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/matlab_bgl_all_sp_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matlab_bgl_all_sp_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/matlab_bgl_all_sp_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matlab_bgl_all_sp_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/matlab_bgl_all_sp_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matlab_bgl_all_sp_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/matlab_bgl_all_sp_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matlab_bgl_all_sp_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/matlab_bgl_all_sp_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matlab_bgl_all_sp_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/matlab_bgl_sp_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matlab_bgl_sp_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/matlab_bgl_sp_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matlab_bgl_sp_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/matlab_bgl_sp_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matlab_bgl_sp_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/matlab_bgl_sp_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matlab_bgl_sp_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/matlab_bgl_sp_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matlab_bgl_sp_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/matlab_bgl_sp_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/matlab_bgl_sp_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/max_flow_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/max_flow_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/max_flow_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/max_flow_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/max_flow_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/max_flow_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/max_flow_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/max_flow_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/max_flow_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/max_flow_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/max_flow_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/max_flow_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/merge_options.m: -------------------------------------------------------------------------------- 1 | function options = merge_options(default_options,varargin) 2 | % MERGE_OPTIONS Merge a set of default options with options from varargin 3 | % The set of options in varargin can be a list of key,value pairs, or a 4 | % struct with the same information. 5 | 6 | % David F. Gleich 7 | % Copyright, Stanford University, 2008 8 | 9 | %% History 10 | % 2008-09-25: Initial coding 11 | %% 12 | 13 | if ~isempty(varargin) && mod(length(varargin),2) == 0 14 | options = merge_structs(struct(varargin{:}),default_options); 15 | elseif length(varargin)==1 && isstruct(varargin{1}) 16 | options = merge_structs(varargin{1},default_options); 17 | elseif ~isempty(varargin) 18 | error('matlag_bgl:optionsParsing',... 19 | 'There were an odd number of key-value pairs of options specified'); 20 | else 21 | options = default_options; 22 | end -------------------------------------------------------------------------------- /matlab_bgl/private/merge_structs.m: -------------------------------------------------------------------------------- 1 | function S = merge_structs(A, B) 2 | % MERGE_STRUCTS Merge two structures. 3 | % 4 | % S = merge_structs(A, B) makes the structure S have all the fields from A 5 | % and B. Conflicts are resolved by using the value in A. 6 | % 7 | 8 | % 9 | % merge_structs.m 10 | % David Gleich 11 | % 12 | % Revision 1.00 13 | % 19 Octoboer 2005 14 | % 15 | 16 | S = A; 17 | 18 | fn = fieldnames(B); 19 | 20 | for ii = 1:length(fn) 21 | if (~isfield(A, fn{ii})) 22 | S.(fn{ii}) = B.(fn{ii}); 23 | end; 24 | end; 25 | 26 | -------------------------------------------------------------------------------- /matlab_bgl/private/mst_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/mst_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/mst_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/mst_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/mst_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/mst_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/mst_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/mst_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/mst_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/mst_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/mst_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/mst_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/path_from_pred_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/path_from_pred_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/path_from_pred_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/path_from_pred_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/path_from_pred_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/path_from_pred_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/path_from_pred_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/path_from_pred_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/path_from_pred_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/path_from_pred_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/path_from_pred_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/path_from_pred_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/planar_drawing_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_drawing_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/planar_drawing_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_drawing_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/planar_drawing_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_drawing_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/planar_drawing_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_drawing_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/planar_drawing_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_drawing_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/planar_drawing_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_drawing_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/planar_edges_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_edges_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/planar_edges_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_edges_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/planar_edges_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_edges_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/planar_edges_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_edges_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/planar_edges_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_edges_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/planar_edges_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_edges_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/planar_test_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_test_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/planar_test_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_test_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/planar_test_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_test_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/planar_test_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_test_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/planar_test_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_test_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/planar_test_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/planar_test_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/test_matching_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/test_matching_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/test_matching_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/test_matching_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/test_matching_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/test_matching_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/test_matching_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/test_matching_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/test_matching_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/test_matching_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/test_matching_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/test_matching_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/private/todo.m: -------------------------------------------------------------------------------- 1 | 2 | 3 | % 4 | % check dijkstra for only positive values 5 | % 6 | % write graph xml reader 7 | % 8 | % add graph struct type... 9 | % 10 | % ctrl-c mex files 11 | % 12 | % 13 | % 14 | 15 | % graph constructions 16 | % - butterfly graph [A xy labels] = butterfly_graph(levels) 17 | % - cycle graph [A xy] = cycle_graph(nodes) 18 | % - complete graph [A xy] = complete_graph(nodes) 19 | % - hypercube graph A = hypercube_graph(nodes) 20 | % - grid graph A = hypergrid_graph(n1,n2,...) 21 | % - generalized petersen graph 22 | % - random subgraph 23 | % - k-ary tree 24 | % - graph_product 25 | % - line_graph 26 | % - circulant graph (generalization of complete graph) 27 | % - wheel graph 28 | % - degree sequence 29 | 30 | % graph algorithms 31 | % - greedy vertex cover 32 | % - eulerian tour 33 | % - prufer code (to/from tree) 34 | % - degree sequence 35 | 36 | % graph embeddigns 37 | % - circular embedding 38 | % - ranked embedding 39 | 40 | % data structures 41 | % - incidence matrix 42 | % - symmetrize graph (aka. make_undirected) 43 | 44 | fprintf('Wanna help? Send me email!'); 45 | 46 | -------------------------------------------------------------------------------- /matlab_bgl/private/todo_3_0_release.m: -------------------------------------------------------------------------------- 1 | % finish reweighted_graphs.m 2 | % add more to test_main.m 3 | % finish new_in_3_0.m 4 | % finish matching_dmperm.m 5 | % add root vertex to prim's algorithm 6 | % check documentation for core_numbers 7 | % 8 | -------------------------------------------------------------------------------- /matlab_bgl/private/topological_order_mex.mexa64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/topological_order_mex.mexa64 -------------------------------------------------------------------------------- /matlab_bgl/private/topological_order_mex.mexglx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/topological_order_mex.mexglx -------------------------------------------------------------------------------- /matlab_bgl/private/topological_order_mex.mexmac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/topological_order_mex.mexmac -------------------------------------------------------------------------------- /matlab_bgl/private/topological_order_mex.mexmaci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/topological_order_mex.mexmaci -------------------------------------------------------------------------------- /matlab_bgl/private/topological_order_mex.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/topological_order_mex.mexw32 -------------------------------------------------------------------------------- /matlab_bgl/private/topological_order_mex.mexw64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/matlab_bgl/private/topological_order_mex.mexw64 -------------------------------------------------------------------------------- /matlab_bgl/push_relabel_max_flow.m: -------------------------------------------------------------------------------- 1 | function [varargout]=push_relabel_max_flow(A,u,v,varargin) 2 | % PUSH_RELABEL_MAX_FLOW Goldberg's push-relabel max flow algorithm 3 | % 4 | % This function calls Boost's implementation of Goldberg's push relabel 5 | % algorithm to compute a maximum flow in a graph. 6 | % 7 | % See the max_flow function for calling information and return parameters. 8 | % This function just calls max_flow(...,struct('algname','push_relabel')); 9 | % 10 | % Example: 11 | % load('graphs/max_flow_example.mat'); 12 | % push_relabel_max_flow(A,1,8) 13 | 14 | % David Gleich 15 | % Copyright, Stanford University, 2007-2008 16 | 17 | %% History 18 | % 2007-07-07: Initial version 19 | % 2008-10-07: Changed options parsing 20 | %% 21 | 22 | algname = 'push_relabel'; 23 | if ~isempty(varargin), 24 | options = merge_options(struct(),varargin{:}); 25 | options.algname= algname; 26 | else options = struct('algname',algname); 27 | end 28 | 29 | varargout = cell(1,max(nargout,1)); 30 | [varargout{:}] = max_flow(A,u,v,options); 31 | -------------------------------------------------------------------------------- /matlab_bgl/star_graph.m: -------------------------------------------------------------------------------- 1 | function [A xy] = star_graph(n) 2 | % STAR_GRAPH Generate the star graph of order n 3 | % 4 | % The star graph is a simple star with n vertices. Vertex n is the center 5 | % vertex. 6 | % 7 | % [A xy] = star_graph(n) generates a star graph with n vertices and 8 | % returns the adjacency matrix in A. The matrix xy stores two-dimensional 9 | % coordinates for each vertex. 10 | % 11 | % Example: 12 | % [A xy] = star_graph(10); 13 | % gplot(A,xy); 14 | % 15 | % See also WHEEL_GRAPH, CYCLE_GRAPH 16 | 17 | % David Gleich 18 | % Copyright, Stanford University, 2007-2008 19 | 20 | %% History 21 | % 2007-09-29: Changed output to double 22 | %% 23 | 24 | 25 | i = 1:n-1; 26 | j = n*ones(1,n-1); 27 | A = sparse(i,j,1,n,n); 28 | A = A|A'; 29 | A = double(A); 30 | 31 | xy = [[cos(2*pi*(i./(n-1))) 0]' [sin(2*pi*(i./(n-1))) 0]']; 32 | -------------------------------------------------------------------------------- /matlab_bgl/test/assert.m: -------------------------------------------------------------------------------- 1 | function assert(condition,varargin) 2 | 3 | if condition, return; 4 | else 5 | error(varargin{:}); 6 | end 7 | -------------------------------------------------------------------------------- /matlab_bgl/test/rtest_2.m: -------------------------------------------------------------------------------- 1 | function rval=rtest_2() 2 | 3 | rval = 0; 4 | try 5 | load ../graphs/cs-stanford.mat 6 | [ci s] = components(A); 7 | if (max(ci) ~= 4391) 8 | error('Incorrect number of components'); 9 | end; 10 | rval = 1; 11 | catch 12 | lasterr 13 | end -------------------------------------------------------------------------------- /matlab_bgl/test/rtest_5_henderson.m: -------------------------------------------------------------------------------- 1 | function rval=rtest_5_henderson() 2 | 3 | rval = 0; 4 | try 5 | rand('state',0); 6 | A = erdos_reyni(100,.1); 7 | if full(max(max(A))) > 1 8 | error('erdos_reyni.m does not return an adjacency matrix.'); 9 | end 10 | rval = 1; 11 | catch 12 | lasterr 13 | end -------------------------------------------------------------------------------- /matlab_bgl/test/rtest_6.m: -------------------------------------------------------------------------------- 1 | function rval = rtest_6() 2 | 3 | rval = 0; 4 | 5 | try 6 | 7 | % create a line graph 8 | n = 10; 9 | A = sparse(1:n-1,2:n,1,n,n); 10 | A = A+A'; 11 | 12 | u = 1; 13 | v = 5; 14 | 15 | d = dist_uv(A,u,v); 16 | 17 | if any(d(v+1:end) > 0) 18 | error('breadth_first_search did not stop correctly'); 19 | end 20 | 21 | rval = 1; 22 | catch 23 | lasterr 24 | end 25 | 26 | end 27 | 28 | function dmap = dist_uv(A,u,v) 29 | vstar = v; 30 | dmap = ipdouble(zeros(size(A,1),1)); 31 | function stop=on_tree_edge(ei,u,v) 32 | dmap(v) = dmap(u)+1; 33 | stop = (v ~= vstar); 34 | end 35 | breadth_first_search(A,u,struct('tree_edge',@on_tree_edge)); 36 | dmap = double(dmap); 37 | end 38 | 39 | -------------------------------------------------------------------------------- /matlab_bgl/test/rtest_7_karsi.m: -------------------------------------------------------------------------------- 1 | function rval=rtest_7_karsi 2 | % Test the flow-graph that Karci identified as causing a problem with the 3 | % min-cut computation. The min-cut value should always be equal to the 4 | % max-flow value. 5 | G = [0 46 0 46 0 0 0 0 0 0 461; 6 | 0 0 46 0 46 0 0 0 0 0 236; 7 | 0 0 0 0 0 46 0 0 0 0 23; 8 | 0 0 0 0 46 0 46 0 0 0 300; 9 | 0 0 0 0 0 46 0 46 0 0 46; 10 | 0 0 0 0 0 0 0 0 46 0 46; 11 | 0 0 0 0 0 0 0 46 0 0 23; 12 | 0 0 0 0 0 0 0 0 46 0 73; 13 | 0 0 0 0 0 0 0 0 0 0 183; 14 | 46 46 56 46 95 58 56 23 0 0 0; 15 | 0 0 0 0 0 0 0 0 0 0 0]; 16 | G=sparse(G); 17 | try 18 | [f c] = max_flow(G,10,11); 19 | [i j v] = find(G); 20 | I = c(i)>c(j); % form an indicator variable for edges crossing the cut 21 | cv = sum(I.*v); 22 | if cv~=f, error('Incorrect cut value'); end 23 | rval=1; 24 | catch 25 | lasterr 26 | end 27 | -------------------------------------------------------------------------------- /matlab_bgl/test/rtest_all.m: -------------------------------------------------------------------------------- 1 | D = dir; 2 | 3 | numtests = 0; 4 | results = []; 5 | 6 | for di = 1:length(D) 7 | f = D(di); 8 | if f.isdir 9 | continue; 10 | end 11 | 12 | [pathstr,name,ext] = fileparts(f.name); 13 | 14 | if ~strcmp(ext,'.m') 15 | continue 16 | end; 17 | 18 | if strcmp('rtest_all.m', f.name) 19 | continue; 20 | end 21 | 22 | if strmatch('rtest',f.name) 23 | numtests = numtests+1; 24 | 25 | [pathstr,name,ext] = fileparts(f.name); 26 | rval = eval(name); 27 | results(numtests) = rval; 28 | 29 | switch(rval) 30 | case 1 31 | fprintf('%s passed\n', name); 32 | case 0 33 | fprintf('** %s FAILED!!\n', name); 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /matlab_bgl/test/test_breadth_first_search.m: -------------------------------------------------------------------------------- 1 | function distmap = test_breadth_first_search(A,u) 2 | 3 | distmap = ipdouble(zeros(size(A,1),1)); 4 | distmap(u) = 0; 5 | 6 | function on_tree_edge(ei,u,v) 7 | distmap(v) = distmap(u)+1; 8 | end 9 | 10 | breadth_first_search(A,u,struct('tree_edge',@on_tree_edge)); 11 | 12 | distmap = double(distmap); 13 | end -------------------------------------------------------------------------------- /matlab_bgl/test/test_components.m: -------------------------------------------------------------------------------- 1 | function test_components 2 | 3 | %% 4 | msgid = 'matlab_bgl:test_components'; 5 | 6 | %% biconnected_components 7 | load('../graphs/tarjan-biconn.mat'); 8 | [a C] = biconnected_components(A); -------------------------------------------------------------------------------- /matlab_bgl/test/test_depth_first_search.m: -------------------------------------------------------------------------------- 1 | function distmap = test_depth_first_search(A,u) 2 | 3 | distmap = -1*ones(size(A,1),1); 4 | 5 | distmap = ipdouble(distmap); 6 | distmap(u) = 0; 7 | 8 | function on_tree_edge(ei,u,v) 9 | distmap(v) = distmap(u)+1; 10 | end 11 | 12 | depth_first_search(A,u,struct('tree_edge',@on_tree_edge)); 13 | 14 | distmap = double(distmap); 15 | end -------------------------------------------------------------------------------- /matlab_bgl/test/test_searches.m: -------------------------------------------------------------------------------- 1 | %% astar_search 2 | 3 | %% bfs 4 | 5 | %% breadth_first_search 6 | 7 | %% dfs 8 | 9 | %% depth_first_search 10 | 11 | -------------------------------------------------------------------------------- /matlab_bgl/test_dag.m: -------------------------------------------------------------------------------- 1 | function dag = test_dag(A,varargin) 2 | % TEST_DAG Tests if a graph is directed and acyclic 3 | % 4 | % dag = test_dag(A) returns 1 if A is the adjacency matrix for a dag and 5 | % returns 0 otherwise. This function just calls topological order and 6 | % checks the output to determine if the graph is a dag. It is provided 7 | % merely for expository purposes. 8 | % 9 | % Example: 10 | % n = 10; A = sparse(1:n-1, 2:n, 1, n, n); % construct a simple dag 11 | % test_dag(A) 12 | % A(10,1) = 1; % complete the cycle 13 | % test_dag(A) 14 | 15 | % David Gleich 16 | % Copyright, Stanford University, 2007-2008 17 | 18 | %% History 19 | %% 20 | 21 | dag = 1; 22 | if isempty(topological_order(A,varargin{:})) 23 | dag = 0; 24 | end 25 | -------------------------------------------------------------------------------- /matlab_bgl/test_planar_graph.m: -------------------------------------------------------------------------------- 1 | function is_planar = test_planar_graph(G) 2 | % TEST_PLANAR_GRAPH Test if a graph is planar 3 | % 4 | % This function is just a convinence wrapper around 5 | % boyer_myrvold_planarity_test. 6 | % 7 | % Example: 8 | % A = clique_graph(5); 9 | % test_planar_graph(A) 10 | % A(4,5)=0; A(5,4)=0; % make K_5 into a planar graph 11 | % test_planar_graph(A) 12 | 13 | % David Gleich 14 | % Copyright, Stanford University, 2008 15 | 16 | %% History 17 | % 2007-09-29: Initial coding 18 | %% 19 | 20 | is_planar = boyer_myrvold_planarity_test(G); 21 | -------------------------------------------------------------------------------- /matlab_bgl/tree_from_pred.m: -------------------------------------------------------------------------------- 1 | function T = tree_from_pred(pred) 2 | % TREE_FROM_PRED Convert a predecessor array into a tree 3 | % 4 | % T = tree_from_pred(pred) returns the predecessor array as an 5 | % unweighted adjacency matrix 6 | % pred(i) = 0 if vertex i is a source vertex u, 7 | % pred(i) = 0 if vertex i has no predecessor associated with it, or 8 | % pred(i) = j where j is the parent of vertex i in the tree. 9 | % 10 | % Example: 11 | % load('graphs/dominator_tree_example.mat'); 12 | % p = lengauer_tarjan_dominator_tree(A,1); 13 | % T = tree_from_pred(p); 14 | % 15 | % See also BFS, DFS, LENGAUER_TARJAN_DOMINATOR_TREE 16 | 17 | % David Gleich 18 | % Copyright, Stanford University, 2007-2008 19 | 20 | %% History 21 | % 2007-07-12: Initial version 22 | % 2008-09-23: Reformatted common section. 23 | %% 24 | 25 | n = length(pred); 26 | mask = pred~=0; 27 | I = 1:n; 28 | T = sparse(I(mask),pred(mask),1,n,n); 29 | -------------------------------------------------------------------------------- /matlab_bgl/wheel_graph.m: -------------------------------------------------------------------------------- 1 | function [A xy] = wheel_graph(n) 2 | % WHEEL_GRAPH Construct a wheel graph of order n 3 | % 4 | % The wheel graph is a cycle graph of order n-1 along with an additional 5 | % vertex that connects all the remaining vertices. (Run the example and it 6 | % will be extremely clear if you are still confused.) 7 | % 8 | % [A xy] = wheel_graph(n) returns the adjacency matrix for the wheel graph 9 | % of order n. The matrix xy stores two-dimensional coordinates for each 10 | % vertex. 11 | % 12 | % Example: 13 | % [A xy] = wheel_graph(10); 14 | % gplot(A,xy); 15 | % 16 | % See also CYCLE_GRAPH, STAR_GRAPH 17 | 18 | % David Gleich 19 | % Copyright, Stanford University, 2007-2008 20 | 21 | %% History 22 | % 2007-09-29: Changed output to double, fixed output for i=0,1 23 | %% 24 | 25 | if n>1 26 | i = 1:(n-1); 27 | j = [i(2:end) i(1)]; 28 | i = [i i]; 29 | j = [j n*ones(1,n-1)]; 30 | A = sparse(i,j,1,n,n); 31 | A = A|A'; 32 | A = double(A); 33 | else 34 | i=[]; 35 | A = sparse(n,n); 36 | end 37 | 38 | i = i(1:end/2); 39 | if n>0 40 | xy = [ [cos(2*pi*(i./(n-1))) 0]' [sin(2*pi*(i./(n-1))) 0]' ]; 41 | else 42 | xy = zeros(0,2); 43 | end 44 | -------------------------------------------------------------------------------- /mit_matlab_functions/BFS.m: -------------------------------------------------------------------------------- 1 | % Implementation of breadth-first-search of a graph 2 | % INPUTs: adjacency list, node index 3 | % OUTPUTs: BFS tree 4 | 5 | function T=BFS(adjL,i0) 6 | 7 | discovered=[i0]; 8 | q=[i0]; 9 | T=cell(length(adjL),1); 10 | 11 | while not(isempty(q)) 12 | j=q(1); q=q(2:length(q)); % pop the front 13 | neigh=adjL{j}; 14 | for nn=1:length(neigh) 15 | if isempty(find(discovered==neigh(nn))) 16 | T{j}=[T{j}, neigh(nn)]; 17 | discovered=[discovered, neigh(nn)]; 18 | q=[q, neigh(nn)]; 19 | end 20 | end 21 | end -------------------------------------------------------------------------------- /mit_matlab_functions/BounovaPhDThesis2009.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/mit_matlab_functions/BounovaPhDThesis2009.pdf -------------------------------------------------------------------------------- /mit_matlab_functions/DFS.m: -------------------------------------------------------------------------------- 1 | % Implementation of depth-first-search of a graph 2 | % INPUTs: adjacency list, node index 3 | % OUTPUTs: DFS tree 4 | 5 | function Tc=DFS(adjL,i0) 6 | 7 | discovered=[i0]; 8 | stack=[i0]; 9 | T=cell(length(adjL),1); 10 | 11 | while not(isempty(stack)) 12 | j=stack(length(stack)); stack=stack(1:length(stack)-1); % pop the back 13 | neigh=adjL{j}; 14 | for nn=1:length(neigh) 15 | if isempty(find(discovered==neigh(nn))) 16 | T{neigh(nn)}=j; % re-assign the parent 17 | discovered=[discovered, neigh(nn)]; 18 | stack=[stack, neigh(nn)]; 19 | end 20 | end 21 | end 22 | 23 | % convert tree from parent to children's oriented tree 24 | Tc=cell(length(T),1); 25 | for t=1:length(T) 26 | if not(isempty(T{t})) 27 | Tc{T{t}}=[Tc{T{t}}, t]; 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /mit_matlab_functions/PriceModel.m: -------------------------------------------------------------------------------- 1 | % Routine implementing the Price model for network growth 2 | % INPUTs: n - final number of vertices 3 | % p_k - fraction of vertices with degree k 4 | % probability a new vertex attaches to any of the degree-k vertices is 5 | % (k+1)p_k/(m+1), where m - mean number of new citations per vertex 6 | % OUTPUTs: adjacency matrix, directed 7 | % source: "The Structure and Function of Complex Networks", M.E.J. Newman 8 | % Gergana Bounova, Last modified: March 18, 2006 9 | 10 | function adj = PriceModel(n) 11 | 12 | adj = zeros(n); 13 | adj(1,1) = 1; 14 | vertices = 1; 15 | 16 | while vertices < n 17 | % attach new vertex 18 | vertices = vertices + 1; 19 | adj(vertices,vertices) = 1; 20 | 21 | [deg,indeg,outdeg] = degrees(adj); % get indegree values 22 | m = 0; % mean in-degree (per vertex) 23 | for k=1:vertices 24 | pk(k) = numel(find(indeg==k))/vertices; 25 | m = m + pk(k)*k; 26 | end 27 | 28 | for i=1:vertices 29 | if rand < (i+1)*pk(i)/(m+1) 30 | adj(vertices,i)=adj(vertices,i)+1; % add a link 31 | end 32 | end 33 | 34 | end 35 | adj=adj-diag(diag(adj)); % remove 1s along the diagonal -------------------------------------------------------------------------------- /mit_matlab_functions/add_edges.m: -------------------------------------------------------------------------------- 1 | % Add multiple edges in an edgelist % INPUTS: original (non-compact) edgelist % OUTPUTS: final compact edgelist (no row repetitions) % Gergana Bounova, Last updated: October 7, 2009 function elc=add_edges(el) el2=[el(:,1), el(:,2)]; % make the edge list searchable w/o the weights visited=[]; % mark visited edges elc=[]; for e=1:length(el) if sum(ismember(visited,el2(e,:),'rows'))==0 % if not visited yet ind=ismember(el2,el2(e,:),'rows'); ind=find(ind==1); % these are all the ocurrences of el(e,:) elc=[elc; el(e,1), el(e,2), sum(el(ind,3))]; visited=[visited; el2(e,:)]; end end -------------------------------------------------------------------------------- /mit_matlab_functions/adj2adjL.m: -------------------------------------------------------------------------------- 1 | % Converts an adjacency graph representation to an adjacency list 2 | % Valid for a general (directed, not simple) network model, but edge 3 | % weights get lost in the conversion. 4 | % INPUT: an adjacency matrix, NxN, N - # of nodes 5 | % OUTPUT: cell structure for adjacency list: x{i_1}=[j_1,j_2 ...] 6 | % Gergana Bounova, October 1, 2009 7 | 8 | 9 | function L = adj2adjL(adj) 10 | 11 | n = length(adj); % number of nodes 12 | 13 | L=cell(n,1); 14 | for i=1:length(adj) 15 | L{i}=find(adj(i,:)>0); 16 | end -------------------------------------------------------------------------------- /mit_matlab_functions/adj2edgeL.m: -------------------------------------------------------------------------------- 1 | % Converts adjacency matrix (nxn) to edge list (mx3) 2 | % INPUTS: adjacency matrix: nxn 3 | % OUTPUTS: edge list: mx3 4 | % Gergana Bounova, Last updated: October 2, 2009 5 | 6 | function el=adj2edgeL(adj) 7 | 8 | n=numnodes(adj); % number of nodes 9 | edges=find(adj>0); % indices of all edges 10 | 11 | el=[]; 12 | for e=1:length(edges) 13 | [i,j]=ind2ij(edges(e),n,n); % node indices of edge e 14 | el=[el; i j adj(i,j)]; 15 | end -------------------------------------------------------------------------------- /mit_matlab_functions/adj2inc.m: -------------------------------------------------------------------------------- 1 | % This program converts an adjacency matrix representation to an incidence 2 | % Convert adjacency matrix to an incidence matrix 3 | % Valid for directed/undirected, simple/not simple graph 4 | % INPUTs: adjacency matrix, NxN, N - number of nodes 5 | % OUTPUTs: incidence matrix: N x number of edges 6 | % Gergana Bounova, Last Updated: October 3, 2009 7 | 8 | function inc = adj2inc(adj) 9 | 10 | n=numnodes(adj); 11 | m=numedges(adj); 12 | inc=zeros(n,m); % initialize incidence matrix 13 | edges=find(adj>0); 14 | 15 | if isdirected(adj) 16 | for e=1:m 17 | [i,j]=ind2ij(edges(e),n,n); 18 | inc(i,e)=-1; 19 | inc(j,e)=1; 20 | end 21 | else 22 | cnt=0; % counting edges 23 | for e=1:length(edges) 24 | [i,j]=ind2ij(edges(e),n,n); 25 | ind_sym=ij2ind(j,i,n,n); 26 | if ind_sym0;% make all edges weight 1 10 | 11 | % clear the diagonal (selfloops) 12 | ind=find(diag(adj)==1); 13 | for i=1:length(ind) 14 | adj(ind(i),ind(i))=0; 15 | end -------------------------------------------------------------------------------- /mit_matlab_functions/adj2str.m: -------------------------------------------------------------------------------- 1 | % Converts an adjacency matrix to a one-line string representation 2 | % INPUTS: adjacency matrix, nxn 3 | % OUTPUTS: string 4 | % The nomenclature used to construct the string is arbitrary. Here we use 5 | % .i1.j1.k1,.i2.j2.k2,.... 6 | % Gergana Bounova, Last updated: October 6, 2009 7 | 8 | function str=adj2str(adj) 9 | 10 | % in '.i1.j1.k1,.i2.j2.k2,....', dot: signifies new neighbor, comma: next node 11 | str=''; 12 | n=numnodes(adj); 13 | 14 | for i=1:n 15 | neigh=kneighbors(adj,i,1); 16 | for k=1:length(neigh) 17 | str=strcat(str,'.',num2str(neigh(k))); 18 | end 19 | str=strcat(str,','); % close this node's neighbors list 20 | end -------------------------------------------------------------------------------- /mit_matlab_functions/adjL2adj.m: -------------------------------------------------------------------------------- 1 | % Convert an adjacency list to an adjacency matrix 2 | % INPUTS: adjancency matrix: nxn 3 | % OUTPUTS: adjacency list {n} 4 | % Note: short lines but not very good variable space management 5 | % Gergana Bounova, Last updated: October 6, 2009 6 | 7 | function adj=adjL2adj(adjL) 8 | 9 | for i=1:length(adjL) 10 | for j=1:length(adjL{i}) 11 | adj(i,adjL{i}(j))=1; 12 | end 13 | end 14 | 15 | % for undirected graphs, this routine may result in non-square matrices 16 | n=size(adj,1); 17 | m=size(adj,2); 18 | 19 | if not(m==n) % add zeros to square 20 | if n0; 15 | [deg,indeg,outdeg] = degrees(adj); 16 | C=zeros(n,1); % initialize clustering coefficient 17 | 18 | % multiplication change in the clust coeff formula 19 | if isdirected(adj) 20 | coeff=1; 21 | else 22 | coeff=2; 23 | end 24 | 25 | for i=1:n 26 | neigh=kneighbors(adj,i,1); 27 | adj_s=subgraph(adj,neigh); 28 | edges_s=numedges(adj_s); 29 | if deg(i)==1 | deg(i)==0 30 | C(i)=0; 31 | continue 32 | end 33 | C(i)=coeff*edges_s/deg(i)/(deg(i)-1); 34 | end 35 | 36 | C1=loops3(adj)/num_conn_triples(adj); 37 | C2=sum(C)/n; -------------------------------------------------------------------------------- /mit_matlab_functions/degrees.m: -------------------------------------------------------------------------------- 1 | % Compute the total degree, in-degree and out-degree of a graph based on 2 | % the adjacency matrix 3 | % INPUTS: adjacency matrix 4 | % OUTPUTS: degree, indegre and outdegree vectors 5 | % Gergana Bounova, Last Updated: October 2, 2009 6 | 7 | function [deg,indeg,outdeg]=degrees(adj) 8 | 9 | indeg = sum(adj); 10 | outdeg = sum(adj'); 11 | 12 | if isdirected(adj) 13 | deg = indeg + outdeg; % total degree 14 | else 15 | % undirected graph: indeg=outdeg 16 | deg = indeg + diag(adj)'; % add self-loops twice, if any 17 | end -------------------------------------------------------------------------------- /mit_matlab_functions/diameter.m: -------------------------------------------------------------------------------- 1 | % The longest shortest path between any two nodes nodes in the network % INPUTS: adjacency matrix, adj % OUTPUTS: network diameter, diam % Gergana Bounova, Last updated: October 19, 2009 %update by Jesse Blocher December 2009 because diamter is not taking max %distance, just the max of that last i. function diam = diameter(adj) n = numnodes(adj); diams = zeros(1,n); for i=1:numnodes(adj) d=simple_dijkstra(adj,i); diams(i) = max(d); end diam = max(diams); -------------------------------------------------------------------------------- /mit_matlab_functions/distance_distribution.m: -------------------------------------------------------------------------------- 1 | % The number of pairs of nodes at a distance x, divided by the total number of pairs n(n-1) 2 | % Source: Mahadevan et al, "Systematic Topology Analysis and Generation Using Degree Correlations" 3 | % INPUTS: adjacency matrix, (nxn) 4 | % OUTPUTS: distribution vector ((n-1)x1): {k_i} where k_i is the # of pairs at a distance i, normalized 5 | 6 | function ddist=distance_distribution(adj) 7 | 8 | n=numnodes(adj); 9 | 10 | dij=[]; 11 | for i=1:n 12 | d=simple_dijkstra(adj,i); 13 | dij=[dij; d]; 14 | end 15 | 16 | for i=1:n-1 17 | ddist(i)=length(find(dij==i)); 18 | end 19 | ddist=ddist/n/(n-1); -------------------------------------------------------------------------------- /mit_matlab_functions/draw_circ_graph.m: -------------------------------------------------------------------------------- 1 | % Draw a circular graph with links and nodes in order of degree 2 | % Strategy: position vertices in a regular n-polygon 3 | % INPUTs: adj - adjacency matrix 4 | % OUTPUTs: a figure 5 | % Gergana Bounova, February 21, 2006 6 | 7 | function [] = draw_circ_graph(adj) 8 | 9 | n = numnodes(adj); % number of nodes 10 | [degs,indeg,outdeg]=degrees(adj); 11 | [degs, Y] = sort(degs); 12 | angl = 2*pi/n; % rotation angle 13 | 14 | for k=1:n 15 | x(Y(k)) = real(exp(angl*(k-1)*i)); 16 | y(Y(k)) = imag(exp(angl*(k-1)*i)); 17 | end 18 | 19 | for k=1:n 20 | plot(x(k),y(k),'bo') 21 | text(1.1*x(k),1.1*y(k),strcat('v',num2str(k))); 22 | hold off; hold on; 23 | end 24 | 25 | edges=find(adj>0); 26 | set(gcf,'Color',[1,1,1]) 27 | 28 | for e=1:length(edges) 29 | [ii,jj]=ind2ij(edges(e),n,n); 30 | line([x(ii) x(jj)],[y(ii) y(jj)]); 31 | hold off; hold on; 32 | end 33 | axis off; -------------------------------------------------------------------------------- /mit_matlab_functions/edgeL2adj.m: -------------------------------------------------------------------------------- 1 | % Converts edge list to adjacency matrix 2 | % INPUTS: edgelist: mx3 3 | % OUTPUTS: adjacency matrix nxn 4 | % Note: information about nodes is lost: indices only (i1,...in) remain 5 | % Gergana Bounova, Last updated: October 6, 2009 6 | 7 | function adj=edgeL2adj(el) 8 | 9 | nodes=sort(unique([el(:,1) el(:,2)])); % get all nodes, sorted 10 | n=numel(nodes); % number of unique nodes 11 | adj=zeros(n); % initialize adjacency matrix 12 | 13 | for i=1:size(el,1) % across all edges 14 | adj(find(nodes==el(i,1)),find(nodes==el(i,2)))=el(i,3); 15 | end -------------------------------------------------------------------------------- /mit_matlab_functions/edgeL2adjL.m: -------------------------------------------------------------------------------- 1 | % Converts an edgelist to an adjacency list 2 | % INPUTS: edgelist, (mx3) 3 | % OUTPUTS: adjacency list 4 | % Gergana Bounova, Last updated: October 13, 2006 5 | 6 | function adjL = edgeL2adjL(el) 7 | 8 | nodes = unique([el(:,1)' el(:,2)']); 9 | n = numel(nodes); % number of nodes 10 | adjL=cell(n,1); 11 | 12 | for e=1:length(el) 13 | adjL{el(e,1)}=[adjL{el(e,1)},el(e,2)]; 14 | end -------------------------------------------------------------------------------- /mit_matlab_functions/edgeL2pajek.m: -------------------------------------------------------------------------------- 1 | % Converts an edgelist matrix representation to a Pajek .net readable format 2 | % INPUT: an edgelist matrix, mx3, a filename, string format 3 | % OUTPUT: text format of Pajek readable .net file 4 | % EXAMPLE 5 | % *Vertices 4 6 | % 1 "14" 0.1000 0.5000 0.5000 7 | % 2 "31" 0.1000 0.4975 0.5000 8 | % 3 "46" 0.1000 0.4950 0.5000 9 | % 4 "51" 0.1001 0.4925 0.5000 10 | % *Edges 11 | % 14 31 1 12 | % 46 51 1 13 | % 51 60 1 14 | % Gergana Bounova, Last updated: October 7, 2009 15 | 16 | function []=edgeL2pajek(el,filename) 17 | 18 | nodes=unique([el(:,1)', el(:,2)']); 19 | n=length(nodes); % number of nodes 20 | m = size(el,1); % number of edges 21 | 22 | fid = fopen(filename,'wt','native'); 23 | 24 | fprintf(fid,'*Vertices %6i\n',n); 25 | 26 | for i=1:n 27 | fprintf(fid,' %3i %s %1.4f %1.4f %1.4f\n',i,strcat('"',num2str(nodes(i)),'"'),rand,rand,0); 28 | end 29 | 30 | fprintf(fid,'*Edges\n'); 31 | for i=1:m 32 | fprintf(fid,' %4i %4i %2i\n',el(i,1),el(i,2),el(i,3)); 33 | end 34 | 35 | fclose(fid) 36 | 37 | -------------------------------------------------------------------------------- /mit_matlab_functions/edgeL2simple.m: -------------------------------------------------------------------------------- 1 | % Convert an edge list of a general graph to the edge list of a simple 2 | % graph (no loops, no double edges) - great for quick data clean up 3 | % INPUTS: edgelist (mx3), m - number of edges 4 | % OUTPUTs: edge list of the corresponding simple graph 5 | % Gergana Bounova, Last updated: October 4, 2009 6 | 7 | function el=edgeL2simple(el) 8 | 9 | m=length(el); % number of edges 10 | el(:,3)=ones(m,1); % make all edge weights 1 11 | 12 | ind=find(not(el(:,1)-el(:,2)==0)); % indices of the "non-self-loops" 13 | el=el(ind,:); -------------------------------------------------------------------------------- /mit_matlab_functions/eigencentrality.m: -------------------------------------------------------------------------------- 1 | % The ith component of the eigenvector corresponding to the greatest 2 | % eigenvalue gives the centrality score of the ith node in the network. 3 | % INPUTs: adjacency matrix 4 | % OUTPUTs: eigen(-centrality) vector 5 | % Gergana Bounova, Last Updated: October 14, 2009 6 | %TODO: rename so this is my own file J Blocher Dec 2009 7 | function x=eigencentrality(adj) 8 | if issparse(adj) 9 | [V,D]=eigs(adj); 10 | else 11 | [V,D]=eig(adj); 12 | end 13 | [max_eig,ind]=max(diag(D)); 14 | x=V(:,ind); -------------------------------------------------------------------------------- /mit_matlab_functions/el2geom.m: -------------------------------------------------------------------------------- 1 | % Plot geometry based on extended edgelist % INPUTS: extended edgelist el[0]=[n1 n2 m x1 y1 x2 y2] % OUTPUTS: geometry plot, higher-weight links are thicker and lighter % Note: (x1,y2) are the Euclidean coordinates of n1, (x2,y2) - n2 resp. % gergana bounova, last updated: april 24, 2007 function []=el2geom(el) set(gcf,'Color',[1 1 1]) map=colormap('hot'); for i=1:size(el,1) % plot line between two nodes x1=el(i,4); y1=el(i,5); x2=el(i,6); y2=el(i,7); % edge weights ============== if el(i,3)<2 color=map(8,:); linew=1; elseif el(i,3)>=2 & el(i,3)<3 color=map(2*8,:); linew=2; elseif el(i,3)>=3 & el(i,3)<4 color=map(3*8,:); linew=3; elseif el(i,3)>=4 & el(i,3)<5 color=map(4*8,:); linew=4; elseif el(i,3)>=5 & el(i,3)<6 color=map(5*8,:); linew=5; elseif el(i,3)>=6 & el(i,3)<7 color=map(6*8,:); linew=6; elseif el(i,3)>=7 & el(i,3)<8 color=map(7*8,:); linew=7; elseif el(i,3)>=8 color=map(8*8,:); linew=8; end line([x1 x2],[y1 y2],'LineWidth',linew,'Color',color) hold off; hold on; end axis equal -------------------------------------------------------------------------------- /mit_matlab_functions/fiedler_vector.m: -------------------------------------------------------------------------------- 1 | % The vector corresponding to the second smallest eigenvalue of the Laplacian matrix 2 | % INPUTs: adjacency matrix (nxn) 3 | % OUTPUTs: fiedler vector (nx1) 4 | 5 | function fv=fiedler_vector(adj) 6 | 7 | L=laplacian_matrix(adj); 8 | [V,D]=eig(L); 9 | 10 | [ds,Y]=sort(diag(D)); 11 | fv=V(:,Y(2)); -------------------------------------------------------------------------------- /mit_matlab_functions/giant_component.m: -------------------------------------------------------------------------------- 1 | % extract giant component from a network 2 | % INPUTS: adjacency matrix 3 | % OUTPUTS: giant comp matrix and node indeces 4 | % Gergana Bounova, Last Updated: October 2, 2009 5 | 6 | 7 | function [GC,gc_nodes]=giant_component(adj) 8 | 9 | comps=find_conn_comp(adj); 10 | 11 | L=[]; 12 | for k=1:length(comps) 13 | L=[L, length(comps{k})]; 14 | end 15 | [maxL,ind_max]=max(L); 16 | 17 | gc_nodes=comps{ind_max}; 18 | GC=subgraph(adj,gc_nodes); -------------------------------------------------------------------------------- /mit_matlab_functions/graph_complement.m: -------------------------------------------------------------------------------- 1 | % Returns the complement of a graph % INPUTs: adj - original graph adjacency matrix % OUTPUTs: complement graph adjacency matrix % Gergana Bounova, February 2, 2006 function adj_c = graph_complement(adj) adj_c=ones(size(adj))-adj; -------------------------------------------------------------------------------- /mit_matlab_functions/graph_dual.m: -------------------------------------------------------------------------------- 1 | % Finds the dual of a graph; a dual is the inverted nodes-edges graph % This is also called the line graph, adjoint graph or the edges adjacency % INPUTs: incidence matrix % OUTPUTs: incidence matrix of the corresponding dual graph % Gergana Bounova, February 13, 2006 function inc_d = graph_dual(inc) inc_d=inc'; -------------------------------------------------------------------------------- /mit_matlab_functions/graph_spectrum.m: -------------------------------------------------------------------------------- 1 | % The eigenvalues of the Laplacian of the graph 2 | % INPUTs: adjacency matrix 3 | % OUTPUTs: laplacian eigenvalues, sorted 4 | 5 | function s=graph_spectrum(adj) 6 | 7 | L=laplacian_matrix(adj); 8 | [v,D]=eig(L); 9 | s=sort(diag(D)); -------------------------------------------------------------------------------- /mit_matlab_functions/ij2ind.m: -------------------------------------------------------------------------------- 1 | % Converts matrix coordinates to array index 2 | % INPUTS: matrix coordinates i,j and matrix size (m,n) 3 | % OUTPUTS: corresponding array index 4 | % Gergana Bounova, Last Updated: October 2, 2009 5 | 6 | function ind=ij2ind(i,j,m,n) 7 | 8 | if i>m | j>n 9 | 'coordinates larger than matrix size' 10 | return 11 | end 12 | 13 | ind=(j-1)*m+i; -------------------------------------------------------------------------------- /mit_matlab_functions/ind2ij.m: -------------------------------------------------------------------------------- 1 | % Converts index to (i,j) entry in a (ixj) matrix 2 | % INPUTS: index, and matrix size (m,n) 3 | % OUTPUTS: i,j coordinates of ind 4 | % Gergana Bounova, Last Updated: January 13, 2007 5 | 6 | 7 | function [i,j]=ind2ij(ind,m,n) 8 | 9 | if ind>m*n 10 | 'index bigger than matrix size' 11 | return 12 | end 13 | 14 | if mod(ind,m)==0 15 | i=m; 16 | j=ind/m; 17 | elseif mod(ind,m)>0 18 | i=mod(ind,m); 19 | j=1+(ind-i)/m; 20 | end -------------------------------------------------------------------------------- /mit_matlab_functions/iscomplete.m: -------------------------------------------------------------------------------- 1 | % Checks whether a (sub)graph is complete, i.e. whether every node is 2 | % linked to every other node. Only makes sense for unweighted graphs. 3 | % INPUTS: adjacency matrix, adj, nxn 4 | % OUTPUTS: Boolean variable, true/false 5 | % Gergana Bounova, Last Updated: October 1, 2009 6 | 7 | function S=iscomplete(adj) 8 | 9 | S=false; % default 10 | 11 | adj=adj>0; % remove weights 12 | n=numnodes(adj); 13 | 14 | if sum(adj)==ones(1,n)*(n-1) | sum(adj)==ones(1,n)*n % or w/ n selfloops 15 | S=true; 16 | end -------------------------------------------------------------------------------- /mit_matlab_functions/isdirected.m: -------------------------------------------------------------------------------- 1 | % Using the matrix symmetry condition. For other data structures, convert 2 | % to matrix and use issymmetric, or write your own ... 3 | % INPUTS: adjacency matrix 4 | % OUTPUTS: boolean variable 5 | % Gergana Bounova, Last updated: October 1, 2009 6 | 7 | function S=isdirected(adj) 8 | 9 | S=not(issymmetric(adj)); -------------------------------------------------------------------------------- /mit_matlab_functions/iseulerian.m: -------------------------------------------------------------------------------- 1 | % Check if a graph is Eulerian, i.e. it has an Eulerian circuit 2 | % "A connected undirected graph is Eulerian if and only if every graph vertex has an even degree." 3 | % "A connected directed graph is Eulerian if and only if every graph vertex has equal in- and out- degree." 4 | % INPUTS: adjacency matrix 5 | % OUTPUTS: Boolean variable 6 | % Gergana Bounova, Last Updated: October 2, 2009 7 | 8 | 9 | function S=iseulerian(adj) 10 | 11 | S=false; 12 | 13 | [degs,indeg,outdeg]=degrees(adj); 14 | odd=find(mod(degs,2)==1); 15 | 16 | if not(isdirected(adj)) & isconnected(adj) & isempty(odd) % if connected and all degrees are even 17 | S=true; 18 | return 19 | elseif isdirected(adj) & isconnected(adj) & indeg==outdeg % connected and in-degrees equal out-degrees 20 | S=true; 21 | return 22 | elseif isconnected(adj) & numel(odd)==2 23 | fprintf('there is an Eulerian trail from node %2i to node %2i\n',odd(1),odd(2)); 24 | return 25 | end -------------------------------------------------------------------------------- /mit_matlab_functions/isregular.m: -------------------------------------------------------------------------------- 1 | % Checks whether a graph is regular, i.e. every node has the same degree. 2 | % Defined for unweighted graphs only. 3 | % INPUTS: adjacency matrix nxn 4 | % OUTPUTS: Boolean, yes/no 5 | % Gergana Bounova, Last updated: October 1, 2009 6 | 7 | function S=isregular(adj) 8 | 9 | S=true; 10 | 11 | adj=adj>0; % remove weights 12 | degs=sum(adj); 13 | for i=1:length(adj) 14 | if not(degs(i)==degs(1)) 15 | S=false; 16 | return 17 | end 18 | end -------------------------------------------------------------------------------- /mit_matlab_functions/issimple.m: -------------------------------------------------------------------------------- 1 | % Checks whether a graph is simple (no self-loops, no multiple edges) 2 | % INPUTs: adj - adjacency matrix 3 | % OUTPUTs: S - a Boolean variable 4 | % Gergana Bounova, Last updated: October 1, 2009 5 | 6 | function S = issimple(adj) 7 | 8 | S=true; 9 | 10 | % check for self-loops 11 | sl=selfloops(adj); 12 | if sl>0 13 | S=false; 14 | return 15 | end 16 | 17 | % check for double edges 18 | me=multiedges(adj); 19 | if me>0 20 | S=false; 21 | return 22 | end -------------------------------------------------------------------------------- /mit_matlab_functions/issymmetric.m: -------------------------------------------------------------------------------- 1 | % Checks whether a matrix is symmetric (has to be square) 2 | % Check whether mat=mat^T 3 | % INPUTS: adjacency matrix 4 | % OUTPUTS: boolean variable, {0,1} 5 | % Gergana Bounova, October 1, 2009 6 | 7 | function S = issymmetric(mat) 8 | 9 | S = false; % default 10 | if mat == transpose(mat) 11 | S = true; 12 | end -------------------------------------------------------------------------------- /mit_matlab_functions/istree.m: -------------------------------------------------------------------------------- 1 | % Check whether a graph is a tree 2 | % Source: "Intro to Graph Theory" by Bela Bollobas 3 | % INPUTS: adjacency matrix 4 | % OUTPUTS: Boolean variable 5 | % Gergana Bounova, Last Updated: June 19, 2007 6 | 7 | function S=istree(adj) 8 | 9 | S=false; 10 | 11 | if isconnected(adj) & numedges(adj)==numnodes(adj)-1 12 | S=true; 13 | end -------------------------------------------------------------------------------- /mit_matlab_functions/isweighted.m: -------------------------------------------------------------------------------- 1 | % Check whether a graph is weighted, i.e not all edges are 0,1. 2 | % INPUTS: edge list, m x 3 3 | % OUTPUTS: Boolean variable, yes/no 4 | % Gergana Bounova, Last updated: October 1, 2009 5 | 6 | function S=isweighted(el) 7 | 8 | S=false; 9 | 10 | w=unique(el(:,3)); % unique edge weights only 11 | if length(w)>1 12 | % there must be other weights than 1 13 | S=true; 14 | end -------------------------------------------------------------------------------- /mit_matlab_functions/kneighbors.m: -------------------------------------------------------------------------------- 1 | % Finds the number of k-neighbors (k links away) for every node 2 | % INPUTS: adjacency matrix, node index, k - number of links 3 | % OUTPUTS: vector of k-neighbors indices 4 | % Gergana Bounova, May 3, 2006 5 | 6 | function kneigh = kneighbors(adj,ind,k) 7 | 8 | adjk = adj; 9 | for i=1:k-1 10 | adjk = adjk*adj; 11 | end 12 | 13 | kneigh = find(adjk(ind,:)>0); -------------------------------------------------------------------------------- /mit_matlab_functions/laplacian_matrix.m: -------------------------------------------------------------------------------- 1 | % The Laplacian matrix of a graph (the difference b/w the degree and the 2 | % adjacency matrices) - note: this is the normalized Laplacian 3 | % INPUTS: adjacency matrix 4 | % OUTPUTs: Laplacian matrix 5 | 6 | function L=laplacian_matrix(adj) 7 | 8 | [deg,indeg,outdeg]=degrees(adj); 9 | L=diag(deg)-adj; 10 | 11 | 12 | % NORMALIZED Laplacian ============= 13 | 14 | % n=numnodes(adj); 15 | % [deg,indeg,outdeg]=degrees(adj); 16 | 17 | % L=zeros(n); 18 | % edges=find(adj>0); 19 | % 20 | % for e=1:length(edges) 21 | % [ii,jj]=ind2ij(edges(e),n,n); 22 | % if ii==jj 23 | % L(ii,ii)=1; 24 | % continue 25 | % end 26 | % L(ii,jj)=-1/sqrt(deg(ii)*deg(jj)); 27 | % end -------------------------------------------------------------------------------- /mit_matlab_functions/link_density.m: -------------------------------------------------------------------------------- 1 | % Computes the link density of a graph, defined as num_edges divided by 2 | % num_nodes(num_nodes-1)/2 where the latter is the max possible num edges. 3 | % The graph needs to be non-trivial (more than 1 node). 4 | % Gergana Bounova, Last Update: October 1, 2009 5 | 6 | function d=link_density(adj) 7 | 8 | n=numnodes(adj); 9 | m=numedges(adj); 10 | d=2*m/n/(n-1); -------------------------------------------------------------------------------- /mit_matlab_functions/loops3.m: -------------------------------------------------------------------------------- 1 | % Calculates number of loops of length 3 2 | % INPUTs: adj - adjacency matrix 3 | % OUTPUTs: L3 - number of triangles (loops of length 3) 4 | % Valid for an undirected network 5 | % Gergana Bounova, April 6, 2006 6 | 7 | function L3 = loops3(adj) 8 | 9 | L3 = trace(adj^3)/6; % trace(adj^3)/3! -------------------------------------------------------------------------------- /mit_matlab_functions/min_span_tree.m: -------------------------------------------------------------------------------- 1 | % Prim's minimal spanning tree algorithm % Prim's alg idea: % start at any node, find closest neighbor and mark edges % for all remaining nodes, find closest to previous cluster, mark edge % continue until no nodes remain % INPUTS: graph defined by adjacency matrix % OUTPUTS: matrix specifying minimum spanning tree (subgraph) % Gergana Bounova, March 14, 2005 function tr = min_span_tree(adj) % check if graph is connected: if not(isconnected(adj)) 'graph is not connected, no spanning tree exists' return end n = length(adj); % number of nodes tr = zeros(n); adj(find(adj==0))=inf; % set all zeros in the matrix to inf conn_nodes = 1; % nodes part of the min-span-tree rem_nodes = [2:n]; % remaining nodes while length(rem_nodes)>0 [minlink]=min(min(adj(conn_nodes,rem_nodes))); ind=find(adj(conn_nodes,rem_nodes)==minlink); ind_j=ceil(ind(1)/length(conn_nodes)); ind_i=mod(ind(1),length(conn_nodes)); if ind_i==0 ind_i=length(conn_nodes); end i=conn_nodes(ind_i); j=rem_nodes(ind_j); % gets back to adj indices tr(i,j)=1; tr(j,i)=1; conn_nodes = [conn_nodes j]; rem_nodes = setdiff(rem_nodes,j); end -------------------------------------------------------------------------------- /mit_matlab_functions/multiedges.m: -------------------------------------------------------------------------------- 1 | % counts the number of multiple edges in the graph 2 | % INPUT: adjacency matrix 3 | % OUTPUT: interger, number of double edges 4 | % Last Updated: Gergana Bounova, October 1, 2009 5 | 6 | function mE=multiedges(adj) 7 | 8 | mE=length(find(adj>1)); -------------------------------------------------------------------------------- /mit_matlab_functions/node_betweenness_slow.m: -------------------------------------------------------------------------------- 1 | % Betweenness centrality measure: number of shortest paths running though a 2 | % vertex. Compute for all vertices. 3 | % Note: Valid for a general graph. Using 'number of shortest paths through a node' definition 4 | % INPUTS: adjacency (distances) matrix (nxn) 5 | % OUTPUTS: betweeness vector for all vertices (nx1) 6 | % 7 | % Gergana Bounova, October 13, 2009 8 | 9 | function betw = node_betweenness_slow(adj) 10 | 11 | n = numnodes(adj); 12 | spaths=inf(n,n); 13 | 14 | % calculate number of shortest paths 15 | for k=1:n-1 16 | adjk=adj^k; 17 | for i=1:n 18 | for j=1:n 19 | if adjk(i,j)>0 20 | spaths(i,j)=min([spaths(i,j) adjk(i,j)]); 21 | end 22 | end 23 | end 24 | end 25 | 26 | betw = zeros(1,n); 27 | for i=1:n 28 | [J_st,route_st,J,route]=shortest_pathDP(adj,i,i,n); 29 | for j=1:n 30 | if i==j 31 | continue 32 | end 33 | %[J_st,route_st]=shortest_pathDP(adj,i,j,n); 34 | [J_ji,step_ind] = min(J(:,j)); 35 | route_ji = [j, route(step_ind,j).path]; 36 | betw(route_ji(2:length(route_ji)-1)) = betw(route_ji(2:length(route_ji)-1)) + 1/spaths(j,i); 37 | end 38 | end 39 | 40 | betw=betw/nchoosek(n,2); -------------------------------------------------------------------------------- /mit_matlab_functions/num_conn_comp.m: -------------------------------------------------------------------------------- 1 | % Calculate the number of connected components using the Laplacian 2 | % eigenvalues - counting the number of zeros 3 | % INPUTS: adjacency matrix 4 | % OUTPUTs: positive integer - number of connected components 5 | % Gergana Bounova, Last updated: October 22, 2009 6 | 7 | function nc=num_conn_comp(adj) 8 | 9 | s=graph_spectrum(adj); 10 | nc=numel(find(s<10^(-5))); % zero eigenvalues are not really zero in matlab -------------------------------------------------------------------------------- /mit_matlab_functions/num_conn_triples.m: -------------------------------------------------------------------------------- 1 | % Counts the number of connected triples in a graph 2 | % INPUTs: adjacency matrix 3 | % OUTPUTs: integer - num conn triples 4 | % Gergana Bounova, Last updated: October 9, 2009 5 | 6 | function c=num_conn_triples(adj) 7 | 8 | c=0; 9 | for i=1:length(adj) 10 | neigh=kneighbors(adj,i,1); 11 | if length(neigh)<2 12 | continue % handle leaves, no triple here 13 | end 14 | c=c+nchoosek(length(neigh),2); 15 | end 16 | c=c-2*loops3(adj); % due to the symmetry triangles repeat 3 times in the nchoosek count -------------------------------------------------------------------------------- /mit_matlab_functions/numedges.m: -------------------------------------------------------------------------------- 1 | % Returns the total number of edges given the adjacency matrix % Valid for both directed and undirected, simple or general graph % INPUTs: adjacency matrix % OUTPUTs: m - total number of edges/links % Gergana Bounova, Last Updated: October 1, 2009 function m = numedges(adj) sl=selfloops(adj); % counting the number of self-loops if issymmetric(adj) & sl==0 % undirected simple graph m=sum(sum(adj))/2; return elseif issymmetric(adj) & sl>0 sl=selfloops(adj); m=(sum(sum(adj))-sl)/2+sl; % counting the self-loops only once return elseif not(issymmetric(adj)) % directed graph (not necessarily simple) m=sum(sum(adj)); return end -------------------------------------------------------------------------------- /mit_matlab_functions/numnodes.m: -------------------------------------------------------------------------------- 1 | % Returns the number of nodes, given an adjacency list 2 | % also works for an adjacency matrix 3 | % INPUTs: adjacency list: {i:j_1,j_2 ..} 4 | % OUTPUTs: number of nodes 5 | % Gergana Bounova, February 19, 2006 6 | 7 | 8 | 9 | function n = numnodes(L) 10 | 11 | n = length(L); -------------------------------------------------------------------------------- /mit_matlab_functions/pajek2adj.m: -------------------------------------------------------------------------------- 1 | % This program extracts an adjacency matrix from a pajek text (.net) file 2 | % INPUT .net text filename, n - number of nodes in the graph 3 | % OUTPUT: adjacency matrix, nxn, n - # nodes 4 | % Note: It is much easier to read the edge list from text so this routine 5 | % uses pajek2edgeL.m 6 | % Gergana Bounova, October 7, 2009 7 | 8 | function adj = pajek2adj(filename,n) 9 | 10 | el=pajek2edgeL(filename,n); 11 | adj=edgeL2adj(el); -------------------------------------------------------------------------------- /mit_matlab_functions/pajek2edgeL.m: -------------------------------------------------------------------------------- 1 | % This program extracts an edge list from a pajek text (.net) file 2 | % INPUT .net text filename, n - number of nodes in the graph 3 | % OUTPUT: edge list, mx3, m - # edges 4 | % Gergana Bounova, October 7, 2009 5 | 6 | function el=pajek2edgeL(filename,n) 7 | 8 | [e1,e2,e3] = textread(filename,'%6d%6d%6d','headerlines',n+2); 9 | el=[e1,e2,e3]; 10 | 11 | % ALTERNATIVE: Not using the number of nodes as an input: 12 | % f=fopen(filename,'r'); 13 | % C = textscan(f, '%s'); 14 | % c=C{1}; 15 | % ind_edges=find(ismember(c, '*Edges')==1); 16 | % 17 | % e1=[]; e2=[]; e3=[]; 18 | % for cc=ind_edges:length(c) 19 | % % two indices are edges, one is weight and again 20 | % if mod(ind_edges,3)==mod(cc,3) % this is edge weight 21 | % e3=[e3, str2num(c{cc})]; 22 | % elseif mod(ind_edges,3)==mod(cc-1,3) % this is node 1 23 | % e1=[e1, str2num(c{cc})]; 24 | % elseif mod(ind_edges,3)==mod(cc-2,3) % this is node 2 25 | % e2=[e2, str2num(c{cc})]; 26 | % end 27 | % end 28 | % 29 | % el=[e1',e2',e3']; -------------------------------------------------------------------------------- /mit_matlab_functions/pajek2xyz.m: -------------------------------------------------------------------------------- 1 | % Read x,y,(z) node coordinates from a pajek .net file - useful for plotting in Matlab 2 | % INPUTS: filename, string format 3 | % OUTPUTS: x,y,z coordinate vectors; z is empty if 2D 4 | % Gergana Bounova, Last updated: October 7, 2009 5 | 6 | function [x,y,z]=pajek2xyz(filename) 7 | 8 | f=fopen(filename,'r'); 9 | C = textscan(f, '%s'); 10 | c=C{1}; 11 | ind_edges=find(ismember(c, '*Edges')==1); 12 | 13 | % c{1}='*Vertices', n=str2num(c{2}); % number of nodes 14 | % c{3},c{8},c{13},...c{5k+3} are node indices 15 | % c{4},c{9},c{14},...c{5k+4} are 'vi', between them are coordinates 16 | 17 | x=[]; y=[]; z=[]; % initialize coordinates 18 | 19 | for cc=3:ind_edges-1 20 | if mod(cc,5)==4 21 | x=[x, str2num(c{cc+1})]; 22 | y=[y, str2num(c{cc+2})]; 23 | z=[z, str2num(c{cc+3})]; 24 | end 25 | end -------------------------------------------------------------------------------- /mit_matlab_functions/pdf_cdf_rank.m: -------------------------------------------------------------------------------- 1 | % Compute the pdf, cdf and rank distributions for a sequence of values % INPUTS: sequence of values: x, size 1xn, 'plot' - 'on' or 'off' % OUTPUTS: pdf, cdf and rank distribution values % Note: pdf = frequency, cdf = cumulative frequency, rank = log-log scale of the sorted sequence % Gergana Bounova, Last Updated: June 27, 2007 function [xpdf,ypdf,xcdf,ycdf,logk,logx]=pdf_cdf_rank(x,plt) xx=unique(x); for ii=1:numel(xx) xcdf(ii) = xx(ii); ycdf(ii) = length(find(x>=xx(ii)))/numel(x); xpdf(ii) = xx(ii); ypdf(ii) = length(find(xx(ii)==x))/numel(x); end x=-sort(-x); logk=log(1:length(x)); logx=log(x); if strcmp(plt,'on') set(gcf,'color',[1,1,1]) subplot(1,3,1) plot(xpdf,ypdf,'k.') title('pdf') subplot(1,3,2) plot(xcdf,ycdf,'k.') title('cdf') subplot(1,3,3) plot(logk,logx,'k.') title('rank') end -------------------------------------------------------------------------------- /mit_matlab_functions/purge.m: -------------------------------------------------------------------------------- 1 | % Removes a subset from a set, but preserves order of elements 2 | % Similar to setdiff - which reorders the elements 3 | % INPUTs: original set A, subset to remove B 4 | % OUTPUTs: new purged set Anew 5 | % Gergana Bounova, Last updated: October 12, 2009 6 | 7 | function Anew = purge(A,B) 8 | 9 | Anew = []; 10 | for a=1:numel(A) 11 | % remove element B(b) 12 | if isempty(find(B==A(a))) 13 | Anew=[Anew, A(a)]; 14 | end 15 | end -------------------------------------------------------------------------------- /mit_matlab_functions/random_number.m: -------------------------------------------------------------------------------- 1 | % Random number generator between 1 and n, using the computer clock 2 | % INPUTS - upper bound on random number, if not given returns number between 0 and 1 3 | % OUTPUTS - random number between 1 and n (0 and 1 default) 4 | % Gergana Bounova, October 24, 2005 5 | 6 | function rn = random_number(n) 7 | 8 | for m=1:10 9 | tic; 10 | for i=1:ceil(rand*100) 11 | (2*rand)^ceil(rand*100); 12 | end 13 | rnum(m) = toc; 14 | end 15 | 16 | ind=ceil(rand*length(rnum)); 17 | if nargin<1 18 | rn=rnum(ind)/max(rnum); 19 | else 20 | rn = rnum(ind)*n/max(rnum); 21 | end -------------------------------------------------------------------------------- /mit_matlab_functions/rich_club_metric.m: -------------------------------------------------------------------------------- 1 | % Compute the rich club metric for a graph 2 | % INPUTs: adjacency matrix, nxn, k - threshold number of links 3 | % OUTPUTs: rich club metric 4 | % Source: Colizza, Flammini, Serrano, Vespignani, "Detecting rich-club 5 | % ordering in complex networks", Nature Physics, vol 2, Feb 2006 6 | % Gergana Bounova, Last updated: October 16, 2009 7 | 8 | function phi=rich_club_metric(adj,k) 9 | 10 | [deg,indeg,outdeg]=degrees(adj); 11 | 12 | Nk=find(deg>k); % find the nodes with degree > k 13 | 14 | adjk=subgraph(adj,Nk); 15 | Ek=numedges(adjk); % find the # of edges among nodes with deg > k 16 | 17 | phi=2*Ek/length(Nk)/(length(Nk)-1); -------------------------------------------------------------------------------- /mit_matlab_functions/s_metric.m: -------------------------------------------------------------------------------- 1 | % The sum of products of degrees across all edges 2 | % Source: "Towards a Theory of Scale-Free Graphs: Definition, Properties, 3 | % and Implications", by Li, Alderson, Doyle, Willinger 4 | % Note: The total degree is used regardless of whether the graph is directed or not. 5 | % INPUTs: adjacency matrix 6 | % OUTPUTs: s-metric 7 | 8 | function s=s_metric(adj) 9 | 10 | [deg,indeg,outdeg]=degrees(adj); 11 | el=adj2edgeL(adj); 12 | 13 | s=0; 14 | for e=1:length(el) 15 | s=s+deg(el(e,1))*deg(el(e,2)); 16 | end 17 | 18 | % ALTERNATIVE ================ 19 | % [deg,indeg,outdeg]=degrees(adj); 20 | % edges=find(adj>0); 21 | % s=0; 22 | % for e=1:length(edges) 23 | % [i,j]=ind2ij(edges(e),n,n); 24 | % s=s+deg(i)*deg(j); 25 | % end -------------------------------------------------------------------------------- /mit_matlab_functions/selfloops.m: -------------------------------------------------------------------------------- 1 | % counts the number of self-loops in the graph 2 | % INPUT: adjacency matrix 3 | % OUTPUT: interger, number of self-loops 4 | % Last Updated: Gergana Bounova, October 1, 2009 5 | 6 | function sl=selfloops(adj) 7 | 8 | sl=sum(diag(adj)); -------------------------------------------------------------------------------- /mit_matlab_functions/simple_dijkstra.m: -------------------------------------------------------------------------------- 1 | % Implements a simple version of the Dijkstra shortest path algorithm % Returns the distance from a single vertex to all others, doesn't save the path % INPUTS: adjacency matrix (adj), start node (s) % OUTPUTS: shortest path length between start and end nodes % shortest path length from start node to all other nodes % need set of vertices and connecting edges % Note: works with a weighted/directed matrix % % Gergana Bounova, Last Updated: December 13, 2004 function d = simple_dijkstra(adj,s) n=numnodes(adj); d = inf*ones(1,n); % distance s-all nodes d(s) = 0; % s-s distance T = 1:n; % node set with shortest paths not found while not(isempty(T)) [dmin,ind] = min(d(T)); for j=1:length(T) if adj(T(ind),T(j))>0 & d(T(j))>d(T(ind))+adj(T(ind),T(j)) d(T(j))=d(T(ind))+adj(T(ind),T(j)); end end T = setdiff(T,T(ind)); end -------------------------------------------------------------------------------- /mit_matlab_functions/subgraph.m: -------------------------------------------------------------------------------- 1 | % This function outputs the adjacency matrix of a subgraph given the 2 | % supergraph and the node subset of the subgraph 3 | % INPUTs: adj - supergraph adjacency matrix, S - vector of subgraph node indices 4 | % OUTPUTs: adj_sub - adjacency matrix of the subgraph 5 | % Gergana Bounova, January 5, 2006 6 | 7 | function adj_sub = subgraph(adj,S) 8 | 9 | adj_sub = adj(S,S); 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /mit_matlab_functions/symmetrize.m: -------------------------------------------------------------------------------- 1 | % Symmetrize a non-symmetric matrix 2 | % INPUTS: a matrix - nxn 3 | % OUTPUT: corresponding symmetric matrix - nxn 4 | % ASSUMPTION: This works for an adjacency matrix - if an edge exists in one 5 | % direction, it will be placed in the other as well. For matrices in which 6 | % mat(i,j)/=mat(j,i), it will pick the larger (nonzero) value to symmetrize 7 | % - which may not be the desired effect in general. 8 | % Gergana Bounova, Last Updated: October 1, 2009 9 | 10 | function [adj_sym]=symmetrize(adj) 11 | 12 | adj_sym=max(adj,transpose(adj)); -------------------------------------------------------------------------------- /mit_matlab_functions/symmetrize_edgeL.m: -------------------------------------------------------------------------------- 1 | % Making an edgelist (representation of a graph) symmetric 2 | % INPUTs: edge list, mx3 3 | % OUTPUTs: symmetrized edge list, mx3 4 | % Gergana Bounova, Last updated: October 8, 2009 5 | 6 | function el=symmetrize_edgeL(el) 7 | 8 | el2=[el(:,1), el(:,2)]; 9 | 10 | for e=1:length(el) 11 | ind=ismember(el2,[el2(e,2),el2(e,1)],'rows'); 12 | if sum(ind)==0 13 | el=[el; el(e,2), el(e,1), el(e,3)]; 14 | end 15 | end 16 | 17 | % Alternative: Using the adjacency matrix 18 | % adj=edgeL2adj(el); 19 | % adj=symmetrize(adj); 20 | % el=adj2edgeL(adj); -------------------------------------------------------------------------------- /network/apl_diam_fast.m: -------------------------------------------------------------------------------- 1 | % Compute average path length for a network - the average shortest path 2 | % AND Diameter - minimizes use of Dijkstra method. 3 | % Updated to use faster Dijkstra method from Matlab Central by Joseph Kirk. 4 | % INPUTS: adjL - matrix of weights/distances between nodes 5 | % OUTPUTS: average path length: the average of the shortest paths between every two edges 6 | % Note: works for directed/undirected networks 7 | 8 | % The longest shortest path between any two nodes nodes in the network 9 | % INPUTS: adjacency matrix, adj 10 | % OUTPUTS: network diameter, diam 11 | % Jesse Blocher, Dec 2009. 12 | 13 | 14 | function [l diam] = apl_diam_fast(adj) 15 | if ~isconnected(adj) 16 | error('Adjacency matrix not connected for computation of path length and diameter'); 17 | end; 18 | n=numnodes(adj); 19 | dij = dijkstra(adj, adj); 20 | diam = max(max(dij)); 21 | l=sum(sum(dij))/(n^2-n); % sum and average across everything but the diagonal -------------------------------------------------------------------------------- /network/betweenness_fast.m: -------------------------------------------------------------------------------- 1 | % Betweenness centrality measure: number of shortest paths running though a 2 | % vertex. Output for all vertices. 3 | % Jesse Blocher December 2009 4 | 5 | function btwn = betweenness_fast(adj) 6 | 7 | % inputs: adjacency (distances) matrix N x N 8 | % outputs: betweeness measures vector for all vertices 1 X N 9 | % use dijkstra shortest path algorithm which produces a N x N cell array of shortest paths 10 | % Then, use cellfun to process those paths - first, remove endpoints, 11 | 12 | 13 | if ~isconnected(adj) 14 | warning('Graph not connected in betweenness_fast. Extracting Giant Component.'); 15 | comp = giant_component(adj); 16 | else 17 | comp = adj; 18 | end; 19 | [dij paths] = dijkstra(comp, comp); 20 | 21 | remove_endpoints = cellfun(@getMiddle, paths, 'UniformOutput', false); 22 | btwn = zeros(1,length(comp)); 23 | for i=1:length(comp) 24 | btwn(i) = getBetweenness(i, remove_endpoints, comp); 25 | end; 26 | 27 | 28 | -------------------------------------------------------------------------------- /network/betweenness_fastDC.m: -------------------------------------------------------------------------------- 1 | % Betweenness centrality measure: number of shortest paths running though a 2 | % vertex. Output for all vertices. 3 | % Jesse Blocher December 2009 4 | % Added Distributed Computing to see if it speeds up 5 | 6 | %function btwn = betweenness_fastDC(adj) 7 | 8 | % inputs: adjacency (distances) matrix N x N 9 | % outputs: betweeness measures vector for all vertices 1 X N 10 | % use dijkstra shortest path algorithm which produces a N x N cell array of shortest paths 11 | % Then, use cellfun to process those paths - first, remove endpoints, 12 | 13 | %{ 14 | if ~isconnected(adj) 15 | warning('Graph not connected in betweenness_fast. Extracting Giant Component.'); 16 | comp = giant_component(adj); 17 | else 18 | comp = adj; 19 | end; 20 | %} 21 | [dij paths] = dijkstra(comp, comp); 22 | remove_endpoints = cellfun(@getMiddle, paths, 'UniformOutput', false); 23 | 24 | %btwn = zeros(1,length(comp)); 25 | jm = findResource('scheduler','configuration','local'); 26 | job1 = createJob(jm, ... 27 | 'FileDependencies', {'findNode.m','removeDiagonal.m','getBetweenness.m'} ... 28 | ); 29 | 30 | for i=1:length(comp) 31 | createTask(job1, @getBetweenness, 1, {i, remove_endpoints, comp}); 32 | end; 33 | submit(job1); 34 | waitForState(job1) 35 | btwn = getAllOutputArguments(job1); 36 | %destroy(job1); 37 | 38 | -------------------------------------------------------------------------------- /network/betweenness_fastPF.m: -------------------------------------------------------------------------------- 1 | % Betweenness centrality measure: number of shortest paths running though a 2 | % vertex. Output for all vertices. 3 | % Jesse Blocher December 2009 4 | % Added ParFor loop to see if it speeds up 5 | 6 | function btwn = betweenness_fastPF(adj) 7 | % inputs: adjacency (distances) matrix N x N 8 | % outputs: betweeness measures vector for all vertices 1 X N 9 | % use dijkstra shortest path algorithm which produces a N x N cell array of shortest paths 10 | % Then, use cellfun to process those paths - first, remove endpoints, 11 | 12 | 13 | if ~isconnected(adj) 14 | warning('Graph not connected in betweenness_fast. Extracting Giant Component.'); 15 | comp = giant_component(adj); 16 | else 17 | comp = adj; 18 | end; 19 | 20 | [dij paths] = dijkstra(comp, comp); 21 | remove_endpoints = cellfun(@getMiddle, paths, 'UniformOutput', false); 22 | btwn = zeros(1,length(comp)); 23 | matlabpool; 24 | parfor i=1:length(comp) 25 | btwn(i) = getBetweenness(i, remove_endpoints, comp); 26 | end; 27 | matlabpool close; 28 | -------------------------------------------------------------------------------- /network/btwn_test.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jblocher/matlab-network-utilities/07607ffa930e837098e0b61a1cb8ab0b9a20cef1/network/btwn_test.mat -------------------------------------------------------------------------------- /network/closeness_fast.m: -------------------------------------------------------------------------------- 1 | % Computes the closeness centrality for every vertex: 1/sum(dist to all other nodes) 2 | % For disconnected graphs can use: sum_over_t(2^-d(i,t)), idea Dangalchev (2006) 3 | % INPUTs: graph representation (adjacency matrix nxn) 4 | % OUTPUTs: vector of centralities, nx1 5 | % Source: social networks literature 6 | % 7 | % Gergana Bounova, Last updated: October 9, 2009 8 | % new Dijkstra algorithm used by J Blocher December 2009. 9 | 10 | function C=closeness_fast(adj) 11 | 12 | dij = dijkstra(adj, adj); 13 | C = 1./sum(dij,2); 14 | -------------------------------------------------------------------------------- /network/findNode.m: -------------------------------------------------------------------------------- 1 | function boolHere = findNode(vec, num) 2 | %A cellarray find function to determine if a node is in a path for 3 | %betwenness calculation 4 | % input: vector vec is any vector 5 | % num is a number to be found in the vector 6 | % output: boolean T/F if it is there or not 7 | % J Blocher December 2009 8 | boolHere = ~isempty(find(vec == num, 1)); -------------------------------------------------------------------------------- /network/getAllBetweenness.m: -------------------------------------------------------------------------------- 1 | % Betweenness centrality measure: number of shortest paths running though a 2 | % vertex. Output for all vertices. 3 | % Jesse Blocher December 2009 4 | 5 | function btwn = getAllBetweenness(adj, conn_comp, paths) 6 | 7 | % inputs: adjacency (distances) matrix N x N 8 | % outputs: betweeness measures vector for all vertices 1 X N 9 | % use dijkstra shortest path algorithm which produces a N x N cell array of shortest paths 10 | % Then, use cellfun to process those paths - first, remove endpoints, 11 | 12 | 13 | if ~isconnected(adj) 14 | warning('Graph not connected in getAllBetweenness. Extracting Giant Component. All others set to 0'); 15 | comp = getGiantComponent(adj, conn_comp); 16 | else 17 | comp = adj; 18 | end; 19 | % if these are supplied use them (it's faster) else compute them 20 | if nargin < 3 21 | [dij paths] = dijkstra(comp, comp); 22 | clear dij; 23 | end; 24 | if nargin < 2 25 | conn_comp = find_conn_comp(adj); 26 | end; 27 | 28 | remove_endpoints = cellfun(@getMiddle, paths, 'UniformOutput', false); 29 | allnodes = [remove_endpoints{:}]; %removes diagonal i to i self-loops and endpoints 30 | btwn = histc(allnodes, 1:length(adj)); 31 | if issymmetric(adj) 32 | %remove double-counting 33 | btwn = btwn/2; 34 | end; 35 | -------------------------------------------------------------------------------- /network/getAllCloseness.m: -------------------------------------------------------------------------------- 1 | % Computes the closeness centrality for every vertex: 1/sum(dist to all other nodes) 2 | % if second arg, dij, is not included, it is computed by a (slow) dijkstra algorithm. 3 | % INPUTs: adj: adjacency matrix N X N 4 | % dij (optional): distance from each node i to each node j from a shortest path algo N x N 5 | % OUTPUTs: vector of centralities, N x 1 6 | % Source: Moody notes 7 | % 8 | % J. Blocher updated December 2009 9 | function C=getAllCloseness(adj, dij) 10 | 11 | if nargin < 2 12 | dij = sparse(all_shortest_paths(adj)); 13 | end 14 | 15 | C = 1./sum(dij,2); 16 | -------------------------------------------------------------------------------- /network/getAvgPathLength.m: -------------------------------------------------------------------------------- 1 | % Compute average path length for a network - the average shortest path 2 | % Updated to use faster Dijkstra method from Matlab Central by Joseph Kirk. 3 | % INPUTs: adj: adjacency matrix N X N 4 | % dij (optional): distance from each node i to each node j from a shortest path algo N x N 5 | % OUTPUTs: scalar l which is avg path length for network 6 | % Jesse Blocher, Dec 2009. 7 | 8 | function l = apl_diam_fast(adj, dij) 9 | if nargin < 2 10 | dij = sparse(all_shortest_paths(adj)); 11 | end; 12 | if ~isconnected(adj) 13 | %if graph is not connected distance from i to j can be Inf and blow up this calc. 14 | dij = removeInf(dij); 15 | end; 16 | n=num_vertices(adj); 17 | l=sum(sum(dij))/(n^2-n); % sum and average across everything but the diagonal -------------------------------------------------------------------------------- /network/getBetweenness.m: -------------------------------------------------------------------------------- 1 | function bt = getBetweenness(i, remove_endpoints ,comp) 2 | % Computes the betweenness of node i in cell array remove_endpoints derived from component comp 3 | % Inputs: 4 | % i is node i 5 | % remove_endpoints is cell array of paths from i to j 6 | % comp is connected component which generated remove_endpoints 7 | % Outputs: bt is an integer count of every shortest path node is on. 8 | % Note: This is not very fast. 9 | disp(strcat('Computing betweenness for i:', num2str(i))); 10 | btwn_chk = cellfun(@findNode, remove_endpoints, num2cell(i*ones(size(comp,1),size(comp,2))) ); 11 | bt = sum(sum(removeDiagonal(btwn_chk)))/2; 12 | if issymmetric(comp) 13 | bt = bt/2; %this is to remove double counting 14 | end; -------------------------------------------------------------------------------- /network/getDiameter.m: -------------------------------------------------------------------------------- 1 | % Computes Diameter of a network. 2 | % Updated to use faster Dijkstra method from Matlab Central by Joseph Kirk. 3 | % only calls Dijkstra method if dij not provided. 4 | % The longest shortest path between any two nodes nodes in the network 5 | % INPUTs: adj: adjacency matrix N X N 6 | % dij (optional): distance from each node i to each node j from a shortest path algo N x N 7 | % OUTPUTS: network diameter, diam 8 | % Note: works for directed/undirected networks 9 | % Jesse Blocher, Dec 2009. 10 | 11 | 12 | function diam = apl_diam_fast(adj, dij) 13 | if nargin < 2 14 | dij = sparse(all_shortest_paths(adj)); 15 | end; 16 | if ~isconnected(adj) 17 | %if graph is not connected distance from i to j can be Inf and blow up this calc. 18 | dij = removeInf(dij); 19 | end; 20 | diam = max(max(dij)); 21 | -------------------------------------------------------------------------------- /network/getGiantComponent.m: -------------------------------------------------------------------------------- 1 | % Extracts giant component from a network 2 | % INPUTS: adjacency matrix, adj 3 | % optional comps, cell array of components from find_conn_comp 4 | % OUTPUTS: giant comp matrix and node indeces 5 | % J Blocher December 2009 6 | 7 | function [GC,gc_nodes] = getGiantComponent(adj, ci, sizes) 8 | % updated using Matlab BGL 9 | if nargin < 2 10 | [ci sizes] = components(adj); 11 | end; 12 | [maxL,ind_max]=max(sizes); 13 | gc_nodes=find(ci == ind_max)'; 14 | %this is Bounova - pretty trivial, though 15 | GC=subgraph(adj,gc_nodes); -------------------------------------------------------------------------------- /network/removeDiagonal.m: -------------------------------------------------------------------------------- 1 | function adj_r = removeDiagonal(adj) 2 | %sets the diagonal of a N x N adjacency matrix equal to all 0 3 | 4 | adj_r = (eye(size(adj)) == 0).*adj; -------------------------------------------------------------------------------- /network/removeInf.m: -------------------------------------------------------------------------------- 1 | function dij_finite = removeInf(dij_inf) 2 | %removes inf values from distance matrix 3 | 4 | dij_finite = dij_inf.*(dij_inf < inf); 5 | %that multiplied 0*inf = NaN, so set NaN = 0; 6 | dij_finite(isnan(dij_finite)) = 0; 7 | -------------------------------------------------------------------------------- /nlaplacian.m: -------------------------------------------------------------------------------- 1 | function L = laplacian(A) 2 | % NLAPLACIAN Compute the normalized Laplacian matrix for a graph. 3 | % 4 | % L = nlaplacian(A) computes the weighted normalized Laplacian matrix for a 5 | % symmetric adjacency matrix A. 6 | % 7 | % If A has unit weights, then the Laplacian is unweighted. 8 | % 9 | 10 | % 11 | % David Gleich 12 | % October 29th, 2005 13 | % 14 | 15 | % 16 | % History 17 | % 18 | % 10 May 2007 19 | % Fixed documentation about the code to talk about the normalized Laplacian. 20 | % 21 | 22 | d = sparse(sum(A,2)); 23 | 24 | L = diag(d) - A; 25 | Dhalf = diag(sparse(1./sqrt(d))); 26 | L = Dhalf*(L*Dhalf); 27 | 28 | -------------------------------------------------------------------------------- /processMemory.m: -------------------------------------------------------------------------------- 1 | function mem = processMemory(S) 2 | % takes a whos memory structure and processes it to sum all the values up 3 | % to a single memory number. 4 | b = 0; 5 | for i = 1:length(S) 6 | s = S(i,1); 7 | b = b + s.bytes; 8 | end; 9 | mem = b/1000000;%megabytes 10 | -------------------------------------------------------------------------------- /quickCorr.m: -------------------------------------------------------------------------------- 1 | function [S V] = quickCorr(A) 2 | %Computes a correlation matrix using SVD, so very fast. 3 | % [S V] = quickCorr(A) 4 | % A is input matrix, will compute correlations of the columns of A 5 | % 6 | % S is the diagonal matrix with eigenvalues on the diagonal 7 | % V is the eigenvector matrix 8 | % compute corr = V*S*S*V'; 9 | 10 | Anorm = A-repmat(mean(A,1),[size(A,1),1]); 11 | 12 | Anorm=Anorm./repmat(sqrt(sum(Anorm.^2,1)),[size(A,1),1]); 13 | 14 | [U,S,V]=svd(Anorm,'econ'); --------------------------------------------------------------------------------