Skip to content

Commit 5ae7685

Browse files
authored
Merge pull request #13 from DEIS-Tools/inconsistent_lookup
Inconsistent lookup
2 parents 4ad7168 + c712553 commit 5ae7685

File tree

8 files changed

+539
-76
lines changed

8 files changed

+539
-76
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ if(Boost_ROOT)
4747
endif()
4848

4949
add_subdirectory(${CMAKE_SOURCE_DIR}/src/)
50+
51+
set(LIBSTRATEGY_BuildTests "Build tests of libstrategy" ON)
52+
if(BUILD_TESTING AND LIBSTRATEGY_BuildTests)
53+
enable_testing()
54+
add_subdirectory(test)
55+
endif()

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.7)
2-
project(z2s C CXX)
2+
project(libstrategy C CXX)
33
set(CMAKE_CXX_STANDARD 17)
44
set(CMAKE_INCLUDE_CURRENT_DIR ON)
55
option(LIBSTRATEGY_OnlyLibrary "Build only as library." OFF)
@@ -38,6 +38,6 @@ install(TARGETS strategy
3838
RUNTIME DESTINATION bin
3939
LIBRARY DESTINATION lib
4040
ARCHIVE DESTINATION lib)
41-
install (FILES errors.h libz2s.h SimpleTree.h ZonotopStrategy.h DESTINATION include/libstrategy)
41+
install (FILES errors.h SimpleTree.h ZonotopStrategy.h DESTINATION include/libstrategy)
4242

4343

src/SimpleTree.cpp

Lines changed: 75 additions & 72 deletions
Large diffs are not rendered by default.

src/SimpleTree.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class SimpleTree {
3838
public:
3939
SimpleTree(const SimpleTree& orig) = default;
4040
virtual ~SimpleTree() = default;
41-
static SimpleTree parse(std::istream&, bool simplify = true, bool subsumption = true, double accuracy = 0);
41+
static SimpleTree parse(std::istream&, bool simplify = false, bool subsumption = false, double accuracy = 0);
4242
static SimpleTree parse(std::istream&, bool simplify, bool subsumption, double accuracy, std::vector<double>& exactness);
4343
std::ostream& print(std::ostream& stream) const;
4444
std::ostream& print_c(std::ostream& stream, std::string name) const;
@@ -81,7 +81,7 @@ class SimpleTree {
8181
void action_nodes(std::vector<std::shared_ptr<node_t>>& nodes, uint32_t low, uint32_t high, uint32_t varid);
8282
std::pair<double,double> compute_min_max();
8383
bool check_tiles(node_t* start, std::vector<std::shared_ptr<node_t>>& , std::vector<std::pair<double,double>>& bounds, double val, double minval, double maxval, bool minimization, size_t offset);
84-
bool subsumes(std::vector<std::pair<double,double>>& bounds, std::vector<std::pair<double,double>>& obounds, double val, bool minimization, size_t offset, double& best, std::pair<double,double>& closest);
84+
bool subsumes(const std::vector<std::pair<double,double>>& bounds, std::vector<std::pair<double,double>>& obounds, const double val, const bool minimization, size_t offset, double& best, std::pair<double,double>& closest);
8585
void get_ranks(std::set<std::pair<double, node_t*>>& values, node_t* start);
8686
void set_ranks(std::unordered_map<double,double>& values);
8787
std::ostream& print_c(std::ostream& stream, size_t disc, std::unordered_set<const node_t*>& printed, size_t tabs = 0) const;
@@ -113,6 +113,9 @@ class SimpleTree {
113113
return _low < other._low;
114114
return _high < other._high;
115115
}
116+
std::shared_ptr<node_t>& operator[](bool b) {
117+
return b ? _high : _low;
118+
}
116119
};
117120

118121
std::vector<std::string> _actions;

test/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
find_package (Boost COMPONENTS unit_test_framework REQUIRED)
3+
include_directories (${TEST_SOURCE_DIR}/src
4+
${Boost_INCLUDE_DIRS}
5+
${libstrategy_SOURCE_DIR}
6+
)
7+
add_definitions (-DBOOST_TEST_DYN_LINK)
8+
9+
add_executable (unordered_load unordered_load.cpp)
10+
add_executable (inconsistent_lookup inconsistent_lookup.cpp)
11+
12+
target_link_libraries(unordered_load ${Boost_LIBRARIES} strategy)
13+
target_link_libraries(inconsistent_lookup ${Boost_LIBRARIES} strategy)
14+
15+
add_test(NAME unordered_load COMMAND unordered_load)
16+
add_test(NAME inconsistent_lookup COMMAND inconsistent_lookup)
17+
set_tests_properties(inconsistent_lookup PROPERTIES
18+
ENVIRONMENT STRATEGY_DIR=${CMAKE_CURRENT_SOURCE_DIR}/strategies)

test/inconsistent_lookup.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 2021 Peter G. Jensen <[email protected]>
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#define BOOST_TEST_MODULE UnorderedLoad
19+
20+
#include <boost/test/unit_test.hpp>
21+
#include <fstream>
22+
23+
#include "SimpleTree.h"
24+
25+
BOOST_AUTO_TEST_CASE(DirectoryTest)
26+
{
27+
BOOST_REQUIRE(getenv("STRATEGY_DIR"));
28+
}
29+
30+
BOOST_AUTO_TEST_CASE(Inconsistent1)
31+
{
32+
std::string strategy = getenv("STRATEGY_DIR");
33+
strategy += "/inconsistent1.strategy";
34+
std::ifstream in(strategy);
35+
auto tree = SimpleTree::parse(in, false, false);
36+
double vars[] = {10};
37+
auto act18 = tree.value(vars,nullptr, 0);
38+
auto act19 = tree.value(vars,nullptr, 1);
39+
BOOST_REQUIRE_LT(act18, act19);
40+
}
41+
42+
BOOST_AUTO_TEST_CASE(Inconsistent1Simplify)
43+
{
44+
std::string strategy = getenv("STRATEGY_DIR");
45+
strategy += "/inconsistent1.strategy";
46+
std::ifstream in(strategy);
47+
auto tree = SimpleTree::parse(in, true, false);
48+
double vars[] = {10};
49+
BOOST_REQUIRE_LT(tree.value(vars,nullptr, 0), tree.value(vars,nullptr, 1));
50+
}
51+
52+
BOOST_AUTO_TEST_CASE(Inconsistent1SimplifySubsumption)
53+
{
54+
std::string strategy = getenv("STRATEGY_DIR");
55+
strategy += "/inconsistent1.strategy";
56+
std::ifstream in(strategy);
57+
auto tree = SimpleTree::parse(in, true, true);
58+
double vars[] = {10};
59+
BOOST_REQUIRE_LT(tree.value(vars,nullptr, 0), tree.value(vars,nullptr, 1));
60+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{"version":1.0,"type":"state->regressor","representation":"map","actions":{
2+
"0":"movement0.P0->movement0.F0T1 { isReady(id, 0, 1), tau, t := 0, position[id] := -1, punish(id, 0, 1) }",
3+
"1":"movement0.P0->movement0.F0T2 { isReady(id, 0, 2), tau, t := 0, position[id] := -1, punish(id, 0, 2) }"
4+
},"statevars":[
5+
"taskExe1.location"
6+
],"pointvars":[
7+
],"locationnames":{
8+
"movement0.location":{
9+
"0":"P0",
10+
"1":"F0T1",
11+
"2":"F0T2",
12+
"3":"F0T3",
13+
"4":"P1",
14+
"5":"F1T2",
15+
"6":"F1T3",
16+
"7":"P2",
17+
"8":"F2T1",
18+
"9":"F2T3",
19+
"10":"P3",
20+
"11":"F3T1",
21+
"12":"F3T2"
22+
},
23+
"taskExe0.location":{
24+
"0":"Waiting",
25+
"1":"T0",
26+
"2":"T1",
27+
"3":"T2",
28+
"4":"T3"
29+
},
30+
"movement1.location":{
31+
"0":"P0",
32+
"1":"F0T1",
33+
"2":"F0T2",
34+
"3":"F0T3",
35+
"4":"P1",
36+
"5":"F1T2",
37+
"6":"F1T3",
38+
"7":"P2",
39+
"8":"F2T1",
40+
"9":"F2T3",
41+
"10":"P3",
42+
"11":"F3T1",
43+
"12":"F3T2"
44+
},
45+
"taskExe1.location":{
46+
"0":"Waiting",
47+
"1":"T0",
48+
"2":"T1",
49+
"3":"T2",
50+
"4":"T3"
51+
},
52+
"movement2.location":{
53+
"0":"P0",
54+
"1":"F0T1",
55+
"2":"F0T2",
56+
"3":"F0T3",
57+
"4":"P1",
58+
"5":"F1T2",
59+
"6":"F1T3",
60+
"7":"P2",
61+
"8":"F2T1",
62+
"9":"F2T3",
63+
"10":"P3",
64+
"11":"F3T1",
65+
"12":"F3T2"
66+
},
67+
"taskExe2.location":{
68+
"0":"Waiting",
69+
"1":"T0",
70+
"2":"T1",
71+
"3":"T2",
72+
"4":"T3"
73+
}
74+
},"regressors":{
75+
"(4)":
76+
{"type":"act->point->val","representation":"simpletree","minimize":0,"regressor":
77+
{
78+
"0" : -58.52619021830245
79+
}
80+
},
81+
"(2)":
82+
{"type":"act->point->val","representation":"simpletree","minimize":0,"regressor":
83+
{
84+
"1" : -104.5393376817416
85+
}
86+
},
87+
"(10)":
88+
{"type":"act->point->val","representation":"simpletree","minimize":0,"regressor":
89+
{
90+
"0" : -39.75,
91+
"1" : -26.30381528710121
92+
}
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)