Skip to content

Commit

Permalink
Merge from dev, version 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Bigey committed Jan 25, 2018
2 parents 12dab26 + f0ee96d commit 05b7093
Show file tree
Hide file tree
Showing 14 changed files with 849 additions and 308 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Change Log

## [v1.1.0](https://github.com/terae/graph/tree/v1.1.0) (2018-01-17)
## [v1.1.1](https://github.com/terae/graph/releases/tag/v1.1.0) (2018-01-25)
[Full Changelog](https://github.com/terae/compare/v1.1.0...v1.1.1)

## [v1.1.0](https://github.com/terae/graph/releases/tag/v1.1.0) (2018-01-17)
[Full Changelog](https://github.com/terae/graph/compare/v1.0.1...v1.1.0)

## [v1.0.1](https://github.com/terae/graph/tree/v1.0.1) (2018-01-06)
## [v1.0.1](https://github.com/terae/graph/releases/tag/v1.1.1) (2018-01-06)


\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set(LIBRARY_CMAKE_PROJECT_CONFIG_FILE "${LIBRARY_CMAKE_CONFIG_DIR}/${LIBRARY_NAM
##
## PROJECT
##
project(${LIBRARY_NAME} LANGUAGES CXX VERSION 1.1.0)
project(${LIBRARY_NAME} LANGUAGES CXX VERSION 1.1.1)

##
## OPTIONS
Expand Down
5 changes: 1 addition & 4 deletions benchmarks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
# Build/run graph.hpp benchmarks, eg. CXX=g++-7 make
#

all: generation_files graph_benchmarks
all: graph_benchmarks
bash -c 'time ./graph_benchmarks'

graph_benchmarks: src/benchmarks.cpp ../single_include/graph.hpp
$(CXX) -std=c++11 -pthread $(CXXFLAGS) -DNDEBUG -O3 -flto -I third-party/benchpress/src/benchpress -I ../single_include src/benchmarks.cpp $(LDFLAGS) -o $@

generation_files:
(test -e files/grid_graph.txt && test -e files/complete_graph.txt) || (cd files; g++ generate_files.cpp -o exec; ./exec; rm exec)

clean:
rm -f graph_benchmarks
168 changes: 94 additions & 74 deletions benchmarks/src/benchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

#define BENCHPRESS_CONFIG_MAIN

#include <fstream>
#include <sstream>
#include <benchpress.hpp>
#include <cmath>
#include <fstream>
#include <graph.hpp>
#include <pthread.h>
#include <cmath>
#include <random>
#include <sstream>
#include <thread>

#define MAX 500

struct Coord {
int x, y;
Coord(int x_ = 0, int y_ = 0) : x(x_), y(y_) {}
friend std::ostream &operator<<(std::ostream &os, const Coord &c) {
return os << '[' << c.x << ", " << c.y << ']';
}
Expand All @@ -28,7 +32,7 @@ struct Coord {
return y < c.y;
}
};
using Graph_grid = graph_undirected<Coord, int, double>;
using Graph_grid = graph_undirected<Coord, int, int>;
using Graph_directed = graph_directed <std::string, int, double>;

struct StartUp {
Expand All @@ -46,41 +50,26 @@ struct StartUp {
};
StartUp startup;

enum class EMode { input, output, make_complete/*, search*/ };

static void bench(benchpress::context &ctx,
const std::string &in_path,
const EMode mode) {
// using string streams for benmarking to factor-out cold-cache disk access
#if defined( FROMFILE )
std::ifstream istr;
{
istr.open(in_path, std::ifstream::in);
if (!istr) {
std::cerr << "Unexistant file '" << in_path << "'." << std::endl;
exit(1);
}
}
#else
std::stringstream istr;
{
// read file into string stream
std::ifstream input_file(in_path);
if (input_file) {
istr << input_file.rdbuf();
input_file.close();
} else {
std::cerr << "Unexistant file '" << in_path << "'." << std::endl;
exit(1);
enum class EMode { input, output, make_complete, astar/*, search*/ };

static void bench(benchpress::context &ctx, const EMode mode) {
graph_undirected<Coord, int, double> grid_graph;
if (mode == EMode::input || mode == EMode::output) {
for (int x{-MAX + 1}; x < MAX; ++x) {
for (int y{-MAX + 1}; y < MAX; ++y) {
grid_graph({x, y}, {x, y + 1}) = 1;
grid_graph({x, y}, {x + 1, y}) = 1;
}
}
}
#endif

switch (mode) {
// benchmarking input
/// Benchmarking input
case EMode::input: {
ctx.reset_timer();
std::stringstream istr;
istr << grid_graph;

ctx.reset_timer();
for (size_t i{0}; i < ctx.num_iterations(); ++i) {
// clear flags and rewind
istr.clear();
Expand All @@ -92,16 +81,14 @@ static void bench(benchpress::context &ctx,
break;
}

// benmarking output
/// Benchmarking output
case EMode::output: {
// create GRAPH value from input
Graph_grid g;
istr >> g;
std::stringstream ostr;
ctx.reset_timer();
std::ostringstream ostr;

ctx.reset_timer();
for (size_t i{0}; i < ctx.num_iterations(); ++i) {
ostr << g;
ostr << grid_graph;

// reset data
ostr.str(std::string());
Expand All @@ -110,50 +97,83 @@ static void bench(benchpress::context &ctx,
break;
}

// benchmarking big amount of nodes and edges
/// Benchmarking big amount of nodes and edges
case EMode::make_complete: {
Graph_directed g;
istr >> g;
std::stringstream ostr;
graph_directed<std::string, int, double> complete_graph;
for (int i{1}; i <= MAX; ++i) {
complete_graph["node " + std::to_string(i)] = i;
}

ctx.reset_timer();
for (size_t i{0}; i < ctx.num_iterations(); ++i) {
complete_graph.link_all_nodes(42.0);
}

break;
}

/// Benchmarking A* Search algorithm
case EMode::astar: {
Graph_grid g;
for (int x{-4 * MAX + 1}; x < 4 * MAX; ++x) {
for (int y{-4 * MAX + 1}; y < 4 * MAX; ++y) {
g[ {x, y}] = x * 100000 + y;
}
}

int a{0}, b{0}, c{0}, d{0};
// all nodes linked in the upper-right corner
for (int x{0}; x < 4 * MAX; ++x) {
for (int y{0}; y < 4 * MAX; ++y) {
a += g.add_edge({x, y}, {x, y + 1}, 1);
a += g.add_edge({x, y}, {x + 1, y}, 1);
}
}
std::default_random_engine generator;
std::uniform_int_distribution<int> negative(-4 * MAX + 1, 0);
std::uniform_int_distribution<int> positive(0, 4 * MAX);

for (int i{0}; i < 200000; ++i) {
int x{positive(generator)};
int y{negative(generator)};
b += g.add_edge({x, y}, {x, y + 1}, 1);
b += g.add_edge({x, y}, {x + 1, y}, 1);
}

for (int i{0}; i < 200000; ++i) {
int x{negative(generator)};
int y{positive(generator)};
c += g.add_edge({x, y}, {x, y + 1}, 1);
c += g.add_edge({x, y}, {x + 1, y}, 1);
}

for (int i{0}; i < 400000; ++i) {
int x{negative(generator)};
int y{negative(generator)};
d += g.add_edge({x, y}, {x, y + 1}, 1);
d += g.add_edge({x, y}, {x + 1, y}, 1);
}

ctx.reset_timer();
g.link_all_nodes(42.0);
for (size_t i{0}; i < ctx.num_iterations(); ++i) {
auto astar = search::make_astar(g, Coord(4 * MAX, 4 * MAX));
auto search_result = astar.run(g.find({-4 * MAX + 1, -4 * MAX + 1}), [](const Graph_grid::const_iterator & it) -> int {
// Return Manhattan distance
return std::abs(4 * MAX - it->first.x) + std::abs(4 * MAX - it->first.y);
});
}

break;
}
}
}

#define BENCHMARKING_I(mode, title, in_path) \
#define BENCHMARKING_I(mode, title) \
BENCHMARK((title), [](benchpress::context* ctx) {\
bench(*ctx, (in_path), (mode)); \
bench(*ctx, (mode)); \
});

BENCHMARKING_I(EMode::input, "parse grid_graph.txt", "files/grid_graph.txt")
BENCHMARKING_I(EMode::output, "dump grid_graph.txt", "files/grid_graph.txt")
BENCHMARKING_I(EMode::make_complete, "link_all complete_graph_9.txt", "files/complete_graph_9.txt")

/*
make all
Generation of 0%...
Generation of 10%...
Generation of 20%...
Generation of 30%...
Generation of 40%...
Generation of 50%...
Generation of 60%...
Generation of 70%...
Generation of 80%...
Generation of 90%...
Write on the file 'grid_graph.txt'...
Done.
bash -c 'time ./graph_benchmarks'
parse grid_graph.txt 1 14427270641 ns/op
dump grid_graph.txt 1 11092073379 ns/op
./graph_benchmarks 67.453s
real 1m7,469s
user 1m6,762s
sys 0m0,584s
*/
BENCHMARKING_I(EMode::input, "parse grid_graph.txt")
BENCHMARKING_I(EMode::output, "dump grid_graph.txt")
BENCHMARKING_I(EMode::make_complete, "make_complete a graph of 1000 nodes")
BENCHMARKING_I(EMode::astar, "astar on a graph of 1000 nodes")
2 changes: 1 addition & 1 deletion doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "A STL-like graph library"
PROJECT_NUMBER = 1.1.0
PROJECT_NUMBER = 1.1.1
PROJECT_BRIEF =
PROJECT_LOGO =
OUTPUT_DIRECTORY = .
Expand Down
Loading

0 comments on commit 05b7093

Please sign in to comment.