Skip to content

Commit

Permalink
Merge pull request #13 from DEIS-Tools/inconsistent_lookup
Browse files Browse the repository at this point in the history
Inconsistent lookup
  • Loading branch information
petergjoel authored Sep 10, 2021
2 parents 4ad7168 + c712553 commit 5ae7685
Show file tree
Hide file tree
Showing 8 changed files with 539 additions and 76 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ if(Boost_ROOT)
endif()

add_subdirectory(${CMAKE_SOURCE_DIR}/src/)

set(LIBSTRATEGY_BuildTests "Build tests of libstrategy" ON)
if(BUILD_TESTING AND LIBSTRATEGY_BuildTests)
enable_testing()
add_subdirectory(test)
endif()
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.7)
project(z2s C CXX)
project(libstrategy C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
option(LIBSTRATEGY_OnlyLibrary "Build only as library." OFF)
Expand Down Expand Up @@ -38,6 +38,6 @@ install(TARGETS strategy
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install (FILES errors.h libz2s.h SimpleTree.h ZonotopStrategy.h DESTINATION include/libstrategy)
install (FILES errors.h SimpleTree.h ZonotopStrategy.h DESTINATION include/libstrategy)


147 changes: 75 additions & 72 deletions src/SimpleTree.cpp

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/SimpleTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SimpleTree {
public:
SimpleTree(const SimpleTree& orig) = default;
virtual ~SimpleTree() = default;
static SimpleTree parse(std::istream&, bool simplify = true, bool subsumption = true, double accuracy = 0);
static SimpleTree parse(std::istream&, bool simplify = false, bool subsumption = false, double accuracy = 0);
static SimpleTree parse(std::istream&, bool simplify, bool subsumption, double accuracy, std::vector<double>& exactness);
std::ostream& print(std::ostream& stream) const;
std::ostream& print_c(std::ostream& stream, std::string name) const;
Expand Down Expand Up @@ -81,7 +81,7 @@ class SimpleTree {
void action_nodes(std::vector<std::shared_ptr<node_t>>& nodes, uint32_t low, uint32_t high, uint32_t varid);
std::pair<double,double> compute_min_max();
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);
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);
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);
void get_ranks(std::set<std::pair<double, node_t*>>& values, node_t* start);
void set_ranks(std::unordered_map<double,double>& values);
std::ostream& print_c(std::ostream& stream, size_t disc, std::unordered_set<const node_t*>& printed, size_t tabs = 0) const;
Expand Down Expand Up @@ -113,6 +113,9 @@ class SimpleTree {
return _low < other._low;
return _high < other._high;
}
std::shared_ptr<node_t>& operator[](bool b) {
return b ? _high : _low;
}
};

std::vector<std::string> _actions;
Expand Down
18 changes: 18 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

find_package (Boost COMPONENTS unit_test_framework REQUIRED)
include_directories (${TEST_SOURCE_DIR}/src
${Boost_INCLUDE_DIRS}
${libstrategy_SOURCE_DIR}
)
add_definitions (-DBOOST_TEST_DYN_LINK)

add_executable (unordered_load unordered_load.cpp)
add_executable (inconsistent_lookup inconsistent_lookup.cpp)

target_link_libraries(unordered_load ${Boost_LIBRARIES} strategy)
target_link_libraries(inconsistent_lookup ${Boost_LIBRARIES} strategy)

add_test(NAME unordered_load COMMAND unordered_load)
add_test(NAME inconsistent_lookup COMMAND inconsistent_lookup)
set_tests_properties(inconsistent_lookup PROPERTIES
ENVIRONMENT STRATEGY_DIR=${CMAKE_CURRENT_SOURCE_DIR}/strategies)
60 changes: 60 additions & 0 deletions test/inconsistent_lookup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2021 Peter G. Jensen <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define BOOST_TEST_MODULE UnorderedLoad

#include <boost/test/unit_test.hpp>
#include <fstream>

#include "SimpleTree.h"

BOOST_AUTO_TEST_CASE(DirectoryTest)
{
BOOST_REQUIRE(getenv("STRATEGY_DIR"));
}

BOOST_AUTO_TEST_CASE(Inconsistent1)
{
std::string strategy = getenv("STRATEGY_DIR");
strategy += "/inconsistent1.strategy";
std::ifstream in(strategy);
auto tree = SimpleTree::parse(in, false, false);
double vars[] = {10};
auto act18 = tree.value(vars,nullptr, 0);
auto act19 = tree.value(vars,nullptr, 1);
BOOST_REQUIRE_LT(act18, act19);
}

BOOST_AUTO_TEST_CASE(Inconsistent1Simplify)
{
std::string strategy = getenv("STRATEGY_DIR");
strategy += "/inconsistent1.strategy";
std::ifstream in(strategy);
auto tree = SimpleTree::parse(in, true, false);
double vars[] = {10};
BOOST_REQUIRE_LT(tree.value(vars,nullptr, 0), tree.value(vars,nullptr, 1));
}

BOOST_AUTO_TEST_CASE(Inconsistent1SimplifySubsumption)
{
std::string strategy = getenv("STRATEGY_DIR");
strategy += "/inconsistent1.strategy";
std::ifstream in(strategy);
auto tree = SimpleTree::parse(in, true, true);
double vars[] = {10};
BOOST_REQUIRE_LT(tree.value(vars,nullptr, 0), tree.value(vars,nullptr, 1));
}
95 changes: 95 additions & 0 deletions test/strategies/inconsistent1.strategy
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{"version":1.0,"type":"state->regressor","representation":"map","actions":{
"0":"movement0.P0->movement0.F0T1 { isReady(id, 0, 1), tau, t := 0, position[id] := -1, punish(id, 0, 1) }",
"1":"movement0.P0->movement0.F0T2 { isReady(id, 0, 2), tau, t := 0, position[id] := -1, punish(id, 0, 2) }"
},"statevars":[
"taskExe1.location"
],"pointvars":[
],"locationnames":{
"movement0.location":{
"0":"P0",
"1":"F0T1",
"2":"F0T2",
"3":"F0T3",
"4":"P1",
"5":"F1T2",
"6":"F1T3",
"7":"P2",
"8":"F2T1",
"9":"F2T3",
"10":"P3",
"11":"F3T1",
"12":"F3T2"
},
"taskExe0.location":{
"0":"Waiting",
"1":"T0",
"2":"T1",
"3":"T2",
"4":"T3"
},
"movement1.location":{
"0":"P0",
"1":"F0T1",
"2":"F0T2",
"3":"F0T3",
"4":"P1",
"5":"F1T2",
"6":"F1T3",
"7":"P2",
"8":"F2T1",
"9":"F2T3",
"10":"P3",
"11":"F3T1",
"12":"F3T2"
},
"taskExe1.location":{
"0":"Waiting",
"1":"T0",
"2":"T1",
"3":"T2",
"4":"T3"
},
"movement2.location":{
"0":"P0",
"1":"F0T1",
"2":"F0T2",
"3":"F0T3",
"4":"P1",
"5":"F1T2",
"6":"F1T3",
"7":"P2",
"8":"F2T1",
"9":"F2T3",
"10":"P3",
"11":"F3T1",
"12":"F3T2"
},
"taskExe2.location":{
"0":"Waiting",
"1":"T0",
"2":"T1",
"3":"T2",
"4":"T3"
}
},"regressors":{
"(4)":
{"type":"act->point->val","representation":"simpletree","minimize":0,"regressor":
{
"0" : -58.52619021830245
}
},
"(2)":
{"type":"act->point->val","representation":"simpletree","minimize":0,"regressor":
{
"1" : -104.5393376817416
}
},
"(10)":
{"type":"act->point->val","representation":"simpletree","minimize":0,"regressor":
{
"0" : -39.75,
"1" : -26.30381528710121
}
}
}
}
Loading

0 comments on commit 5ae7685

Please sign in to comment.