Skip to content

Commit 6f85ea2

Browse files
committed
Merge branch 'sb-graph-dev' into 102-add-configuration-file-to-sbg-partitioner
2 parents 57657e5 + 0b9a099 commit 6f85ea2

200 files changed

Lines changed: 16249 additions & 5748 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v2
15+
- name: Compiler.
16+
run: cc --version
1517
- name: Install deps.
1618
run: |
1719
sudo apt-get update
1820
sudo apt-get install libboost1.83-dev
21+
sudo apt-get install libboost-program-options-dev
1922
sudo apt-get install cmake
2023
sudo apt-get install g++
2124
sudo apt-get install rapidjson-dev

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
1818
add_compile_definitions(SBG_PARTITIONER_LOGGING)
1919
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb -Wall ") # -Werror
2020
else()
21-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder")
21+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder -fconcepts -O3")
2222
endif()
2323

2424
# Output directories

Makefile.in

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Target variables
2+
MODE ?= Release
3+
4+
# The Directories, Source, Includes, Objects, Binary
5+
ROOT := .
6+
3RD_PARTY_DIR := $(ROOT)/3rd-party
7+
GTEST_DIR := googletest-release-1.12.1
8+
GTEST_CODE := $(GTEST_DIR).tar.gz
9+
OBJ_DIR := $(ROOT)/obj
10+
BUILD_DIR := $(OBJ_DIR)/release
11+
AST_DIR := $(ROOT)/ast
12+
BIN_DIR := $(ROOT)/bin
13+
ifeq ($(MODE),Debug)
14+
BUILD_DIR := $(OBJ_DIR)/debug
15+
endif
16+
prefix ?= /usr/local
17+
exec_prefix ?= $(prefix)
18+
includedir ?= $(prefix)/include
19+
libdir ?= $(exec_prefix)/lib
20+
boost_libdir ?= $(prefix)
21+
22+
# Flags, Libraries and Includes
23+
INCLUDES := -I. -I$(boost_libdir)/include
24+
CXXFLAGS := -std=c++17 -Wall -Werror -Wno-reorder -O3 -D BOOST_PHOENIX_STL_TUPLE_H_ -D BOOST_MPL_LIMIT_LIST_SIZE=30 -D BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
25+
ifeq ($(MODE),Debug)
26+
CXXFLAGS += -ggdb
27+
endif
28+
LIB_SBGRAPH = lib/libsbgraph.a
29+
30+
all: $(LIB_SBGRAPH)
31+
32+
include sbg/Makefile.include
33+
include parser/Makefile.include
34+
include eval/Makefile.include
35+
include test/Makefile.include
36+
37+
$(BUILD_DIR)/%.o : %.cpp
38+
$(CC) $(INCLUDES) $(CXXFLAGS) -MM -MT $@ -MF $(patsubst %.o,%.d,$@) $<
39+
$(CC) $(INCLUDES) -c $< -o $@ $(CXXFLAGS)
40+
41+
$(LIB_SBGRAPH): create-folders $(SBG_OBJ) $(UTIL_OBJ) $(PARSER_OBJ) $(EVAL_OBJ)
42+
$(AR) rcs $(LIB_SBGRAPH) $(SBG_OBJ) $(UTIL_OBJ) $(PARSER_OBJ) $(EVAL_OBJ)
43+
44+
lib-gtest: | create-folders
45+
ifeq ("$(wildcard $(3RD_PARTY_DIR)/gtest/usr/lib)","")
46+
cd $(3RD_PARTY_DIR)/gtest; tar xvzf $(GTEST_CODE)
47+
mkdir -p $(3RD_PARTY_DIR)/gtest/build
48+
cd $(3RD_PARTY_DIR)/gtest/build; cmake ../$(GTEST_DIR) -DCMAKE_INSTALL_PREFIX=../usr
49+
cd $(3RD_PARTY_DIR)/gtest/build; make install
50+
rm -rf $(3RD_PARTY_DIR)/gtest/$(GTEST_DIR)
51+
rm -rf $(3RD_PARTY_DIR)/gtest/build
52+
endif
53+
54+
install: | install-folders
55+
@echo "Installing SBG library headers."
56+
@echo ${prefix}
57+
@install $(ROOT)/ast/*.hpp $(includedir)/ast
58+
@install $(ROOT)/sbg/*.hpp $(includedir)/sbg
59+
@install $(ROOT)/util/*.hpp $(includedir)/util
60+
@install $(ROOT)/parser/*.hpp $(includedir)/parser
61+
@install $(ROOT)/eval/*.hpp $(includedir)/eval
62+
@install $(ROOT)/lib/libsbgraph.a $(libdir)/
63+
@echo "Done."
64+
65+
install-folders:
66+
@mkdir -p $(libdir)
67+
@mkdir -p $(includedir)
68+
@mkdir -p $(includedir)/ast
69+
@mkdir -p $(includedir)/sbg
70+
@mkdir -p $(includedir)/util
71+
@mkdir -p $(includedir)/parser
72+
@mkdir -p $(includedir)/eval
73+
74+
create-folders::
75+
@mkdir -p $(ROOT)/lib
76+
@mkdir -p $(OBJ_DIR)
77+
@mkdir -p $(BUILD_DIR)
78+
@mkdir -p $(BUILD_DIR)/$(AST_DIR)
79+
@mkdir -p $(BIN_DIR)
80+
81+
.PHONY: doc
82+
83+
doc:
84+
@mkdir -p $(ROOT)/doc
85+
@mkdir -p $(ROOT)/doc/html
86+
@mkdir -p $(ROOT)/doc/latex
87+
doxygen eval/EVAL.doxyfile
88+
doxygen sbg/SBG.doxyfile
89+
doxygen util/UTIL.doxyfile
90+
91+
test: lib-gtest $(SBG_TEST)
92+
93+
TEST_DIRS := test/parser test/performance test/performance/boost test/eval
94+
95+
clean:
96+
$(RM) -rf $(BIN_DIR) $(OBJ_DIR) $(LIB_SBGRAPH) $(ROOT)/lib $(ROOT)/include $(3RD_PARTY_DIR)/gtest/usr
97+
for dir in $(TEST_DIRS); do \
98+
$(RM) -rf $$dir/bin; \
99+
$(RM) -rf $$dir/obj; \
100+
$(RM) -rf $$dir/test_data; \
101+
done
102+
103+
help:
104+
@echo "make MODE=<Debug|Release> prefix=<PATH> exec_prefix=<PATH> includedir=<PATH> libdir=<PATH> boost_libdir=<PATH>"
105+
@echo "Default values:"
106+
@echo ""
107+
@echo "MODE=Debug"
108+
@echo "prefix=/usr/local"
109+
@echo "exec_prefix=/usr/local"
110+
@echo "includedir=/usr/local/include"
111+
@echo "libdir=/usr/local/lib"
112+
@echo "boost_libdir=/usr/local/include"

algorithms/cc/cc.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ namespace LIB {
3333
PWMap connectedComponents(SBG g)
3434
{
3535
auto begin = std::chrono::high_resolution_clock::now();
36-
const PWMapAF &fact_ = g.fact();
3736

3837
if (!g.V().isEmpty()) {
39-
PWMap rmap = fact_.createPWMap(g.V()), old_rmap = fact_.createPWMap();
38+
PWMap rmap = PW_FACT.createPWMap(g.V()), old_rmap = PW_FACT.createPWMap();
4039

4140
if (g.E().isEmpty())
4241
return rmap;
@@ -68,7 +67,7 @@ PWMap connectedComponents(SBG g)
6867
end - begin);
6968
Util::SBG_LOG << "Total CC exec time: " << total.count() << "\n";
7069

71-
return fact_.createPWMap();
70+
return PW_FACT.createPWMap();
7271
}
7372

7473
} // namespace LIB

algorithms/cutvertex/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ target_sources(
22
sbgraph
33
PRIVATE
44
cut_vertex.cpp
5+
cv_fact.cpp
6+
maxdeg_cv.cpp
57
)

algorithms/cutvertex/cut_vertex.cpp

Lines changed: 8 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -28,124 +28,20 @@ namespace SBG {
2828
namespace LIB {
2929

3030
////////////////////////////////////////////////////////////////////////////////
31-
// Cut-set algorithm -----------------------------------------------------------
31+
// Vertex Cut Set Algorithm Abstract Strategy Constructors ---------------------
3232
////////////////////////////////////////////////////////////////////////////////
3333

34-
CutVertex::CutVertex(const DSBG &dsbg, bool debug)
35-
: fact_(dsbg.fact()), dsbg_(dsbg), debug_(debug) {}
34+
CVStrategy::CVStrategy() {}
3635

37-
member_imp(CutVertex, DSBG, dsbg);
38-
member_imp(CutVertex, bool, debug);
36+
////////////////////////////////////////////////////////////////////////////////
37+
// Vertex Cut Set Algorithm Interface ------------------------------------------
38+
////////////////////////////////////////////////////////////////////////////////
3939

40-
PWMap CutVertex::getDegMap(const DSBG &dsbg)
41-
{
42-
Set V = dsbg.V();
43-
PWMap mapB = dsbg.mapB(), mapD = dsbg.mapD();
44-
45-
auto dims = V.arity();
46-
MD_NAT zero(dims, 0), one(dims, 1);
47-
PWMap dmap = fact_.createPWMap(fact_.createMap(V, Exp(zero)));
48-
49-
for (const Map &SE : dsbg.subEmap()) {
50-
Set dom = SE.dom();
51-
MD_NAT n(dims, dom.cardinal());
52-
Set vsB = mapB.image(dom), vsD = mapD.image(dom);
53-
if (vsB.cardinal() == 1) {
54-
PWMap ith = dmap.restrict(vsD).offsetImage(n);
55-
dmap = ith.combine(dmap);
56-
ith = dmap.restrict(vsB).offsetImage(one);
57-
dmap = ith.combine(dmap);
58-
}
59-
else if (vsD.cardinal() == 1) {
60-
PWMap ith = dmap.restrict(vsB).offsetImage(n);
61-
dmap = ith.combine(dmap);
62-
ith = dmap.restrict(vsD).offsetImage(one);
63-
dmap = ith.combine(dmap);
64-
}
65-
else {
66-
PWMap ith = dmap.restrict(vsB.cup(vsD)).offsetImage(one);
67-
dmap = ith.combine(dmap);
68-
}
69-
}
70-
71-
return dmap;
72-
}
40+
CutVertex::CutVertex(CVStratPtr strat) : strategy_(std::move(strat)) {}
7341

74-
Set CutVertex::calculate()
42+
Set CutVertex::calculate(const DSBG& dsbg) const
7543
{
76-
auto begin = std::chrono::high_resolution_clock::now();
77-
DSBG dg = dsbg();
78-
PWMap Vmap = dg.Vmap(), mapB = dg.mapB(), mapD = dg.mapD();
79-
PWMap rmap = SCC(dg, debug()).calculate();
80-
Set newD = fact_.createSet(), oldD = newD, visitedV = newD, V = dg.V();
81-
if (debug())
82-
Util::SBG_LOG << "initial dg vertex cut set:\n" << dg << "\n";
83-
84-
PWMap dmap = getDegMap(dg);
85-
// Degree map
86-
if (debug())
87-
Util::SBG_LOG << "initial dmap: " << dmap << "\n\n";
88-
89-
while (rmap.dom() != rmap.image()) {
90-
oldD = newD;
91-
92-
MD_NAT aux = dmap.image().maxElem();
93-
MD_NAT vmax = dmap.preImage(fact_.createSet(aux)).minElem();
94-
Set vmaxSV = Vmap.image(fact_.createSet(vmax));
95-
newD = newD.cup(fact_.createSet(vmax));
96-
97-
if (!visitedV.intersection(vmaxSV).isEmpty()) {
98-
MD_NAT vmaxD = newD.intersection(Vmap.preImage(vmaxSV)).minElem();
99-
100-
SetPiece mdi;
101-
for (unsigned int j = 0; j < vmax.arity(); ++j) {
102-
if (vmax[j] < vmaxD[j]) {
103-
NAT st = vmaxD[j] - vmax[j];
104-
NAT beg = vmax[j] % st;
105-
mdi.emplaceBack(Interval(beg, st, vmax[j]));
106-
}
107-
108-
else
109-
mdi.emplaceBack(Interval(vmaxD[j], vmax[j] - vmaxD[j], Inf));
110-
}
111-
if (debug()) {
112-
Util::SBG_LOG << "vmax: " << vmax << "\n";
113-
Util::SBG_LOG << "vmaxD: " << vmaxD << "\n";
114-
Util::SBG_LOG << "mdi: " << mdi << "\n\n";
115-
}
116-
Set mdi_set = fact_.createSet(mdi);
117-
newD = newD.cup(mdi_set.intersection(Vmap.preImage(vmaxSV)));
118-
}
119-
120-
// Update graph info erasing newD vertices
121-
visitedV = visitedV.cup(vmaxSV);
122-
dg = dg.eraseVertices(newD);
123-
Vmap = dg.Vmap();
124-
mapB = dg.mapB();
125-
mapD = dg.mapD();
126-
127-
// Update degree map
128-
dmap = getDegMap(dg);
129-
130-
// Resulting SCC from induced graph
131-
rmap = SCC(dg, debug()).calculate();
132-
133-
if (debug()) {
134-
Util::SBG_LOG << "oldD: " << oldD << "\n";
135-
Util::SBG_LOG << "newD: " << newD << "\n";
136-
Util::SBG_LOG << "resulting graph:\n" << dg << "\n";
137-
Util::SBG_LOG << "new degree map: " << dmap << "\n";
138-
Util::SBG_LOG << "new rmap: " << rmap << "\n\n";
139-
}
140-
}
141-
auto end = std::chrono::high_resolution_clock::now();
142-
143-
auto total = std::chrono::duration_cast<std::chrono::microseconds>(
144-
end - begin
145-
);
146-
Util::SBG_LOG << "Total vertex cut set exec time: " << total.count() << " [μs]\n\n";
147-
148-
return newD.compact();
44+
return strategy_->calculate(dsbg);
14945
}
15046

15147
} // namespace LIB

algorithms/cutvertex/cut_vertex.hpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @file cut_vertex.hpp
22
3-
@brief <b>Cut Vertex Set SBG implementation</b>
3+
@brief <b>SBG Vertex Cut Set Algorithm Abstract Interface</b>
44
55
<hr>
66
@@ -24,40 +24,47 @@
2424
#ifndef SBG_CUTVERTEX_HPP
2525
#define SBG_CUTVERTEX_HPP
2626

27-
#include "sbg/sbg.hpp"
27+
#include "algorithms/scc/scc_fact.hpp"
2828

2929
namespace SBG {
3030

3131
namespace LIB {
3232

3333
///////////////////////////////////////////////////////////////////////////////
34-
// Cut-set algorithm ----------------------------------------------------------
34+
// Vertex Cut Set Algorithm Abstract Strategy ---------------------------------
3535
///////////////////////////////////////////////////////////////////////////////
3636

37+
class CVStrategy;
38+
39+
typedef std::unique_ptr<CVStrategy> CVStratPtr;
40+
3741
/**
38-
* @brief Aims to calculate a minimum cut-set of vertices, that is, a set of
42+
* @brief Aims to calculate a minimum cut set of vertices, that is, a set of
3943
* vertices such that if these vertices are taken out, the resulting graph has no
4044
* SCC left. Since this is a NP-hard problem, heuristics are used, and thus is
4145
* not guaranteed that the set is actually minimum.
4246
*/
47+
class CVStrategy {
48+
public:
49+
virtual ~CVStrategy() = default;
4350

44-
struct CutVertex {
45-
private:
46-
const PWMapAF &fact_;
51+
CVStrategy();
4752

48-
//*** SBG info, constant
49-
member_class(DSBG, dsbg);
53+
virtual Set calculate(const DSBG& dsbg) const = 0;
54+
};
5055

51-
//-----------------------------
52-
member_class(bool, debug);
56+
///////////////////////////////////////////////////////////////////////////////
57+
// Vertex Cut Set Algorithm Interface (context) -------------------------------
58+
///////////////////////////////////////////////////////////////////////////////
5359

60+
class CutVertex {
5461
public:
55-
CutVertex(const DSBG &dsbg, bool debug);
62+
CutVertex(CVStratPtr strat);
5663

57-
Set calculate();
64+
Set calculate(const DSBG& dsbg) const;
5865

5966
private:
60-
PWMap getDegMap(const DSBG &dsbg);
67+
CVStratPtr strategy_;
6168
};
6269

6370
} // namespace LIB

0 commit comments

Comments
 (0)