Skip to content

Commit 761df62

Browse files
committed
Merge branch 'sb-graph-dev' into sb-graph-tearing
2 parents 23ef569 + e865fd4 commit 761df62

89 files changed

Lines changed: 4783 additions & 2294 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/c-cpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
run: |
2828
autoconf
2929
./configure
30-
make MODE=Release
30+
make compile MODE=Release
3131
3232
- name: Tests
3333
working-directory: ./

.vscode/c_cpp_properties.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${default}",
7+
"${workspaceFolder}/sbg",
8+
"${workspaceFolder}/3rd-party/gtest/usr/include",
9+
"${workspaceFolder}/**"
10+
],
11+
"defines": [],
12+
"cStandard": "c17",
13+
"cppStandard": "c++17",
14+
"intelliSenseMode": "linux-clang-x64"
15+
}
16+
],
17+
"version": 4
18+
}

.vscode/settings.json

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,65 @@
3232
"tuple": "cpp",
3333
"type_traits": "cpp",
3434
"utility": "cpp",
35-
"typeinfo": "cpp"
35+
"typeinfo": "cpp",
36+
"deque": "cpp",
37+
"string": "cpp",
38+
"unordered_set": "cpp",
39+
"cmath": "cpp",
40+
"csetjmp": "cpp",
41+
"csignal": "cpp",
42+
"cstddef": "cpp",
43+
"cstring": "cpp",
44+
"any": "cpp",
45+
"atomic": "cpp",
46+
"strstream": "cpp",
47+
"barrier": "cpp",
48+
"bit": "cpp",
49+
"bitset": "cpp",
50+
"cfenv": "cpp",
51+
"charconv": "cpp",
52+
"cinttypes": "cpp",
53+
"codecvt": "cpp",
54+
"compare": "cpp",
55+
"complex": "cpp",
56+
"concepts": "cpp",
57+
"condition_variable": "cpp",
58+
"coroutine": "cpp",
59+
"cuchar": "cpp",
60+
"forward_list": "cpp",
61+
"map": "cpp",
62+
"set": "cpp",
63+
"expected": "cpp",
64+
"algorithm": "cpp",
65+
"iterator": "cpp",
66+
"memory": "cpp",
67+
"memory_resource": "cpp",
68+
"numeric": "cpp",
69+
"optional": "cpp",
70+
"random": "cpp",
71+
"regex": "cpp",
72+
"source_location": "cpp",
73+
"string_view": "cpp",
74+
"system_error": "cpp",
75+
"format": "cpp",
76+
"future": "cpp",
77+
"iomanip": "cpp",
78+
"latch": "cpp",
79+
"mutex": "cpp",
80+
"numbers": "cpp",
81+
"ranges": "cpp",
82+
"scoped_allocator": "cpp",
83+
"semaphore": "cpp",
84+
"shared_mutex": "cpp",
85+
"span": "cpp",
86+
"spanstream": "cpp",
87+
"stacktrace": "cpp",
88+
"stdfloat": "cpp",
89+
"stop_token": "cpp",
90+
"syncstream": "cpp",
91+
"thread": "cpp",
92+
"typeindex": "cpp",
93+
"valarray": "cpp",
94+
"variant": "cpp"
3695
}
3796
}

Makefile.in

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# Target variables
1+
#///////////////////////////////////////////////////////////////////////////////
2+
# Variables --------------------------------------------------------------------
3+
#///////////////////////////////////////////////////////////////////////////////
4+
5+
# Configuration
26
MODE ?= Release
37

4-
# The Directories, Source, Includes, Objects, Binary
8+
# Directories
59
ROOT := .
610
3RD_PARTY_DIR := $(ROOT)/3rd-party
711
GTEST_DIR := googletest-release-1.12.1
@@ -14,54 +18,74 @@ BIN_DIR := $(ROOT)/bin
1418
ifeq ($(MODE), Debug)
1519
BUILD_DIR := $(OBJ_DIR)/debug
1620
endif
21+
PERF_DIR := test/performance
22+
23+
# Installation paths
1724
prefix ?= /usr/local
1825
exec_prefix ?= $(prefix)
1926
includedir ?= $(prefix)/include
2027
libdir ?= $(exec_prefix)/lib
2128
boost_libdir ?= $(prefix)
2229

23-
.PHONY: doc clean create-folders install install-folders lib-gtest test
24-
25-
#///////////////////////////////////////////////////////////////////////////////
26-
# Compilation ------------------------------------------------------------------
27-
#///////////////////////////////////////////////////////////////////////////////
28-
29-
# Flags, Libraries and Includes
30+
# Flags and includes
3031
INCLUDES := -I. -I$(boost_libdir)/include
3132
CXXFLAGS := -std=c++17 -Wno-reorder -O3
3233
ifeq ($(MODE),Debug)
3334
CXXFLAGS += -ggdb -Wall -Werror
35+
CXXFLAGS += -D SBG_PARTITIONER_LOGGING
3436
endif
37+
38+
# Target
3539
LIB_SBGRAPH = lib/libsbgraph.a
3640

37-
all: $(LIB_SBGRAPH)
41+
#///////////////////////////////////////////////////////////////////////////////
42+
# PHONY ------------------------------------------------------------------------
43+
#///////////////////////////////////////////////////////////////////////////////
44+
45+
.PHONY: doc clean create-folders install install-folders lib-gtest test
46+
47+
#///////////////////////////////////////////////////////////////////////////////
48+
# Compilation ------------------------------------------------------------------
49+
#///////////////////////////////////////////////////////////////////////////////
3850

3951
include util/Makefile.include
4052
include sbg/Makefile.include
53+
include ast/Makefile.include
4154
include parser/Makefile.include
42-
include eval/Makefile.include
55+
include algorithms/cc/Makefile.include
56+
include algorithms/matching/Makefile.include
57+
include algorithms/scc/Makefile.include
58+
include algorithms/cutvertex/Makefile.include
59+
include algorithms/toposort/Makefile.include
4360
include algorithms/partitioner/Makefile.include
61+
include algorithms/misc/Makefile.include
62+
include eval/Makefile.include
63+
include test/performance/Makefile.include
64+
65+
LIB_SRC = $(UTIL_SRC) $(SBG_SRC) $(AST_SRC) $(PARSER_SRC) $(EVAL_SRC) $(ALG_SRC)
66+
67+
LIB_OBJ = $(UTIL_OBJ) $(SBG_OBJ) $(AST_OBJ) $(PARSER_OBJ) $(EVAL_OBJ) $(ALG_OBJ)
68+
69+
# Objects compilation
70+
$(LIB_SRC:%.cpp=$(BUILD_DIR)/%.o): $(BUILD_DIR)/%.o: %.cpp | create-folders
71+
$(CXX) -c $< $(INCLUDES) -MMD -MP $(CXXFLAGS) -o $@
72+
73+
compile: $(LIB_SBGRAPH) $(PARSER_BIN) $(EVAL_BIN) $(PARTITIONER_BIN)
4474

4575
create-folders::
4676
@mkdir -p $(ROOT)/lib
4777
@mkdir -p $(OBJ_DIR)
4878
@mkdir -p $(BUILD_DIR)
49-
@mkdir -p $(BUILD_DIR)/$(AST_DIR)
5079
@mkdir -p $(BIN_DIR)
5180

52-
$(BUILD_DIR)/%.o : %.cpp | create-folders
53-
$(CC) $(INCLUDES) $(CXXFLAGS) -MM -MT $@ -MF $(patsubst %.o,%.d,$@) $<
54-
$(CC) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
55-
56-
LIB_SRC := $(shell find ast parser sbg eval util algorithms/partitioner -type f -name "*.cpp" ! -name "main.cpp")
57-
LIB_OBJ = $(addprefix $(BUILD_DIR)/, $(LIB_SRC:.cpp=.o))
58-
59-
$(LIB_SBGRAPH): create-folders $(LIB_OBJ)
81+
$(LIB_SBGRAPH): $(LIB_OBJ) | create-folders
6082
$(AR) rcs $(LIB_SBGRAPH) $(LIB_OBJ)
6183

62-
DEPS = $(addprefix $(BUILD_DIR)/, $(LIB_SRC:.cpp=.d))
84+
#///////////////////////////////////////////////////////////////////////////////
85+
# Dependencies -----------------------------------------------------------------
86+
#///////////////////////////////////////////////////////////////////////////////
6387

64-
-include $(DEPS)
88+
-include $(LIB_OBJ:.o=.d)
6589

6690
#///////////////////////////////////////////////////////////////////////////////
6791
# Library Installation ---------------------------------------------------------
@@ -70,23 +94,10 @@ DEPS = $(addprefix $(BUILD_DIR)/, $(LIB_SRC:.cpp=.d))
7094
install: | install-folders
7195
@echo "Installing SBG library headers."
7296
@echo ${prefix}
73-
@install $(ROOT)/ast/*.hpp $(includedir)/ast
74-
@install $(ROOT)/sbg/*.hpp $(includedir)/sbg
75-
@install $(ROOT)/util/*.hpp $(includedir)/util
76-
@install $(ROOT)/parser/*.hpp $(includedir)/parser
77-
@install $(ROOT)/eval/*.hpp $(includedir)/eval
78-
@install $(ROOT)/lib/libsbgraph.a $(libdir)/
97+
@find $(ROOT) -name '*.hpp' -printf '%P\n' | xargs -I % install -D $(ROOT)/% \
98+
$(includedir)/%
7999
@echo "Done."
80100

81-
install-folders:
82-
@mkdir -p $(libdir)
83-
@mkdir -p $(includedir)
84-
@mkdir -p $(includedir)/ast
85-
@mkdir -p $(includedir)/sbg
86-
@mkdir -p $(includedir)/util
87-
@mkdir -p $(includedir)/parser
88-
@mkdir -p $(includedir)/eval
89-
90101
#///////////////////////////////////////////////////////////////////////////////
91102
# Testing ----------------------------------------------------------------------
92103
#///////////////////////////////////////////////////////////////////////////////
@@ -101,7 +112,8 @@ ifeq ("$(wildcard $(3RD_PARTY_DIR)/gtest/usr/lib)","")
101112
rm -rf $(3RD_PARTY_DIR)/gtest/build
102113
endif
103114

104-
test: lib-gtest
115+
test: compile lib-gtest perf-compile
116+
@./bin/sbg-performance
105117
@cd $(TEST_DIR) && ./compile_run_tests.sh
106118

107119
#///////////////////////////////////////////////////////////////////////////////
@@ -123,7 +135,8 @@ doc:
123135
TEST_DIRS := test/parser test/performance test/performance/boost test/eval
124136

125137
clean:
126-
$(RM) -rf $(BIN_DIR) $(OBJ_DIR) $(LIB_SBGRAPH) $(ROOT)/lib $(ROOT)/include $(3RD_PARTY_DIR)/gtest/usr
138+
$(RM) -rf $(BIN_DIR) $(OBJ_DIR) $(LIB_SBGRAPH) $(ROOT)/lib $(ROOT)/include \
139+
$(3RD_PARTY_DIR)/gtest/usr
127140
for dir in $(TEST_DIRS); do \
128141
$(RM) -rf $$dir/bin; \
129142
$(RM) -rf $$dir/obj; \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The simplest way to compile this package is:
5050

5151
2. Type `./configure` to run the configuration script.
5252

53-
3. Type `make` to compile the library `libsbgraph.a`
53+
3. Type `make compile` to compile the library `libsbgraph.a`.
5454

5555
4. Type `sudo make install` to install the library and header files in the
5656
default installation folders.

algorithms/cc/Makefile.include

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Directories
2+
CC_DIR := algorithms/cc
3+
4+
# Sources
5+
CC_SRC := $(CC_DIR)/cc.cpp
6+
ALG_SRC += $(CC_SRC)
7+
8+
# Objects
9+
ALG_OBJ += $(addprefix $(BUILD_DIR)/, $(CC_SRC:.cpp=.o))
10+
11+
# Build folders
12+
create-folders::
13+
@mkdir -p $(BUILD_DIR)/$(CC_DIR)

algorithms/cc/cc.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*******************************************************************************
2+
3+
This file is part of Set--Based Graph Library.
4+
5+
SBG Library is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
SBG Library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with SBG Library. If not, see <http://www.gnu.org/licenses/>.
17+
18+
******************************************************************************/
19+
20+
#include <chrono>
21+
22+
#include "algorithms/cc/cc.hpp"
23+
#include "util/logger.hpp"
24+
25+
namespace SBG {
26+
27+
namespace LIB {
28+
29+
////////////////////////////////////////////////////////////////////////////////
30+
// Connected components --------------------------------------------------------
31+
////////////////////////////////////////////////////////////////////////////////
32+
33+
PWMap connectedComponents(SBG g)
34+
{
35+
auto begin = std::chrono::high_resolution_clock::now();
36+
const PWMapAF &fact_ = g.fact();
37+
38+
if (!g.V().isEmpty()) {
39+
PWMap rmap = fact_.createPWMap(g.V()), old_rmap = fact_.createPWMap();
40+
41+
if (g.E().isEmpty())
42+
return rmap;
43+
44+
do {
45+
old_rmap = rmap;
46+
47+
PWMap ermap1 = rmap.composition(g.map1());
48+
PWMap ermap2 = rmap.composition(g.map2());
49+
50+
PWMap rmap1 = ermap1.minAdjMap(ermap2);
51+
PWMap rmap2 = ermap2.minAdjMap(ermap1);
52+
rmap1 = rmap1.combine(rmap);
53+
rmap2 = rmap2.combine(rmap);
54+
55+
PWMap aux_rmap = rmap1.minMap(rmap2);
56+
rmap = rmap.minMap(aux_rmap);
57+
58+
if (!(rmap == old_rmap)) {
59+
rmap = aux_rmap;
60+
rmap = rmap.mapInf();
61+
}
62+
} while (rmap != old_rmap);
63+
64+
return rmap.compact();
65+
}
66+
auto end = std::chrono::high_resolution_clock::now();
67+
auto total = std::chrono::duration_cast<std::chrono::microseconds>(
68+
end - begin);
69+
Util::SBG_LOG << "Total CC exec time: " << total.count() << "\n";
70+
71+
return fact_.createPWMap();
72+
}
73+
74+
} // namespace LIB
75+
76+
} // namespace SBG

algorithms/cc/cc.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/** @file cc.hpp
2+
3+
@brief <b>Connected Components SBG implementation</b>
4+
5+
<hr>
6+
7+
This file is part of Set--Based Graph Library.
8+
9+
SBG Library is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
SBG Library is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with SBG Library. If not, see <http://www.gnu.org/licenses/>.
21+
22+
******************************************************************************/
23+
24+
#ifndef SBG_CC_HPP
25+
#define SBG_CC_HPP
26+
27+
#include "sbg/sbg.hpp"
28+
29+
namespace SBG {
30+
31+
namespace LIB {
32+
33+
////////////////////////////////////////////////////////////////////////////////
34+
// Connected components --------------------------------------------------------
35+
////////////////////////////////////////////////////////////////////////////////
36+
37+
PWMap connectedComponents(SBG g);
38+
39+
} // namespace LIB
40+
41+
} // namespace SBG
42+
43+
#endif

0 commit comments

Comments
 (0)