Coder Social home page Coder Social logo

sea's Introduction


Space-Efficient
Algorithms

Build Status License: GPL v3 Coverage Status Quality Gate Reliability

SEA is a project to research and implement an open C++ library for Space-Efficient (Graph) Algorithms (SEA). Besides the running time of algorithms, their space requirements cause a problem if dealing with huge data sets or executing them on tiny devices where memory is heavily limited. Therefore, we want to provide algorithms and data structures to tackle this problem by treating space as a scarce resource.

Table of Contents

Motivation

Space-efficient algorithms in practice are justified by two main arguments. The first one is that due to memory limitation of a real computer a space-efficient algorithm runs on instances where a non space-efficient algorithm would crash due to out of memory errors. This is especially interesting where all cores of a computer should be used and multiple algorithms compete for the available memory. The second reason is that space-efficient algorithms can run faster on huge instances because they use less memory and therefore cause less cache faults. (A cache fault occurs when a system must move some of the data stored in the memory to a slower one, i.e., from the L1/L2/L3 cache of the CPU to the RAM or from the RAM to the disc drive.)

We now show these two points on an example. Assume we need to compute an Eulerian tour in an outerplanar graph. Without going into detail, we use the Hierholzer algorithm where one key step of the algorithm is the creation of recursive graph instances. There are many other graph algorithms that need to create recursive subgraphs, such as computing tree decompositions. The first step to make the algorithm space-efficient is to handle the recursive graph instances with a subgraph stack. We have implemented a folklore algorithm and a space-efficient version of it and run tests to measure the running time and the space requirements of both algorithms.

The next image shows the space requirements of the creation of subgraph instances using a space-efficient subgraph stack (blue line) and a simple subgraph stack, which creates subgraphs instances by copying vertices and edges of the original graph that remain in the subgraph together with a mapping between the new vertex numbering and the original vertex numbering, for easy translation. The system the tests have been run on has an Intel Core i7-3770T CPU @ 2.50GHz with 16 GB of RAM and 32 GB swap. Note that the simple subgraph stack exhibits a large runtime penalty as soon as cache faults become a large problem because of having to use the swap space.

Algorithms and Data Structures

This section gives you a brief overview over the implemented algorithms and data structures. For a detailed documentation click on an algorithm. For some data structures and algorithms we also provide a folklore implementation that we use to compare the memory consumption and runtime efficiency.

Algorithms

Algorithm Runtime Memory (bits) Details
Depth First Search O(n+m) O(n+m) here
Depth First Search O(n+m) O(n log(log n)) here
Depth First Search O((n+m) log n) O((log(3)+ε) n) here
Reverse DFS O(n+m) O(n log(log n)) here
Breadth First Search O(n+m) O(n) here
Cut-Vertex O(n+m) O(n+m) here
Biconnected-Component O(n+m) O(n+m) here
Outerplanar Detection O(n log(log n)) O(n) here

Data Structures

  • InitializedArray: An array consisting of fields that in total can be initialized with an user defined value in constant time by using O(1) computer words. The array provides constant time access (read/write) to fields.
  • Graph(G = {V, E}): An adjacency list graph representation that occupies O((n + m) log n) bits.
  • Bitset: A bitset of n bits that supports access in O(1) time and occupies O(n) bits.
  • AVL tree: A self-balancing binary tree with O(log(n)) time for search, insertion and removal of a node.
  • Choice Dictionary: A bitset that supports a choice operation in O(1) time that returns the position of a bit set to 1. The choice dictionary occupies O(n) bits.
  • Rank-Select: A bit sequence that supports the operations rank(k) and select(k) in O(1) time and occupies O(n) bits. rank(k) returns the number of set bits up to index k, and select(k) returns the index of the k-th set bit.
  • Ragged Dictionary: A set of n/log(n) key-value tuples with O(log(log(n))) time for get, insert and remove operations. The ragged dictionary occupies O(n) bits.
  • Static-Space Storage: A sequence of n bit packs of variable size that can be accessed in O(1) time and occupies O(n + N) bits. N is the total usable size of the static-space storage.
  • Subraph Stack: Initialized with an n-vertex m-edge graph the stack allows to remove vertices and edges and provides a resulting graph using O(n + m) bits.

Build

  1. Install CMake and a C++ compiler for your specific operating system.
  2. Build a make file for your system by using CMake -> cmake .
  3. Build the artifacts by executing make -> make

Now, the include folder contains the necessary header files and the lib folder contains the build library.

If you encounter any bugs, missing or misleading documentation, do not hesitate to create an issue ticket.

Using the Library

  • Copy the include/sealib folder into your own project's include path.
  • Copy the lib/libsealib.so file into your own project's library path. Make sure that the environment variable LD_LIBRARY_PATH also points there, or else the shared library won't be found.
  • Include the header files you want to use in your code.
  • Compile with correct -I and -L flags, and use -std=c++11.

Usage example

#include <vector>
#include <sealib/_types.h>
#include <sealib/iterator/dfs.h>
#include <sealib/graph/graphcreator.h>

using namespace Sealib;

bool reachable(DirectedGraph &g, uint64_t a, uint64_t b) {
    bool ret = false;
    std::vector<bool> started(100);
    std::vector<bool> done(100);
    DFS::nloglognBitDFS(g,
                        [&](uint64_t u) {
                            started[u]=1;
                            if (u == b && started[a] && !done[a]) {
                                ret = true;
                            }
                        },
                        DFS_NOP_EXPLORE, DFS_NOP_EXPLORE,
                        [&](uint64_t u) { done[u]=1; });
    return ret;
}

int main(void) {
    DirectedGraph g = GraphCreator::kOutdegree(100, 30);
    return reachable(g, 10, 25);
}

Compile with:

clang++ -I<include-path> -L<libary-path> -std=c++11 -o reachable reachable.cpp -lsealib

Run the executable:

export LD_LIBRARY_PATH=<library-path>
./reachable

Project Structure

.
├── CMakeLists.txt  # CMake build script
├── LICENSE         # Licence description
├── README.md       # You are reading this file now
├── third-party     # Third party libraries
├── include         # The library's header files (*.h)
├── src             # The library's source files (*.cpp)
├── src-view        # The source files for the visualization (*.cpp)
├── test            # The test files
├── lib             # The library files
└── bin             # Executable files to test the project

Research

We publish most of our research on arXiv.org.

License

Licensed under the MIT licence. For detailed license information look inside the LICENSE file.

Acknowledgments

Funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) – 379157101.

sea's People

Contributors

andrej-sajenko avatar dppl avatar frankkammer avatar jmeintrup avatar vytautas-hermann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sea's Issues

Master Failed

The current build failed, because of unexpected values in the graph test class.

Unfortunately the pull request build was successful and therefore the pull request was
merged into the master directly.

@shsr04 Can you check it please?
/home/travis/build/thm-mni-ii/sea/test/graph_test.cpp:89: Failure

g++ linker errors

(visual branch) When using g++, the build fails due to a linker error: https://travis-ci.org/thm-mni-ii/sea/builds/437500592

[100%] Linking CXX executable bin/main
CMakeFiles/main.dir/src-view/examples.cpp.o: In function `SealibVisual::VisualDFS::run()':
examples.cpp:(.text+0x206): undefined reference to `void Sealib::DFS::process_small<Sealib::ExtendedSegmentStack>(unsigned int, Sealib::Graph*, Sealib::CompactArray*, Sealib::ExtendedSegmentStack*, void (*)(unsigned int, Sealib::Graph*, Sealib::CompactArray*, Sealib::ExtendedSegmentStack*), std::function<void (unsigned int)>, std::function<void (unsigned int, unsigned int)>, std::function<void (unsigned int, unsigned int)>, std::function<void (unsigned int)>)'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/main] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2

Linear Time DFS

Implement a linear time DFS on

  • directed
  • undirected

graphs using O(log n) extra bits

Hierholzer's Algorithm

Implementation of Hierholzer's algorithm to find eulerian trails in constant time with O(n + m) bits of working memory.

bfs_test.cpp fails

/home/vytautas/Dokumente/sea/test/bfs_test.cpp:39: Failure
Expected equality of these values:
c2
wich is: 0
order * degree
wich is: 10000

I'm getting this message while running the tests.

Expand Bitset

The Sealib::Bitset implementation should include all the essential functionality of the boost::dynamic_bitset class, as specified here: https://www.boost.org/doc/libs/1_67_0/libs/dynamic_bitset/dynamic_bitset.html

Required:

class Bitset {
//constructors:
  Bitset(sizetype bits, unsigned long value);
  Bitset(Bitset&);

  Bitset operator~(); 

  unsigned long to_ulong();
};

//static procedures:
Bitset operator&(Bitset&, Bitset&);
Bitset operator|(Bitset&, Bitset&);

In-Place Initializable Arrays

Implement an array that can be

  • read in O(1) time
  • written in O(1) time
  • and initialised in O(1) time
    with O(1) extra bit.

iterator_test.cpp fails

iterator_test.cpp:44: FailureExpected equality of these values:
  count
    Which is: 1639
  setSize
    Which is: 5000

I have been getting that error from the iterator_test.
Did this test pass the travis build test?

Visualisation

Find a good graph library that allows us to visualise our algorithms.

Master is not up to date

Some files got reset to an earlier state with the latest merge, for example

src/bfs.cpp
src/dfs.h
src/segmentstack.cpp
...

Some important fixes that were already in master have been reverted. This happened because the source branch that was merged into master was out-of-date.

Please reset to the previous state and make a clean merge, or everyone will have local conflicts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.