Skip to content

Commit fe81251

Browse files
committed
Updated algorithms struct + Makefiles
1 parent 750c839 commit fe81251

36 files changed

Lines changed: 1859 additions & 1373 deletions

Makefile.in

Lines changed: 49 additions & 19 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,49 +18,73 @@ 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)
33-
CXXFLAGS += -ggdb -Wall -Werror
34+
CXXFLAGS += -ggdb -Wall -Werror
3435
endif
36+
37+
# Target
3538
LIB_SBGRAPH = lib/libsbgraph.a
3639

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

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

4674
create-folders::
4775
@mkdir -p $(ROOT)/lib
4876
@mkdir -p $(OBJ_DIR)
4977
@mkdir -p $(BUILD_DIR)
5078
@mkdir -p $(BIN_DIR)
5179

52-
LIB_OBJ = $(UTIL_OBJ) $(SBG_OBJ) $(AST_OBJ) $(PARSER_OBJ) $(EVAL_OBJ) $(ALG_OBJ)
53-
54-
$(LIB_SBGRAPH): create-folders $(LIB_OBJ)
80+
$(LIB_SBGRAPH): $(LIB_OBJ) | create-folders
5581
$(AR) rcs $(LIB_SBGRAPH) $(LIB_OBJ)
5682

57-
DEPS = $(addprefix $(BUILD_DIR)/, $(LIB_SRC:.cpp=.d))
83+
#///////////////////////////////////////////////////////////////////////////////
84+
# Dependencies -----------------------------------------------------------------
85+
#///////////////////////////////////////////////////////////////////////////////
5886

59-
-include $(DEPS)
87+
-include $(LIB_OBJ:.o=.d)
6088

6189
#///////////////////////////////////////////////////////////////////////////////
6290
# Library Installation ---------------------------------------------------------
@@ -96,7 +124,8 @@ ifeq ("$(wildcard $(3RD_PARTY_DIR)/gtest/usr/lib)","")
96124
rm -rf $(3RD_PARTY_DIR)/gtest/build
97125
endif
98126

99-
test: lib-gtest
127+
test: compile lib-gtest perf-compile
128+
@./bin/sbg-performance
100129
@cd $(TEST_DIR) && ./compile_run_tests.sh
101130

102131
#///////////////////////////////////////////////////////////////////////////////
@@ -118,7 +147,8 @@ doc:
118147
TEST_DIRS := test/parser test/performance test/performance/boost test/eval
119148

120149
clean:
121-
$(RM) -rf $(BIN_DIR) $(OBJ_DIR) $(LIB_SBGRAPH) $(ROOT)/lib $(ROOT)/include $(3RD_PARTY_DIR)/gtest/usr
150+
$(RM) -rf $(BIN_DIR) $(OBJ_DIR) $(LIB_SBGRAPH) $(ROOT)/lib $(ROOT)/include \
151+
$(3RD_PARTY_DIR)/gtest/usr
122152
for dir in $(TEST_DIRS); do \
123153
$(RM) -rf $$dir/bin; \
124154
$(RM) -rf $$dir/obj; \

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
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Directories
2+
CV_DIR := algorithms/cutvertex
3+
4+
# Sources
5+
CV_SRC := $(CV_DIR)/cut_vertex.cpp
6+
ALG_SRC += $(CV_SRC)
7+
8+
# Objects
9+
ALG_OBJ += $(addprefix $(BUILD_DIR)/, $(CV_SRC:.cpp=.o))
10+
11+
# Build folders
12+
create-folders::
13+
@mkdir -p $(BUILD_DIR)/$(CV_DIR)

0 commit comments

Comments
 (0)