Changeset 3f0880
- Timestamp:
- 10/04/10 11:40:53 (3 years ago)
- Children:
- 3507df
- Parents:
- 487b47
- git-author:
- Tiago de Paula Peixoto <tiago@…> (10/03/10 23:47:29)
- git-committer:
- Tiago de Paula Peixoto <tiago@…> (10/04/10 11:40:53)
- Location:
- src
- Files:
-
- 4 added
- 3 edited
-
graph/generation/Makefile.am (modified) (2 diffs)
-
graph/generation/graph_generation.cc (modified) (2 diffs)
-
graph/generation/graph_geometric.cc (added)
-
graph/generation/graph_geometric.hh (added)
-
graph/generation/graph_lattice.cc (added)
-
graph/generation/graph_lattice.hh (added)
-
graph_tool/generation/__init__.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/graph/generation/Makefile.am
r366c32 r3f0880 23 23 graph_union_vprop.cc \ 24 24 graph_union_eprop.cc \ 25 graph_triangulation.cc 25 graph_triangulation.cc \ 26 graph_lattice.cc \ 27 graph_geometric.cc 28 26 29 27 30 libgraph_tool_generation_la_include_HEADERS = \ … … 31 34 graph_union.hh \ 32 35 graph_triangulation.hh \ 36 graph_lattice.hh \ 37 graph_geometric.hh \ 33 38 sampler.hh -
src/graph/generation/graph_generation.cc
r55dc15 r3f0880 98 98 void triangulation(GraphInterface& gi, python::object points, boost::any pos, 99 99 string type, bool periodic); 100 void lattice(GraphInterface& gi, python::object oshape, bool periodic); 101 void geometric(GraphInterface& gi, python::object opoints, double r, 102 python::object orange, bool periodic, boost::any pos); 100 103 101 104 using namespace boost::python; … … 111 114 def("edge_property_union", &edge_property_union); 112 115 def("triangulation", &triangulation); 116 def("lattice", &lattice); 117 def("geometric", &geometric); 113 118 } -
src/graph_tool/generation/__init__.py
re7674f r3f0880 35 35 graph_union 36 36 triangulation 37 lattice 38 geometric_graph 37 39 38 40 Contents … … 48 50 49 51 __all__ = ["random_graph", "random_rewire", "predecessor_tree", "line_graph", 50 "graph_union", "triangulation" ]52 "graph_union", "triangulation", "lattice", "geometric_graph"] 51 53 52 54 … … 643 645 >>> from numpy.random import seed, random 644 646 >>> seed(42) 645 >>> points = random((500, 2))*4647 >>> points = random((500, 2)) * 4 646 648 >>> g, pos = gt.triangulation(points) 647 649 >>> weight = g.new_edge_property("double") # Edge weights corresponding to … … 694 696 _prop("v", g, pos), type, periodic) 695 697 return g, pos 698 699 700 def lattice(shape, periodic=False): 701 r""" 702 Generate a N-dimensional square lattice. 703 704 Parameters 705 ---------- 706 shape : list or :class:`~numpy.ndarray` 707 List of sizes in each dimension. 708 periodic : bool (optional, default: False) 709 If ``True``, periodic boundary conditions will be used. 710 711 Returns 712 ------- 713 lattice_graph : :class:`~graph_tool.Graph` 714 The generated graph. 715 716 See Also 717 -------- 718 triangulation: 2D or 3D triangulation 719 random_graph: random graph generation 720 721 Examples 722 -------- 723 >>> g = gt.lattice([10,10]) 724 >>> gt.graph_draw(g, size=(8,8), output="lattice.png") 725 <...> 726 >>> g = gt.lattice([10,20], periodic=True) 727 >>> gt.graph_draw(g, size=(8,8), output="lattice_periodic.png") 728 <...> 729 >>> g = gt.lattice([10,10,10]) 730 >>> gt.graph_draw(g, size=(8,8), output="lattice_3d.png") 731 <...> 732 733 .. image:: lattice.png 734 .. image:: lattice_periodic.png 735 .. image:: lattice_3d.png 736 737 *Left:* 10x10 2D lattice. *Middle:* 10x20 2D periodic lattice (torus). 738 *Right:* 10x10x10 3D lattice. 739 740 References 741 ---------- 742 .. [lattice] http://en.wikipedia.org/wiki/Square_lattice 743 744 """ 745 746 g = Graph(directed=False) 747 libgraph_tool_generation.lattice(g._Graph__graph, shape, periodic) 748 return g 749 750 751 def geometric_graph(points, radius, ranges=None): 752 r""" 753 Generate a geometric network form a set of N-dimensional points. 754 755 Parameters 756 ---------- 757 points : list or :class:`~numpy.ndarray` 758 List of points. This must be a two-dimensional array, where the rows are 759 coordinates in a N-dimensional space. 760 radius : float 761 Pairs of points with an euclidean distance lower than this parameters 762 will be connected. 763 ranges : list or :class:`~numpy.ndarray` (optional, default: None) 764 If provided, periodic boundary conditions will be assumed, and the 765 values of this parameter it will be used as the ranges in all 766 dimensions. It must be a two-dimensional array, where each row will 767 cointain the lower and upper bound of each dimension. 768 769 Returns 770 ------- 771 geometric_graph : :class:`~graph_tool.Graph` 772 The generated graph. 773 pos : :class:`~graph_tool.PropertyMap` 774 A vertex property map with the position of each vertex. 775 776 Notes 777 ----- 778 A geometric graph [geometric-graph]_ is generated by connecting points 779 embedded in a N-dimensional euclidean space which are at a distance equal to 780 or smaller than a given radius. 781 782 See Also 783 -------- 784 triangulation: 2D or 3D triangulation 785 random_graph: random graph generation 786 lattice : N-dimensional square lattice 787 788 Examples 789 -------- 790 >>> from numpy.random import seed, random 791 >>> seed(42) 792 >>> points = random((500, 2)) * 4 793 >>> g, pos = gt.geometric_graph(points, 0.3) 794 >>> gt.graph_draw(g, pos=pos, pin=True, size=(8,8), output="geometric.png") 795 <...> 796 >>> g, pos = gt.geometric_graph(points, 0.3, [(0,4), (0,4)]) 797 >>> gt.graph_draw(g, size=(8,8), output="geometric_periodic.png") 798 <...> 799 800 .. image:: geometric.png 801 .. image:: geometric_periodic.png 802 803 *Left:* Geometric network with random points. *Right:* Same network, but 804 with periodic boundary conditions. 805 806 References 807 ---------- 808 .. [geometric-graph] Jesper Dall and Michael Christensen, "Random geometric 809 graphs", Phys. Rev. E 66, 016121 (2002), DOI: 10.1103/PhysRevE.66.016121 810 811 """ 812 813 g = Graph(directed=False) 814 pos = g.new_vertex_property("vector<double>") 815 if type(points) != numpy.ndarray: 816 points = numpy.array(points) 817 if len(points.shape) < 2: 818 raise ValueError("points list must be a two-dimensional array!") 819 if ranges is not None: 820 periodic = True 821 if type(ranges) != numpy.ndarray: 822 ranges = numpy.array(ranges, dtype="float") 823 else: 824 ranges = array(ranges, dtype="float") 825 else: 826 periodic = False 827 ranges = () 828 829 libgraph_tool_generation.geometric(g._Graph__graph, points, float(radius), 830 ranges, periodic, 831 _prop("v", g, pos)) 832 return g, pos
Note: See TracChangeset
for help on using the changeset viewer.


