├── .gitignore
├── .gitmodules
├── .idea
├── dictionaries
│ └── rhl.xml
└── vcs.xml
├── .travis.yml
├── CMakeLists.txt
├── README.md
├── ctl.spec
├── ctl
├── abstract_simplex
│ ├── abstract_simplex.hpp
│ └── simplex_boundary.hpp
├── cell_complex
│ ├── cell_complex.hpp
│ ├── complex_boundary.hpp
│ └── detail
│ │ └── data_wrapper.hpp
├── chain
│ ├── chain.hpp
│ └── chain_add.hpp
├── cover
│ └── cover.hpp
├── ctl.hpp
├── cube
│ ├── cube.hpp
│ ├── cube_boundary.hpp
│ └── detail
│ │ └── cube.hpp
├── example
│ └── example.hpp
├── finite_field
│ └── finite_field.hpp
├── graded_chain_complex
│ ├── filtration_iterator.hpp
│ ├── graded_boundary.hpp
│ ├── graded_cell_complex.hpp
│ └── less.hpp
├── hash
│ ├── MurmurHash3.hpp
│ ├── city.hpp
│ └── hash.hpp
├── io
│ └── io.hpp
├── matrix
│ ├── iterator_property_map.hpp
│ ├── matrix.hpp
│ └── offset_maps.hpp
├── maximal_cliques
│ ├── clique_output_iterator.h
│ ├── maximal_cliques.hpp
│ ├── test_clique_output_iterator.cpp
│ └── test_maximal_cliques.cpp
├── metrics
│ └── metric.hpp
├── nbhd_graph
│ ├── all_pairs.hpp
│ ├── epsilon_search.hpp
│ └── nbhd_graph.hpp
├── one_skeleton
│ ├── complex_to_graph.hpp
│ ├── graph_to_metis.hpp
│ └── one_skeleton.hpp
├── parallel
│ ├── build_blowup_complex
│ │ └── build_blowup_complex.hpp
│ ├── chain_complex
│ │ └── chain_complex.hpp
│ ├── filtration
│ │ └── filtration.hpp
│ ├── homology
│ │ ├── homology.hpp
│ │ └── persistence.hpp
│ ├── partition_covers
│ │ ├── .covers.h.swn
│ │ ├── .covers.h.swo
│ │ ├── cover_data.hpp
│ │ ├── cover_stats.hpp
│ │ ├── covers.hpp
│ │ └── graph_partition.hpp
│ └── utility
│ │ └── timer.hpp
├── persistence
│ ├── barcodes
│ │ └── barcodes.hpp
│ ├── compute_barcodes.hpp
│ ├── compute_betti.hpp
│ ├── persistence.hpp
│ ├── persistence_data.hpp
│ └── unpair_cells.hpp
├── points
│ └── points.hpp
├── product_cell
│ ├── iterator_product_boundary.hpp
│ ├── iterator_product_cell.hpp
│ ├── product_boundary.hpp
│ ├── product_cell.hpp
│ └── product_cell_less.hpp
├── term
│ ├── term.hpp
│ ├── term_less.hpp
│ └── term_tags.hpp
├── utility
│ └── timer.hpp
├── vr
│ ├── incremental_complex.hpp
│ ├── inductive_complex.hpp
│ └── vr.hpp
└── weight_data
│ ├── weight_data.hpp
│ └── weight_functor.hpp
├── dependencies
├── CMakeLists.txt
├── CMakeModules
│ ├── CXX11.cmake
│ ├── FindANN.cmake
│ ├── FindGTest.cmake
│ ├── FindMETIS.cmake
│ └── FindTBB.cmake
└── catch
│ └── catch.hpp
├── doc
├── AUTHORS
├── Doxyfile.in
├── LICENSE
└── ct.bib
├── man
├── build_clique.1
├── complex_size.1
├── concurrent_homology.1
├── cover_homology.1
├── duplicate.1
├── euler.1
├── gpcover.1
├── metowgh.1
├── oneskeleton.1
├── persistence.1
├── wghtomet.1
└── write_filtration.1
├── python
├── CMakeLists.txt
├── ctl.cpp
├── wrap_complex.hpp
├── wrap_cube.hpp
├── wrap_ff.hpp
├── wrap_persistence.hpp
├── wrap_prod_complex.hpp
├── wrap_product.hpp
├── wrap_simplex.hpp
├── wrap_term.hpp
└── wrap_vr.hpp
├── tests
├── CMakeLists.txt
├── ctl_test.cpp
├── test_abstract_simplex.cpp
├── test_blowup_tool.cpp
├── test_chain.cpp
├── test_cover_generation.cpp
├── test_cover_tool.cpp
├── test_cube.cpp
├── test_cubical_chain_complex.cpp
├── test_filtration.cpp
├── test_finite_field.cpp
├── test_one_skeleton.cpp
├── test_product_cell.cpp
├── test_simplicial_chain_complex.cpp
└── test_vr.cpp
├── tools
├── CMakeLists.txt
├── alpha.cpp
├── betti.cpp
├── build_blobs.cpp
├── cech.cpp
├── clique_tool.cpp
├── complex_size.cpp
├── complex_to_graph_tool.cpp
├── concurrent_homology_tool.cpp
├── cover_homology_tool.cpp
├── euler_tool.cpp
├── gpcover_tool.cpp
├── graph_to_metis_tool.cpp
├── metis_to_graph_tool.cpp
├── ngraph.cpp
├── persistence.cpp
├── phat_tool.cpp
├── sphere.cpp
├── vr.cpp
├── witness.cpp
└── write_filtration_tool.cpp
└── travis
├── ci_fedora.sh
├── ci_osx.sh
└── ci_ubuntu.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | CTestTest*.cmake
2 | tests/ctl_test
3 | dependencies/ann
4 | dependencies/gtest
5 | dependencies/metis
6 | dependencies/boost
7 | dependencies/tbb
8 | **/test_multi
9 | deps/gtest
10 | deps/CMakeFiles
11 | deps/Makefile
12 | deps/CMakeCache.txt
13 | distributed/distributed_persistence
14 | ctl/chain_complex/tm
15 | ctl/cube/test_cube
16 | ctl/distributed/distributed_persistence_serial
17 | tools/vr
18 | tools/ngraph
19 | ctl/vr/incremental_test
20 | ctl/vr/test
21 | tools/convert_asc_format
22 | tools/ctl2phat
23 | doc/doxygen/*
24 | tools/convert_asc_format
25 | tools/ctl2phat
26 | doc/doxygen/*
27 | ctl/distributed/distributed_persistence
28 | Doxyfile
29 | tools/distributed_persistence
30 | examples/
31 | tools/cover_homology
32 | tools/concurrent_homology
33 | tools/write_filtration
34 | cover_test
35 | bin/
36 | include/
37 | install_manifest.txt
38 | tools/gpcover
39 | ctl/parallel/build_blowup_complex/blowup_test
40 | ctl/product_cell/test_product_cell
41 | tools/metowgh
42 | tools/oneskeleton
43 | tools/wghtomet
44 | tools/complex_size
45 | tools/persistence
46 | build_clique
47 | duplicate
48 | euler
49 | tf
50 | *.*.swp
51 | test_persistence
52 | test_chain
53 | test_simplex
54 | test_filtration
55 | error
56 | tc
57 | */ts
58 | Makefile
59 | CMakeCache.txt
60 | cmake_install.cmake
61 | *CMakeFiles/
62 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "pybind11"]
2 | path = dependencies/pybind11
3 | url = https://github.com/pybind/pybind11.git
4 |
--------------------------------------------------------------------------------
/.idea/dictionaries/rhl.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: cpp
2 |
3 | # sudo:required is needed for trusty images
4 | sudo: required
5 | dist: trusty
6 |
7 | matrix:
8 | include:
9 | #Disable this until we figure out how to deal with constexpr function bug in gcc 4.9
10 | #- os: linux
11 | # compiler: gcc
12 | # addons:
13 | # apt:
14 | # sources:
15 | # - ubuntu-toolchain-r-test
16 | # packages:
17 | # - g++-4.9
18 | # - libann-dev
19 | # - libboost-all-dev
20 | # - libtbb-dev
21 | # - libmetis-dev
22 | # env: COMPILER=g++-4.9
23 | - os: linux
24 | compiler: gcc
25 | addons:
26 | apt:
27 | sources:
28 | - ubuntu-toolchain-r-test
29 | packages:
30 | - g++-5
31 | - libann-dev
32 | - libboost-all-dev
33 | - libtbb-dev
34 | - libmetis-dev
35 | env: COMPILER=g++-5
36 | - os: linux
37 | compiler: clang
38 | addons:
39 | apt:
40 | sources:
41 | - ubuntu-toolchain-r-test
42 | - llvm-toolchain-precise-3.6
43 | packages:
44 | - clang-3.6
45 | - libann-dev
46 | - libboost-all-dev
47 | - libtbb-dev
48 | - libmetis-dev
49 | env: COMPILER=clang++-3.6
50 | - os: linux
51 | compiler: clang
52 | addons:
53 | apt:
54 | sources:
55 | - ubuntu-toolchain-r-test
56 | - llvm-toolchain-precise-3.7
57 | packages:
58 | - clang-3.7
59 | - libann-dev
60 | - libboost-all-dev
61 | - libtbb-dev
62 | - libmetis-dev
63 | env: COMPILER=clang++-3.7
64 | - os: osx
65 | osx_image: xcode7.3
66 | compiler: clang
67 | env: CCOMPILER='clang' CXXCOMPILER='clang++'
68 |
69 | before_install:
70 | - |
71 | if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
72 | sudo apt-get install --yes libann-dev
73 | export CC=${COMPILER} CXX=${COMPILER}
74 | elif [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
75 | brew tap homebrew/science
76 | brew install cmake mpich tbb boost ann metis
77 | export CC=${CCOMPILER} CXX=${CXXCOMPILER}
78 | fi
79 |
80 | script:
81 | - mkdir build
82 | - cd build
83 | - cmake ..
84 | - make VERBOSE=1
85 | - make test
86 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | project(ctl CXX)
2 | #stop the whining
3 | cmake_minimum_required(VERSION 2.6.2)
4 | if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6)
5 | if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3)
6 | cmake_policy(VERSION 2.8.4)
7 | else()
8 | cmake_policy(VERSION 2.6)
9 | endif()
10 | endif()
11 |
12 |
13 | # CTL must be built "out-of-source", so we start by ensuring that the
14 | # source and build directories are different.
15 | if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
16 | message(FATAL_ERROR "In-source build attempted; please clean the CMake cache and then switch to an out-of-source build, e.g., rm CMakeCache.txt && rm -Rf CMakeFiles/ && mkdir build/ && cd build/ && cmake ..")
17 | endif()
18 |
19 | set(CMAKE_BUILD_TYPE Release)
20 |
21 | #Frame pointers are useful for profiling.
22 | #Complaints and pedantry accepted here.
23 | add_definitions("-fno-omit-frame-pointer -pedantic -Wall -ansi -std=c++14")
24 |
25 | #Handle dependencies
26 | set(CTL_DEPS ${CMAKE_SOURCE_DIR}/dependencies)
27 | include( dependencies/CMakeLists.txt)
28 | include_directories(${CMAKE_CURRENT_SOURCE_DIR})
29 | include_directories(${CTL_DEPS})
30 | include_directories(${CTL_DEPS}/pybind11/include/)
31 | #Compile all the tools
32 | add_subdirectory( tools)
33 |
34 | #Compile all the tools
35 | enable_testing()
36 | add_subdirectory( tests)
37 | add_subdirectory( python)
38 |
39 | #All of this is for make install
40 | set(CTL_INCLUDE_INSTALL_DIR ${CMAKE_SOURCE_DIR}/include)
41 | set(CTL_DOC_INSTALL_DIR ${CMAKE_SOURCE_DIR}/doc)
42 | set(CTL_BIN_INSTALL_DIR ${CMAKE_SOURCE_DIR}/bin)
43 | set(CTL_EXAMPLES_INSTALL_DIR ${CMAKE_SOURCE_DIR}/examples)
44 |
45 | install( DIRECTORY ${CMAKE_SOURCE_DIR}/ctl
46 | DESTINATION include
47 | FILES_MATCHING PATTERN "*.h"
48 | PATTERN "CMakeFiles" EXCLUDE)
49 |
50 | install( DIRECTORY ${CMAKE_SOURCE_DIR}/tools
51 | DESTINATION share/ctl/tools
52 | FILES_MATCHING PATTERN "*.cpp"
53 | PATTERN "CMakeLists.txt"
54 | PATTERN "CMakeFiles" EXCLUDE)
55 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # README #
2 | This C++11 library provides a set of generic tools for:
3 |
4 | * Building Neighborhood Graphs
5 | * Building Cellular Complexes
6 | * Computing [persistent] homology over finite fields
7 | * Parallel algorithm(s) for homology
8 |
9 | ## LICENSE ##
10 | * CTL is licensed under the BSD.
11 | * See LICENSE for more info.
12 |
13 | ## DEPENDENCIES ##
14 |
15 | CTL has dependencies.
16 | - boost
17 | - tbb
18 | - metis
19 | - ann (for \epsilon nearest neighbors, we plan to move to a more up to date neighborhood computer)
20 |
21 | We strongly recommend installing them on your system either
22 | as root or with the help of your system administrator via your operating systems
23 | package manager e.g. apt on debian based systems, yum on RHEL systems, or
24 | brew/port/fink on OSX.
25 |
26 | please see .travis.yml for an example of how to to this, and our CI results to clarify is a given commit will build.
27 |
28 | If you wish to install your own dependencies in another way, you can manually edit:
29 | build_dependencies.txt
30 |
31 | If you encounter any issues, make sure to file it:
32 | https://github.com/appliedtopology/ctl/issues
33 |
34 | This list of the dependencies is below and we have annoted
35 | which packages we can auto-help you install locally.
36 |
37 | C++14 compiler (clang or gcc)
38 | Boost
39 | Intel TBB
40 | METIS (make metis) (used for graph partitioning)
41 | ANN (make ann) (used for nearest neighbor querying..)
42 | Doxygen (Optional)
43 |
44 | ## BUILDING ##
45 | 0. You may specify paths to the include/link directories here:
46 | `vim build_dependencies.txt`
47 | 1. CMake will use what you specify, and if you dont it will look on the system
48 | for dependencies (and ideally find them...)
49 | 2. Create makefiles
50 | `mkdir build; cd build; cmake ..`
51 | 3. Compile: (the -j option makes in parallel)
52 | `make -j`
53 |
54 | ### For OS/X Users: ###
55 | If you plan on using the default compiler (clang)
56 | then when installing boost ensure that you use:
57 | brew install boost ---build-from-source --with-c++11 --with-mpi --with-program_options --with-clang --without-single
58 | and after `cmake .` ensure that the compiler chosen is clang via `ccmake .` /usr/bin/c++
59 | is a good choice.
60 |
61 | Since libstdc++ (GNU C++ STL) and libc++ (Clang C++ STL) are not ABI compatible
62 | one needs to take care to use the correct compilers for libraries linked against.
63 | if boost is compiled with gcc, you cannot use clang to compile CTL and vice versa.
64 |
65 |
66 | ## INSTALL ##
67 | OS/X:
68 | `brew tap appliedtopology/software`
69 | `brew install --HEAD ctl`
70 |
71 | This sticks the headers into the default location on your system and all the tools into the appropriate path/bin directory
72 |
73 | ## SUBMITTING PATCHES ##
74 | Please Do! Accepting Pull Requests via github.
75 |
76 | ### Future ###
77 | We hope to add support for:
78 | * [Persistent] Co-homology
79 | * Zig Zag Persistence
80 | * Multidimensional Persistence
81 | * Tidy Sets
82 | * OpenGL Visualizations
83 | * Bindings to other languages such as Python, MATLAB, and R
84 |
85 | Feel free to fork and help development. Do ask questions!
86 |
--------------------------------------------------------------------------------
/ctl.spec:
--------------------------------------------------------------------------------
1 | Name: ctl
2 | Version: 0
3 | Release: noop
4 | Summary: A computational topology library
5 | License: BSD-3
6 | BuildArch: x86_64
7 | Source0: https://github.com/appliedtopology/%{name}/archive/%{commit0}.tar.gz#/%{name}-%{shortcommit0}.tar.gz
8 | BuildRequires: gcc make git zip
9 | BuildRequires: boost-devel
10 | BuildRequires: ann-devel
11 | BuildRequires: tbb-devel
12 | BuildRequires: metis-devel
13 | BuildRequires: doxygen
14 |
15 | BuildRequires: boost
16 | BuildRequires: ann
17 | BuildRequires: tbb
18 | BuildRequires: metis
19 | BuildRequires: doxygen
20 |
21 | %description
22 | A computational topology library
23 | %prep
24 | %autosetup -n %{name}-%{shortcommit0}
25 |
26 | %build
27 | mkdir build
28 | cd build
29 | cmake ..
30 | make %{?_smp_flags}
31 |
32 | %install
33 | make install
34 |
35 | %files
36 | %{_bindir}/*
37 | %{_libdir}/*
38 |
39 | %changelog
40 |
--------------------------------------------------------------------------------
/ctl/cell_complex/complex_boundary.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTL_COMPLEX_BOUNDARY_H
2 | #define CTL_COMPLEX_BOUNDARY_H
3 | /*******************************************************************************
4 | * ********** BSD-3 License ****************
5 | *******************************************************************************/
6 | //STL
7 | #include // std::iterator, std::input_iterator_tag
8 |
9 | //non exported functionality
10 | namespace ctl{
11 | namespace detail{
12 | template< typename Complex_, typename Term_, typename Cell_boundary_>
13 | class _const_boundary_iterator:
14 | public std::iterator< std::input_iterator_tag,
15 | Term_,
16 | std::ptrdiff_t,
17 | const Term_*,
18 | const Term_>{
19 | typedef _const_boundary_iterator< Complex_, Term_, Cell_boundary_> Self;
20 | typedef Complex_ Complex;
21 | typedef Term_ Term;
22 | typedef Cell_boundary_ Cell_boundary;
23 |
24 | public:
25 | //default
26 | _const_boundary_iterator() {}
27 |
28 | //copy
29 | _const_boundary_iterator( const Self & i):
30 | complex ( i.complex),
31 | next_term( i.next_term),
32 | //future_term( i.future_term),
33 | end_term( i.end_term),
34 | term( i.term) {}
35 |
36 | //move
37 | _const_boundary_iterator( Self && i):
38 | complex ( std::move( i.complex)),
39 | next_term ( std::move( i.next_term)),
40 | end_term ( std::move( i.end_term)),
41 | term( std::move( i.term)) { i.complex = NULL; }
42 |
43 | //begin constructor
44 | _const_boundary_iterator( Complex& _complex,
45 | Cell_boundary & _bd,
46 | const typename Complex::Cell& cell):
47 | complex( &_complex),
48 | next_term ( _bd.begin( cell)),
49 | end_term( _bd.end( cell)){
50 | _next_term();
51 | }
52 | //end constructor
53 | _const_boundary_iterator( Complex & _complex): complex( &_complex){
54 | _end_term();
55 | }
56 | Self& operator=( const Self& from){
57 | complex = from.complex;
58 | next_term = from.next_term;
59 | end_term = from.end_term;
60 | term = from.term;
61 | return *this;
62 | }
63 | bool operator==( const Self & i) const { return term == i.term;}
64 | bool operator!=( const Self & i) const { return term != i.term;}
65 | Self& operator++(){
66 | _next_term();
67 | return *this;
68 | }
69 | Self operator++(int){
70 | Self tmp = *this;
71 | _next_term();
72 | return tmp;
73 | }
74 | Term& operator*(){ return term; }
75 | Term* operator->(){ return &term; }
76 | protected:
77 | void _next_term(){
78 | if( next_term != end_term){
79 | term.cell() = complex->find_cell( next_term->cell());
80 | term.coefficient( next_term->coefficient());
81 | ++next_term;
82 | return;
83 | }
84 | _end_term();
85 | }
86 |
87 | void _end_term(){ term.cell() = complex->end(); }
88 |
89 | Complex* complex;
90 | typename Cell_boundary::const_iterator next_term;
91 | typename Cell_boundary::const_iterator end_term;
92 | Term term;
93 | }; //class _const_boundary_iterator
94 | } //detail namespace
95 | } //ctl namespace
96 |
97 | //exported functionality
98 | namespace ctl{
99 |
100 | template< typename Complex_,
101 | typename Cell_boundary_ = typename Complex_::Cell_boundary,
102 | typename Iterator_ = typename Complex_::iterator >
103 | class Complex_boundary {
104 | typedef Complex_boundary< Complex_> Self;
105 | typedef typename Cell_boundary_::Term Cell_term;
106 | public:
107 | //export types
108 | typedef typename Cell_term::Coefficient Coefficient;
109 | typedef Complex_ Complex;
110 | typedef Cell_boundary_ Cell_boundary;
111 | typedef Iterator_ Iterator;
112 | typedef typename Complex::size_type size_type;
113 | //Complex boundary terms are iterators
114 | typedef typename Cell_term::template
115 | rebind< Iterator, Coefficient>::T Term;
116 | typedef ctl::detail::_const_boundary_iterator< Complex,
117 | Term,
118 | Cell_boundary>
119 | const_iterator;
120 | //copy constructor
121 | Complex_boundary( Complex_boundary & f): _complex( f._complex) {};
122 | //move constructor, we don't care since we store references
123 | Complex_boundary( Complex_boundary && f): _complex( f._complex) {};
124 |
125 | Complex_boundary( Complex & complex): _complex( complex) {};
126 |
127 | const_iterator begin( const typename Term::Cell & c) const {
128 | return const_iterator( _complex, _complex.cell_boundary(), c->first);
129 | }
130 | const_iterator end( const typename Term::Cell & c) const {
131 | return const_iterator( _complex);
132 | }
133 | size_type length( const typename Term::Cell & c) const {
134 | return _complex.cell_boundary().length( c->first);
135 | }
136 |
137 | private:
138 | Complex & _complex;
139 | }; // class Complex_boundary
140 |
141 | } //namespace ctl
142 |
143 | #endif //CTLIB_COMPLEX_BOUNDARY_H
144 |
--------------------------------------------------------------------------------
/ctl/cell_complex/detail/data_wrapper.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTL_DATA_WRAPPER_H
2 | #define CTL_DATA_WRAPPER_H
3 | #include
4 | /*******************************************************************************
5 | * BSD-3
6 | *******************************************************************************
7 | * Copyright (C) Ryan H. Lewis 2014
8 | *******************************************************************************
9 | * NOTES:
10 | * We use this to associate a single number to every cell opaquely.
11 | *******************************************************************************/
12 |
13 | namespace ctl {
14 | namespace detail {
15 |
16 | struct Default_data {
17 | constexpr bool operator==( const Default_data & d) const{ return true; }
18 | constexpr bool operator<( const Default_data & d) const { return false; }
19 | }; //class Default_data for complex.
20 |
21 | template< typename Data_>
22 | class Data_wrapper : public Data_ {
23 | private:
24 | typedef Data_wrapper< Data_> Self;
25 | public:
26 | typedef std::size_t Id;
27 | //default
28 | Data_wrapper(): Data_(), id_( 0) {}
29 | //id
30 | Data_wrapper( const Id & tid): Data_(), id_( tid){}
31 | //copy
32 | Data_wrapper( const Data_wrapper & from) : Data_( from), id_( from.id_){}
33 | //move
34 | Data_wrapper( Data_wrapper && from): Data_( std::forward( from)),
35 | id_( std::move( from.id_)){
36 | }
37 |
38 | Self& operator=( const Self & from){
39 | Data_::operator=( from);
40 | id_ = from.id_;
41 | return *this;
42 | }
43 |
44 | Self& operator=( Self && from){
45 | Data_::operator=( from);
46 | id_ = std::move( from.id_);
47 | return *this;
48 | }
49 |
50 | bool operator<( const Self & from) const{
51 | return Data_::operator<( from);
52 | }
53 |
54 | bool operator==( const Self & b) const {
55 | return (id_ == b.id_) && Data_::operator==( b);
56 | }
57 | bool operator!= (const Self & b) const { return !((*this)==b); }
58 | Id id() const { return id_; }
59 | void id( Id n){ id_ = n; }
60 | private:
61 | Id id_;
62 | }; // class Data_wrapper
63 |
64 | template< typename Stream>
65 | Stream& operator<<( Stream & out, const Default_data & d){ return out; }
66 | template< typename Stream>
67 | Stream& operator<<( Stream & out, const Default_data && d){ return out; }
68 | } //namespace detail
69 |
70 | } //namespace ctl
71 |
72 | #endif //CTL_DEFAULT_WRAPPER
73 |
--------------------------------------------------------------------------------
/ctl/cover/cover.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTL_COVER_HPP
2 | #define CTL_COVER_HPP
3 | #include
4 | #include
5 | #include
6 |
7 | namespace ctl {
8 | template< typename Complex>
9 | decltype(auto)
10 | open_star_cover(const Complex& K, const std::function& f){
11 | ctl::Simplicial_complex<> nerve;
12 | std::vector< ctl::Abstract_simplex> map_to_nerve;
13 | map_to_nerve.reserve(K.size());
14 | for(const auto& sigma : K){
15 | ctl::Abstract_simplex tau;
16 | for( const auto& vtx: sigma.first){ tau.insert(f(vtx)); }
17 | const auto& tau_cell = nerve.insert_closed_cell( tau);
18 | //TODO: These should be references..
19 | map_to_nerve.emplace_back(tau_cell.first->first);
20 | }
21 | return std::make_pair(nerve, map_to_nerve);
22 | }
23 |
24 | }//end namespace ctl
25 | #endif //CTL_COVER_HPP
26 |
--------------------------------------------------------------------------------
/ctl/ctl.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTLIB_CTL_H
2 | #define CTLIB_CTL_H
3 | /*******************************************************************************
4 | * Copyright (C) Ryan H. Lewis 2014
5 | *******************************************************************************
6 | * ********** BSD-3 License ****************
7 | *******************************************************************************/
8 | #include
9 | #include
10 |
11 | //Abstract Cube
12 | //TODO
13 |
14 | //IO
15 | #include
16 |
17 | //Product Cell
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | //Coefficients
25 | //Finite Fields
26 | #include
27 |
28 | //Chain Complex
29 | #include
30 | #include
31 |
32 | //Weight Data
33 | #include
34 | #include
35 |
36 |
37 | //Term
38 | #include
39 | #include
40 | #include
41 |
42 | //Chain
43 | #include
44 | #include
45 |
46 | //Barcodes
47 | //#include
48 |
49 | //Filtration
50 | #include
51 | #include
52 | #include
53 |
54 | //Graphs & metrics
55 | #include
56 | #include
57 | #include
58 |
59 | //VR
60 | #include
61 |
62 | #include
63 |
64 | //Facilities for extracting the one_skeleton
65 | #include
66 | #include
67 | #include
68 |
69 | //Parallel library (multithreaded)
70 | #include
71 | #include
72 | #include
73 | #include
74 | #include
75 | #include
76 | #include
77 | #include
78 | #include
79 | #include
80 |
81 | #include
82 | #include
83 | #include
84 |
85 | //Persistence
86 | #include
87 | #include
88 | #include
89 | #include
90 |
91 | //Not implemented
92 | //#include
93 |
94 | #endif //CTLIB_CTL_H
95 |
--------------------------------------------------------------------------------
/ctl/example/example.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTLIB_EXAMPLE_H
2 | #define CTLIB_EXAMPLE_H
3 | /*******************************************************************************
4 | * Copyright (C) Ryan H. Lewis 2014
5 | *******************************************************************************
6 | * Release under BSD-3 License See LICENSE
7 | *******************************************************************************
8 | * NOTES
9 | *
10 | *
11 | *******************************************************************************/
12 | //STL
13 | //#include < .. >
14 |
15 | //CTL
16 | //#include
17 |
18 | //non-exported functionality
19 | namespace ctl {
20 | namespace detail{} // end namespace detail
21 | } //ctl namespace
22 |
23 | //exported functionality
24 | namespace ctl{} //namespace ctl
25 |
26 |
27 | #endif //CTLIB_EXAMPLE_H
28 |
--------------------------------------------------------------------------------
/ctl/graded_chain_complex/filtration_iterator.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTLIB_FILTRATION_ITERATOR_H
2 | #define CTLIB_FILTRATION_ITERATOR_H
3 | /*******************************************************************************
4 | * Copyright (C) Ryan H. Lewis 2014
5 | *******************************************************************************
6 | * ********** BSD-3 License ****************
7 | *******************************************************************************/
8 | /**
9 | * NOTES: This header is DEPRECATED!
10 | */
11 | //STL
12 | #include
13 |
14 | //private functionality
15 | //the multiplier gracefully handles reverse iterators.
16 | namespace ctl{
17 | namespace detail{
18 | template< typename Iterator, int multiplier>
19 | class _filtration_iterator :
20 | public std::iterator< std::random_access_iterator_tag,
21 | typename Iterator::value_type> {
22 | public:
23 | //Does not matter to be defined since we inherit
24 | typedef typename Iterator::difference_type difference_type;
25 | typedef typename Iterator::value_type value_type;
26 | typedef typename Iterator::pointer pointer;
27 | typedef typename Iterator::reference reference;
28 | typedef std::random_access_iterator_tag iterator_category;
29 | private:
30 | typedef typename Iterator::difference_type diff_type;
31 | typedef _filtration_iterator< Iterator, multiplier> Self;
32 | public:
33 |
34 | //default
35 | _filtration_iterator(): i(), p( 0) {}
36 | //copy
37 | _filtration_iterator( const Self & f): i( f.i), p( f.p) {};
38 | //move
39 | _filtration_iterator( Self && f): i( std::move( f.i)),
40 | p( std::move(f.p)) {};
41 | //special
42 | _filtration_iterator( const Iterator & i_,
43 | const std::size_t p_): i( i_), p( p_) {}
44 | Self& operator++(){
45 | p+=multiplier; i++;
46 | return *this;
47 | }
48 | Self operator++(int){
49 | Self r( *this);
50 | ++(*this);
51 | return r;
52 | }
53 | Self& operator--(){
54 | p-=multiplier; i--;
55 | return *this;
56 | }
57 | Self operator--(int){
58 | Self r( *this);
59 | --(*this);
60 | return r;
61 | }
62 | //deref
63 | pointer operator->() const { return &(*i); }
64 | reference operator*(){ return *i; }
65 | //comparisons
66 | bool operator!=(const Self& r) const { return (i != r.i); }
67 | bool operator==(const Self& r) const { return !operator!=(r); }
68 | bool operator<(const Self& r) const { return (i < r.i); }
69 | bool operator<=(const Self& r) const { return (i <= r.i); }
70 | bool operator>(const Self& r) const { return (i > r.i); }
71 | bool operator>=(const Self& r) const { return (i >= r.i); }
72 | //arithmetic
73 | Self operator+(const diff_type n) const { return Self(i+n, p+n); }
74 | Self operator-(const diff_type n) const { return Self(i-n, p-n); }
75 | diff_type operator-(const Self& a) const { return i-a.i; }
76 | Self& operator=(const Self& r) { i = r.i; p = r.p; return *this; }
77 | Self& operator+=(const difference_type n) { i+=n; p+=n; return *this;}
78 | Self& operator-=(const difference_type n) { i-=n; p-=n; return *this;}
79 | reference operator[](const std::size_t n) const { return *(i+n); }
80 | std::size_t pos() const { return p; }
81 | //the details
82 | private:
83 | Iterator i;
84 | std::size_t p;
85 | }; //class _filtration_iterator
86 | } //namespace detail
87 | } //namespace ctl
88 | #endif //CTLIB_FILTRATION_ITERATOR_H
89 |
--------------------------------------------------------------------------------
/ctl/graded_chain_complex/less.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTLIB_FILTRATION_LESS_H
2 | #define CTLIB_FILTRATION_LESS_H
3 | /*******************************************************************************
4 | *******************************************************************************
5 | * Copyright (C) Ryan H. Lewis 2014
6 | *******************************************************************************
7 | * ********** BSD-3 License ****************
8 | *******************************************************************************/
9 | //exported functionality
10 | namespace ctl{
11 |
12 | struct Id_less{
13 | constexpr Id_less(){}
14 | template< typename Cell_iterator>
15 | bool operator()( const Cell_iterator & a, const Cell_iterator & b) const {
16 | return a->second.id() < b->second.id();
17 | }
18 | }; //struct Id_less
19 |
20 | //Order by data, break ties by cell order
21 | struct Cell_less{
22 | constexpr Cell_less(){}
23 |
24 | template< typename Cell_iterator>
25 | bool operator()( const Cell_iterator & a, const Cell_iterator & b) const {
26 | return (a->second < b->second) ||
27 | (!(b->second < a->second) && (a->first < b->first));
28 | }
29 | }; //struct Cell_less
30 |
31 | } //namespace ctl
32 |
33 | #endif //CTLIB_FILTRATION_LESS_H
34 |
--------------------------------------------------------------------------------
/ctl/hash/hash.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTLIB_HASH_H
2 | #define CTLIB_HASH_H
3 | /*******************************************************************************
4 | * -Academic Honesty-
5 | * Plagarism: The unauthorized use or close imitation of the language and
6 | * thoughts of another author and the representation of them as one's own
7 | * original work, as by not crediting the author.
8 | * (Encyclopedia Britannica, 2008.)
9 | *
10 | * You are free to use the code according to the license below, but, please
11 | * do not commit acts of academic dishonesty. We strongly encourage and request
12 | * that for any [academic] use of this source code one should cite one the
13 | * following works:
14 | *
15 | * \cite{hatcher, z-ct-10}
16 | *
17 | * See ct.bib for the corresponding bibtex entries.
18 | * !!! DO NOT CITE THE USER MANUAL !!!
19 | *******************************************************************************
20 | * Copyright (C) Ryan H. Lewis 2014
21 | *******************************************************************************
22 | * ********** BSD-3 License ****************
23 | *******************************************************************************/
24 |
25 | #define CTL_USE_CITY
26 |
27 | //STL
28 | #include
29 |
30 | //CTL
31 | namespace ctl{
32 | namespace hash{
33 | #include
34 | #include
35 | } //end namespace hash
36 | } //end namespace ctl
37 | //non-exported functionality
38 | namespace ctl{
39 | namespace detail{
40 | namespace cth = ctl::hash;
41 | template< typename Container>
42 | inline
43 | std::size_t murmur3_hash( const Container & key, std::false_type){
44 | typedef typename Container::value_type T;
45 | std::size_t out;
46 | //MurmurHash3_x86_32
47 | //MurmurHash3_x86_128
48 | cth::MurmurHash3_x64_128 ( (const char*)&(*(key.begin())),
49 | sizeof(T)*key.size(), key.size(), &out );
50 | return out;
51 | }
52 |
53 | template< typename T>
54 | inline std::size_t murmur3_hash( const T & t, std::true_type){
55 | std::size_t out;
56 | cth::MurmurHash3_x86_128( (const char*)&t, sizeof(T), 1, &out);
57 | return out;
58 | }
59 |
60 | template< typename Container>
61 | inline std::size_t city_hash( const Container & key, std::false_type){
62 | typedef typename Container::value_type T;
63 | return cth::CityHash64WithSeed( (const char*)&(*(key.begin())),
64 | sizeof(T)*key.size(),key.size());
65 | }
66 |
67 | template< typename T>
68 | inline std::size_t city_hash( const T & t, std::true_type){
69 | return cth::CityHash64WithSeed( (const char*)&(t),
70 | sizeof(T),1);
71 | }
72 |
73 | template< typename T>
74 | inline std::size_t pjw_hash( const T & key){
75 | std::size_t h, g;
76 | h = 0;
77 | for( auto i : key){
78 | h = (h << 4) + i;
79 | if ((g = h & 0xf0000000)) {
80 | h = h^(g >> 24);
81 | h = h^g;
82 | }
83 | }
84 | return h;
85 | }
86 | template< typename T>
87 | inline std::size_t jenkins_hash( const T & key){
88 | std::size_t hash=0;
89 | for(auto i : key){
90 | hash += i;
91 | hash += (hash << 10);
92 | hash ^= (hash >> 6);
93 | }
94 | hash += (hash << 3);
95 | hash ^= (hash >> 11);
96 | hash += (hash << 15);
97 | return hash;
98 | }
99 |
100 | } //detail namespace
101 | } //ctl namespace
102 |
103 | namespace ctl {
104 |
105 | template< typename T>
106 | std::size_t hash_function( const T & key){
107 | #ifdef CTL_USE_MURMUR
108 | return detail::murmur3_hash( key, std::is_integral< T>());
109 | #elif defined( CTL_USE_CITY)
110 | return detail::city_hash( key, std::is_integral< T>());
111 | #elif defined( CTL_USE_JENKINS)
112 | return detail::jenkins_hash( key);
113 | #else
114 | return detail::pjw_hash( key);
115 | #endif
116 | }
117 |
118 | template< typename T>
119 | struct Hash{
120 | std::size_t operator()( const T & key) const{
121 | return hash_function( key);
122 | }
123 | }; //class Hash
124 | } //namespace ctl
125 | #endif //CTLIB_HASH_H
126 |
--------------------------------------------------------------------------------
/ctl/io/io.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTLIB_IO_H
2 | #define CTLIB_IO_H
3 | /*******************************************************************************
4 | * Copyright (C) Ryan H. Lewis 2011
5 | *******************************************************************************
6 | * Released under BSD-3 License. See LICENSE
7 | *******************************************************************************/
8 | //STL
9 | #include
10 | #include
11 |
12 | namespace ctl{
13 | constexpr char delta[] = "\u2202";
14 | constexpr char sigma[] = "\u03C3";
15 | constexpr char tau[] = "\u1D6D5";
16 | constexpr char otimes[] = "\u2297";
17 | constexpr char oplus[] = "\u2295";
18 |
19 | struct identity {
20 | template
21 | inline constexpr auto operator()(U&& v) const noexcept
22 | -> decltype(std::forward(v))
23 | {
24 | return std::forward(v);
25 | }
26 | template
27 | inline constexpr U& operator[](U& v) const noexcept { return v; }
28 |
29 | template
30 | constexpr auto operator()(X && y, U&& v) const noexcept
31 | -> decltype(std::forward(v))
32 | {
33 | return std::forward(v);
34 | }
35 |
36 | template
37 | constexpr bool operator()(Cell && c, U&& v, bool f) const noexcept {
38 | return true;
39 | }
40 |
41 | };
42 |
43 | template< typename Stream>
44 | bool open_file( Stream & in, const char* file_name){
45 | in.open( file_name);
46 | return in.is_open();
47 | }
48 | template< typename Stream>
49 | void close_file( Stream & in){ in.close(); }
50 |
51 | template< typename Stream>
52 | bool get_line( Stream & in, std::string & line, std::size_t & line_num){
53 | while( in.good()){
54 | std::getline( in, line);
55 | ++line_num;
56 | switch( line[0]){
57 | case '#':
58 | case '%':
59 | case '\0':
60 | break;
61 | default:
62 | return true;
63 | }
64 | }
65 | return false;
66 | }
67 |
68 | } //namespace ctl
69 |
70 | #endif //CTLIB_IO_H
71 |
--------------------------------------------------------------------------------
/ctl/matrix/matrix.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTL_MATRIX_H
2 | #define CTL_MATRIX_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | namespace ctl {
9 |
10 | /**
11 | * @brief Defines a Sparse matrix using the Dictionary of Keys
12 | * Storage type
13 | *
14 | * It stoes a ctl::Chain< ctl::Term< Coefficient, Index> >
15 | * where index references the row or column index.
16 | *
17 | * @tparam C
18 | * @tparam T
19 | */
20 | template< typename Coeff, typename Cell=std::size_t>
21 | using Sparse_matrix = std::vector< ctl::Chain< ctl::Term< Cell, Coeff> > >;
22 |
23 | template< typename Iterator>
24 | using Offset_map = ctl::Pos_offset_map< Iterator>;
25 |
26 | template< typename Coeff, typename Offset_map, typename Cell=std::size_t>
27 | using Sparse_matrix_map = ctl::iterator_property_map< typename Sparse_matrix< Coeff, Cell>::iterator,
28 | Offset_map,
29 | typename Sparse_matrix< Coeff,Cell>::value_type,
30 | typename Sparse_matrix< Coeff,Cell>::value_type&>;
31 | }
32 |
33 | #endif //CTL_MATRIX_H
34 |
--------------------------------------------------------------------------------
/ctl/maximal_cliques/clique_output_iterator.h:
--------------------------------------------------------------------------------
1 | // clique_output_iterator.h
2 | // Gabe Weaver
3 | // August 20, 2008
4 | //
5 | // Exports Clique_output_iterator class
6 |
7 | // Class: Clique_output_iterator
8 | //
9 | // Simply couts the set representing the clique
10 |
11 | #ifndef _CTL_CLIQUE_OUTPUT_ITERATOR_H_
12 | #define _CTL_CLIQUE_OUTPUT_ITERATOR_H_
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | namespace ctl {
20 |
21 | template< class Clique_>
22 | class Clique_output_iterator :
23 | public std::iterator< std::output_iterator_tag,
24 | Clique_,
25 | void,
26 | void,
27 | void> {
28 | public:
29 | Clique_output_iterator() : num_cliques_( 0) {}
30 | Clique_output_iterator&
31 | operator=( const Clique_& clique)
32 | {
33 | ++num_cliques_;
34 | typename Clique_::const_iterator clique_iter;
35 | for ( clique_iter = clique.begin();
36 | clique_iter != clique.end();
37 | clique_iter++) {
38 | std::cout << (*clique_iter) << " ";
39 | }
40 | std::cout << std::endl;
41 | return *this;
42 | }
43 |
44 | Clique_output_iterator& operator*() { return *this; }
45 | Clique_output_iterator& operator++() { return *this; }
46 | Clique_output_iterator& operator++( int) { return *this; }
47 | int num() {
48 | return num_cliques_;
49 | }
50 | private:
51 | int num_cliques_;
52 | };
53 |
54 | } // namespace ctl
55 |
56 | #endif // _CTL_CLIQUE_OUTPUT_ITERATOR_H_
57 |
--------------------------------------------------------------------------------
/ctl/maximal_cliques/test_clique_output_iterator.cpp:
--------------------------------------------------------------------------------
1 | // test_clique_output_iterator.C
2 | // Gabe Weaver
3 | // August 19, 2008
4 |
5 | #include
6 | #include "clique_output_iterator.h"
7 |
8 | int main(int argc, char *argv[])
9 | {
10 | typedef std::set Clique;
11 | typedef std::set< Clique > CliqueSet;
12 |
13 | CliqueSet cliques;
14 | CliqueSet::iterator clique_iter;
15 |
16 | int c1[4] = { 22, 33, 44, 55 };
17 | int c2[6] = { 5, 10, 15, 20, 25, 30 };
18 |
19 | Clique clique1(c1, c1 + 4);
20 | Clique clique2(c2, c2 + 6);
21 |
22 | cliques.insert(clique1);
23 | cliques.insert(clique2);
24 |
25 | ctl::Clique_output_iterator out;
26 |
27 | for (clique_iter = cliques.begin();
28 | clique_iter != cliques.end();
29 | clique_iter++) {
30 | Clique clique = (Clique)(*clique_iter);
31 | *out++ = clique;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/ctl/maximal_cliques/test_maximal_cliques.cpp:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (C) Ryan H. Lewis 2014
3 | *******************************************************************************
4 | * Release under BSD-3 License See LICENSE
5 | *******************************************************************************
6 | * NOTES
7 | * Based on original implementation by Gabe Weaver
8 | *******************************************************************************/
9 |
10 | // Standard & STL
11 | #include // ifstream, cerr
12 |
13 | // BGL
14 | #include
15 |
16 | // CTL
17 | #include
18 | #include
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | int main(int argc, char *argv[]) {
25 | typedef boost::graph_traits< ctl::Nbhd_graph> graph_traits;
26 | typedef graph_traits::vertex_descriptor vertex_descriptor;
27 | typedef std::vector< vertex_descriptor> Vector;
28 |
29 | // Parse command line
30 | if( argc < 2) {
31 | std::cerr << argv[0] << " graph" << std::endl;
32 | std::exit(1);
33 | }
34 |
35 | // Establish input stream
36 | std::ifstream in;
37 | ctl::open_file( in, argv[1]);
38 |
39 | // Read the graph
40 | ctl::Nbhd_graph graph;
41 | in >> graph;
42 |
43 | // Setup the output iterator
44 | ctl::Clique_output_iterator< Vector> out;
45 |
46 | // Count number of maximal cliques
47 | ctl::Timer timer;
48 | timer.start();
49 | ctl::maximal_cliques(graph, out);
50 | std::cout << out.num() << " cliques in " << timer.get() << " seconds" <<
51 | std::endl;
52 | return 0;
53 | }
54 |
--------------------------------------------------------------------------------
/ctl/metrics/metric.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTLIB_LP_H
2 | #define CTLIB_LP_H
3 | /*******************************************************************************
4 | * Copyright (C) Ryan H. Lewis 2014
5 | *******************************************************************************
6 | * ********** BSD-3 License ****************
7 | *******************************************************************************/
8 | //exported functionality
9 | namespace ctl{
10 |
11 | template< typename Point, int p=2>
12 | double lp( const Point & a, const Point & b) {
13 | //typedef typename Point::const_iterator iterator;
14 | double dist=0;
15 | auto i = a.begin();
16 | for( auto j = b.begin(); i != a.end(); ++i, ++j){
17 | dist += std::pow((*i)-(*j),p);
18 | }
19 | return dist;
20 | }
21 |
22 | template< typename Point>
23 | double hamming( const Point & a, const Point & b) {
24 | //typedef typename Point::const_iterator iterator;
25 | double dist=0;
26 | auto i = a.begin();
27 | for( auto j = b.begin(); i != a.end(); ++i, ++j){
28 | dist += (*i==*j);
29 | }
30 | return dist;
31 | }
32 |
33 | } //namespace ctl
34 |
35 | #endif //CTLIB_LP_H
36 |
--------------------------------------------------------------------------------
/ctl/nbhd_graph/all_pairs.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTL_ALL_PAIRS_H
2 | #define CTL_ALL_PAIRS_H
3 | /*******************************************************************************
4 | Copyright (C) Ryan H. Lewis 2014
5 | ********** BSD-3 License ****************
6 | *******************************************************************************
7 | * NOTES
8 | * We use the all pairs approach to constuct a graph.
9 | *
10 | *******************************************************************************/
11 |
12 | //STL
13 | #include
14 | #include
15 |
16 | //BOOST
17 | #include
18 |
19 | namespace ctl{
20 | namespace all_pairs{
21 | template< typename It1, typename It2>
22 | double lp( It1 begin1, It1 end1, It2 begin2){
23 | double r = 0.0;
24 | for( ; begin1 != end1; ++begin1, ++begin2){
25 | double v = (*begin1 - *begin2);
26 | r += v*v;
27 | }
28 | return r;
29 | }
30 |
31 |
32 |
33 | template
34 | void construct_graph( const Points& points,
35 | const double epsilon,
36 | Graph& graph) {
37 | typedef typename boost::graph_traits graph_traits;
38 | typedef typename graph_traits::vertex_iterator vertex_iterator;
39 | typedef typename boost::graph_traits< Graph>::vertex_descriptor vertex_descriptor;
40 | typedef typename boost::property_map< Graph,
41 | boost::vertex_name_t>::type name_map_t;
42 | typedef typename boost::property_traits< name_map_t>::value_type vertex_name_t;
43 | typedef std::unordered_map< vertex_name_t, vertex_descriptor> Name_to_descriptor_map;
44 |
45 | name_map_t name_map = boost::get( boost::vertex_name, graph);
46 | Name_to_descriptor_map descriptor( points.size());
47 |
48 | // add vertices
49 | for( std::size_t i = 0; i < points.size(); ++i) {
50 | vertex_descriptor v_descriptor = boost::add_vertex( graph);
51 | name_map[ v_descriptor] = i;
52 | descriptor.emplace( i, v_descriptor);
53 | }
54 |
55 | // add edges
56 | vertex_iterator vi, vj, vlast;
57 | double epsilon_squared = epsilon*epsilon;
58 | for ( std::tie( vi, vlast) = boost::vertices( graph); vi != vlast; ++vi) {
59 | for ( std::tie( vj, vlast) = boost::vertices (graph); vj != vi; ++vj) {
60 |
61 | if( lp(points.begin(name_map[*vi]),
62 | points.end(name_map[*vi]),
63 | points.begin(name_map[*vj])) < epsilon_squared){
64 | boost::add_edge(*vi, *vj, graph);
65 | }
66 | }
67 | }
68 | }
69 | } //end namespace all_pairs
70 | } //end namespace CTL
71 |
72 |
73 | #endif //CTL_ALL_PAIRS_H
74 |
--------------------------------------------------------------------------------
/ctl/one_skeleton/graph_to_metis.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CTL_GRAPH_TO_METIS_H
2 | #define CTL_GRAPH_TO_METIS_H
3 | /*******************************************************************************
4 | Copyright (C) Ryan H. Lewis 2011
5 | *******************************************************************************
6 | * ********** BSD-3 License ****************
7 | ******************************************************************************/
8 | // STL
9 | #include // not sure if algorithm,sstream are necessary yet
10 | #include
11 | #include
12 | #include