Skip to content

Commit 519695e

Browse files
committed
[iss-51]
1 parent b5d18b9 commit 519695e

12 files changed

Lines changed: 159 additions & 136 deletions

File tree

Makefile.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ includedir ?= $(prefix)/include
2020
libdir ?= $(exec_prefix)/lib
2121
boost_libdir ?= $(prefix)
2222

23+
.PHONY: doc clean create-folders install install-folders lib-gtest test
24+
2325
#///////////////////////////////////////////////////////////////////////////////
2426
# Compilation ------------------------------------------------------------------
2527
#///////////////////////////////////////////////////////////////////////////////
@@ -105,8 +107,6 @@ test: lib-gtest
105107
# Documentation ----------------------------------------------------------------
106108
#///////////////////////////////////////////////////////////////////////////////
107109

108-
.PHONY: doc
109-
110110
doc:
111111
@mkdir -p $(ROOT)/doc
112112
@mkdir -p $(ROOT)/doc/html
@@ -120,7 +120,7 @@ doc:
120120
#///////////////////////////////////////////////////////////////////////////////
121121

122122
TEST_DIRS := test/parser test/performance test/performance/boost test/eval
123-
123+
124124
clean:
125125
$(RM) -rf $(BIN_DIR) $(OBJ_DIR) $(LIB_SBGRAPH) $(ROOT)/lib $(ROOT)/include $(3RD_PARTY_DIR)/gtest/usr
126126
for dir in $(TEST_DIRS); do \

eval/main.cpp

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,22 @@ void usage()
117117
std::cout << "\n";
118118
std::cout << " * A SBG program starts with a list (possibly empty) of\n";
119119
std::cout << " assignments, and then continues with a list (possibly\n";
120-
std::cout << " empty) of expressions.\n";
120+
std::cout << " empty) of expressions, each one separated by a\n";
121+
std::cout << " semicolon.";
121122
std::cout << " * Each assignment or expression should be ended with a\n";
122-
std::cout << " semicolon ;\n";
123+
std::cout << " semicolon ;.\n";
123124
std::cout << " * All expressions defined in a SBG program should have the\n";
124-
std::cout << " number of dimensions.\n";
125+
std::cout << " same number of dimensions.\n";
125126
std::cout << " * The first assignment of a SBG program should be\n";
126127
std::cout << " \"dims = k\", where k is the number of the dimensions of\n";
127128
std::cout << " all elements defined in the SBG program. If it is\n";
128129
std::cout << " omitted then is considered to be 1.\n";
129-
std::cout << " * Numerical (and only numerical) variables can be defined.\n";
130-
std::cout << " through an assignment. It is forbidden to use a variable\n";
131-
std::cout << " before its definition.\n";
130+
std::cout << " * It is forbidden to use a variable before its definition.\n";
132131
std::cout << " * Variable names should start with a letter, and then\n";
133132
std::cout << " alfanumeric characters (including \"_\") can be used.\n";
134133
std::cout << " The variable name \"x\" is forbidden, to preserve it\n";
135134
std::cout << " for linear expressions. As explained above, \"dims\"\n";
136135
std::cout << " is also reserved.\n";
137-
std::cout << " * Linear expresssions should include a numeric value for\n";
138-
std::cout << " its slope. That is, to express a constant expression\n";
139-
std::cout << " it should be written as: 0*x+h.\n";
140136
std::cout << " * Both intervals and linear expressions will be parsed as\n";
141137
std::cout << " their multi-dimensional counterparts.\n\n";
142138

@@ -157,26 +153,39 @@ void usage()
157153
std::cout << "files can be analyzed. Also /test files can be consulted\n";
158154
std::cout << "to start writing basic SBG programs.\n\n";
159155

160-
std::cout << "\nA comprehensive list of the available functions to call on SBG"
161-
<< " elements,\nwith a short description of the permitted arguments is";
162-
std::cout << " as follows:\n";
156+
std::cout << "A brief list of available operators:\n";
157+
std::cout << " * Arithmetic expressions: +, -, *, /.\n";
158+
std::cout << " * SBG expressions:\n";
159+
std::cout << " - For linear expressions and maps: + and -.\n";
160+
std::cout << " - For containers (intervals, MDIs, sets): /\\ \n";
161+
std::cout << " (intersection), \\/ (union), \\ (difference),\n";
162+
std::cout << " \' (complement).\n";
163+
std::cout << " * Relational operators for any expression: <, == (equality).";
164+
std::cout << "\n\n";
165+
166+
std::cout << "\nA comprehensive list of the available functions to call on"
167+
<< " SBG elements,\nwith a short description of the correct types for"
168+
<< " arguments is as follows\n(a container is either an interval, a mdi or"
169+
<< " a set):\n\n";
163170
std::cout << " - isEmpty: check if container is empty\n";
164-
std::cout << " --> isEmpty(interval) | isEmpty(set)\n";
165-
std::cout << "\n - isMember: check if an element belongs to a container\n";
166-
std::cout << " --> isMember(nat, interval)\n";
171+
std::cout << " --> isEmpty(container)\n";
167172
std::cout << "\n - minElem: minimum element of a container\n";
168-
std::cout << " --> minElem(interval) | minElem(set)\n";
173+
std::cout << " --> minElem(container)\n";
169174
std::cout << "\n - maxElem: maximum element of a container\n";
170-
std::cout << " --> maxElem(interval) | maxElem(set)\n";
175+
std::cout << " --> maxElem(container)\n";
171176
std::cout << "\n - compose: composition of expressions or maps\n";
172177
std::cout << " --> compose(lexp, lexp) | compose(mdlexp, mdlexp)\n";
173178
std::cout << " | compose(map, map) | compose(pw, pw)\n";
174-
std::cout << "\n - inv: calculate the inverse of an expression.\n";
179+
std::cout << "\n - inv: calculate the inverse of an expression or map.\n";
175180
std::cout << " If the expression is constant in some dimension, returns\n";
176-
std::cout << " inf-inf there\n";
177-
std::cout << " --> inv(lexp) | inv(mdlexp)\n";
178-
std::cout << "\n - image: return the image for a set of elements of the domain";
179-
std::cout << "\n --> image(set, map) | image(set, pw)\n";
181+
std::cout << " inf-inf there. If the argument is a map, it should be\n";
182+
std::cout << " bijective.\n";
183+
std::cout << " --> inv(lexp) | inv(mdlexp) | inv(map) | inv(pw)\n";
184+
std::cout << "\n - image: return the image for a set of elements of the\n";
185+
std::cout << " domain. If no subdomain is specified, the whole domain\n";
186+
std::cout << " is used.";
187+
std::cout << "\n --> image(map) | image(pw) | image(set, map) ";
188+
std::cout << "| image(set, pw)\n";
180189
std::cout << "\n - preImage: return the pre-image for a set of elements in the\n";
181190
std::cout << " image of the map\n";
182191
std::cout << " --> preImage(set, map) | preImage(set, pw)\n";

eval/visitors/eval_expr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ auto pre_image2_visitor_ = Overload {
266266
};
267267

268268
auto dom_visitor_ = Overload {
269-
[](LIB::Map a) { return ExprBaseType(a.dom()); },
270269
[](LIB::PWMap a) { return ExprBaseType(a.dom()); },
271270
[](auto a) {
272271
Util::ERROR("dom_visitor_: wrong arguments ", a, "for dom\n");

parser/main.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,19 @@ void usage()
4040
std::cout << " empty) of expressions, each one separated by a\n";
4141
std::cout << " semicolon.\n";
4242
std::cout << " * Each assignment or expression should be ended with a\n";
43-
std::cout << " semicolon ;\n";
43+
std::cout << " semicolon ;,\n";
4444
std::cout << " * All expressions defined in a SBG program should have the\n";
4545
std::cout << " same number of dimensions.\n";
4646
std::cout << " * The first assignment of a SBG program should be\n";
4747
std::cout << " \"dims = k\", where k is the number of the dimensions of\n";
4848
std::cout << " all elements defined in the SBG program. If it is\n";
4949
std::cout << " omitted then is considered to be 1.\n";
50-
std::cout << " * Numerical (and only numerical) variables can be defined.\n";
51-
std::cout << " through an assignment. It is forbidden to use a variable\n";
52-
std::cout << " before its definition.\n";
50+
std::cout << " * It is forbidden to use a variable before its definition.\n";
5351
std::cout << " * Variable names should start with a letter, and then\n";
5452
std::cout << " alfanumeric characters (including \"_\") can be used.\n";
5553
std::cout << " The variable name \"x\" is forbidden, to preserve it\n";
5654
std::cout << " for linear expressions. As explained above, \"dims\"\n";
5755
std::cout << " is also reserved.\n";
58-
std::cout << " * Linear expresssions should include a numeric value for\n";
59-
std::cout << " its slope, except if its value is equal to 1. That is,\n";
60-
std::cout << " to express a constant expression it should be written\n";
61-
std::cout << " as: 0*x+h.\n\n";
6256

6357
std::cout << "A brief list of the available expressions:\n";
6458
std::cout << " * Arithmetic.\n";

test/README.md

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,45 @@
22

33
This folder contains several files with the '.test' extension that can be used
44
as input of the ../bin binaries. They are also used as input of the parser and
5-
eval unit tests. To run all tests use the `make test` command in the parent
6-
directory.
7-
8-
## For developers
9-
10-
Currently thre submodules are defined:
11-
12-
* performance
13-
14-
* parser
15-
16-
* eval
17-
18-
The first one only measures and outputs execution time of user defined tests.
19-
To profile a new struct a `structname_perf.cpp` file should be created where all
20-
tests could be defined.
21-
22-
The last two check the soundness of the parser and the evaluator with already
23-
defined tests, specifying the input and the expected result. To test a new
24-
struct create a `structname.test` file in the current directory, and create
25-
parser/gt_data/structname and eval/gt_data/structname folders. In each of them
26-
there should be a structname.cpp file with code that logs its result to the
27-
SBG::Util::SBG_LOG structure; and a SBG.log archive with the expected result of
28-
the execution of the .cpp file. Then add structname to 'parser_program' and
29-
'eval_program' constants in the respective parser/parser_test.cpp and
30-
eval/eval_test.cpp files. The actual value of the running each test will be
31-
present in the parser/test_data and eval/test_data folders.
5+
eval unit tests. To run all tests use the `make test` command in the project
6+
root directory. Currently three submodules are defined.
7+
8+
## performance
9+
10+
Measures and outputs execution time of predefined tests.
11+
Currently sets and pws are profiled, as these are the base structs used in
12+
SBGs algorithms. To add a new unit, define a `structname_perf.cpp` file in
13+
the /test/performance folder, and add it to the PERF_SRC list in the Makefile.
14+
In order to build /test/performance/bin/sbg-performance that executes all test
15+
units call `make`.
16+
17+
Additionally, the subdmole /boost implements the construction of an ordinary
18+
graph from a SBG to test the performance of traditional graph algorithms. To
19+
use it execute /test/performance/bin/boost-perf. Alternatively script
20+
/performance/boost/perf_boost.sh can be used, with the following arguments:
21+
a- A test file, i.e. the ones in the /test directory.
22+
b- A number representing the desired algorithm to execute, i.e.:
23+
0 Edmonds Matching, 1 Tarjan SCC, 2 Boost Topological Sort.
24+
c- A number to indicate how many runs of the test should be executed.
25+
d- A number that sets the value of N (size of the model) in the test.
26+
27+
## parser
28+
29+
Meant to check the correctness of the parser, executes system tests.
30+
Expected results are placed in /test/parser/gt_data. To add a new unit include
31+
its name in the parser_program list declared in /test/parser/parser_test.cpp
32+
file. Then add the corresponding .log file in the /test/parser/gt_data folder.
33+
The actual result of running each test will be present in each
34+
/test/parser/test_data directory, with an additional file indicating if the
35+
test succedeed or failed (in which case output differences between expected
36+
and actual results).
37+
38+
## eval
39+
40+
Analogous to parser module, for the evaluator.
41+
42+
## Compilation and execution
43+
44+
Script /test/compile_run_tests.sh builds and runs all tests if no argument is
45+
specified. It also accepts one argument to run an individual suite such as:
46+
`performance`, `parser` or `eval`.

test/compile_run_tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ fi
1414
if [[ -z "$1" || "$1" == "parser" ]]; then
1515
SRC_FILES="../main.cpp ../parser_test.cpp"
1616
GTEST_INCLUDE="-I../../../3rd-party/gtest/usr/include"
17-
LD_FLAGS="-L../../../3rd-party/gtest/usr/lib -lgtest -lgmock"
18-
COMPILE=("g++" "${GTEST_INCLUDE}" "-std=c++17" "${SRC_FILES}"
17+
LD_FLAGS="-L../../../3rd-party/gtest/usr/lib -lgtest -lgmock -lpthread"
18+
COMPILE=("g++" "${GTEST_INCLUDE}" "-std=c++17" "${SRC_FILES}"
1919
"-o parser-test" "${LD_FLAGS}")
2020

2121
echo "BUILDING PARSER SYSTEM TESTS"
@@ -31,7 +31,7 @@ fi
3131
if [[ -z "$1" || "$1" == "eval" ]]; then
3232
SRC_FILES="../main.cpp ../eval_test.cpp"
3333
GTEST_INCLUDE="-I../../../3rd-party/gtest/usr/include"
34-
LD_FLAGS="-L../../../3rd-party/gtest/usr/lib -lgtest -lgmock"
34+
LD_FLAGS="-L../../../3rd-party/gtest/usr/lib -lgtest -lgmock -lpthread"
3535
COMPILE=("g++" "${GTEST_INCLUDE}" "-std=c++17" "${SRC_FILES}"
3636
"-o eval-test" "${LD_FLAGS}")
3737

test/eval/eval_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ TEST_P(EvalTests, Eval)
4949
EXPECT_TRUE(result.good());
5050
}
5151

52-
const char* eval_program[] = {"arithmetic", "interval", "set", "lexp", "map", "pw_map"};
52+
const char* eval_program[] = {"arithmetic", "interval", "set", "lexp", "map"
53+
, "pw_map1", "pw_map2", "pw_map3"};
5354

5455
INSTANTIATE_TEST_SUITE_P(EvalInst, EvalTests, testing::ValuesIn(eval_program));
5556

test/eval/gt_data/pw_map.log

Lines changed: 0 additions & 69 deletions
This file was deleted.

test/eval/gt_data/pw_map1.log

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-------------------------
2+
Parsing succeeded
3+
-------------------------
4+
>>>>>> Eval result <<<<<<
5+
-------------------------
6+
7+
8+
<<>>
9+
--> <<>>
10+
11+
<<{[1:1:10], [100:10:200]} ↦ 1*x-3>>
12+
--> <<{[1:10], [100:10:200]} -> x-3>>
13+
14+
<<{[1:1:10], [100:10:200]} ↦ 1*x-3, {[500:1:600]} ↦ 1*x+5>>
15+
--> <<{[1:10], [100:10:200]} -> x-3, {[500:600]} -> x+5>>
16+
17+
minMap(<<{[1:1:10], [15:3:30]} ↦ 1*x+0, {[12:3:12], [50:5:100]} ↦ 1*x+1>>, <<{[1:2:20], [30:5:60]} ↦ 0*x+100, {[75:5:90], [95:1:100]} ↦ 1*x+0>>)
18+
--> <<{[1:2:9], [15:15], [30:30]} -> x, {[50:5:60]} -> x+1, {[75:5:90], [95:5:100]} -> x>>
19+
20+
reduce(<<{[100:1:200]} ↦ 1*x-1>>)
21+
--> <<{[100:200]} -> 99>>
22+
23+
firstInv(<<{[1:1:10]} ↦ 0*x+10>>)
24+
--> <<{[10:10]} -> 1>>
25+
26+
mapInf(<<{[50:1:50]} ↦ 1*x-49, {[49:1:49]} ↦ 1*x-48, {[3:1:48]} ↦ 1*x+1>>)
27+
--> <<>>
28+

test/eval/gt_data/pw_map2.log

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-------------------------
2+
Parsing succeeded
3+
-------------------------
4+
>>>>>> Eval result <<<<<<
5+
-------------------------
6+
7+
8+
<<>>
9+
--> <<>>
10+
11+
<<{[1:1:10] x [1:1:10], [100:10:1000] x [100:10:1000]} ↦ 1*x+0|2*x+1, {[100:3:199] x [300:5:400]} ↦ 1*x+0|1*x+0>>
12+
--> <<{[1:10]x[1:10], [100:10:1000]x[100:10:1000]} -> x|2x+1, {[100:3:199]x[300:5:400]} -> x|x>>
13+
14+
<<{[1:1:5] x [1:1:5], [10:1:15] x [10:1:15]} ↦ 1*x+0|1*x+0, {[20:3:30] x [20:3:30], [45:5:50] x [45:5:50]} ↦ 2*x+0|2*x+0>>
15+
--> <<{[1:5]x[1:5], [10:15]x[10:15]} -> x|x, {[20:3:29]x[20:3:29], [45:5:50]x[45:5:50]} -> 2x|2x>>
16+
17+
image({[1:1:5] x [1:1:5], [10:1:15] x [10:1:15], [20:3:30] x [35:5:100], [45:5:50] x [45:5:50]}, <<{[1:1:5] x [1:1:5], [10:1:15] x [10:1:15]} ↦ 1*x+0|1*x+0, {[20:3:30] x [20:3:30], [45:5:50] x [45:5:50]} ↦ 2*x+0|2*x+0>>)
18+
--> {[1:5]x[1:5], [10:15]x[10:15], [90:10:100]x[90:10:100]}
19+
20+
preImage({[0:1:25] x [0:1:25]}, <<{[1:1:10] x [1:1:10], [20:5:30] x [20:5:30]} ↦ 0*x+3|0*x+4, {[11:1:14] x [11:1:14], [1:1:10] x [50:5:70]} ↦ 2*x+0|2*x+1>>)
21+
--> {[1:10]x[1:10], [20:5:30]x[20:5:30], [11:12]x[11:12]}
22+
23+
compose(<<{[1:1:10] x [1:1:5], [20:2:30] x [20:2:30]} ↦ 2*x+1|3*x+0, {[15:3:18] x [12:3:18]} ↦ 0*x+0|0*x+0>>, <<{[1:1:30] x [1:1:30]} ↦ 1*x+1|1*x+2>>)
24+
--> <<{[1:9]x[1:3], [19:2:29]x[18:2:28]} -> 2x+3|3x+6, {[14:3:17]x[10:3:16]} -> 0|0>>
25+
26+
minAdj(<<{[10:1:100] x [10:1:100], [101:2:200] x [101:2:200]} ↦ 1*x+0|1*x+0, {[10:1:100] x [101:2:200]} ↦ 2*x+0|2*x+0>>, <<{[5:5:50] x [5:5:50]} ↦ 0*x+1|1*x+0, {[51:3:80] x [51:3:80], [90:1:150] x [95:1:150]} ↦ 2*x+3|2*x+1>>)
27+
--> <<{[10:5:50]x[10:5:50]} -> 1|x, {[51:3:78]x[51:3:78], [90:100]x[95:100], [101:2:149]x[101:2:149]} -> 2x+3|2x+1, {[180:2:200]x[202:4:298]} -> x+3|x+1>>
28+

0 commit comments

Comments
 (0)