commit
80620128bd
5769 changed files with 1558766 additions and 0 deletions
-
0.gitignore
-
25Minigrid2PRISM/CMakeLists.txt
-
44Minigrid2PRISM/exampleConfig.yaml
-
23Minigrid2PRISM/examples/example_guards.prism
-
17Minigrid2PRISM/examples/example_guards.txt
-
19Minigrid2PRISM/examples/example_guards.yaml
-
17Minigrid2PRISM/examples/example_module.txt
-
36Minigrid2PRISM/examples/example_module.yaml
-
13Minigrid2PRISM/examples/example_probabilities.txt
-
5Minigrid2PRISM/examples/example_probabilities.yaml
-
200Minigrid2PRISM/main.cpp
-
11Minigrid2PRISM/util/CMakeLists.txt
-
304Minigrid2PRISM/util/ConfigYaml.cpp
-
186Minigrid2PRISM/util/ConfigYaml.h
-
200Minigrid2PRISM/util/Grid.cpp
-
67Minigrid2PRISM/util/Grid.h
-
107Minigrid2PRISM/util/MinigridGrammar.h
-
32Minigrid2PRISM/util/OptionParser.cpp
-
13Minigrid2PRISM/util/OptionParser.h
-
243Minigrid2PRISM/util/PrismFormulaPrinter.cpp
-
68Minigrid2PRISM/util/PrismFormulaPrinter.h
-
742Minigrid2PRISM/util/PrismModulesPrinter.cpp
-
123Minigrid2PRISM/util/PrismModulesPrinter.h
-
8Minigrid2PRISM/util/PrismPrinter.cpp
-
35Minigrid2PRISM/util/PrismPrinter.h
-
105Minigrid2PRISM/util/cell.cpp
-
68Minigrid2PRISM/util/cell.h
-
1331Minigrid2PRISM/util/popl.hpp
-
47carl-parser/.ci/build_travis.sh
-
45carl-parser/.ci/deploy_travis.sh
-
98carl-parser/CMakeLists.txt
-
49carl-parser/README.md
-
12carl-parser/cmake/carlparserConfig.cmake.in
-
61carl-parser/cmake/export_target.cmake
-
73carl-parser/resources/antlr4.cmake
-
BINcarl-parser/resources/lib/antlr-4.7.2-complete.jar
-
71carl-parser/src/CMakeLists.txt
-
463carl-parser/src/carl-parser/ParseTreeVisitor.cpp
-
55carl-parser/src/carl-parser/ParseTreeVisitor.h
-
96carl-parser/src/carl-parser/Parser.cpp
-
64carl-parser/src/carl-parser/Parser.h
-
103carl-parser/src/carl-parser/Serialization.g4
-
121carl-parser/src/carl-parser/Serializer.h
-
99carl-parser/src/carl-parser/smtlib.g4
-
4carl-parser/test/CMakeLists.txt
-
5697carl-parser/test/doctest.h
-
24carl-parser/test/test.cpp
-
12carl/.appveyor.yml
-
99carl/.ci/build.sh
-
13carl/.ci/setup_appveyor.ps1
-
34carl/.ci/setup_travis.sh
-
27carl/.ci/sonarcloud.properties.in
-
92carl/.ci/travis.yml.tpl
-
71carl/.ci/travis_generate.py
-
93carl/.ci/travis_helper.py
-
15carl/.clang-format
-
183carl/CMakeLists.txt
-
23carl/LICENSE
-
10carl/README.md
-
113carl/bindings/CMakeLists.txt
-
4carl/bindings/pycarl/.gitignore
-
140carl/bindings/swig/constraint.i
-
140carl/bindings/swig/constraint.i~
-
123carl/bindings/swig/factorizedpolynomial.i
-
123carl/bindings/swig/factorizedpolynomial.i~
-
185carl/bindings/swig/formula.i
-
179carl/bindings/swig/formula.i~
-
213carl/bindings/swig/formulaclasses.i~
-
244carl/bindings/swig/interval.i
-
244carl/bindings/swig/interval.i~
-
263carl/bindings/swig/monomial.i
-
263carl/bindings/swig/monomial.i~
-
207carl/bindings/swig/polynomial.i
-
207carl/bindings/swig/polynomial.i~
-
238carl/bindings/swig/rational.i
-
238carl/bindings/swig/rational.i~
-
248carl/bindings/swig/rationalfunction.i
-
155carl/bindings/swig/term.i
-
155carl/bindings/swig/term.i~
-
240carl/bindings/swig/variable.i
-
240carl/bindings/swig/variable.i~
-
36carl/cmake/FindBLISS.cmake
-
38carl/cmake/FindCLN.cmake
-
39carl/cmake/FindCoCoA.cmake
-
80carl/cmake/FindEIGEN3.cmake
-
42carl/cmake/FindGINAC.cmake
-
54carl/cmake/FindGMP.cmake
-
29carl/cmake/FindGMPXX.cmake
-
35carl/cmake/FindMPFR.cmake
-
42carl/cmake/FindZ3.cmake
-
26carl/cmake/carlConfig.cmake.in
-
11carl/cmake/carlConfigVersion.cmake.in
-
201carl/cmake/carlmacros.cmake
-
50carl/cmake/clang-tidy.cmake
-
76carl/cmake/compiler-options.cmake
-
3334carl/cmake/cotire.cmake
-
19carl/cmake/coverage-clang.sh
-
28carl/cmake/coverage.cmake
-
71carl/cmake/export.cmake
-
34carl/cmake/install.cmake
@ -0,0 +1,25 @@ |
|||
include(util/CMakeLists.txt) |
|||
|
|||
set(CMAKE_CXX_STANDARD 20) |
|||
|
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'") |
|||
add_definitions(-DLOG_DEBUG) |
|||
|
|||
cmake_minimum_required(VERSION 3.0...3.22) |
|||
|
|||
set(CMAKE_BUILD_TYPE Debug) |
|||
|
|||
project( |
|||
Minigrid2PRISM |
|||
VERSION 0.1 |
|||
LANGUAGES CXX) |
|||
|
|||
find_package(yaml-cpp) |
|||
|
|||
add_executable(main |
|||
${SRCS} |
|||
main.cpp |
|||
) |
|||
|
|||
target_link_libraries(main pthread yaml-cpp::yaml-cpp) |
|||
|
@ -0,0 +1,44 @@ |
|||
--- |
|||
# labels: |
|||
# - label: "AgentIsInGoal" |
|||
# text: "AgentIsInGoal" |
|||
# - label: "Hallo" |
|||
# text: "AgentIsInGoal" |
|||
|
|||
# constants: |
|||
# - constant: "prop_slippery_turn" |
|||
# type: "double" |
|||
# value: "9/9" |
|||
# overwrite: True |
|||
|
|||
properties: |
|||
- property: "FaultProbability" |
|||
value: 0.2 |
|||
- property: "ProbForwardIntended" |
|||
value: 0.1 |
|||
- property: "ProbTurnIntended" |
|||
value: 0.1 |
|||
# - property: "modeltype" |
|||
# value: "smg" |
|||
|
|||
modules: |
|||
- module: "Agent" |
|||
# overwrite: True |
|||
# module_text: | |
|||
# NewModule |
|||
# True |
|||
commands: |
|||
- action: "[Agent_turn_left]" |
|||
guard: "viewAgent=3" |
|||
overwrite: True |
|||
index: 1 |
|||
- action: "[Agent_turn_left]" |
|||
update: "(viewAgent'=3)" |
|||
overwrite: True |
|||
index: 3 |
|||
- action: "[Agent_turn_right]" |
|||
guard: "AgentIsOnSlippery" |
|||
update: "(viewAgent'=3)" |
|||
overwrite: True |
|||
index: [0,1] |
|||
... |
@ -0,0 +1,23 @@ |
|||
mdp |
|||
|
|||
formula AgentCannotMoveEastWall = (colAgent=1&rowAgent=2) | (colAgent=4&rowAgent=2) | (colAgent=4&rowAgent=3) | (colAgent=4&rowAgent=4) | (colAgent=4&rowAgent=1); |
|||
formula AgentCannotMoveNorthWall = (colAgent=1&rowAgent=1) | (colAgent=2&rowAgent=1) | (colAgent=3&rowAgent=1) | (colAgent=2&rowAgent=3) | (colAgent=3&rowAgent=3) | (colAgent=4&rowAgent=1); |
|||
formula AgentCannotMoveSouthWall = (colAgent=2&rowAgent=1) | (colAgent=3&rowAgent=1) | (colAgent=1&rowAgent=4) | (colAgent=2&rowAgent=4) | (colAgent=3&rowAgent=4) | (colAgent=4&rowAgent=4); |
|||
formula AgentCannotMoveWestWall = (colAgent=1&rowAgent=1) | (colAgent=1&rowAgent=2) | (colAgent=4&rowAgent=2) | (colAgent=1&rowAgent=3) | (colAgent=1&rowAgent=4); |
|||
formula AgentIsOnSlippery = false; |
|||
|
|||
module Agent |
|||
colAgent : [1..4] init 4; |
|||
rowAgent : [1..4] init 1; |
|||
viewAgent : [0..3] init 1; |
|||
|
|||
[Agent_turn_right] !AgentIsOnOneWay-> 1.000000: (viewAgent'=mod(viewAgent+1,4)); |
|||
[Agent_turn_left] !AgentIsOnOneWay-> 1.000000: (viewAgent'=viewAgent-1); |
|||
[Agent_turn_left] !AgentIsOnOneWay-> 1.000000: (viewAgent'=3); |
|||
[Agent_move_North] viewAgent=3 & !AgentCannotMoveNorthWall -> 1.000000: (rowAgent'=rowAgent-1); |
|||
[Agent_move_East] colAgent != 1 & rowAgent != 1-> 1.000000: (colAgent'=colAgent+1); |
|||
[Agent_move_South] viewAgent=1 & !AgentCannotMoveSouthWall -> 1.000000: (rowAgent'=rowAgent+1); |
|||
[Agent_move_West] viewAgent=2 & !AgentCannotMoveWestWall -> 1.000000: (colAgent'=colAgent-1); |
|||
endmodule |
|||
|
|||
formula AgentIsOnOneWay = (colAgent=2&rowAgent=1) | (colAgent=3&rowAgent=1); // created through configuration |
@ -0,0 +1,17 @@ |
|||
WGWGWGWGWGWG |
|||
WG XRWG |
|||
WG WGWG WG |
|||
WG WG |
|||
WG WG |
|||
WGWGWGWGWGWG |
|||
------------ |
|||
WGWGWGWGWGWG |
|||
WG WG |
|||
WG WGWG WG |
|||
WG WG |
|||
WG WG |
|||
WGWGWGWGWGWG |
|||
------------ |
|||
------------ |
|||
ProbTurnIntended:0.85 |
|||
ProbForwardIntended:0.25 |
@ -0,0 +1,19 @@ |
|||
--- |
|||
formulas: |
|||
- formula: "AgentIsOnOneWay" |
|||
content: "(colAgent=2&rowAgent=1) | (colAgent=3&rowAgent=1)" |
|||
|
|||
modules: |
|||
- module: "Agent" |
|||
commands: |
|||
- action: "[Agent_move_East]" |
|||
guard: "colAgent != 1 & rowAgent != 1" |
|||
overwrite: True |
|||
- action: "[Agent_turn_right]" |
|||
guard: "!AgentIsOnOneWay" |
|||
overwrite: True |
|||
- action: "[Agent_turn_left]" |
|||
guard: "!AgentIsOnOneWay" |
|||
overwrite: True |
|||
index: [0,1] |
|||
... |
@ -0,0 +1,17 @@ |
|||
WGWGWGWGWGWGWG |
|||
WGZY XRWG |
|||
WG WG |
|||
WG WG |
|||
WG WGWGWGWGWG |
|||
WG AYGGWG |
|||
WGWGWGWGWGWGWG |
|||
-------------- |
|||
WGWGWGWGWGWGWG |
|||
WG WG |
|||
WG WG |
|||
WG WG |
|||
WG WGWGWGWGWG |
|||
WG WG |
|||
WGWGWGWGWGWGWG |
|||
-------------- |
|||
-------------- |
@ -0,0 +1,36 @@ |
|||
--- |
|||
|
|||
properties: |
|||
- property: "modeltype" |
|||
value: "mdp" |
|||
|
|||
formulas: |
|||
- formula: "YellowMovesNorth" |
|||
content: "(rowYellow=2 | rowYellow=3 | rowYellow=4) & colYellow=1 & viewYellow=3" |
|||
- formula: "YellowMovesSouth" |
|||
content: "(rowYellow=2 | rowYellow=3 | rowYellow=4) & colYellow=1 & viewYellow=1" |
|||
|
|||
modules: |
|||
- module: "Yellow" |
|||
overwrite: True |
|||
module_text: | |
|||
colYellow : [1..5] init 1; |
|||
rowYellow : [1..5] init 1; |
|||
viewYellow : [0..3] init 1; |
|||
YellowCarryingYellowBall : bool init false; |
|||
|
|||
[Yellow_turn_right] (!YellowMovesSouth & !YellowMovesNorth) -> 1.000000: (viewYellow'=mod(viewYellow+1,4)); |
|||
[Yellow_turn_left] (!YellowMovesSouth & !YellowMovesNorth) -> 1.000000: (viewYellow'=viewYellow-1); |
|||
[Yellow_turn_left] (!YellowMovesSouth & !YellowMovesNorth) -> 1.000000: (viewYellow'=3); |
|||
[Yellow_move_North] !YellowMovesSouth & viewYellow=3 & !YellowIsOnGoal & !YellowCannotMoveNorthWall & !YellowCannotMoveConditionally -> 1.000000: (rowYellow'=rowYellow-1); |
|||
[Yellow_move_East] !(YellowMovesNorth|YellowMovesSouth) & viewYellow=0 & !YellowIsOnGoal & !YellowCannotMoveEastWall & !YellowCannotMoveConditionally -> 1.000000: (colYellow'=colYellow+1); |
|||
[Yellow_move_South] !YellowMovesNorth & viewYellow=1 & !YellowIsOnGoal & !YellowCannotMoveSouthWall & !YellowCannotMoveConditionally -> 1.000000: (rowYellow'=rowYellow+1); |
|||
[Yellow_move_West] !(YellowMovesNorth|YellowMovesSouth) & viewYellow=2 & !YellowIsOnGoal & !YellowCannotMoveWestWall & !YellowCannotMoveConditionally -> 1.000000: (colYellow'=colYellow-1); |
|||
[Yellow_pickup_YellowBall] !YellowIsCarrying & YellowCannotMoveYellowBall -> (YellowCarryingYellowBall'=true); |
|||
[Yellow_drop_YellowBall_north] YellowCarryingYellowBall & viewYellow=3 & !YellowCannotMoveConditionally & !YellowCannotMoveNorthWall -> (YellowCarryingYellowBall'=false); |
|||
[Yellow_drop_YellowBall_west] YellowCarryingYellowBall & viewYellow=2 & !YellowCannotMoveConditionally & !YellowCannotMoveWestWall -> (YellowCarryingYellowBall'=false); |
|||
[Yellow_drop_YellowBall_south] YellowCarryingYellowBall & viewYellow=1 & !YellowCannotMoveConditionally & !YellowCannotMoveSouthWall -> (YellowCarryingYellowBall'=false); |
|||
[Yellow_drop_YellowBall_east] YellowCarryingYellowBall & viewYellow=0 & !YellowCannotMoveConditionally & !YellowCannotMoveEastWall -> (YellowCarryingYellowBall'=false); |
|||
|
|||
|
|||
... |
@ -0,0 +1,13 @@ |
|||
WGWGWGWG |
|||
WGVRXRWG |
|||
WGnB WG |
|||
WGWGWGWG |
|||
-------- |
|||
WGWGWGWG |
|||
WG WG |
|||
WGnB WG |
|||
WGWGWGWG |
|||
-------- |
|||
-------- |
|||
ProbTurnIntended:0.85 |
|||
ProbForwardIntended:0.25 |
@ -0,0 +1,5 @@ |
|||
--- |
|||
properties: |
|||
- property: "ProbForwardIntended" |
|||
value: 0.98 |
|||
... |
@ -0,0 +1,200 @@ |
|||
#include "util/OptionParser.h"
|
|||
#include "util/MinigridGrammar.h"
|
|||
#include "util/Grid.h"
|
|||
#include "util/ConfigYaml.h"
|
|||
|
|||
#include <iostream>
|
|||
#include <fstream>
|
|||
#include <filesystem>
|
|||
#include <sstream>
|
|||
|
|||
|
|||
std::vector<std::string> parseCommaSeparatedString(std::string const& str) { |
|||
std::vector<std::string> result; |
|||
std::stringstream stream(str); |
|||
while(stream.good()) { |
|||
std::string substr; |
|||
getline(stream, substr, ','); |
|||
substr.at(0) = std::toupper(substr.at(0)); |
|||
result.push_back(substr); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
struct printer { |
|||
typedef boost::spirit::utf8_string string; |
|||
|
|||
void element(string const& tag, string const& value, int depth) const { |
|||
for (int i = 0; i < (depth*4); ++i) std::cout << ' '; |
|||
|
|||
std::cout << "tag: " << tag; |
|||
if (value != "") std::cout << ", value: " << value; |
|||
std::cout << std::endl; |
|||
} |
|||
}; |
|||
|
|||
void print_info(boost::spirit::info const& what) { |
|||
using boost::spirit::basic_info_walker; |
|||
|
|||
printer pr; |
|||
basic_info_walker<printer> walker(pr, what.tag, 0); |
|||
boost::apply_visitor(walker, what.value); |
|||
} |
|||
|
|||
void setProbability(const std::string& gridProperties, const std::vector<Property> configProperties, const std::string& identifier, float& prop) { |
|||
auto start_pos = gridProperties.find(identifier); |
|||
std::string seperator = ";"; |
|||
|
|||
if (start_pos != std::string::npos) { |
|||
auto end_pos = gridProperties.find('\n', start_pos); |
|||
auto value = gridProperties.substr(start_pos + identifier.length() + seperator.size(), end_pos - start_pos - identifier.length()); |
|||
prop = std::stod(value); |
|||
} |
|||
|
|||
auto yaml_config_prop = std::find_if(configProperties.begin(), configProperties.end(), [&identifier](const Property& obj) -> bool {return obj.property == identifier;} ); |
|||
|
|||
if (yaml_config_prop != configProperties.end()) { |
|||
prop = (*yaml_config_prop).value_; |
|||
} |
|||
} |
|||
|
|||
|
|||
int main(int argc, char* argv[]) { |
|||
popl::OptionParser optionParser("Allowed options"); |
|||
|
|||
auto helpOption = optionParser.add<popl::Switch>("h", "help", "Print this help message."); |
|||
auto inputFilename = optionParser.add<popl::Value<std::string>>("i", "input-file", "Filename of the input file."); |
|||
auto outputFilename = optionParser.add<popl::Value<std::string>>("o", "output-file", "Filename for the output file."); |
|||
auto configFilename = optionParser.add<popl::Value<std::string>, popl::Attribute::optional>("c", "config-file", "Filename of the predicate configuration file."); |
|||
|
|||
|
|||
try { |
|||
optionParser.parse(argc, argv); |
|||
|
|||
if(helpOption->count() > 0) { |
|||
std::cout << optionParser << std::endl; |
|||
return EXIT_SUCCESS; |
|||
} |
|||
} catch (const popl::invalid_option &e) { |
|||
return io::printPoplException(e); |
|||
} catch (const std::exception &e) { |
|||
std::cerr << "Exception: " << e.what() << "\n"; |
|||
return EXIT_FAILURE; |
|||
} |
|||
|
|||
std::fstream file {outputFilename->value(0), file.trunc | file.out}; |
|||
std::fstream infile {inputFilename->value(0), infile.in}; |
|||
std::string line, content, background, rewards, properties; |
|||
std::cout << "\n"; |
|||
bool parsingBackground = false; |
|||
bool parsingStateRewards = false; |
|||
bool parsingEnvironmentProperties = false; |
|||
while (std::getline(infile, line) && !line.empty()) { |
|||
if(line.at(0) == '-' && line.at(line.size() - 1) == '-' && parsingBackground) { |
|||
parsingStateRewards = true; |
|||
parsingBackground = false; |
|||
continue; |
|||
} else if (line.at(0) == '-' && line.at(line.size() - 1 ) == '-' && parsingStateRewards) { |
|||
parsingStateRewards = false; |
|||
parsingEnvironmentProperties = true; |
|||
continue; |
|||
} else if(line.at(0) == '-' && line.at(line.size() - 1) == '-') { |
|||
parsingBackground = true; |
|||
continue; |
|||
} |
|||
if(!parsingBackground && !parsingStateRewards && !parsingEnvironmentProperties) { |
|||
content += line + "\n"; |
|||
} else if (parsingBackground) { |
|||
background += line + "\n"; |
|||
} else if(parsingStateRewards) { |
|||
rewards += line + "\n"; |
|||
} else if (parsingEnvironmentProperties) { |
|||
properties += line + "\n"; |
|||
} |
|||
} |
|||
std::cout << "\n"; |
|||
|
|||
pos_iterator_t contentFirst(content.begin()); |
|||
pos_iterator_t contentIter = contentFirst; |
|||
pos_iterator_t contentLast(content.end()); |
|||
MinigridParser<pos_iterator_t> contentParser(contentFirst); |
|||
pos_iterator_t backgroundFirst(background.begin()); |
|||
pos_iterator_t backgroundIter = backgroundFirst; |
|||
pos_iterator_t backgroundLast(background.end()); |
|||
MinigridParser<pos_iterator_t> backgroundParser(backgroundFirst); |
|||
|
|||
cells contentCells; |
|||
cells backgroundCells; |
|||
std::vector<Configuration> configurations; |
|||
std::vector<Property> parsed_properties; |
|||
std::map<coordinates, float> stateRewards; |
|||
float faultyProbability = 0.0; |
|||
float probIntended = 1.0; |
|||
float probTurnIntended = 1.0; |
|||
|
|||
try { |
|||
bool ok = phrase_parse(contentIter, contentLast, contentParser, qi::space, contentCells); |
|||
// TODO if(background is not empty) {
|
|||
ok &= phrase_parse(backgroundIter, backgroundLast, backgroundParser, qi::space, backgroundCells); |
|||
// TODO }
|
|||
if (configFilename->is_set()) { |
|||
YamlConfigParser parser(configFilename->value(0)); |
|||
auto parseResult = parser.parseConfiguration(); |
|||
configurations = parseResult.configurations_; |
|||
parsed_properties = parseResult.properties_; |
|||
} |
|||
|
|||
boost::escaped_list_separator<char> seps('\\', ';', '\n'); |
|||
Tokenizer csvParser(rewards, seps); |
|||
for(auto iter = csvParser.begin(); iter != csvParser.end(); ++iter) { |
|||
int x = std::stoi(*iter); |
|||
int y = std::stoi(*(++iter)); |
|||
float reward = std::stof(*(++iter)); |
|||
stateRewards[std::make_pair(x,y)] = reward; |
|||
} |
|||
if (!properties.empty()) { |
|||
auto faultProbabilityIdentifier = std::string("FaultProbability"); |
|||
auto probForwardIntendedIdentifier = std::string("ProbForwardIntended"); |
|||
auto probTurnIntendedIdentifier = std::string("ProbTurnIntended"); |
|||
|
|||
setProbability(properties, parsed_properties, faultProbabilityIdentifier, faultyProbability); |
|||
setProbability(properties, parsed_properties, probForwardIntendedIdentifier, probIntended); |
|||
setProbability(properties, parsed_properties, probTurnIntendedIdentifier, probTurnIntended); |
|||
} |
|||
if(ok) { |
|||
Grid grid(contentCells, backgroundCells, stateRewards, probIntended, faultyProbability); |
|||
|
|||
auto modelTypeIter = std::find_if(parsed_properties.begin(), parsed_properties.end(), [](const Property& obj) -> bool {return obj.property == "modeltype";}); |
|||
prism::ModelType modelType = prism::ModelType::MDP;; |
|||
if (modelTypeIter != parsed_properties.end()) { |
|||
if ((*modelTypeIter).value_str_ == "smg") { |
|||
modelType = prism::ModelType::SMG; |
|||
} else { |
|||
modelType = prism::ModelType::MDP; |
|||
} |
|||
|
|||
grid.setModelType(modelType); |
|||
} |
|||
|
|||
|
|||
|
|||
//grid.printToPrism(std::cout, configurations);
|
|||
std::stringstream ss; |
|||
grid.printToPrism(ss, configurations); |
|||
std::string str = ss.str(); |
|||
grid.applyOverwrites(str, configurations); |
|||
file << str; |
|||
} |
|||
} catch(qi::expectation_failure<pos_iterator_t> const& e) { |
|||
std::cout << "expected: "; print_info(e.what_); |
|||
std::cout << "got: \"" << std::string(e.first, e.last) << '"' << std::endl; |
|||
std::cout << "Expectation failure: " << e.what() << " at '" << std::string(e.first,e.last) << "'\n"; |
|||
} catch(const std::exception& e) { |
|||
std::cerr << "Exception '" << typeid(e).name() << "' caught:" << e.what() << std::endl; |
|||
std::cerr << "\t" << e.what() << std::endl; |
|||
std::exit(EXIT_FAILURE); |
|||
} |
|||
|
|||
return 0; |
|||
} |
@ -0,0 +1,11 @@ |
|||
list(APPEND SRCS |
|||
${CMAKE_CURRENT_LIST_DIR}/cell.cpp |
|||
${CMAKE_CURRENT_LIST_DIR}/MinigridGrammar.h |
|||
${CMAKE_CURRENT_LIST_DIR}/Grid.cpp |
|||
${CMAKE_CURRENT_LIST_DIR}/PrismPrinter.cpp |
|||
${CMAKE_CURRENT_LIST_DIR}/PrismModulesPrinter.cpp |
|||
${CMAKE_CURRENT_LIST_DIR}/PrismFormulaPrinter.cpp |
|||
${CMAKE_CURRENT_LIST_DIR}/popl.hpp |
|||
${CMAKE_CURRENT_LIST_DIR}/OptionParser.cpp |
|||
${CMAKE_CURRENT_LIST_DIR}/ConfigYaml.cpp |
|||
) |
@ -0,0 +1,304 @@ |
|||
#include "ConfigYaml.h"
|
|||
#include <iostream>
|
|||
|
|||
std::ostream& operator <<(std::ostream &os, const Label& label) { |
|||
os << "\"" << label.label_ << "\"" << "=" << label.text_; |
|||
return os; |
|||
} |
|||
|
|||
std::ostream& operator << (std::ostream &os, const Formula& formula) { |
|||
os << formula.formula_ << "=" << formula.content_; |
|||
return os; |
|||
} |
|||
|
|||
std::ostream& operator << (std::ostream& os, const Command& command) { |
|||
os << command.action_; |
|||
return os; |
|||
} |
|||
|
|||
std::ostream& operator << (std::ostream& os, const Constant& constant) { |
|||
os << "const " << constant.type_ << " " << constant.constant_ << " = " << constant.value_; |
|||
return os; |
|||
} |
|||
|
|||
std::ostream& operator << (std::ostream& os, const Module& module) { |
|||
os << "Module: " << module.module_ << std::endl; |
|||
for (auto& command : module.commands_) { |
|||
os << command << std::endl; |
|||
} |
|||
return os; |
|||
} |
|||
|
|||
std::string Label::createExpression() const { |
|||
if (overwrite_) { |
|||
return "label \"" + label_ + "\" = " + text_ + Configuration::overwrite_identifier_; |
|||
} |
|||
|
|||
return "label \"" + label_ + "\" = " + text_ + Configuration::configuration_identifier_; |
|||
} |
|||
|
|||
std::string Formula::createExpression() const { |
|||
if (overwrite_) { |
|||
return "formula " + formula_ + " = " + content_ + Configuration::overwrite_identifier_; |
|||
} |
|||
|
|||
return "formula " + formula_ + " = " + content_ + Configuration::configuration_identifier_; |
|||
} |
|||
|
|||
std::string Command::createExpression() const { |
|||
if (overwrite_) { |
|||
return action_ + "\t" + guard_ + " -> " + update_ + Configuration::overwrite_identifier_; |
|||
} |
|||
|
|||
return "\t" + action_ + "\t" + guard_ + " -> " + update_+ Configuration::configuration_identifier_; |
|||
} |
|||
|
|||
std::string Constant::createExpression() const { |
|||
if (overwrite_) { |
|||
return "const " + type_ + " " + constant_ + " = " + value_ + Configuration::overwrite_identifier_; |
|||
} |
|||
|
|||
return "const " + type_ + " " + constant_ + " = " + value_ + Configuration::configuration_identifier_; |
|||
} |
|||
|
|||
YAML::Node YAML::convert<Module>::encode(const Module& rhs) { |
|||
YAML::Node node; |
|||
|
|||
node.push_back(rhs.module_); |
|||
node.push_back(rhs.commands_); |
|||
|
|||
return node; |
|||
} |
|||
|
|||
bool YAML::convert<Module>::decode(const YAML::Node& node, Module& rhs) { |
|||
if (!node.Type() == NodeType::Map) { |
|||
return false; |
|||
} |
|||
|
|||
|
|||
rhs.module_ = node["module"].as<std::string>(); |
|||
|
|||
if (node["commands"]) { |
|||
rhs.commands_ = node["commands"].as<std::vector<Command>>(); |
|||
} |
|||
|
|||
if (node["module_text"]) { |
|||
rhs.module_text_ = node["module_text"].as<std::string>(); |
|||
} |
|||
if (node["overwrite"]) { |
|||
rhs.overwrite_module = node["overwrite"].as<bool>(); |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
YAML::Node YAML::convert<Command>::encode(const Command& rhs) { |
|||
YAML::Node node; |
|||
|
|||
node.push_back(rhs.action_); |
|||
node.push_back(rhs.guard_); |
|||
node.push_back(rhs.overwrite_); |
|||
node.push_back(rhs.update_); |
|||
|
|||
return node; |
|||
} |
|||
|
|||
bool YAML::convert<Command>::decode(const YAML::Node& node, Command& rhs) { |
|||
if (!node.Type() == NodeType::Map) { |
|||
return false; |
|||
} |
|||
|
|||
rhs.action_ = node["action"].as<std::string>(); |
|||
if (node["guard"]) { |
|||
rhs.guard_ = node["guard"].as<std::string>(); |
|||
} |
|||
|
|||
if (node["update"]) { |
|||
rhs.update_ = node["update"].as<std::string>(); |
|||
} |
|||
|
|||
if (node["overwrite"]) { |
|||
rhs.overwrite_ = node["overwrite"].as<bool>(); |
|||
} |
|||
if (node["index"]) { |
|||
try { |
|||
rhs.indexes_ = node["index"].as<std::vector<int>>(); |
|||
} |
|||
catch(const std::exception& e) { |
|||
rhs.indexes_ = {node["index"].as<int>()}; |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
YAML::Node YAML::convert<Label>::encode(const Label& rhs) { |
|||
YAML::Node node; |
|||
|
|||
node.push_back(rhs.label_); |
|||
node.push_back(rhs.text_); |
|||
|
|||
return node; |
|||
} |
|||
|
|||
bool YAML::convert<Label>::decode(const YAML::Node& node, Label& rhs) { |
|||
if (!node.Type() == NodeType::Map || !node["label"] || !node["text"]) { |
|||
return false; |
|||
} |
|||
rhs.label_ = node["label"].as<std::string>(); |
|||
rhs.text_ = node["text"].as<std::string>(); |
|||
|
|||
if (node["overwrite"]) { |
|||
rhs.overwrite_ = node["overwrite"].as<bool>(); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
YAML::Node YAML::convert<Formula>::encode(const Formula& rhs) { |
|||
YAML::Node node; |
|||
|
|||
node.push_back(rhs.content_); |
|||
node.push_back(rhs.formula_); |
|||
node.push_back(rhs.overwrite_); |
|||
|
|||
return node; |
|||
} |
|||
|
|||
bool YAML::convert<Formula>::decode(const YAML::Node& node, Formula& rhs) { |
|||
if (!node.IsDefined() || !node.Type() == NodeType::Map || !node["formula"] || !node["content"]) { |
|||
return false; |
|||
} |
|||
|
|||
rhs.formula_ = node["formula"].as<std::string>(); |
|||
rhs.content_ = node["content"].as<std::string>(); |
|||
|
|||
if(node["overwrite"]) { |
|||
rhs.overwrite_ = node["overwrite"].as<bool>(); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
YAML::Node YAML::convert<Constant>::encode(const Constant& rhs) { |
|||
YAML::Node node; |
|||
|
|||
node.push_back(rhs.constant_); |
|||
node.push_back(rhs.value_); |
|||
node.push_back(rhs.type_); |
|||
node.push_back(rhs.overwrite_); |
|||
|
|||
return node; |
|||
} |
|||
|
|||
bool YAML::convert<Constant>::decode(const YAML::Node& node, Constant& rhs) { |
|||
if (!node.IsDefined() || !node.Type() == NodeType::Map || !node["constant"] || !node["type"] || !node["value"]) { |
|||
return false; |
|||
} |
|||
|
|||
rhs.constant_ = node["constant"].as<std::string>(); |
|||
rhs.type_ = node["type"].as<std::string>(); |
|||
rhs.value_ = node["value"].as<std::string>(); |
|||
|
|||
if(node["overwrite"]) { |
|||
rhs.overwrite_ = node["overwrite"].as<bool>(); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
YAML::Node YAML::convert<Property>::encode(const Property& rhs) { |
|||
YAML::Node node; |
|||
|
|||
node.push_back(rhs.property); |
|||
node.push_back(rhs.value_); |
|||
|
|||
return node; |
|||
} |
|||
|
|||
bool YAML::convert<Property>::decode(const YAML::Node& node, Property& rhs) { |
|||
if (!node.IsDefined() || !node["property"] || !node["value"]) { |
|||
return false; |
|||
} |
|||
|
|||
rhs.property = node["property"].as<std::string>(); |
|||
try { |
|||
rhs.value_ = node["value"].as<double>(); |
|||
} |
|||
catch(const std::exception& e) { |
|||
rhs.value_str_ = node["value"].as<std::string>(); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
const std::string Configuration::configuration_identifier_ { "; // created through configuration"}; |
|||
const std::string Configuration::overwrite_identifier_{"; // Overwritten through configuration"}; |
|||
|
|||
YamlConfigParseResult YamlConfigParser::parseConfiguration() { |
|||
std::vector<Configuration> configuration; |
|||
std::vector<Property> properties; |
|||
|
|||
try { |
|||
YAML::Node config = YAML::LoadFile(file_); |
|||
std::vector<Label> labels; |
|||
std::vector<Formula> formulas; |
|||
std::vector<Module> modules; |
|||
std::vector<Constant> constants; |
|||
|
|||
if (config["labels"]) { |
|||
labels = config["labels"].as<std::vector<Label>>(); |
|||
} |
|||
if (config["formulas"]) { |
|||
formulas = config["formulas"].as<std::vector<Formula>>(); |
|||
} |
|||
if (config["modules"]) { |
|||
modules = config["modules"].as<std::vector<Module>>(); |
|||
} |
|||
|
|||
if (config["constants"]) { |
|||
constants = config["constants"].as<std::vector<Constant>>(); |
|||
} |
|||
|
|||
if (config["properties"]) { |
|||
properties = config["properties"].as<std::vector<Property>>(); |
|||
} |
|||
|
|||
for (auto& label : labels) { |
|||
configuration.push_back({label.createExpression(), label.label_ , ConfigType::Label, label.overwrite_}); |
|||
} |
|||
for (auto& formula : formulas) { |
|||
configuration.push_back({formula.createExpression(), formula.formula_ ,ConfigType::Formula, formula.overwrite_}); |
|||
} |
|||
for (auto& module : modules) { |
|||
if (module.overwrite_module) { |
|||
Configuration config = Configuration(module.module_text_, "module " + module.module_ + "\n", ConfigType::Module, true, module.module_, {0}, "endmodule"); |
|||
configuration.push_back(config); |
|||
continue; |
|||
} |
|||
for (auto& command : module.commands_) { |
|||
Configuration config; |
|||
if (!command.guard_.empty() && !command.action_.empty() && command.update_.empty()) { |
|||
config = Configuration(" " + command.guard_, command.action_, ConfigType::GuardOnly, true, module.module_, command.indexes_, "->"); |
|||
} else if (!command.update_.empty() && !command.action_.empty() && command.guard_.empty()) { |
|||
config = Configuration( " " + command.update_, command.action_, ConfigType::UpdateOnly, true, module.module_, command.indexes_, ";"); |
|||
} else { |
|||
config = Configuration(command.createExpression(), command.action_, ConfigType::Module, command.overwrite_, module.module_, command.indexes_); |
|||
} |
|||
|
|||
configuration.push_back(config); |
|||
} |
|||
} |
|||
for (auto& constant : constants) { |
|||
// std::cout << constant.constant_ << std::endl;
|
|||
configuration.push_back({constant.createExpression(), "const " + constant.type_ + " " + constant.constant_, ConfigType::Constant, constant.overwrite_}); |
|||
} |
|||
} |
|||
catch(const std::exception& e) { |
|||
std::cout << "Exception '" << typeid(e).name() << "' caught:" << std::endl; |
|||
std::cout << "\t" << e.what() << std::endl; |
|||
std::cout << "while parsing configuration " << file_ << std::endl; |
|||
} |
|||
|
|||
return YamlConfigParseResult(configuration, properties); |
|||
} |
@ -0,0 +1,186 @@ |
|||
#pragma once |
|||
|
|||
#include <vector> |
|||
#include <ostream> |
|||
#include <utility> |
|||
|
|||
#include "yaml-cpp/yaml.h" |
|||
|
|||
|
|||
enum class ConfigType : char { |
|||
Label = 'L', |
|||
Formula = 'F', |
|||
Module = 'M', |
|||
UpdateOnly = 'U', |
|||
GuardOnly = 'G', |
|||
Constant = 'C' |
|||
}; |
|||
|
|||
struct Configuration |
|||
{ |
|||
static const std::string overwrite_identifier_; |
|||
static const std::string configuration_identifier_; |
|||
|
|||
std::string module_ {}; |
|||
std::string expression_{}; |
|||
std::string identifier_{}; |
|||
std::string end_identifier_{}; |
|||
std::vector<int> indexes_{0}; |
|||
|
|||
ConfigType type_ {ConfigType::Label}; |
|||
bool overwrite_ {false}; |
|||
|
|||
Configuration() = default; |
|||
Configuration(std::string expression |
|||
, std::string identifier |
|||
, ConfigType type |
|||
, bool overwrite = false |
|||
, std::string module = "" |
|||
, std::vector<int> indexes = {0} |
|||
, std::string end_identifier = {";"}) : expression_(expression), identifier_(identifier), type_(type), overwrite_(overwrite), module_{module}, indexes_(indexes), end_identifier_{end_identifier} {} |
|||
|
|||
~Configuration() = default; |
|||
Configuration(const Configuration&) = default; |
|||
|
|||
friend std::ostream& operator << (std::ostream& os, const Configuration& config) { |
|||
os << "Configuration with Type: " << static_cast<char>(config.type_) << std::endl; |
|||
return os << "\tExpression=" << config.expression_ << std::endl; |
|||
} |
|||
}; |
|||
|
|||
struct Property { |
|||
Property() = default; |
|||
Property(const Property&) = default; |
|||
~Property() = default; |
|||
|
|||
std::string property; |
|||
double value_; |
|||
std::string value_str_; |
|||
|
|||
friend std::ostream& operator <<(std::ostream& os, const Property& property); |
|||
}; |
|||
|
|||
struct Constant { |
|||
private: |
|||
|
|||
public: |
|||
std::string constant_; |
|||
std::string type_; |
|||
std::string value_; |
|||
bool overwrite_{false}; |
|||
|
|||
std::string createExpression() const; |
|||
|
|||
friend std::ostream& operator <<(std::ostream &os, const Constant& constant); |
|||
}; |
|||
|
|||
struct Label { |
|||
private: |
|||
|
|||
public: |
|||
std::string text_; |
|||
std::string label_; |
|||
bool overwrite_{false}; |
|||
|
|||
std::string createExpression() const; |
|||
|
|||
friend std::ostream& operator <<(std::ostream &os, const Label& label); |
|||
}; |
|||
|
|||
struct Formula { |
|||
private: |
|||
|
|||
public: |
|||
std::string formula_; |
|||
std::string content_; |
|||
bool overwrite_ {false}; |
|||
|
|||
std::string createExpression() const; |
|||
|
|||
friend std::ostream& operator << (std::ostream &os, const Formula& formula); |
|||
}; |
|||
|
|||
struct Command { |
|||
public: |
|||
std::string action_; |
|||
std::string guard_; |
|||
std::string update_; |
|||
std::vector<int> indexes_{0}; |
|||
bool overwrite_ {false}; |
|||
|
|||
std::string createExpression() const; |
|||
|
|||
friend std::ostream& operator << (std::ostream& os, const Command& command); |
|||
}; |
|||
|
|||
struct Module { |
|||
public: |
|||
|
|||
std::vector<Command> commands_; |
|||
std::string module_; |
|||
std::string module_text_; |
|||
bool overwrite_module{false}; |
|||
|
|||
friend std::ostream& operator << (std::ostream& os, const Module& module); |
|||
}; |
|||
|
|||
|
|||
template<> |
|||
struct YAML::convert<Module> { |
|||
static YAML::Node encode(const Module& rhs); |
|||
static bool decode(const YAML::Node& node, Module& rhs); |
|||
}; |
|||
|
|||
template<> |
|||
struct YAML::convert<Command> { |
|||
static YAML::Node encode(const Command& rhs); |
|||
static bool decode(const YAML::Node& node, Command& rhs); |
|||
}; |
|||
|
|||
|
|||
template<> |
|||
struct YAML::convert<Label> { |
|||
static YAML::Node encode(const Label& rhs); |
|||
static bool decode(const YAML::Node& node, Label& rhs); |
|||
}; |
|||
|
|||
template<> |
|||
struct YAML::convert<Formula> { |
|||
static YAML::Node encode(const Formula& rhs); |
|||
static bool decode(const YAML::Node& node, Formula& rhs); |
|||
}; |
|||
|
|||
template<> |
|||
struct YAML::convert<Constant> { |
|||
static YAML::Node encode(const Constant& rhs); |
|||
static bool decode(const YAML::Node& node, Constant& rhs); |
|||
}; |
|||
|
|||
template<> |
|||
struct YAML::convert<Property> { |
|||
static YAML::Node encode(const Property& rhs); |
|||
static bool decode(const YAML::Node& node, Property& rhs); |
|||
}; |
|||
|
|||
struct YamlConfigParseResult { |
|||
YamlConfigParseResult(std::vector<Configuration> configurations, std::vector<Property> probabilities) |
|||
: configurations_(configurations), properties_(probabilities) {} |
|||
|
|||
~YamlConfigParseResult() = default; |
|||
YamlConfigParseResult(const YamlConfigParseResult&) = default; |
|||
|
|||
std::vector<Configuration> configurations_; |
|||
std::vector<Property> properties_; |
|||
}; |
|||
|
|||
struct YamlConfigParser { |
|||
public: |
|||
YamlConfigParser(std::string file) : file_(file) {} |
|||
YamlConfigParser(const YamlConfigParser&) = delete; |
|||
~YamlConfigParser() = default; |
|||
|
|||
YamlConfigParseResult parseConfiguration(); |
|||
private: |
|||
|
|||
std::string file_; |
|||
}; |
@ -0,0 +1,200 @@ |
|||
#include "Grid.h"
|
|||
#include <boost/algorithm/string/find.hpp>
|
|||
|
|||
#include <algorithm>
|
|||
|
|||
Grid::Grid(cells gridCells, cells background, const std::map<coordinates, float> &stateRewards, const float probIntended, const float faultyProbability) |
|||
: allGridCells(gridCells), background(background), stateRewards(stateRewards), probIntended(probIntended), faultyProbability(faultyProbability) |
|||
{ |
|||
cell max = allGridCells.at(allGridCells.size() - 1); |
|||
maxBoundaries = std::make_pair(max.column - 1, max.row - 1); |
|||
std::copy_if(gridCells.begin(), gridCells.end(), std::back_inserter(walls), [](cell c) { return c.type == Type::Wall; }); |
|||
std::copy_if(gridCells.begin(), gridCells.end(), std::back_inserter(lava), [](cell c) { return c.type == Type::Lava; }); |
|||
std::copy_if(gridCells.begin(), gridCells.end(), std::back_inserter(floor), [](cell c) { return c.type == Type::Floor; }); // TODO CHECK IF ALL AGENTS ARE ADDED TO FLOOR
|
|||
std::copy_if(background.begin(), background.end(), std::back_inserter(slipperyNorth), [](cell c) { return c.type == Type::SlipperyNorth; }); |
|||
std::copy_if(background.begin(), background.end(), std::back_inserter(slipperyEast), [](cell c) { return c.type == Type::SlipperyEast; }); |
|||
std::copy_if(background.begin(), background.end(), std::back_inserter(slipperySouth), [](cell c) { return c.type == Type::SlipperySouth; }); |
|||
std::copy_if(background.begin(), background.end(), std::back_inserter(slipperyWest), [](cell c) { return c.type == Type::SlipperyWest; }); |
|||
std::copy_if(background.begin(), background.end(), std::back_inserter(slipperyNorthWest), [](cell c) { return c.type == Type::SlipperyNorthWest; }); |
|||
std::copy_if(background.begin(), background.end(), std::back_inserter(slipperyNorthEast), [](cell c) { return c.type == Type::SlipperyNorthEast; }); |
|||
std::copy_if(background.begin(), background.end(), std::back_inserter(slipperySouthWest), [](cell c) { return c.type == Type::SlipperySouthWest; }); |
|||
std::copy_if(background.begin(), background.end(), std::back_inserter(slipperySouthEast), [](cell c) { return c.type == Type::SlipperySouthEast; }); |
|||
std::copy_if(gridCells.begin(), gridCells.end(), std::back_inserter(lockedDoors), [](cell c) { return c.type == Type::LockedDoor; }); |
|||
std::copy_if(gridCells.begin(), gridCells.end(), std::back_inserter(unlockedDoors), [](cell c) { return c.type == Type::Door; }); |
|||
std::copy_if(gridCells.begin(), gridCells.end(), std::back_inserter(goals), [](cell c) { return c.type == Type::Goal; }); |
|||
std::copy_if(gridCells.begin(), gridCells.end(), std::back_inserter(keys), [](cell c) { return c.type == Type::Key; }); |
|||
std::copy_if(gridCells.begin(), gridCells.end(), std::back_inserter(boxes), [](cell c) { return c.type == Type::Box; }); |
|||
std::copy_if(gridCells.begin(), gridCells.end(), std::back_inserter(balls), [](cell c) { return c.type == Type::Ball; }); |
|||
std::copy_if(gridCells.begin(), gridCells.end(), std::back_inserter(adversaries), [](cell c) { return c.type == Type::Adversary; }); |
|||
agent = *std::find_if(gridCells.begin(), gridCells.end(), [](cell c) { return c.type == Type::Agent; }); |
|||
floor.push_back(agent); |
|||
|
|||
agentNameAndPositionMap.insert({ "Agent", agent.getCoordinates() }); |
|||
for(auto const& adversary : adversaries) { |
|||
std::string color = adversary.getColor(); |
|||
color.at(0) = std::toupper(color.at(0)); |
|||
try { |
|||
auto success = agentNameAndPositionMap.insert({ color, adversary.getCoordinates() }); |
|||
floor.push_back(adversary); |
|||
if(!success.second) { |
|||
throw std::logic_error("Agent with " + color + " already present\n"); |
|||
} |
|||
} catch(const std::logic_error& e) { |
|||
std::cerr << "Expected agents colors to be different. Agent with color : '" << color << "' already present." << std::endl; |
|||
throw; |
|||
} |
|||
} |
|||
for(auto const& key : keys) { |
|||
std::string color = key.getColor(); |
|||
try { |
|||
auto success = keyNameAndPositionMap.insert({color, key.getCoordinates() }); |
|||
if (!success.second) { |
|||
throw std::logic_error("Multiple keys with same color not supported " + color + "\n"); |
|||
} |
|||
} catch(const std::logic_error& e) { |
|||
std::cerr << "Expected key colors to be different. Key with color : '" << color << "' already present." << std::endl; |
|||
throw; |
|||
} |
|||
} |
|||
for(auto const& color : allColors) { |
|||
cells cellsOfColor; |
|||
std::copy_if(background.begin(), background.end(), std::back_inserter(cellsOfColor), [&color](cell c) { |
|||
return c.type == Type::Floor && c.color == color; |
|||
}); |
|||
if(cellsOfColor.size() > 0) { |
|||
backgroundTiles.emplace(color, cellsOfColor); |
|||
} |
|||
} |
|||
|
|||
if (adversaries.empty()) { |
|||
modelType = prism::ModelType::MDP; |
|||
} else { |
|||
modelType = prism::ModelType::SMG; |
|||
} |
|||
} |
|||
|
|||
std::ostream& operator<<(std::ostream& os, const Grid& grid) { |
|||
int lastRow = 1; |
|||
for(auto const& cell : grid.allGridCells) { |
|||
if(lastRow != cell.row) |
|||
os << std::endl; |
|||
os << static_cast<char>(cell.type) << static_cast<char>(cell.color); |
|||
lastRow = cell.row; |
|||
} |
|||
return os; |
|||
} |
|||
|
|||
cells Grid::getGridCells() { |
|||
return allGridCells; |
|||
} |
|||
|
|||
bool Grid::isBlocked(coordinates p) { |
|||
return isWall(p); |
|||
} |
|||
|
|||
bool Grid::isWall(coordinates p) { |
|||
return std::find_if(walls.begin(), walls.end(), |
|||
[p](cell cell) { |
|||
return cell.row == p.second && cell.column == p.first; |
|||
}) != walls.end(); |
|||
} |
|||
|
|||
|
|||
void Grid::applyOverwrites(std::string& str, std::vector<Configuration>& configuration) { |
|||
for (auto& config : configuration) { |
|||
if (!config.overwrite_) { |
|||
continue; |
|||
} |
|||
for (auto& index : config.indexes_) { |
|||
size_t start_pos; |
|||
std::string search; |
|||
|
|||
if (config.type_ == ConfigType::Formula) { |
|||
search = "formula " + config.identifier_; |
|||
} else if (config.type_ == ConfigType::Label) { |
|||
search = "label " + config.identifier_; |
|||
} else if (config.type_ == ConfigType::Module) { |
|||
search = config.identifier_; |
|||
} else if (config.type_ == ConfigType::UpdateOnly) { |
|||
search = config.identifier_; |
|||
} else if (config.type_ == ConfigType::GuardOnly) { |
|||
search = config.identifier_; |
|||
} |
|||
else if (config.type_ == ConfigType::Constant) { |
|||
search = config.identifier_; |
|||
} |
|||
|
|||
auto iter = boost::find_nth(str, search, index); |
|||
auto end_identifier = config.end_identifier_; |
|||
|
|||
start_pos = std::distance(str.begin(), iter.begin()); |
|||
size_t end_pos = str.find(end_identifier, start_pos); |
|||
|
|||
if (config.type_ == ConfigType::GuardOnly || config.type_ == ConfigType::Module) { |
|||
start_pos += search.length(); |
|||
} else if (config.type_ == ConfigType::UpdateOnly) { |
|||
start_pos = str.find("->", start_pos) + 2; |
|||
} |
|||
|
|||
if (end_pos != std::string::npos && end_pos != 0) { |
|||
std::string expression = config.expression_; |
|||
str.replace(start_pos, end_pos - start_pos , expression); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
void Grid::printToPrism(std::ostream& os, std::vector<Configuration>& configuration) { |
|||
cells northRestriction, eastRestriction, southRestriction, westRestriction; |
|||
cells walkable = floor; |
|||
walkable.insert(walkable.end(), goals.begin(), goals.end()); |
|||
walkable.insert(walkable.end(), boxes.begin(), boxes.end()); |
|||
walkable.insert(walkable.end(), lava.begin(), lava.end()); |
|||
walkable.insert(walkable.end(), keys.begin(), keys.end()); |
|||
walkable.insert(walkable.end(), balls.begin(), balls.end()); |
|||
|
|||
for(auto const& c : walkable) { |
|||
if(isWall(c.getNorth())) northRestriction.push_back(c); |
|||
if(isWall(c.getEast())) eastRestriction.push_back(c); |
|||
if(isWall(c.getSouth())) southRestriction.push_back(c); |
|||
if(isWall(c.getWest())) westRestriction.push_back(c); |
|||
} |
|||
|
|||
|
|||
std::map<std::string, cells> wallRestrictions = {{"North", northRestriction}, {"East", eastRestriction}, {"South", southRestriction}, {"West", westRestriction}}; |
|||
std::map<std::string, cells> slipperyTiles = {{"North", slipperyNorth}, {"East", slipperyEast}, {"South", slipperySouth}, {"West", slipperyWest}, {"NorthWest", slipperyNorthWest}, {"NorthEast", slipperyNorthEast},{"SouthWest", slipperySouthWest},{"SouthEast", slipperySouthEast}}; |
|||
|
|||
std::vector<AgentName> agentNames; |
|||
std::transform(agentNameAndPositionMap.begin(), |
|||
agentNameAndPositionMap.end(), |
|||
std::back_inserter(agentNames), |
|||
[](const std::map<AgentNameAndPosition::first_type,AgentNameAndPosition::second_type>::value_type &pair){return pair.first;}); |
|||
std::string agentName = agentNames.at(0); |
|||
|
|||
prism::PrismFormulaPrinter formulas(os, wallRestrictions, walls, lockedDoors, unlockedDoors, keys, slipperyTiles, lava, goals, agentNameAndPositionMap, faultyProbability > 0.0); |
|||
prism::PrismModulesPrinter modules(os, modelType, maxBoundaries, lockedDoors, unlockedDoors, keys, slipperyTiles, agentNameAndPositionMap, configuration, probIntended, faultyProbability, !lava.empty(), !goals.empty()); |
|||
|
|||
modules.printModelType(modelType); |
|||
for(const auto &agentName : agentNames) { |
|||
formulas.print(agentName); |
|||
} |
|||
if(agentNameAndPositionMap.size() > 1) formulas.printCollisionFormula(agentName); |
|||
formulas.printInitStruct(); |
|||
|
|||
modules.print(); |
|||
|
|||
|
|||
|
|||
|
|||
//if(!stateRewards.empty()) {
|
|||
// modules.printRewards(os, agentName, stateRewards, lava, goals, backgroundTiles);
|
|||
//}
|
|||
|
|||
//if (!configuration.empty()) {
|
|||
// modules.printConfiguration(os, configuration);
|
|||
//}
|
|||
} |
|||
|
|||
void Grid::setModelType(prism::ModelType type) |
|||
{ |
|||
modelType = type; |
|||
} |
@ -0,0 +1,67 @@ |
|||
#pragma once |
|||
|
|||
#include <iostream> |
|||
#include <fstream> |
|||
#include <map> |
|||
#include <utility> |
|||
|
|||
#include "MinigridGrammar.h" |
|||
#include "PrismPrinter.h" |
|||
#include "PrismModulesPrinter.h" |
|||
#include "PrismFormulaPrinter.h" |
|||
#include "ConfigYaml.h" |
|||
|
|||
class Grid { |
|||
public: |
|||
Grid(cells gridCells, cells background, const std::map<coordinates, float> &stateRewards = {}, const float probIntended = 1.0, const float faultyProbability = 0); |
|||
|
|||
cells getGridCells(); |
|||
|
|||
bool isBlocked(coordinates p); |
|||
bool isWall(coordinates p); |
|||
void printToPrism(std::ostream &os, std::vector<Configuration>& configuration); |
|||
void applyOverwrites(std::string& str, std::vector<Configuration>& configuration); |
|||
|
|||
void setModelType(prism::ModelType type); |
|||
|
|||
std::array<bool, 8> getWalkableDirOf8Neighborhood(cell c); |
|||
|
|||
friend std::ostream& operator<<(std::ostream& os, const Grid &grid); |
|||
|
|||
private: |
|||
cells allGridCells; |
|||
cells background; |
|||
coordinates maxBoundaries; |
|||
|
|||
prism::ModelType modelType; |
|||
|
|||
cell agent; |
|||
cells adversaries; |
|||
AgentNameAndPositionMap agentNameAndPositionMap; |
|||
KeyNameAndPositionMap keyNameAndPositionMap; |
|||
|
|||
cells walls; |
|||
cells floor; |
|||
cells slipperyNorth; |
|||
cells slipperyEast; |
|||
cells slipperySouth; |
|||
cells slipperyWest; |
|||
cells slipperyNorthWest; |
|||
cells slipperyNorthEast; |
|||
cells slipperySouthWest; |
|||
cells slipperySouthEast; |
|||
cells lockedDoors; |
|||
cells unlockedDoors; |
|||
cells boxes; |
|||
cells balls; |
|||
cells lava; |
|||
|
|||
cells goals; |
|||
cells keys; |
|||
|
|||
std::map<Color, cells> backgroundTiles; |
|||
|
|||
std::map<coordinates, float> stateRewards; |
|||
const float probIntended; |
|||
const float faultyProbability; |
|||
}; |
@ -0,0 +1,107 @@ |
|||
#pragma once |
|||
|
|||
#include "cell.h" |
|||
|
|||
#include <vector> |
|||
|
|||
#include <boost/tokenizer.hpp> |
|||
#include <boost/fusion/adapted/struct.hpp> |
|||
#include <boost/spirit/include/qi.hpp> |
|||
#include <boost/spirit/include/phoenix.hpp> |
|||
#include <boost/spirit/include/phoenix_operator.hpp> |
|||
#include <boost/variant/recursive_wrapper.hpp> |
|||
#include <boost/spirit/include/support_line_pos_iterator.hpp> |
|||
|
|||
namespace qi = boost::spirit::qi; |
|||
namespace phoenix = boost::phoenix; |
|||
|
|||
typedef boost::spirit::line_pos_iterator<std::string::const_iterator> pos_iterator_t; |
|||
|
|||
typedef std::vector<cell> row; |
|||
typedef std::vector<cell> cells; |
|||
|
|||
BOOST_FUSION_ADAPT_STRUCT( |
|||
cell, |
|||
(Type, type) |
|||
(Color, color) |
|||
) |
|||
|
|||
template<typename It> |
|||
struct annotation_f { |
|||
typedef void result_type; |
|||
|
|||
annotation_f(It first) : first(first) {} |
|||
It const first; |
|||
|
|||
template<typename Val, typename First, typename Last> |
|||
void operator()(Val& v, First f, Last l) const { |
|||
do_annotate(v, f, l, first); |
|||
} |
|||
|
|||
private: |
|||
void static do_annotate(cell& c, It f, It l, It first) { |
|||
c.row = get_line(f) - 1; |
|||
c.column = get_column(first, f) / 2; |
|||
} |
|||
static void do_annotate(...) { std::cerr << "(not having LocationInfo)\n"; } |
|||
}; |
|||
|
|||
template <typename It> |
|||
struct MinigridParser : qi::grammar<It, row()> |
|||
{ |
|||
MinigridParser(It first) : MinigridParser::base_type(row_), annotate(first) |
|||
{ |
|||
using namespace qi; |
|||
type_.add |
|||
("W", Type::Wall) |
|||
(" ", Type::Floor) |
|||
("D", Type::Door) |
|||
("L", Type::LockedDoor) |
|||
("K", Type::Key) |
|||
("A", Type::Ball) |
|||
("B", Type::Box) |
|||
("G", Type::Goal) |
|||
("V", Type::Lava) |
|||
("n", Type::SlipperyNorth) |
|||
("e", Type::SlipperyEast) |
|||
("s", Type::SlipperySouth) |
|||
("w", Type::SlipperyWest) |
|||
("a", Type::SlipperyNorthWest) |
|||
("b", Type::SlipperyNorthEast) |
|||
("c", Type::SlipperySouthWest) |
|||
("d", Type::SlipperySouthEast) |
|||
("X", Type::Agent) |
|||
("Z", Type::Adversary); |
|||
color_.add |
|||
("R", Color::Red) |
|||
("G", Color::Green) |
|||
("B", Color::Blue) |
|||
("P", Color::Purple) |
|||
("Y", Color::Yellow) |
|||
("W", Color::White) |
|||
(" ", Color::None); |
|||
|
|||
cell_ = type_ > color_; |
|||
|
|||
row_ = (cell_ % -qi::char_("\n")); |
|||
|
|||
auto set_location_info = annotate(_val, _1, _3); |
|||
on_success(cell_, set_location_info); |
|||
|
|||
BOOST_SPIRIT_DEBUG_NODE(type_); |
|||
BOOST_SPIRIT_DEBUG_NODE(color_); |
|||
BOOST_SPIRIT_DEBUG_NODE(cell_); |
|||
} |
|||
|
|||
private: |
|||
phoenix::function<annotation_f<It>> annotate; |
|||
|
|||
qi::symbols<char, Type> type_; |
|||
qi::symbols<char, Color> color_; |
|||
|
|||
qi::rule<It, cell()> cell_; |
|||
qi::rule<It, row()> row_; |
|||
}; |
|||
|
|||
typedef boost::tokenizer< boost::escaped_list_separator<char> , std::string::const_iterator, std::string> Tokenizer; |
|||
//std::ostream& operator<<(std::ostream& os, const row& r); |
@ -0,0 +1,32 @@ |
|||
#include <iostream>
|
|||
|
|||
#include "popl.hpp"
|
|||
#include "OptionParser.h"
|
|||
|
|||
namespace io { |
|||
int printPoplException(const popl::invalid_option &e) { |
|||
std::cerr << "Invalid Option Exception: " << e.what() << "\n"; |
|||
std::cerr << "error: "; |
|||
if (e.error() == popl::invalid_option::Error::missing_argument) { |
|||
std::cerr << "missing_argument\n"; |
|||
} else if (e.error() == popl::invalid_option::Error::invalid_argument) { |
|||
std::cerr << "invalid_argument\n"; |
|||
} else if (e.error() == popl::invalid_option::Error::too_many_arguments) { |
|||
std::cerr << "too_many_arguments\n"; |
|||
} else if (e.error() == popl::invalid_option::Error::missing_option) { |
|||
std::cerr << "missing_option\n"; |
|||
} |
|||
|
|||
if (e.error() == popl::invalid_option::Error::missing_option) { |
|||
std::string option_name(e.option()->name(popl::OptionName::short_name, true)); |
|||
if (option_name.empty()) |
|||
option_name = e.option()->name(popl::OptionName::long_name, true); |
|||
std::cerr << "option: " << option_name << "\n"; |
|||
} |
|||
else { |
|||
std::cerr << "option: " << e.option()->name(e.what_name()) << "\n"; |
|||
std::cerr << "value: " << e.value() << "\n"; |
|||
} |
|||
return EXIT_FAILURE; |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
#pragma once |
|||
|
|||
#include <iostream> |
|||
|
|||
#include "popl.hpp" |
|||
|
|||
#define INPUT_ERROR 1 |
|||
#define INPUT_OK 0 |
|||
|
|||
namespace io { |
|||
int printPoplException(const popl::invalid_option &e); |
|||
|
|||
} |
@ -0,0 +1,243 @@ |
|||
#include "PrismFormulaPrinter.h"
|
|||
|
|||
#include <map>
|
|||
#include <string>
|
|||
#include <algorithm>
|
|||
|
|||
|
|||
std::string oneOffToString(const int &offset) { |
|||
return offset != 0 ? ( offset == 1 ? "+1" : "-1" ) : ""; |
|||
} |
|||
|
|||
std::string vectorToDisjunction(const std::vector<std::string> &formulae) { |
|||
bool first = true; |
|||
std::string disjunction = ""; |
|||
for(const auto &formula : formulae) { |
|||
if(first) first = false; |
|||
else disjunction += " | "; |
|||
disjunction += formula; |
|||
} |
|||
return disjunction; |
|||
} |
|||
|
|||
std::string cellToConjunction(const AgentName &agentName, const cell &c) { |
|||
return "col" + agentName + "=" + std::to_string(c.column) + "&row" + agentName + "=" + std::to_string(c.row); |
|||
} |
|||
|
|||
std::string cellToConjunctionWithOffset(const AgentName &agentName, const cell &c, const std::string &xOffset, const std::string &yOffset){ |
|||
return "col" + agentName + xOffset + "=" + std::to_string(c.column) + "&row" + agentName + yOffset + "=" + std::to_string(c.row); |
|||
} |
|||
|
|||
std::string coordinatesToConjunction(const AgentName &agentName, const coordinates &c, const ViewDirection viewDirection) { |
|||
return "col" + agentName + "=" + std::to_string(c.first) + "&row" + agentName + "=" + std::to_string(c.second) + "&view" + agentName + "=" + std::to_string(viewDirection); |
|||
} |
|||
|
|||
std::string objectPositionToConjunction(const AgentName &agentName, const std::string &identifier, const std::pair<int, int> &relativePosition) { |
|||
std::string xOffset = oneOffToString(relativePosition.first); |
|||
std::string yOffset = oneOffToString(relativePosition.second); |
|||
return "col" + agentName + xOffset + "=col" + identifier + "&row" + agentName + yOffset + "=row" + identifier; |
|||
} |
|||
std::string objectPositionToConjunction(const AgentName &agentName, const std::string &identifier, const std::pair<int, int> &relativePosition, const ViewDirection viewDirection) { |
|||
std::string xOffset = oneOffToString(relativePosition.first); |
|||
std::string yOffset = oneOffToString(relativePosition.second); |
|||
return "col" + agentName + xOffset + "=col" + identifier + "&row" + agentName + yOffset + "=row" + identifier + "&view" + agentName + "=" + std::to_string(viewDirection); |
|||
} |
|||
|
|||
std::map<ViewDirection, coordinates> getAdjacentCells(const cell &c) { |
|||
return {{1, c.getNorth()}, {2, c.getEast()}, {3, c.getSouth()}, {0, c.getWest()}}; |
|||
} |
|||
|
|||
std::map<ViewDirection, std::pair<int, int>> getRelativeAdjacentCells() { |
|||
return { {1, {0,+1}}, {2, {-1,0}}, {3, {0,-1}}, {0, {+1,0}} }; |
|||
} |
|||
|
|||
std::map<std::string, std::pair<int, int>> getRelativeSurroundingCells() { |
|||
return { {"NorthWest", {-1,-1}}, {"North", { 0,-1}}, {"NorthEast", {+1,-1}}, |
|||
{"West", {-1, 0}}, {"East", {+1, 0}}, |
|||
{"SouthWest", {-1,+1}}, {"South", { 0,+1}}, {"SouthEast", {+1,+1}} }; |
|||
} |
|||
|
|||
namespace prism { |
|||
PrismFormulaPrinter::PrismFormulaPrinter(std::ostream &os, const std::map<std::string, cells> &restrictions, const cells &walls, const cells &lockedDoors, const cells &unlockedDoors, const cells &keys, const std::map<std::string, cells> &slipperyTiles, const cells &lava, const cells &goals, const AgentNameAndPositionMap &agentNameAndPositionMap, const bool faulty) |
|||
: os(os), restrictions(restrictions), walls(walls), lockedDoors(lockedDoors), unlockedDoors(unlockedDoors), keys(keys), slipperyTiles(slipperyTiles), lava(lava), goals(goals), agentNameAndPositionMap(agentNameAndPositionMap), faulty(faulty) |
|||
{ } |
|||
|
|||
void PrismFormulaPrinter::print(const AgentName &agentName) { |
|||
conditionalMovementRestrictions.clear(); |
|||
for(const auto& [direction, cells] : restrictions) { |
|||
printRestrictionFormula(agentName, direction, cells); |
|||
} |
|||
|
|||
if(slipperyBehaviour()) { |
|||
for(const auto& [direction, cells] : slipperyTiles) { |
|||
printIsOnFormula(agentName, "Slippery", cells, direction); |
|||
} |
|||
std::vector<std::string> allSlipperyDirections; |
|||
for(const auto &[slipperyType, _] : slipperyTiles) { |
|||
allSlipperyDirections.push_back(agentName + "IsOnSlippery" + slipperyType); |
|||
} |
|||
os << buildFormula(agentName + "IsOnSlippery", vectorToDisjunction(allSlipperyDirections)); |
|||
|
|||
for(const auto& [direction, relativePosition] : getRelativeSurroundingCells()) { |
|||
printSlipRestrictionFormula(agentName, direction); |
|||
} |
|||
} else { |
|||
os << buildFormula(agentName + "IsOnSlippery", "false"); |
|||
} |
|||
if(!lava.empty()) printIsOnFormula(agentName, "Lava", lava); |
|||
if(!goals.empty()) printIsOnFormula(agentName, "Goal", goals); |
|||
|
|||
|
|||
for(const auto& key : keys) { |
|||
std::string identifier = capitalize(key.getColor()) + key.getType(); |
|||
printRelativeIsInFrontOfFormulaWithCondition(agentName, identifier, "!" + identifier + "PickedUp"); |
|||
portableObjects.push_back(agentName + "Carrying" + identifier); |
|||
} |
|||
|
|||
for(const auto& door : unlockedDoors) { |
|||
std::string identifier = capitalize(door.getColor()) + door.getType(); |
|||
printRestrictionFormulaWithCondition(agentName, identifier, getAdjacentCells(door), "!" + identifier + "Open"); |
|||
printIsNextToFormula(agentName, identifier, getAdjacentCells(door)); |
|||
} |
|||
|
|||
for(const auto& door : lockedDoors) { |
|||
std::string identifier = capitalize(door.getColor()) + door.getType(); |
|||
printRestrictionFormulaWithCondition(agentName, identifier, getAdjacentCells(door), "!" + identifier + "Open"); |
|||
printIsNextToFormula(agentName, identifier, getAdjacentCells(door)); |
|||
} |
|||
|
|||
if(conditionalMovementRestrictions.size() > 0) { |
|||
os << buildFormula(agentName + "CannotMoveConditionally", vectorToDisjunction(conditionalMovementRestrictions)); |
|||
} |
|||
if(portableObjects.size() > 0) { |
|||
os << buildFormula(agentName + "IsCarrying", vectorToDisjunction(portableObjects)); |
|||
} |
|||
} |
|||
|
|||
void PrismFormulaPrinter::printRestrictionFormula(const AgentName &agentName, const std::string &direction, const cells &grid_cells) { |
|||
os << buildFormula(agentName + "CannotMove" + direction + "Wall", buildDisjunction(agentName, grid_cells)); |
|||
} |
|||
|
|||
void PrismFormulaPrinter::printIsOnFormula(const AgentName &agentName, const std::string &type, const cells &grid_cells, const std::string &direction) { |
|||
os << buildFormula(agentName + "IsOn" + type + direction, buildDisjunction(agentName, grid_cells)); |
|||
} |
|||
|
|||
void PrismFormulaPrinter::printIsNextToFormula(const AgentName &agentName, const std::string &type, const std::map<ViewDirection, coordinates> &coordinates) { |
|||
os << buildFormula(agentName + "IsNextTo" + type, buildDisjunction(agentName, coordinates)); |
|||
} |
|||
|
|||
void PrismFormulaPrinter::printRestrictionFormulaWithCondition(const AgentName &agentName, const std::string &reason, const std::map<ViewDirection, coordinates> &coordinates, const std::string &condition) { |
|||
os << buildFormula(agentName + "CannotMove" + reason, "(" + buildDisjunction(agentName, coordinates) + ") & " + condition); |
|||
conditionalMovementRestrictions.push_back(agentName + "CannotMove" + reason); |
|||
} |
|||
|
|||
void PrismFormulaPrinter::printRelativeIsInFrontOfFormulaWithCondition(const AgentName &agentName, const std::string &reason, const std::string &condition) { |
|||
os << buildFormula(agentName + "IsInFrontOf" + reason, "(" + buildDisjunction(agentName, reason) + ") & " + condition); |
|||
} |
|||
|
|||
void PrismFormulaPrinter::printSlipRestrictionFormula(const AgentName &agentName, const std::string &direction) { |
|||
std::pair<int, int> slipCell = getRelativeSurroundingCells().at(direction); |
|||
bool semicolon = anyPortableObject() ? false : true; |
|||
os << buildFormula(agentName + "CannotSlip" + direction, buildDisjunction(agentName, walls, slipCell), semicolon); |
|||
if(!semicolon) os << ";\n"; |
|||
} |
|||
|
|||
void PrismFormulaPrinter::printCollisionFormula(const AgentName &agentName) { |
|||
if(!agentNameAndPositionMap.empty()) { |
|||
os << "formula collision = "; |
|||
bool first = true; |
|||
for(auto const [name, coordinates] : agentNameAndPositionMap) { |
|||
if(name == agentName) continue; |
|||
if(first) first = false; |
|||
else os << " | "; |
|||
os << "(col"+agentName+"=col"+name+"&row"+agentName+"=row"+name+")"; |
|||
} |
|||
os << ";\n"; |
|||
printCollisionLabel(); |
|||
} |
|||
} |
|||
|
|||
void PrismFormulaPrinter::printCollisionLabel() { |
|||
if(!agentNameAndPositionMap.empty()) { |
|||
os << "label \"collision\" = collision;\n"; |
|||
} |
|||
} |
|||
|
|||
void PrismFormulaPrinter::printInitStruct() { |
|||
os << "init\n true\n"; |
|||
//bool first = true;
|
|||
//for(auto const [a, coordinates] : agentNameAndPositionMap) {
|
|||
// if(first) first = false;
|
|||
// else os << " & ";
|
|||
// os << "(col"+a+"="+std::to_string(coordinates.first)+"&row"+a+"="+std::to_string(coordinates.second)+" & ";
|
|||
// os << "(view"+a+"=0|view"+a+"=1|view"+a+"=2|view"+a+"=3) ";
|
|||
// if(faulty) os << " & previousAction"+a+"="+std::to_string(NOFAULT);
|
|||
// os << ")";
|
|||
//}
|
|||
//for(auto const key : keys) {
|
|||
// std::string identifier = capitalize(key.getColor()) + key.getType();
|
|||
// os << " & (col"+identifier+"="+std::to_string(key.column)+"&row"+identifier+"="+std::to_string(key.row)+"&"+identifier+"PickedUp=false) ";
|
|||
//}
|
|||
os << "endinit\n\n"; |
|||
} |
|||
|
|||
|
|||
std::string PrismFormulaPrinter::buildFormula(const std::string &formulaName, const std::string &formula, const bool semicolon) { |
|||
return "formula " + formulaName + " = " + formula + (semicolon ? ";\n": ""); |
|||
} |
|||
|
|||
std::string PrismFormulaPrinter::buildDisjunction(const AgentName &agentName, const std::map<ViewDirection, coordinates> &cells) { |
|||
if(cells.size() == 0) return "false"; |
|||
bool first = true; |
|||
std::string disjunction = ""; |
|||
for(const auto [viewDirection, coordinates] : cells) { |
|||
if(first) first = false; |
|||
else disjunction += " | "; |
|||
disjunction += "(" + coordinatesToConjunction(agentName, coordinates, viewDirection) + ")"; |
|||
} |
|||
return disjunction; |
|||
} |
|||
|
|||
std::string PrismFormulaPrinter::buildDisjunction(const AgentName &agentName, const cells &cells) { |
|||
if(cells.size() == 0) return "false"; |
|||
bool first = true; |
|||
std::string disjunction = ""; |
|||
for(auto const cell : cells) { |
|||
if(first) first = false; |
|||
else disjunction += " | "; |
|||
disjunction += "(" + cellToConjunction(agentName, cell) + ")"; |
|||
} |
|||
return disjunction; |
|||
} |
|||
|
|||
std::string PrismFormulaPrinter::buildDisjunction(const AgentName &agentName, const std::string &reason) { |
|||
std::string disjunction = ""; |
|||
bool first = true; |
|||
for(auto const [viewDirection, relativePosition] : getRelativeAdjacentCells()) { |
|||
if(first) first = false; |
|||
else disjunction += " | "; |
|||
disjunction += "(" + objectPositionToConjunction(agentName, reason, relativePosition, viewDirection) + ")"; |
|||
} |
|||
return disjunction; |
|||
} |
|||
|
|||
std::string PrismFormulaPrinter::buildDisjunction(const AgentName &agentName, const cells &cells, const std::pair<int, int> &offset) { |
|||
std::string disjunction = ""; |
|||
bool first = true; |
|||
std::string xOffset = oneOffToString(offset.first); |
|||
std::string yOffset = oneOffToString(offset.second); |
|||
for(auto const cell : cells) { |
|||
if(first) first = false; |
|||
else disjunction += " | "; |
|||
disjunction += "(" + cellToConjunctionWithOffset(agentName, cell, xOffset, yOffset) + ")"; |
|||
} |
|||
return disjunction; |
|||
} |
|||
|
|||
bool PrismFormulaPrinter::slipperyBehaviour() const { |
|||
return !slipperyTiles.at("North").empty() || !slipperyTiles.at("East").empty() || !slipperyTiles.at("South").empty() || !slipperyTiles.at("West").empty(); |
|||
} |
|||
bool PrismFormulaPrinter::anyPortableObject() const { |
|||
return !keys.empty(); |
|||
} |
|||
} |
@ -0,0 +1,68 @@ |
|||
#pragma once |
|||
|
|||
#include <iostream> |
|||
#include <functional> |
|||
#include "MinigridGrammar.h" |
|||
#include "PrismPrinter.h" |
|||
#include "ConfigYaml.h" |
|||
|
|||
|
|||
std::string oneOffToString(const int &offset); |
|||
std::string vectorToDisjunction(const std::vector<std::string> &formulae); |
|||
std::string cellToConjunction(const AgentName &agentName, const cell &c); |
|||
std::string cellToConjunctionWithOffset(const AgentName &agentName, const cell &c, const std::string &xOffset, const std::string &yOffset); |
|||
std::string coordinatesToConjunction(const AgentName &agentName, const coordinates &c, const ViewDirection viewDirection); |
|||
std::string objectPositionToConjunction(const AgentName &agentName, const std::string &identifier, const std::pair<int, int> &relativePosition); |
|||
std::string objectPositionToConjunction(const AgentName &agentName, const std::string &identifier, const std::pair<int, int> &relativePosition, const ViewDirection viewDirection); |
|||
std::map<ViewDirection, coordinates> getAdjacentCells(const cell &c); |
|||
std::map<ViewDirection, std::pair<int, int>> getRelativeAdjacentCells(); |
|||
std::map<std::string, std::pair<int, int>> getRelativeSurroundingCells(); |
|||
|
|||
namespace prism { |
|||
class PrismFormulaPrinter { |
|||
public: |
|||
PrismFormulaPrinter(std::ostream &os, const std::map<std::string, cells> &restrictions, const cells &walls, const cells &lockedDoors, const cells &unlockedDoors, const cells &keys, const std::map<std::string, cells> &slipperyTiles, const cells &lava, const cells &goals, const AgentNameAndPositionMap &agentNameAndPositionMap, const bool faulty); |
|||
|
|||
void print(const AgentName &agentName); |
|||
|
|||
void printRestrictionFormula(const AgentName &agentName, const std::string &direction, const cells &grid_cells); |
|||
void printIsOnFormula(const AgentName &agentName, const std::string &type, const cells &grid_cells, const std::string &direction = ""); |
|||
void printIsNextToFormula(const AgentName &agentName, const std::string &type, const std::map<ViewDirection, coordinates> &coordinates); |
|||
void printRestrictionFormulaWithCondition(const AgentName &agentName, const std::string &reason, const std::map<ViewDirection, coordinates> &coordinates, const std::string &condition); |
|||
void printRelativeIsInFrontOfFormulaWithCondition(const AgentName &agentName, const std::string &reason, const std::string &condition); |
|||
void printSlipRestrictionFormula(const AgentName &agentName, const std::string &direction); |
|||
|
|||
void printCollisionFormula(const std::string &agentName); |
|||
void printCollisionLabel(); |
|||
|
|||
void printInitStruct(); |
|||
private: |
|||
std::string buildFormula(const std::string &formulaName, const std::string &formula, const bool semicolon = true); |
|||
std::string buildLabel(const std::string &labelName, const std::string &label); |
|||
std::string buildDisjunction(const AgentName &agentName, const std::map<ViewDirection, coordinates> &cells); |
|||
std::string buildDisjunction(const AgentName &agentName, const cells &cells); |
|||
std::string buildDisjunction(const AgentName &agentName, const std::string &reason); |
|||
std::string buildDisjunction(const AgentName &agentName, const cells &cells, const std::pair<int, int> &offset); |
|||
|
|||
bool slipperyBehaviour() const; |
|||
bool anyPortableObject() const; |
|||
|
|||
|
|||
std::ostream &os; |
|||
std::map<std::string, cells> restrictions; |
|||
cells walls; |
|||
cells lockedDoors; |
|||
cells unlockedDoors; |
|||
cells keys; |
|||
std::map<std::string, cells> slipperyTiles; |
|||
cells lava; |
|||
cells goals; |
|||
|
|||
AgentNameAndPositionMap agentNameAndPositionMap; |
|||
|
|||
std::vector<std::string> conditionalMovementRestrictions; |
|||
std::vector<std::string> portableObjects; |
|||
|
|||
bool faulty; |
|||
}; |
|||
} |
@ -0,0 +1,742 @@ |
|||
#include "PrismModulesPrinter.h"
|
|||
|
|||
#include <map>
|
|||
#include <string>
|
|||
#include <stdexcept>
|
|||
|
|||
|
|||
std::string northUpdate(const AgentName &a) { return "(row"+a+"'=row"+a+"-1)"; } |
|||
std::string southUpdate(const AgentName &a) { return "(row"+a+"'=row"+a+"+1)"; } |
|||
std::string eastUpdate(const AgentName &a) { return "(col"+a+"'=col"+a+"+1)"; } |
|||
std::string westUpdate(const AgentName &a) { return "(col"+a+"'=col"+a+"-1)"; } |
|||
|
|||
namespace prism { |
|||
|
|||
PrismModulesPrinter::PrismModulesPrinter(std::ostream& os, const ModelType &modelType, const coordinates &maxBoundaries, const cells &lockedDoors, const cells &unlockedDoors, const cells &keys, const std::map<std::string, cells> &slipperyTiles, const AgentNameAndPositionMap &agentNameAndPositionMap, std::vector<Configuration> config, const float probIntended, const float faultyProbability, const bool anyLava, const bool anyGoals) |
|||
: os(os), modelType(modelType), maxBoundaries(maxBoundaries), lockedDoors(lockedDoors), unlockedDoors(unlockedDoors), keys(keys), slipperyTiles(slipperyTiles), agentNameAndPositionMap(agentNameAndPositionMap), configuration(config), probIntended(probIntended), faultyProbability(faultyProbability), anyLava(anyLava), anyGoals(anyGoals) { |
|||
numberOfPlayer = agentNameAndPositionMap.size(); |
|||
size_t index = 0; |
|||
for(auto begin = agentNameAndPositionMap.begin(); begin != agentNameAndPositionMap.end(); begin++, index++) { |
|||
agentIndexMap[begin->first] = index; |
|||
} |
|||
} |
|||
|
|||
void PrismModulesPrinter::printModelType(const ModelType &modelType) { |
|||
switch(modelType) { |
|||
case(ModelType::MDP): |
|||
os << "mdp"; |
|||
break; |
|||
case(ModelType::SMG): |
|||
os << "smg"; |
|||
break; |
|||
} |
|||
os << "\n\n"; |
|||
} |
|||
|
|||
std::ostream& PrismModulesPrinter::print() { |
|||
for(const auto [agentName, initialPosition] : agentNameAndPositionMap) { |
|||
agentNameActionMap[agentName] = {}; |
|||
} |
|||
|
|||
for(const auto &key : keys) { |
|||
printPortableObjectModule(key); |
|||
} |
|||
for(const auto &door : unlockedDoors) { |
|||
printDoorModule(door, true); |
|||
} |
|||
for(const auto &door : lockedDoors) { |
|||
printDoorModule(door, false); |
|||
} |
|||
|
|||
for(const auto [agentName, initialPosition] : agentNameAndPositionMap) { |
|||
printRobotModule(agentName, initialPosition); |
|||
} |
|||
|
|||
if(agentNameAndPositionMap.size() > 1) { |
|||
printMoveModule(); |
|||
} |
|||
|
|||
if(faultyBehaviour()) { |
|||
for(const auto [agentName, initialPosition] : agentNameAndPositionMap) { |
|||
printFaultyMovementModule(agentName); |
|||
} |
|||
} |
|||
|
|||
if(agentNameAndPositionMap.size() > 1) { |
|||
for(const auto [agentName, index] : agentIndexMap) { |
|||
printPlayerStruct(agentName); |
|||
} |
|||
} |
|||
|
|||
if (!configuration.empty()) { |
|||
printConfiguration(configuration); |
|||
} |
|||
|
|||
return os; |
|||
} |
|||
|
|||
|
|||
void PrismModulesPrinter::printConfiguration(const std::vector<Configuration>& configurations) { |
|||
for (auto& configuration : configurations) { |
|||
if (configuration.overwrite_ || configuration.type_ == ConfigType::Module) { |
|||
continue; |
|||
} |
|||
os << configuration.expression_ << std::endl; |
|||
} |
|||
} |
|||
|
|||
void PrismModulesPrinter::printConstants(const std::vector<std::string> &constants) { |
|||
for (auto& constant : constants) { |
|||
os << constant << std::endl; |
|||
} |
|||
} |
|||
|
|||
void PrismModulesPrinter::printPortableObjectModule(const cell &object) { |
|||
std::string identifier = capitalize(object.getColor()) + object.getType(); |
|||
os << "\nmodule " << identifier << std::endl; |
|||
os << " col" << identifier << " : [-1.." << maxBoundaries.first << "];\n"; |
|||
os << " row" << identifier << " : [-1.." << maxBoundaries.second << "];\n"; |
|||
os << " " << identifier << "PickedUp : bool;\n"; |
|||
os << "\n"; |
|||
|
|||
for(const auto [name, position] : agentNameAndPositionMap) { |
|||
printPortableObjectActions(name, identifier); |
|||
} |
|||
os << "endmodule\n\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printPortableObjectActions(const std::string &agentName, const std::string &identifier, const bool canBeDroped) { |
|||
std::string actionName = "[" + agentName + "_pickup_" + identifier + "]"; |
|||
agentNameActionMap.at(agentName).insert({PICKUP, actionName}); |
|||
os << " " << actionName << " true -> (col" << identifier << "'=-1) & (row" << identifier << "'=-1) & (" << identifier << "PickedUp'=true);\n"; |
|||
if(canBeDroped) { |
|||
actionName = "[" + agentName + "_drop_" + identifier + "_north]"; |
|||
agentNameActionMap.at(agentName).insert({DROP, actionName}); |
|||
os << " " << actionName << " " << " true -> (col" << identifier << "'=col" << agentName << ") & (row" << identifier << "'=row" << agentName << "-1) & (" << identifier << "PickedUp'=false);\n"; |
|||
actionName = "[" + agentName + "_drop_" + identifier + "_west]"; |
|||
agentNameActionMap.at(agentName).insert({DROP, actionName}); |
|||
os << " " << actionName << " " << " true -> (col" << identifier << "'=col" << agentName << "-1) & (row" << identifier << "'=row" << agentName << ") & (" << identifier << "PickedUp'=false);\n"; |
|||
actionName = "[" + agentName + "_drop_" + identifier + "_south]"; |
|||
agentNameActionMap.at(agentName).insert({DROP, actionName}); |
|||
os << " " << actionName << " " << " true -> (col" << identifier << "'=col" << agentName << ") & (row" << identifier << "'=row" << agentName << "+1) & (" << identifier << "PickedUp'=false);\n"; |
|||
actionName = "[" + agentName + "_drop_" + identifier + "_east]"; |
|||
agentNameActionMap.at(agentName).insert({DROP, actionName}); |
|||
os << " " << actionName << " " << " true -> (col" << identifier << "'=col" << agentName << "+1) & (row" << identifier << "'=row" << agentName << ") & (" << identifier << "PickedUp'=false);\n"; |
|||
} |
|||
} |
|||
|
|||
void PrismModulesPrinter::printDoorModule(const cell &door, const bool &opened) { |
|||
std::string identifier = capitalize(door.getColor()) + door.getType(); |
|||
os << "\nmodule " << identifier << std::endl; |
|||
os << " " << identifier << "Open : bool;\n"; |
|||
os << "\n"; |
|||
|
|||
if(opened) { |
|||
for(const auto [name, position] : agentNameAndPositionMap) { |
|||
printUnlockedDoorActions(name, identifier); |
|||
} |
|||
} else { |
|||
for(const auto [name, position] : agentNameAndPositionMap) { |
|||
printLockedDoorActions(name, identifier); |
|||
} |
|||
} |
|||
os << "endmodule\n\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printLockedDoorActions(const std::string &agentName, const std::string &identifier) { |
|||
std::string actionName = "[" + agentName + "_toggle_" + identifier + "]"; |
|||
agentNameActionMap.at(agentName).insert({NOFAULT, actionName}); |
|||
os << " " << actionName << " !" << identifier << "Open -> (" << identifier << "Open'=true);\n"; |
|||
actionName = "[" + agentName + "_toggle_" + identifier + "]"; |
|||
agentNameActionMap.at(agentName).insert({NOFAULT, actionName}); |
|||
os << " " << actionName << " " << identifier << "Open -> (" << identifier << "Open'=false);\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printUnlockedDoorActions(const std::string &agentName, const std::string &identifier) { |
|||
std::string actionName = "[" + agentName + "_toggle_" + identifier + "]"; |
|||
agentNameActionMap.at(agentName).insert({NOFAULT, actionName}); |
|||
os << " " << actionName << " !" << identifier << "Open -> (" << identifier << "Open'=true);\n"; |
|||
actionName = "[" + agentName + "_toggle_" + identifier + "]"; |
|||
agentNameActionMap.at(agentName).insert({NOFAULT, actionName}); |
|||
os << " " << actionName << " " << identifier << "Open -> (" << identifier << "Open'=false);\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printRobotModule(const AgentName &agentName, const coordinates &initialPosition) { |
|||
os << "\nmodule " << agentName << std::endl; |
|||
os << " col" << agentName << " : [1.." << maxBoundaries.first << "];\n"; |
|||
os << " row" << agentName << " : [1.." << maxBoundaries.second << "];\n"; |
|||
os << " view" << agentName << " : [0..3];\n"; |
|||
|
|||
printTurnActionsForRobot(agentName); |
|||
printMovementActionsForRobot(agentName); |
|||
if(slipperyBehaviour()) printSlipperyMovementActionsForRobot(agentName); |
|||
|
|||
for(const auto &door : unlockedDoors) { |
|||
std::string identifier = capitalize(door.getColor()) + door.getType(); |
|||
printUnlockedDoorActionsForRobot(agentName, identifier); |
|||
} |
|||
|
|||
for(const auto &door : lockedDoors) { |
|||
std::string identifier = capitalize(door.getColor()) + door.getType(); |
|||
std::string key = capitalize(door.getColor()) + "Key"; |
|||
printLockedDoorActionsForRobot(agentName, identifier, key); |
|||
} |
|||
|
|||
for(const auto &key : keys) { |
|||
std::string identifier = capitalize(key.getColor()) + key.getType(); |
|||
os << " " << agentName << "Carrying" << identifier << " : bool;\n"; |
|||
printPortableObjectActionsForRobot(agentName, identifier); |
|||
} |
|||
|
|||
//printNonMovementActionsForRobot(agentName);
|
|||
|
|||
|
|||
os << "\n" << actionStream.str(); |
|||
actionStream.str(std::string()); |
|||
|
|||
if(agentNameAndPositionMap.size() > 1 && agentName == "Agent" && anyGoals) printDoneActions(agentName); |
|||
os << "endmodule\n\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printPortableObjectActionsForRobot(const std::string &a, const std::string &i, const bool canBeDroped) { |
|||
actionStream << " [" << a << "_pickup_" << i << "] " << " !" << a << "IsCarrying & " << a << "IsInFrontOf" << i << " -> (" << a << "Carrying" << i << "'=true);\n"; |
|||
if(canBeDroped) { |
|||
actionStream << " [" << a << "_drop_" << i << "_north]\t" << a << "Carrying" << i << " & view" << a << "=3 & !" << a << "CannotMoveConditionally & !" << a << "CannotMoveNorthWall -> (" << a << "Carrying" << i << "'=false);\n"; |
|||
actionStream << " [" << a << "_drop_" << i << "_west] \t" << a << "Carrying" << i << " & view" << a << "=2 & !" << a << "CannotMoveConditionally & !" << a << "CannotMoveWestWall -> (" << a << "Carrying" << i << "'=false);\n"; |
|||
actionStream << " [" << a << "_drop_" << i << "_south]\t" << a << "Carrying" << i << " & view" << a << "=1 & !" << a << "CannotMoveConditionally & !" << a << "CannotMoveSouthWall -> (" << a << "Carrying" << i << "'=false);\n"; |
|||
actionStream << " [" << a << "_drop_" << i << "_east] \t" << a << "Carrying" << i << " & view" << a << "=0 & !" << a << "CannotMoveConditionally & !" << a << "CannotMoveEastWall -> (" << a << "Carrying" << i << "'=false);\n"; |
|||
actionStream << "\n"; |
|||
} |
|||
} |
|||
|
|||
void PrismModulesPrinter::printUnlockedDoorActionsForRobot(const std::string &agentName, const std::string &identifier) { |
|||
actionStream << " [" << agentName << "_toggle_" << identifier << "] " << agentName << "CannotMove" << identifier << " -> true;\n"; |
|||
actionStream << " [" << agentName << "_toggle_" << identifier << "] " << agentName << "IsNextTo" << identifier << " -> true;\n"; |
|||
actionStream << "\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printLockedDoorActionsForRobot(const std::string &agentName, const std::string &identifier, const std::string &key) { |
|||
actionStream << " [" << agentName << "_toggle_" << identifier << "] " << agentName << "CannotMove" << identifier << " & " << agentName << "Carrying" << key << " -> true;\n"; |
|||
actionStream << " [" << agentName << "_toggle_" << identifier << "] " << agentName << "IsNextTo" << identifier << " & " << agentName << "Carrying" << key << " -> true;\n"; |
|||
actionStream << "\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printTurnActionsForRobot(const AgentName &a) { |
|||
actionStream << printTurnGuard(a, "right", RIGHT, "true") << printTurnUpdate(a, {1.0, "(view"+a+"'=mod(view"+a+"+1,4))"}, RIGHT); |
|||
actionStream << printTurnGuard(a, "left", LEFT, "view"+a+">0") << printTurnUpdate(a, {1.0, "(view"+a+"'=view"+a+"-1)"}, LEFT); |
|||
actionStream << printTurnGuard(a, "left", LEFT, "view"+a+"=0") << printTurnUpdate(a, {1.0, "(view"+a+"'=3)"}, LEFT); |
|||
} |
|||
|
|||
void PrismModulesPrinter::printMovementActionsForRobot(const AgentName &a) { |
|||
actionStream << printMovementGuard(a, "North", 3) << printMovementUpdate(a, {1.0, northUpdate(a)}); |
|||
actionStream << printMovementGuard(a, "East", 0) << printMovementUpdate(a, {1.0, eastUpdate(a)}); |
|||
actionStream << printMovementGuard(a, "South", 1) << printMovementUpdate(a, {1.0, southUpdate(a)}); |
|||
actionStream << printMovementGuard(a, "West", 2) << printMovementUpdate(a, {1.0, westUpdate(a)}); |
|||
if(faultyBehaviour()) { |
|||
std::string actionName = "[" + a + "_stuck]"; |
|||
agentNameActionMap.at(a).insert({FORWARD, actionName}); |
|||
actionStream << " " << actionName << " " << "previousAction" << a << "=" << std::to_string(FORWARD); |
|||
actionStream << " & ((view" << a << "=0 & " << a << "CannotMoveEastWall) |"; |
|||
actionStream << " (view" << a << "=1 & " << a << "CannotMoveSouthWall) |"; |
|||
actionStream << " (view" << a << "=2 & " << a << "CannotMoveWestWall) |"; |
|||
actionStream << " (view" << a << "=3 & " << a << "CannotMoveNorthWall) ) -> true;\n"; |
|||
} |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::printMovementGuard(const AgentName &a, const std::string &direction, const size_t &viewDirection) { |
|||
std::string actionName = "[" + a + "_move_" + direction + "]"; |
|||
agentNameActionMap.at(a).insert({FORWARD, actionName}); |
|||
std::string guard = " " + actionName + " " + viewVariable(a, viewDirection); |
|||
if(slipperyBehaviour()) guard += " & !" + a + "IsOnSlippery"; |
|||
if(anyLava) guard += " & !" + a + "IsOnLava"; |
|||
if(anyGoals && a == "Agent") guard += " & !" + a + "IsOnGoal"; |
|||
guard += " & !" + a + "CannotMove" + direction + "Wall"; |
|||
if(anyPortableObject() || !lockedDoors.empty() || !unlockedDoors.empty()) guard += " & !" + a + "CannotMoveConditionally"; |
|||
guard += " -> "; |
|||
return guard; |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::printMovementUpdate(const AgentName &a, const update &u) const { |
|||
return updateToString(u) + ";\n"; |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::printTurnGuard(const AgentName &a, const std::string &direction, const ActionId &actionId, const std::string &cond) { |
|||
std::string actionName = "[" + a + "_turn_" + direction + "]"; |
|||
agentNameActionMap.at(a).insert({actionId, actionName}); |
|||
std::string guard = " " + actionName; |
|||
if(slipperyBehaviour()) guard += " !" + a + "IsOnSlippery & "; |
|||
if(anyLava) guard += " !" + a + "IsOnLava &"; |
|||
guard += cond + " -> "; |
|||
return guard; |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::printTurnUpdate(const AgentName &a, const update &u, const ActionId &actionId) const { |
|||
return updateToString(u) + ";\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printNonMovementActionsForRobot(const AgentName &agentName) { |
|||
for(auto const [actionId, action] : nonMovementActions) { |
|||
std::string actionName = "[" + agentName + "_" + action + "]"; |
|||
agentNameActionMap.at(agentName).insert({actionId, actionName}); |
|||
actionStream << " " << actionName << " true -> true;\n"; |
|||
} |
|||
} |
|||
|
|||
void PrismModulesPrinter::printSlipperyMovementActionsForRobot(const AgentName &a) { |
|||
if(!slipperyTiles.at("North").empty()) { |
|||
printSlipperyMovementActionsForNorth(a); |
|||
printSlipperyTurnActionsForNorth(a); |
|||
} |
|||
if(!slipperyTiles.at("East").empty()) { |
|||
printSlipperyMovementActionsForEast(a) ; |
|||
printSlipperyTurnActionsForEast(a); |
|||
} |
|||
if(!slipperyTiles.at("South").empty()) { |
|||
printSlipperyMovementActionsForSouth(a); |
|||
printSlipperyTurnActionsForSouth(a); |
|||
} |
|||
if(!slipperyTiles.at("West").empty()) { |
|||
printSlipperyMovementActionsForWest(a) ; |
|||
printSlipperyTurnActionsForWest(a); |
|||
} |
|||
if(!slipperyTiles.at("NorthWest").empty()) { |
|||
printSlipperyMovementActionsForNorthWest(a); |
|||
printSlipperyTurnActionsForNorthWest(a); |
|||
} |
|||
if(!slipperyTiles.at("NorthEast").empty()) { |
|||
printSlipperyMovementActionsForNorthEast(a); |
|||
printSlipperyTurnActionsForNorthEast(a); |
|||
} |
|||
if(!slipperyTiles.at("SouthWest").empty()) { |
|||
printSlipperyMovementActionsForSouthWest(a); |
|||
printSlipperyTurnActionsForSouthWest(a); |
|||
} |
|||
if(!slipperyTiles.at("SouthWest").empty()) { |
|||
printSlipperyMovementActionsForSouthWest(a); |
|||
printSlipperyTurnActionsForSouthWest(a); |
|||
} |
|||
} |
|||
|
|||
void PrismModulesPrinter::printSlipperyMovementActionsForNorth(const AgentName &a) { |
|||
actionStream << printSlipperyMovementGuard(a, "North", 3, {"!"+a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, northUpdate(a)}, {(1 - probIntended) * 1/2, northUpdate(a)+"&"+eastUpdate(a)}, {(1 - probIntended) * 1/2, northUpdate(a)+"&"+westUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 3, { a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1/2, northUpdate(a)+"&"+eastUpdate(a)}, {1/2, northUpdate(a)+"&"+westUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 3, {"!"+a+"CannotSlipNorth", a+"CannotSlipNorthEast", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, northUpdate(a)}, {(1 - probIntended), northUpdate(a)+"&"+westUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 3, {"!"+a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, northUpdate(a)}, {(1 - probIntended), northUpdate(a)+"&"+eastUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 3, { a+"CannotSlipNorth", a+"CannotSlipNorthEast", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)+"&"+westUpdate(a) } }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 3, {"!"+a+"CannotSlipNorth", a+"CannotSlipNorthEast", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 3, { a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, northUpdate(a)+"&"+eastUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 3, { a+"CannotSlipNorth", a+"CannotSlipNorthEast", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", {}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "North", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, westUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, westUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", { {1, westUpdate(a) } }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 2, { a+"CannotSlipWest", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "North", {}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "North", 0, {"!"+a+"CannotSlipEast", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, eastUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 0, { a+"CannotSlipEast", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", { {1, eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 0, {"!"+a+"CannotSlipEast", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", { {1, eastUpdate(a) } }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 0, { a+"CannotSlipEast", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "North", {}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "North", 1, {"!"+a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "North", { {probIntended, southUpdate(a) }, {1 - probIntended, "true"} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "North", 1, { a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "North", { {1, "true"} }) << ";\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printSlipperyMovementActionsForEast(const AgentName &a) { |
|||
actionStream << printSlipperyMovementGuard(a, "East", 0, {"!"+a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a)}, {(1 - probIntended) * 1/2, eastUpdate(a)+"&"+southUpdate(a)}, {(1 - probIntended) * 1/2, eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 0, { a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1/2, eastUpdate(a)+"&"+southUpdate(a)}, {1/2, eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 0, {"!"+a+"CannotSlipEast", a+"CannotSlipSouthEast", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a)}, {(1 - probIntended), eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 0, {"!"+a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a)}, {(1 - probIntended), eastUpdate(a)+"&"+southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 0, { a+"CannotSlipEast", a+"CannotSlipSouthEast", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+northUpdate(a) } }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 0, {"!"+a+"CannotSlipEast", a+"CannotSlipSouthEast", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 0, { a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 0, { a+"CannotSlipEast", a+"CannotSlipSouthEast", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", {}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "East", 3, {"!"+a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, northUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 3, { a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 3, {"!"+a+"CannotSlipNorth", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, northUpdate(a) } }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 3, { a+"CannotSlipNorth", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "East", {}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "East", 1, {"!"+a+"CannotSlipSouth", "!"+a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, southUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 1, { a+"CannotSlipSouth", "!"+a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, eastUpdate(a)+"&"+southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 1, {"!"+a+"CannotSlipSouth", a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", { {1, southUpdate(a) } }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 1, { a+"CannotSlipSouth", a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "East", {}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "East", 2, {"!"+a+"CannotSlipEast"}) << printSlipperyMovementUpdate(a, "East", { {probIntended, eastUpdate(a) }, {1 - probIntended, "true"} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "East", 2, { a+"CannotSlipEast"}) << printSlipperyMovementUpdate(a, "East", { {1, "true"} }) << ";\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printSlipperyMovementActionsForSouth(const AgentName &a) { |
|||
actionStream << printSlipperyMovementGuard(a, "South", 1, {"!"+a+"CannotSlipSouth", "!"+a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a)}, {(1 - probIntended) * 1/2, southUpdate(a)+"&"+eastUpdate(a)}, {(1 - probIntended) * 1/2, southUpdate(a)+"&"+westUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 1, { a+"CannotSlipSouth", "!"+a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1/2, southUpdate(a)+"&"+eastUpdate(a)}, {1/2, southUpdate(a)+"&"+westUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 1, {"!"+a+"CannotSlipSouth", a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a)}, {(1 - probIntended), southUpdate(a)+"&"+westUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 1, {"!"+a+"CannotSlipSouth", "!"+a+"CannotSlipSouthEast", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, southUpdate(a)}, {(1 - probIntended), southUpdate(a)+"&"+eastUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 1, { a+"CannotSlipSouth", a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)+"&"+westUpdate(a) } }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 1, {"!"+a+"CannotSlipSouth", a+"CannotSlipSouthEast", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 1, { a+"CannotSlipSouth", "!"+a+"CannotSlipSouthEast", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, southUpdate(a)+"&"+eastUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 1, { a+"CannotSlipSouth", a+"CannotSlipSouthEast", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", {}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "South", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, westUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, westUpdate(a)+"&"+southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", { {1, westUpdate(a) } }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 2, { a+"CannotSlipWest", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "South", {}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "South", 0, {"!"+a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, eastUpdate(a) }, {1 - probIntended, eastUpdate(a)+"&"+southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 0, { a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", { {1, eastUpdate(a)+"&"+southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 0, {"!"+a+"CannotSlipEast", a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", { {1, eastUpdate(a) } }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 0, { a+"CannotSlipEast", a+"CannotSlipSouthEast"}) << printSlipperyMovementUpdate(a, "South", {}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "South", 3, {"!"+a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "South", { {probIntended, northUpdate(a) }, {1 - probIntended, "true"} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "South", 3, { a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "South", { {1, "true"} }) << ";\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printSlipperyMovementActionsForWest(const AgentName &a) { |
|||
actionStream << printSlipperyMovementGuard(a, "West", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipSouthWest", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a)}, {(1 - probIntended) * 1/2, westUpdate(a)+"&"+southUpdate(a)}, {(1 - probIntended) * 1/2, westUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipSouthWest", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1/2, westUpdate(a)+"&"+southUpdate(a)}, {1/2, westUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipSouthWest", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a)}, {(1 - probIntended), westUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipSouthWest", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a)}, {(1 - probIntended), westUpdate(a)+"&"+southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 2, { a+"CannotSlipWest", a+"CannotSlipSouthWest", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+northUpdate(a) } }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipSouthWest", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipSouthWest", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 2, { a+"CannotSlipWest", a+"CannotSlipSouthWest", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", {}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "West", 3, {"!"+a+"CannotSlipNorth", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, northUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 3, { a+"CannotSlipNorth", "!"+a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 3, {"!"+a+"CannotSlipNorth", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, northUpdate(a) } }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 3, { a+"CannotSlipNorth", a+"CannotSlipNorthWest"}) << printSlipperyMovementUpdate(a, "West", {}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "West", 1, {"!"+a+"CannotSlipSouth", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, southUpdate(a) }, {1 - probIntended, westUpdate(a)+"&"+southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 1, { a+"CannotSlipSouth", "!"+a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, westUpdate(a)+"&"+southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 1, {"!"+a+"CannotSlipSouth", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", { {1, southUpdate(a) } }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 1, { a+"CannotSlipSouth", a+"CannotSlipSouthWest"}) << printSlipperyMovementUpdate(a, "West", {}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "West", 0, {"!"+a+"CannotSlipWest"}) << printSlipperyMovementUpdate(a, "West", { {probIntended, westUpdate(a) }, {1 - probIntended, "true"} }) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "West", 0, { a+"CannotSlipWest"}) << printSlipperyMovementUpdate(a, "West", {{1, "true"}}) << ";\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printSlipperyTurnActionsForNorth(const AgentName &a) { |
|||
actionStream << printSlipperyTurnGuard(a, "right", "North", RIGHT, {"!"+a+"CannotSlipNorth"}, "true") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"+1,4))"}, { 1 - probIntended, northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "right", "North", RIGHT, { a+"CannotSlipNorth"}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << ";\n"; |
|||
|
|||
actionStream << printSlipperyTurnGuard(a, "left", "North", LEFT, {"!"+a+"CannotSlipNorth"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=view"+a+"-1)"}, {1 - probIntended, northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "North", LEFT, {"!"+a+"CannotSlipNorth"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=3)"}, {1 - probIntended, northUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "North", LEFT, { a+"CannotSlipNorth"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"-1)"} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "North", LEFT, { a+"CannotSlipNorth"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=3)"} }) << ";\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printSlipperyTurnActionsForEast(const AgentName &a) { |
|||
actionStream << printSlipperyTurnGuard(a, "right", "East", RIGHT, {"!"+a+"CannotSlipEast"}, "true") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"+1,4))"}, { 1 - probIntended, eastUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "right", "East", RIGHT, { a+"CannotSlipEast"}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << ";\n"; |
|||
|
|||
actionStream << printSlipperyTurnGuard(a, "left", "East", LEFT, {"!"+a+"CannotSlipEast"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=view"+a+"-1)"}, {1 - probIntended, eastUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "East", LEFT, {"!"+a+"CannotSlipEast"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=3)"}, {1 - probIntended, eastUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "East", LEFT, { a+"CannotSlipEast"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"-1)"} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "East", LEFT, { a+"CannotSlipEast"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=3)"} }) << ";\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printSlipperyTurnActionsForSouth(const AgentName &a) { |
|||
actionStream << printSlipperyTurnGuard(a, "right", "South", RIGHT, {"!"+a+"CannotSlipSouth"}, "true") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"+1,4))"}, { 1 - probIntended, southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "right", "South", RIGHT, { a+"CannotSlipSouth"}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << ";\n"; |
|||
|
|||
actionStream << printSlipperyTurnGuard(a, "left", "South", LEFT, {"!"+a+"CannotSlipSouth"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=view"+a+"-1)"}, {1 - probIntended, southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "South", LEFT, {"!"+a+"CannotSlipSouth"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=3)"}, {1 - probIntended, southUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "South", LEFT, { a+"CannotSlipSouth"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"-1)"} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "South", LEFT, { a+"CannotSlipSouth"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=3)"} }) << ";\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printSlipperyTurnActionsForWest(const AgentName &a) { |
|||
actionStream << printSlipperyTurnGuard(a, "right", "West", RIGHT, {"!"+a+"CannotSlipWest"}, "true") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=mod(view"+a+"+1,4))"}, { 1 - probIntended, westUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "right", "West", RIGHT, { a+"CannotSlipWest"}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << ";\n"; |
|||
|
|||
actionStream << printSlipperyTurnGuard(a, "left", "West", LEFT, {"!"+a+"CannotSlipWest"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=view"+a+"-1)"}, {1 - probIntended, westUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "West", LEFT, {"!"+a+"CannotSlipWest"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {probIntended, "(view"+a+"'=3)"}, {1 - probIntended, westUpdate(a)} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "West", LEFT, { a+"CannotSlipWest"}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"-1)"} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "West", LEFT, { a+"CannotSlipWest"}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=3)"} }) << ";\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printSlipperyMovementActionsForNorthWest(const AgentName &a) { throw std::logic_error("The logic for SlipperyNorthWest tiles is not yet implemented."); } |
|||
void PrismModulesPrinter::printSlipperyTurnActionsForNorthWest(const AgentName &a){ throw std::logic_error("The logic for SlipperyNorthWest tiles is not yet implemented."); } |
|||
|
|||
void PrismModulesPrinter::printSlipperyMovementActionsForNorthEast(const AgentName &a) { |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 0, {"!"+a+"CannotSlipNorthEast", "!"+a+"CannotSlipEast"}) << printSlipperyMovementUpdate(a, "", {{probIntended, eastUpdate(a)}, {1-probIntended, northUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 0, {"!"+a+"CannotSlipNorthEast", a+"CannotSlipEast"}) << printSlipperyMovementUpdate(a, "", {{1, northUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 0, { a+"CannotSlipNorthEast", "!"+a+"CannotSlipEast"}) << printSlipperyMovementUpdate(a, "", {{1, eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 0, { a+"CannotSlipNorthEast", a+"CannotSlipEast"}) << printSlipperyMovementUpdate(a, "", {{1, "true"}}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 3, {"!"+a+"CannotSlipNorthEast", "!"+a+"CannotSlipNorth"}) << printSlipperyMovementUpdate(a, "", {{probIntended, northUpdate(a)}, {1-probIntended, eastUpdate(a)+"&"+northUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 3, {"!"+a+"CannotSlipNorthEast", a+"CannotSlipNorth"}) << printSlipperyMovementUpdate(a, "", {{1, northUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 3, { a+"CannotSlipNorthEast", "!"+a+"CannotSlipNorth"}) << printSlipperyMovementUpdate(a, "", {{1, northUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 3, { a+"CannotSlipNorthEast", a+"CannotSlipNorth"}) << printSlipperyMovementUpdate(a, "", {{1, "true"}}) << ";\n"; |
|||
|
|||
|
|||
float pd3 = (1 - probIntended) / 3; |
|||
float pi3 = probIntended; |
|||
|
|||
float sum2 = probIntended + 2 * (1 - probIntended)/3; |
|||
float pd2 = (1 - probIntended) / sum2; |
|||
float pi2 = probIntended / sum2; |
|||
|
|||
float sum1 = probIntended + (1 - probIntended)/3; |
|||
float pd1 = (1 - probIntended) / sum1; |
|||
float pi1 = probIntended / sum1; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, {"!"+a+"CannotSlipNorthEast", "!"+a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{pi3, southUpdate(a)}, {pd3, northUpdate(a)+"&"+eastUpdate(a)}, {pd3, eastUpdate(a)}, {pd3, southUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, {"!"+a+"CannotSlipNorthEast", "!"+a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{1/3.f, northUpdate(a)+"&"+eastUpdate(a)}, {1/3.f, eastUpdate(a)}, {1/3.f, southUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, {"!"+a+"CannotSlipNorthEast", "!"+a+"CannotSlipEast", a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{pi1, southUpdate(a)}, {pd2, northUpdate(a)+"&"+eastUpdate(a)}, {pd2, eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, {"!"+a+"CannotSlipNorthEast", "!"+a+"CannotSlipEast", a+"CannotSlipSouthEast", a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{1/2.f, northUpdate(a)+"&"+eastUpdate(a)}, {1/2.f, eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, {"!"+a+"CannotSlipNorthEast", a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{pi1, southUpdate(a)}, {pd2, northUpdate(a)+"&"+eastUpdate(a)}, {pd2, southUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, {"!"+a+"CannotSlipNorthEast", a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{1/2.f, northUpdate(a)+"&"+eastUpdate(a)}, {1/2.f, southUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, {"!"+a+"CannotSlipNorthEast", a+"CannotSlipEast", a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{pi1, southUpdate(a)}, {pd1, northUpdate(a)+"&"+eastUpdate(a) }}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, {"!"+a+"CannotSlipNorthEast", a+"CannotSlipEast", a+"CannotSlipSouthEast", a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{1, northUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, { a+"CannotSlipNorthEast", "!"+a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{pi1, southUpdate(a)}, {pd2, eastUpdate(a)}, {pd2, southUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, { a+"CannotSlipNorthEast", "!"+a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{1/2.f, eastUpdate(a)}, {1/2.f, southUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, { a+"CannotSlipNorthEast", "!"+a+"CannotSlipEast", a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{pi1, southUpdate(a)}, {pd1, eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, { a+"CannotSlipNorthEast", "!"+a+"CannotSlipEast", a+"CannotSlipSouthEast", a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{1, eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, { a+"CannotSlipNorthEast", a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{pi1, southUpdate(a)}, {pd1, southUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, { a+"CannotSlipNorthEast", a+"CannotSlipEast", "!"+a+"CannotSlipSouthEast", a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{1, southUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, { a+"CannotSlipNorthEast", a+"CannotSlipEast", a+"CannotSlipSouthEast", "!"+a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{1, southUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 1, { a+"CannotSlipNorthEast", a+"CannotSlipEast", a+"CannotSlipSouthEast", a+"CannotSlipSouth"}) << printSlipperyMovementUpdate(a, "", {{1, "true"}}) << ";\n"; |
|||
|
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipNorthWest", "!"+a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{pi3, westUpdate(a)}, {pd3, northUpdate(a)+"&"+westUpdate(a)}, {pd3, northUpdate(a)}, {pd3, northUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipNorthWest", "!"+a+"CannotSlipNorth", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{pi2, westUpdate(a)}, {pd2, northUpdate(a)+"&"+westUpdate(a)}, {pd2, northUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipNorthWest", a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{pi2, westUpdate(a)}, {pd2, northUpdate(a)+"&"+westUpdate(a)}, {pd2, northUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, {"!"+a+"CannotSlipWest", "!"+a+"CannotSlipNorthWest", a+"CannotSlipNorth", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{pi1, westUpdate(a)}, {pd1, northUpdate(a)+"&"+westUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipNorthWest", "!"+a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{pi2, westUpdate(a)}, {pd2, northUpdate(a)}, {pd2, northUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipNorthWest", "!"+a+"CannotSlipNorth", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{pi1, westUpdate(a)}, {pd1, northUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipNorthWest", a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{pi1, westUpdate(a)}, {pd1, northUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, {"!"+a+"CannotSlipWest", a+"CannotSlipNorthWest", a+"CannotSlipNorth", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{1, westUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipNorthWest", "!"+a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{1/3.f, northUpdate(a)+"&"+westUpdate(a)}, {1/3.f, northUpdate(a)}, {1/3.f, northUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipNorthWest", "!"+a+"CannotSlipNorth", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{1/2.f, northUpdate(a)+"&"+westUpdate(a)}, {1/2.f, northUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipNorthWest", a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{1/2.f, northUpdate(a)+"&"+westUpdate(a)}, {1/2.f, northUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, { a+"CannotSlipWest", "!"+a+"CannotSlipNorthWest", a+"CannotSlipNorth", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{1, northUpdate(a)+"&"+westUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, { a+"CannotSlipWest", a+"CannotSlipNorthWest", "!"+a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{1/2.f, northUpdate(a)}, {1/2.f, northUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, { a+"CannotSlipWest", a+"CannotSlipNorthWest", "!"+a+"CannotSlipNorth", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{1, northUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, { a+"CannotSlipWest", a+"CannotSlipNorthWest", a+"CannotSlipNorth", "!"+a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{1, northUpdate(a)+"&"+eastUpdate(a)}}) << ";\n"; |
|||
actionStream << printSlipperyMovementGuard(a, "NorthEast", 2, { a+"CannotSlipWest", a+"CannotSlipNorthWest", a+"CannotSlipNorth", a+"CannotSlipNorthEast"}) << printSlipperyMovementUpdate(a, "", {{1, "true"}}) << ";\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printSlipperyTurnActionsForNorthEast(const AgentName &a) { |
|||
actionStream << printSlipperyTurnGuard(a, "right", "NorthEast", RIGHT, {}, "true") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=mod(view"+a+"+1,4))"} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "NorthEast", LEFT, {}, "view"+a+">0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=view"+a+"-1)"} }) << ";\n"; |
|||
actionStream << printSlipperyTurnGuard(a, "left", "NorthEast", LEFT, {}, "view"+a+"=0") << printSlipperyTurnUpdate(a, { {1, "(view"+a+"'=3)"} }) << ";\n"; |
|||
|
|||
} |
|||
|
|||
void PrismModulesPrinter::printSlipperyMovementActionsForSouthWest(const AgentName &a){ throw std::logic_error("The logic for SlipperySouthWest tiles is not yet implemented."); } |
|||
void PrismModulesPrinter::printSlipperyTurnActionsForSouthWest(const AgentName &a){ throw std::logic_error("The logic for SlipperySouthWest tiles is not yet implemented."); } |
|||
void PrismModulesPrinter::printSlipperyMovementActionsForSouthEast(const AgentName &a){ throw std::logic_error("The logic for SlipperySouthEast tiles is not yet implemented."); } |
|||
void PrismModulesPrinter::printSlipperyTurnActionsForSouthEast(const AgentName &a){ throw std::logic_error("The logic for SlipperySouthEast tiles is not yet implemented."); } |
|||
|
|||
|
|||
std::string PrismModulesPrinter::printSlipperyMovementGuard(const AgentName &a, const std::string &direction, const ViewDirection &viewDirection, const std::vector<std::string> &guards) { |
|||
std::string actionName = "[" + a + "_move_" + viewDirectionToString.at(viewDirection) + "]"; |
|||
agentNameActionMap.at(a).insert({FORWARD, actionName}); |
|||
return " " + actionName + " " + viewVariable(a, viewDirection) + " & " + a + "IsOnSlippery" + direction + " & " + buildConjunction(a, guards) + " -> "; |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::printSlipperyMovementUpdate(const AgentName &a, const std::string &direction, const updates &u) const { |
|||
return updatesToString(u); |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::printSlipperyTurnGuard(const AgentName &a, const std::string &direction, const std::string &tiltDirection, const ActionId &actionId, const std::vector<std::string> &guards, const std::string &cond) { |
|||
std::string actionName = "[" + a + "_turn_" + direction + "]"; |
|||
agentNameActionMap.at(a).insert({actionId, actionName}); |
|||
return " " + actionName + " " + a + "IsOnSlippery" + tiltDirection + " & " + buildConjunction(a, guards) + " & " + cond + " -> "; |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::printSlipperyTurnUpdate(const AgentName &a, const updates &u) { |
|||
return updatesToString(u); |
|||
} |
|||
|
|||
void PrismModulesPrinter::printFaultyMovementModule(const AgentName &a) { |
|||
os << "\nmodule " << a << "FaultyBehaviour" << std::endl; |
|||
os << " previousAction" << a << " : [0.." + std::to_string(NOFAULT) + "];\n"; |
|||
|
|||
std::set<size_t> exclude = {PICKUP, DROP, TOGGLE, DONE}; |
|||
for(const auto [actionId, actionName] : agentNameActionMap.at(a)) { |
|||
if(exclude.count(actionId) > 0) continue; |
|||
os << " " << actionName << faultyBehaviourGuard(a, actionId) << " -> " << faultyBehaviourUpdate(a, actionId) << ";\n"; |
|||
} |
|||
os << "endmodule\n\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printMoveModule() { |
|||
os << "\nmodule " << "Arbiter" << std::endl; |
|||
os << " clock : [0.." << agentIndexMap.size() - 1 << "];\n"; |
|||
|
|||
for(const auto [agentName, actions] : agentNameActionMap) { |
|||
for(const auto [actionId, actionName] : actions) { |
|||
os << " " << actionName << " " << moveGuard(agentName) << " -> " << moveUpdate(agentName) << ";\n"; |
|||
} |
|||
} |
|||
os << "endmodule\n\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printConfiguredActions(const AgentName &agentName) { |
|||
for (auto& config : configuration) { |
|||
if (config.type_ == ConfigType::Module && !config.overwrite_ && agentName == config.module_) { |
|||
os << config.expression_ ; |
|||
} |
|||
} |
|||
|
|||
os << "\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printDoneActions(const AgentName &agentName) { |
|||
os << " [" << agentName << "_on_goal]" << agentName << "IsOnGoal & clock=0 -> true;\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printPlayerStruct(const AgentName &agentName) { |
|||
os << "player " << agentName << "\n\t"; |
|||
bool first = true; |
|||
for(const auto [actionId, actionName] : agentNameActionMap.at(agentName)) { |
|||
if(first) first = false; |
|||
else os << ", "; |
|||
os << actionName; |
|||
} |
|||
if(agentName == "Agent" && anyGoals) os << ", [Agent_on_goal]"; |
|||
os << "\nendplayer\n"; |
|||
} |
|||
|
|||
void PrismModulesPrinter::printRewards(const AgentName &agentName, const std::map<coordinates, float> &stateRewards, const cells &lava, const cells &goals, const std::map<Color, cells> &backgroundTiles) { |
|||
if(lava.size() != 0) { |
|||
os << "rewards \"" << agentName << "SafetyNoBFS\"\n"; |
|||
os << "\t" <<agentName << "IsInLavaAndNotDone: -100;\n"; |
|||
os << "endrewards\n"; |
|||
} |
|||
|
|||
if (!goals.empty() || !lava.empty()) { |
|||
os << "rewards \"" << agentName << "SafetyNoBFSAndGoal\"\n"; |
|||
if(goals.size() != 0) os << "\t" << agentName << "IsInGoalAndNotDone: 100;\n"; |
|||
if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n"; |
|||
os << "endrewards\n"; |
|||
} |
|||
|
|||
os << "rewards \"" << agentName << "Time\"\n"; |
|||
os << "\t!" << agentName << "IsInGoal : -1;\n"; |
|||
if(goals.size() != 0) os << "\t" << agentName << "IsInGoalAndNotDone: 100;\n"; |
|||
if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n"; |
|||
os << "endrewards\n"; |
|||
|
|||
if(stateRewards.size() > 0) { |
|||
os << "rewards \"" << agentName << "SafetyWithBFS\"\n"; |
|||
if(lava.size() != 0) os << "\t" << agentName << "IsInLavaAndNotDone: -100;\n"; |
|||
for(auto const [coordinates, reward] : stateRewards) { |
|||
os << "\txAgent=" << coordinates.first << "&yAgent=" << coordinates.second << " : " << reward << ";\n"; |
|||
} |
|||
os << "endrewards\n"; |
|||
} |
|||
if(stateRewards.size() > 0) { |
|||
os << "rewards \"" << agentName << "SafetyWithBFSAndGoal\"\n"; |
|||
if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone: 100;\n"; |
|||
if(lava.size() != 0) os << "\tAgentIsInLavaAndNotDone: -100;\n"; |
|||
for(auto const [coordinates, reward] : stateRewards) { |
|||
os << "\txAgent=" << coordinates.first << "&yAgent=" << coordinates.second << " : " << reward << ";\n"; |
|||
} |
|||
os << "endrewards\n"; |
|||
} |
|||
|
|||
for(auto const entry : backgroundTiles) |
|||
{ |
|||
std::cout << getColor(entry.first) << " "; |
|||
for(auto const cell : entry.second){ |
|||
std::cout << cell.getCoordinates().first << " " << cell.getCoordinates().second << std::endl; |
|||
} |
|||
} |
|||
if(backgroundTiles.size() > 0) { |
|||
os << "rewards \"TaxiReward\"\n"; |
|||
os << "\t!AgentIsInGoal : -1;\n"; |
|||
std::string allPassengersPickedUp = ""; |
|||
bool first = true; |
|||
for(auto const [color, cells] : backgroundTiles) { |
|||
if(cells.size() == 0) continue; |
|||
if(first) first = false; else allPassengersPickedUp += "&"; |
|||
std::string c = getColor(color); |
|||
c.at(0) = std::toupper(c.at(0)); |
|||
std::string visitedLabel = agentName + "_picked_up_" + c; |
|||
allPassengersPickedUp += visitedLabel; |
|||
os << "[" << agentName << "_pickup_" << c << "] true : 100;\n"; |
|||
} |
|||
if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone & " << allPassengersPickedUp << " : 100;\n"; |
|||
if(goals.size() != 0) os << "\tAgentIsInGoalAndNotDone & !(" << allPassengersPickedUp << ") : -100;\n"; |
|||
os << "endrewards"; |
|||
} |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::faultyBehaviourGuard(const AgentName &agentName, const ActionId &actionId) const { |
|||
if(faultyBehaviour()) { |
|||
if(actionId == NOFAULT) { |
|||
return "(previousAction" + agentName + "=" + std::to_string(NOFAULT) + ") "; |
|||
} else { |
|||
return "(previousAction" + agentName + "=" + std::to_string(NOFAULT) + " | previousAction" + agentName + "=" + std::to_string(actionId) + ") "; |
|||
} |
|||
} else { |
|||
return ""; |
|||
} |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::faultyBehaviourUpdate(const AgentName &agentName, const ActionId &actionId) const { |
|||
if(actionId != NOFAULT) { |
|||
return updatesToString({ {1 - faultyProbability, "(previousAction" + agentName + "'=" + std::to_string(NOFAULT) + ")"}, {faultyProbability, "(previousAction" + agentName + "'=" + std::to_string(actionId) + ")" } }); |
|||
} else { |
|||
return "true"; |
|||
} |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::moveGuard(const AgentName &agentName) const { |
|||
return "clock=" + std::to_string(agentIndexMap.at(agentName)); |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::moveUpdate(const AgentName &agentName) const { |
|||
size_t agentIndex = agentIndexMap.at(agentName); |
|||
return (agentIndex == numberOfPlayer - 1) ? "(clock'=0) " : "(clock'=" + std::to_string(agentIndex + 1) + ") "; |
|||
|
|||
} |
|||
|
|||
std::string PrismModulesPrinter::updatesToString(const updates &updates) const { |
|||
if(updates.empty()) return "true"; |
|||
std::string updatesString = ""; |
|||
bool first = true; |
|||
for(auto const update : updates) { |
|||
if(first) first = false; |
|||
else updatesString += " + "; |
|||
updatesString += updateToString(update); |
|||
} |
|||
return updatesString; |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::updateToString(const update &u) const { |
|||
return std::to_string(u.first) + ": " + u.second; |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::viewVariable(const AgentName &agentName, const size_t &agentDirection) const { |
|||
return "view" + agentName + "=" + std::to_string(agentDirection); |
|||
} |
|||
|
|||
bool PrismModulesPrinter::anyPortableObject() const { |
|||
return !keys.empty(); |
|||
} |
|||
|
|||
bool PrismModulesPrinter::faultyBehaviour() const { |
|||
return faultyProbability > 0.0f; |
|||
} |
|||
|
|||
bool PrismModulesPrinter::slipperyBehaviour() const { |
|||
return !slipperyTiles.at("North").empty() || !slipperyTiles.at("East").empty() || !slipperyTiles.at("South").empty() || !slipperyTiles.at("West").empty(); |
|||
} |
|||
|
|||
bool PrismModulesPrinter::isGame() const { |
|||
return modelType == ModelType::SMG; |
|||
} |
|||
|
|||
std::string PrismModulesPrinter::buildConjunction(const AgentName &a, std::vector<std::string> formulae) const { |
|||
if(formulae.empty()) return "true"; |
|||
std::string conjunction = ""; |
|||
bool first = true; |
|||
for(auto const formula : formulae) { |
|||
if(first) first = false; |
|||
else conjunction += " & "; |
|||
conjunction += formula; |
|||
} |
|||
return conjunction; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,123 @@ |
|||
#pragma once |
|||
|
|||
#include <iostream> |
|||
#include <set> |
|||
#include <functional> |
|||
#include "MinigridGrammar.h" |
|||
#include "PrismPrinter.h" |
|||
#include "ConfigYaml.h" |
|||
|
|||
|
|||
std::string northUpdate(const AgentName &a); |
|||
std::string southUpdate(const AgentName &a); |
|||
std::string eastUpdate(const AgentName &a); |
|||
std::string westUpdate(const AgentName &a); |
|||
|
|||
namespace prism { |
|||
class PrismModulesPrinter { |
|||
public: |
|||
PrismModulesPrinter(std::ostream& os, const ModelType &modelType, const coordinates &maxBoundaries, const cells &lockedDoors, const cells &unlockedDoors, const cells &keys, const std::map<std::string, cells> &slipperyTiles, const AgentNameAndPositionMap &agentNameAndPositionMap, std::vector<Configuration> config, const float probIntended, const float faultyProbability, const bool anyLava, const bool anyGoals); |
|||
|
|||
std::ostream& print(); |
|||
|
|||
void printModelType(const ModelType &modelType); |
|||
|
|||
|
|||
bool isGame() const; |
|||
private: |
|||
void printPortableObjectModule(const cell &object); |
|||
void printPortableObjectActions(const std::string &agentName, const std::string &identifier, const bool canBeDroped = false); |
|||
|
|||
void printDoorModule(const cell &object, const bool &opened); |
|||
void printLockedDoorActions(const std::string &agentName, const std::string &identifier); |
|||
void printUnlockedDoorActions(const std::string &agentName, const std::string &identifier); |
|||
|
|||
void printRobotModule(const AgentName &agentName, const coordinates &initialPosition); |
|||
void printPortableObjectActionsForRobot(const std::string &agentName, const std::string &identifier, const bool canBeDroped = false); |
|||
void printUnlockedDoorActionsForRobot(const std::string &agentName, const std::string &identifier); |
|||
void printLockedDoorActionsForRobot(const std::string &agentName, const std::string &identifier, const std::string &key); |
|||
void printMovementActionsForRobot(const std::string &a); |
|||
void printTurnActionsForRobot(const std::string &a); |
|||
void printNonMovementActionsForRobot(const AgentName &agentName); |
|||
void printSlipperyMovementActionsForRobot(const AgentName &a); |
|||
void printSlipperyMovementActionsForNorth(const AgentName &a); |
|||
void printSlipperyMovementActionsForEast(const AgentName &a); |
|||
void printSlipperyMovementActionsForSouth(const AgentName &a); |
|||
void printSlipperyMovementActionsForWest(const AgentName &a); |
|||
void printSlipperyTurnActionsForNorth(const AgentName &a); |
|||
void printSlipperyTurnActionsForEast(const AgentName &a); |
|||
void printSlipperyTurnActionsForSouth(const AgentName &a); |
|||
void printSlipperyTurnActionsForWest(const AgentName &a); |
|||
void printSlipperyMovementActionsForNorthWest(const AgentName &a); |
|||
void printSlipperyTurnActionsForNorthWest(const AgentName &a); |
|||
void printSlipperyMovementActionsForNorthEast(const AgentName &a); |
|||
void printSlipperyTurnActionsForNorthEast(const AgentName &a); |
|||
void printSlipperyMovementActionsForSouthWest(const AgentName &a); |
|||
void printSlipperyTurnActionsForSouthWest(const AgentName &a); |
|||
void printSlipperyMovementActionsForSouthEast(const AgentName &a); |
|||
void printSlipperyTurnActionsForSouthEast(const AgentName &a); |
|||
|
|||
std::string printMovementGuard(const AgentName &a, const std::string &direction, const size_t &viewDirection); |
|||
std::string printMovementUpdate(const AgentName &a, const update &update) const; |
|||
std::string printTurnGuard(const AgentName &a, const std::string &direction, const ActionId &actionId, const std::string &cond = ""); |
|||
std::string printTurnUpdate(const AgentName &a, const update &u, const ActionId &actionId) const; |
|||
std::string printSlipperyMovementGuard(const AgentName &a, const std::string &direction, const ViewDirection &viewDirection, const std::vector<std::string> &guards); |
|||
std::string printSlipperyMovementUpdate(const AgentName &a, const std::string &direction, const updates &u) const; |
|||
std::string printSlipperyTurnGuard(const AgentName &a, const std::string &direction, const std::string &tiltDirection, const ActionId &actionId, const std::vector<std::string> &guards, const std::string &cond); |
|||
std::string printSlipperyTurnUpdate(const AgentName &a, const updates &u); |
|||
|
|||
void printFaultyMovementModule(const AgentName &a); |
|||
void printMoveModule(); |
|||
|
|||
void printConstants(const std::vector<std::string> &constants); |
|||
|
|||
void printDoneActions(const AgentName &agentName); |
|||
void printPlayerStruct(const AgentName &agentName); |
|||
void printRewards(const AgentName &agentName, const std::map<coordinates, float> &stateRewards, const cells &lava, const cells &goals, const std::map<Color, cells> &backgroundTiles); |
|||
|
|||
void printConfiguration(const std::vector<Configuration>& configurations); |
|||
void printConfiguredActions(const AgentName &agentName); |
|||
|
|||
bool anyPortableObject() const; |
|||
bool faultyBehaviour() const; |
|||
bool slipperyBehaviour() const; |
|||
std::string moveGuard(const AgentName &agentName) const; |
|||
std::string faultyBehaviourGuard(const AgentName &agentName, const ActionId &actionId) const; |
|||
std::string faultyBehaviourUpdate(const AgentName &agentName, const ActionId &actionId) const; |
|||
std::string moveUpdate(const AgentName &agentName) const; |
|||
std::string updatesToString(const updates &updates) const; |
|||
std::string updateToString(const update &u) const; |
|||
|
|||
std::string viewVariable(const AgentName &agentName, const size_t &agentDirection) const; |
|||
|
|||
|
|||
std::string buildConjunction(const AgentName &a, std::vector<std::string> formulae) const; |
|||
|
|||
|
|||
std::ostream &os; |
|||
std::stringstream actionStream; |
|||
|
|||
ModelType const &modelType; |
|||
coordinates const &maxBoundaries; |
|||
AgentName agentName; |
|||
cells lockedDoors; |
|||
cells unlockedDoors; |
|||
cells keys; |
|||
std::map<std::string, cells> slipperyTiles; |
|||
|
|||
const bool anyLava; |
|||
const bool anyGoals; |
|||
|
|||
AgentNameAndPositionMap agentNameAndPositionMap; |
|||
std::map<AgentName, size_t> agentIndexMap; |
|||
size_t numberOfPlayer; |
|||
float const faultyProbability; |
|||
float const probIntended; |
|||
std::vector<Configuration> configuration; |
|||
std::vector<ViewDirection> viewDirections = {0, 1, 2, 3}; |
|||
std::map<ViewDirection, std::string> viewDirectionToString = {{0, "East"}, {1, "South"}, {2, "West"}, {3, "North"}}; |
|||
std::vector<std::pair<size_t, std::string>> nonMovementActions = { {PICKUP, "pickup"}, {DROP, "drop"}, {TOGGLE, "toggle"}, {DONE, "done"} }; |
|||
|
|||
std::map<AgentName, std::set<std::pair<ActionId, std::string>>> agentNameActionMap; |
|||
}; |
|||
} |
@ -0,0 +1,8 @@ |
|||
#include "PrismPrinter.h"
|
|||
|
|||
#include <algorithm>
|
|||
|
|||
std::string capitalize(std::string string) { |
|||
string[0] = std::toupper(string[0]); |
|||
return string; |
|||
} |
@ -0,0 +1,35 @@ |
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <map> |
|||
|
|||
#include "cell.h" |
|||
|
|||
#define NOFAULT 7 |
|||
#define LEFT 0 |
|||
#define RIGHT 1 |
|||
#define FORWARD 2 |
|||
#define PICKUP 3 |
|||
#define DROP 4 |
|||
#define TOGGLE 5 |
|||
#define DONE 6 |
|||
|
|||
|
|||
typedef std::string AgentName; |
|||
typedef size_t ViewDirection; |
|||
typedef std::pair<std::string, coordinates> AgentNameAndPosition; |
|||
typedef AgentNameAndPosition KeyNameAndPosition; |
|||
typedef std::map<AgentNameAndPosition::first_type, AgentNameAndPosition::second_type> AgentNameAndPositionMap; |
|||
typedef std::map<KeyNameAndPosition::first_type, KeyNameAndPosition::second_type> KeyNameAndPositionMap; |
|||
typedef std::pair<cell, std::string> CellAndCondition; |
|||
typedef std::pair<float, std::string> update; |
|||
typedef std::vector<update> updates; |
|||
typedef int8_t ActionId; |
|||
|
|||
std::string capitalize(std::string string); |
|||
|
|||
namespace prism { |
|||
enum class ModelType { |
|||
MDP, SMG |
|||
}; |
|||
} |
@ -0,0 +1,105 @@ |
|||
#include "cell.h"
|
|||
|
|||
#include <stdexcept>
|
|||
#include <algorithm>
|
|||
|
|||
std::ostream &operator<<(std::ostream &os, const cell &c) { |
|||
os << static_cast<char>(c.type) << static_cast<char>(c.color); |
|||
os << " at (" << c.column << "," << c.row << ")"; |
|||
return os; |
|||
} |
|||
|
|||
coordinates cell::getCoordinates() const { |
|||
return std::make_pair(column, row); |
|||
} |
|||
|
|||
cell cell::getNorth(const std::vector<cell> &grid) const { |
|||
auto north = std::find_if(grid.begin(), grid.end(), [this](const cell &c) { |
|||
return this->row - 1 == c.row && this->column == c.column; |
|||
}); |
|||
if(north == grid.end()) { |
|||
throw std::logic_error{ "Cannot get cell north of (" + std::to_string(row) + "," + std::to_string(column) + ")"}; |
|||
std::exit(EXIT_FAILURE); |
|||
} |
|||
return *north; |
|||
} |
|||
|
|||
cell cell::getEast(const std::vector<cell> &grid) const { |
|||
auto east = std::find_if(grid.begin(), grid.end(), [this](const cell &c) { |
|||
return this->row == c.row && this->column + 1 == c.column; |
|||
}); |
|||
if(east == grid.end()) { |
|||
throw std::logic_error{ "Cannot get cell east of (" + std::to_string(row) + "," + std::to_string(column) + ")"}; |
|||
std::exit(EXIT_FAILURE); |
|||
} |
|||
return *east; |
|||
} |
|||
|
|||
cell cell::getSouth(const std::vector<cell> &grid) const { |
|||
auto south = std::find_if(grid.begin(), grid.end(), [this](const cell &c) { |
|||
return this->row + 1 == c.row && this->column == c.column; |
|||
}); |
|||
if(south == grid.end()) { |
|||
throw std::logic_error{ "Cannot get cell south of (" + std::to_string(row) + "," + std::to_string(column) + ")"}; |
|||
std::exit(EXIT_FAILURE); |
|||
} |
|||
return *south; |
|||
} |
|||
|
|||
cell cell::getWest(const std::vector<cell> &grid) const { |
|||
auto west = std::find_if(grid.begin(), grid.end(), [this](const cell &c) { |
|||
return this->row == c.row && this->column - 1 == c.column; |
|||
}); |
|||
if(west == grid.end()) { |
|||
throw std::logic_error{ "Cannot get cell west of (" + std::to_string(row) + "," + std::to_string(column) + ")"}; |
|||
std::exit(EXIT_FAILURE); |
|||
} |
|||
return *west; |
|||
} |
|||
|
|||
std::string cell::getColor() const { |
|||
switch(color) { |
|||
case Color::Red: return "red"; |
|||
case Color::Green: return "green"; |
|||
case Color::Blue: return "blue"; |
|||
case Color::Purple: return "purple"; |
|||
case Color::Yellow: return "yellow"; |
|||
case Color::None: return "transparent"; |
|||
default: return ""; |
|||
//case Color::Grey = 'G',
|
|||
} |
|||
} |
|||
|
|||
std::string cell::getType() const { |
|||
switch(type) { |
|||
case Type::Wall: return "Wall"; |
|||
case Type::Floor: return "Floor"; |
|||
case Type::Door: return "Door"; |
|||
case Type::LockedDoor: return "LockedDoor"; |
|||
case Type::Key: return "Key"; |
|||
case Type::Ball: return "Ball"; |
|||
case Type::Box: return "Box"; |
|||
case Type::Goal: return "Goal"; |
|||
case Type::Lava: return "Lava"; |
|||
case Type::Agent: return "Agent"; |
|||
case Type::Adversary: return "Adversary"; |
|||
case Type::SlipperyNorth: return "SlipperyNorth"; |
|||
case Type::SlipperySouth: return "SlipperySouth"; |
|||
case Type::SlipperyEast: return "SlipperyEast"; |
|||
case Type::SlipperyWest: return "SlipperyWest"; |
|||
default: return ""; |
|||
} |
|||
} |
|||
|
|||
std::string getColor(Color color) { |
|||
switch(color) { |
|||
case Color::Red: return "red"; |
|||
case Color::Green: return "green"; |
|||
case Color::Blue: return "blue"; |
|||
case Color::Purple: return "purple"; |
|||
case Color::Yellow: return "yellow"; |
|||
case Color::None: return "transparent"; |
|||
default: return ""; |
|||
//case Color::Grey = 'G',
|
|||
} |
|||
} |
@ -0,0 +1,68 @@ |
|||
#pragma once |
|||
|
|||
#include <iostream> |
|||
#include <utility> |
|||
#include <vector> |
|||
|
|||
typedef std::pair<int, int> coordinates; |
|||
|
|||
class Grid; |
|||
|
|||
enum class Type : char { |
|||
Wall = 'W', |
|||
Floor = ' ', |
|||
Door = 'D', |
|||
LockedDoor = 'L', |
|||
Key = 'K', |
|||
Ball = 'A', |
|||
Box = 'B', |
|||
Goal = 'G', |
|||
Lava = 'V', |
|||
Agent = 'X', |
|||
Adversary = 'Z', |
|||
SlipperyNorth = 'n', |
|||
SlipperySouth = 's', |
|||
SlipperyEast = 'e', |
|||
SlipperyWest = 'w', |
|||
SlipperyNorthWest = 'a', |
|||
SlipperyNorthEast = 'b', |
|||
SlipperySouthWest = 'c', |
|||
SlipperySouthEast = 'd' |
|||
}; |
|||
enum class Color : char { |
|||
Red = 'R', |
|||
Green = 'G', |
|||
Blue = 'B', |
|||
Purple = 'P', |
|||
Yellow = 'Y', |
|||
White = 'W', |
|||
//Grey = 'G', |
|||
None = ' ' |
|||
}; |
|||
|
|||
constexpr std::initializer_list<Color> allColors = {Color::Red, Color::Green, Color::Blue, Color::Purple, Color::Yellow}; |
|||
std::string getColor(Color color); |
|||
|
|||
class cell { |
|||
public: |
|||
coordinates getNorth() const { return std::make_pair(column, row - 1); } |
|||
coordinates getSouth() const { return std::make_pair(column, row + 1); } |
|||
coordinates getEast() const { return std::make_pair(column + 1, row); } |
|||
coordinates getWest() const { return std::make_pair(column - 1, row); } |
|||
|
|||
cell getNorth(const std::vector<cell> &grid) const; |
|||
cell getEast(const std::vector<cell> &grid) const; |
|||
cell getSouth(const std::vector<cell> &grid) const; |
|||
cell getWest(const std::vector<cell> &grid) const; |
|||
|
|||
friend std::ostream& operator<<(std::ostream& os, const cell& cell); |
|||
|
|||
coordinates getCoordinates() const; |
|||
std::string getColor() const; |
|||
std::string getType() const; |
|||
|
|||
int row; |
|||
int column; |
|||
Type type; |
|||
Color color; |
|||
}; |
1331
Minigrid2PRISM/util/popl.hpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,47 @@ |
|||
#!/usr/bin/env bash |
|||
|
|||
pushd . |
|||
|
|||
mkdir -p cache/ |
|||
|
|||
pushd cache/ |
|||
|
|||
if [ ! -d cache/carl ]; then |
|||
if [ ${TRAVIS_BRANCH} == "master14" ]; then |
|||
git clone https://github.com/smtrat/carl.git --branch master14 |
|||
else |
|||
git clone https://github.com/smtrat/carl.git |
|||
fi |
|||
else |
|||
pushd carl/ |
|||
git fetch |
|||
git reset --hard origin/master |
|||
popd |
|||
fi |
|||
|
|||
mkdir -p carl/build |
|||
pushd carl/build/ |
|||
cmake -D DEVELOPER=ON -D BUILD_ADDONS=OFF ../ || return 1 |
|||
if [ ${TRAVIS_BRANCH} == "master14" ]; then |
|||
make lib_carl || return 1 |
|||
else |
|||
make carl || return 1 |
|||
fi |
|||
popd |
|||
|
|||
popd |
|||
|
|||
|
|||
mkdir -p build |
|||
cd build/ |
|||
|
|||
cmake ../ || return 1 |
|||
make || return 1 |
|||
|
|||
# Build a second time to avoid problems in macOS |
|||
cmake ../ || return 1 |
|||
make || return 1 |
|||
|
|||
./test/carl-parser-test || return 1 |
|||
|
|||
popd |
@ -0,0 +1,45 @@ |
|||
#!/usr/bin/env bash |
|||
|
|||
if [[ ${TASK} == "DEPLOY" && ${TRAVIS_BRANCH} == "master14" ]]; then |
|||
BRANCH="deploy-`git rev-parse --short HEAD`" |
|||
git checkout --orphan $BRANCH |
|||
|
|||
git add .gitignore CMakeLists.txt README.md |
|||
git add cmake/ resources/ src/ test/ |
|||
git add -f lib/ |
|||
git add -f src/generated/ |
|||
|
|||
git commit -m "Prebuild parser" |
|||
git tag -fa deploy-latest -m "latest version" |
|||
|
|||
git remote add github https://${GH_TOKEN}@github.com/smtrat/carl-parser.git |
|||
git push github $BRANCH --tags --force |
|||
|
|||
git config remote.github.fetch +refs/heads/*:refs/remotes/github/* |
|||
git fetch --unshallow github |
|||
|
|||
for branch in `git for-each-ref --sort=committerdate --format='%(refname:short)'` |
|||
do |
|||
# Avoid deleting branches other than deploy-<commitid> |
|||
if [[ ! "$branch" =~ ^github/deploy-[0-9a-f]+$ ]]; then |
|||
continue |
|||
fi |
|||
|
|||
# Avoid deleting branches referenced by tags |
|||
tags=`git log --oneline --decorate $branch | grep "tag:"` |
|||
if [[ ! -z "$tags" ]]; then |
|||
continue |
|||
fi |
|||
|
|||
# Avoid deleting branches less than a week old |
|||
now=`date +%s` |
|||
lastcommit=`git log --pretty=format:'%at' -1 $branch` |
|||
days=$(((now-lastcommit)/3600/24)) |
|||
if [ "$days" -lt 7 ]; then |
|||
continue |
|||
fi |
|||
|
|||
echo "Deleting $branch..." |
|||
git push github --delete ${branch#github/} |
|||
done |
|||
fi |
@ -0,0 +1,98 @@ |
|||
cmake_minimum_required(VERSION 3.0.0) |
|||
project(carl-parser) |
|||
|
|||
option(BUILD_JAR "Built ANTLR jar file" OFF) |
|||
|
|||
set(DYNAMIC_EXT ".so") |
|||
set(STATIC_EXT ".a") |
|||
if(APPLE) |
|||
set(DYNAMIC_EXT ".dylib") |
|||
set(STATIC_EXT ".a") |
|||
elseif (WIN32) |
|||
set(DYNAMIC_EXT ".dll") |
|||
set(STATIC_EXT ".lib") |
|||
endif() |
|||
|
|||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # Matches "Clang" and "AppleClang" |
|||
if (APPLE) |
|||
message(STATUS "Using clang ${CMAKE_CXX_COMPILER_VERSION} on apple") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -stdlib=libc++") |
|||
|
|||
## RPATH settings |
|||
set(CMAKE_MACOSX_RPATH 1) |
|||
# don't skip the full RPATH for the build tree |
|||
SET(CMAKE_SKIP_BUILD_RPATH FALSE) |
|||
# when building, don't use the install RPATH already (but only when installing) |
|||
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) |
|||
# the RPATH to be used when installing |
|||
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") |
|||
# add the automatically determined parts of the RPATH |
|||
# which point to directories outside the build tree to the install RPATH |
|||
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) |
|||
|
|||
else() |
|||
message(STATUS "Using clang ${CMAKE_CXX_COMPILER_VERSION}") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") |
|||
endif() |
|||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_RELEASE_FLAGS} -O3 -fomit-frame-pointer -msse -msse2 -funroll-loops") |
|||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_DEBUG_FLAGS} -O1") |
|||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
|||
message(STATUS "Using g++ ${CMAKE_CXX_COMPILER_VERSION}") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wunknown-pragmas") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmax-errors=5 -fdiagnostics-color=auto") |
|||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_RELEASE_FLAGS} -O3") |
|||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_DEBUG_FLAGS} -O1") |
|||
else() |
|||
message(WARNING "Possibly unsupported compiler ${CMAKE_CXX_COMPILER_ID}") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") |
|||
endif() |
|||
|
|||
# Require carl |
|||
find_package(carl REQUIRED) |
|||
# Output information about carl |
|||
get_target_property(carlLOCATION lib_carl LOCATION) |
|||
message(STATUS "Using carl ${carl_VERSION} from ${carlLOCATION}.") |
|||
|
|||
# External projects |
|||
include(ExternalProject) |
|||
SET_DIRECTORY_PROPERTIES(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/resources) |
|||
|
|||
set(ANTLR_VERSION "4.7.2") |
|||
if (BUILD_JAR) |
|||
message(STATUS "Built jar file of ANTLR ${ANTLR_VERSION}") |
|||
else() |
|||
message(STATUS "Use shipped jar file of ANTLR ${ANTLR_VERSION}") |
|||
endif() |
|||
include(resources/antlr4.cmake) |
|||
|
|||
# Add actual sources |
|||
add_subdirectory(src) |
|||
|
|||
# tests |
|||
enable_testing() |
|||
add_subdirectory(test) |
|||
|
|||
# Add all targets to the build-tree export set |
|||
set(EXPORT_TARGETS "carl-parser") |
|||
export(TARGETS ${EXPORT_TARGETS} FILE "${PROJECT_BINARY_DIR}/carlparserTargets.cmake") |
|||
|
|||
message(STATUS "Registered with cmake") |
|||
export(PACKAGE carlparser) |
|||
|
|||
set(INCLUDE_DIR include/) |
|||
include(CMakePackageConfigHelpers) |
|||
include(cmake/export_target.cmake) |
|||
|
|||
export_target(DEP_TARGETS antlr4shared) |
|||
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src") |
|||
configure_package_config_file( |
|||
cmake/carlparserConfig.cmake.in |
|||
${PROJECT_BINARY_DIR}/carlparserConfig.cmake |
|||
INSTALL_DESTINATION ${PROJECT_BINARY_DIR} |
|||
PATH_VARS INCLUDE_DIR |
|||
) |
|||
|
|||
|
|||
if (APPLE) |
|||
message(WARNING "If tests are unsuccessful or errors occur, try running 'cmake ..' and 'make' once again.") |
|||
endif() |
@ -0,0 +1,49 @@ |
|||
Parser for carl data structures |
|||
-------------------------------------- |
|||
|
|||
This is an [ANTLR](http://www.antlr.org)-based parser which is meant as an extension to [CArL](https://github.com/smtrat/carl). |
|||
|
|||
### Requirements |
|||
|
|||
The parser requires the following tools: |
|||
- CArL |
|||
- Maven |
|||
|
|||
### Building |
|||
|
|||
To build, first [install CArL](https://smtrat.github.io/carl/). Then build carl-parser with |
|||
|
|||
```bash |
|||
mkdir build |
|||
cd build |
|||
cmake .. |
|||
make |
|||
``` |
|||
|
|||
You can run tests with |
|||
|
|||
```bash |
|||
test/carl-parser-test |
|||
``` |
|||
|
|||
or simply with |
|||
|
|||
```bash |
|||
make test |
|||
``` |
|||
|
|||
### Frequent errors |
|||
|
|||
On MacOSX, there is a known problem with the rpath, which might lead to an error when executing the tests. |
|||
The problem can be alleviated by re-running both |
|||
|
|||
```bash |
|||
cmake .. |
|||
make |
|||
``` |
|||
|
|||
### Authors: |
|||
|
|||
- Harold Bruintjes |
|||
- Sebastian Junges |
|||
- Gereon Kremer |
@ -0,0 +1,12 @@ |
|||
## Our library dependencies (contains definitions for IMPORTED targets) |
|||
|
|||
include("@PROJECT_BINARY_DIR@/carlparserTargets.cmake") |
|||
|
|||
@DEP_TARGETS@ |
|||
|
|||
@PACKAGE_INIT@ |
|||
|
|||
set(carlparser_INCLUDE_DIR "@CONF_INCLUDE_DIRS@") |
|||
|
|||
set(carlparser_LIBRARIES carl-parser) |
|||
check_required_components(carlparser) |
@ -0,0 +1,61 @@ |
|||
#### From carl. |
|||
|
|||
function(_export_target_add_lib output TARGET TYPE) |
|||
set(${output} "${${output}} |
|||
|
|||
add_library(${TARGET} ${TYPE} IMPORTED)" PARENT_SCOPE) |
|||
endfunction(_export_target_add_lib) |
|||
function(_export_target_start output TARGET) |
|||
set(${output} "${${output}} |
|||
|
|||
if(NOT TARGET ${TARGET})" PARENT_SCOPE) |
|||
endfunction(_export_target_start) |
|||
function(_export_target_end output) |
|||
set(${output} "${${output}} |
|||
endif()" PARENT_SCOPE) |
|||
endfunction(_export_target_end) |
|||
|
|||
macro(_export_target_set_prop output TARGET REQUIRED PROPERTY) |
|||
get_target_property(VALUE ${TARGET} ${PROPERTY}) |
|||
set(extra_args ${ARGN}) |
|||
list(GET extra_args 0 NEWPROPERTY) |
|||
if(NOT NEWPROPERTY) |
|||
set(NEWPROPERTY ${PROPERTY}) |
|||
endif() |
|||
if(VALUE) |
|||
set(${output} "${${output}} |
|||
set_target_properties(${TARGET} PROPERTIES ${NEWPROPERTY} \"${VALUE}\")") |
|||
elseif(${REQUIRED}) |
|||
message(STATUS "Did not find ${PROPERTY} of ${TARGET} for export.") |
|||
endif() |
|||
endmacro(_export_target_set_prop) |
|||
|
|||
macro(export_target output TARGET) |
|||
get_target_property(TYPE ${TARGET} TYPE) |
|||
_export_target_start(${output} ${TARGET}) |
|||
if(TYPE STREQUAL "SHARED_LIBRARY") |
|||
_export_target_add_lib(${output} ${TARGET} SHARED) |
|||
_export_target_set_prop(${output} ${TARGET} TRUE IMPORTED_LOCATION) |
|||
_export_target_set_prop(${output} ${TARGET} FALSE INTERFACE_INCLUDE_DIRECTORIES) |
|||
_export_target_set_prop(${output} ${TARGET} FALSE LINK_INTERFACE_LIBRARIES) |
|||
elseif(TYPE STREQUAL "STATIC_LIBRARY") |
|||
_export_target_add_lib(${output} ${TARGET} STATIC) |
|||
_export_target_set_prop(${output} ${TARGET} TRUE IMPORTED_LOCATION) |
|||
_export_target_set_prop(${output} ${TARGET} FALSE INTERFACE_INCLUDE_DIRECTORIES) |
|||
_export_target_set_prop(${output} ${TARGET} FALSE LINK_INTERFACE_LIBRARIES IMPORTED_LINK_INTERFACE_LIBRARIES) |
|||
elseif(TYPE STREQUAL "INTERFACE_LIBRARY") |
|||
_export_target_add_lib(${output} ${TARGET} INTERFACE) |
|||
_export_target_set_prop(${output} ${TARGET} TRUE INTERFACE_INCLUDE_DIRECTORIES) |
|||
_export_target_set_prop(${output} ${TARGET} FALSE INTERFACE_LINK_LIBRARIES) |
|||
else() |
|||
message(STATUS "Unknown type ${TYPE}") |
|||
endif() |
|||
if(NOT "${ARGN}" STREQUAL "") |
|||
set(deps ${ARGN}) |
|||
foreach(d ${deps}) |
|||
set(${output} "${${output}} |
|||
set_target_properties(${TARGET} PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES \"${d}\")") |
|||
endforeach() |
|||
endif() |
|||
_export_target_end(${output}) |
|||
endmacro(export_target) |
@ -0,0 +1,73 @@ |
|||
find_program(MAVEN mvn) |
|||
if(NOT MAVEN) |
|||
message(SEND_ERROR "Can not build ANTLR4, missing binary for maven") |
|||
endif() |
|||
|
|||
find_path(UUID_PATH NAMES uuid/uuid.h) |
|||
if(NOT UUID_PATH) |
|||
message(WARNING "Building ANTLR4 C++ runtime will probably fail, could not find uuid.h") |
|||
endif() |
|||
|
|||
ExternalProject_Add( |
|||
ANTLR |
|||
GIT_REPOSITORY "https://github.com/volkm/antlr4.git" |
|||
#GIT_TAG "${ANTLR_VERSION}" |
|||
GIT_TAG "rpath_fix" |
|||
BUILD_IN_SOURCE 1 |
|||
UPDATE_COMMAND "" |
|||
CONFIGURE_COMMAND "" |
|||
BUILD_COMMAND "" |
|||
INSTALL_COMMAND "" |
|||
) |
|||
|
|||
ExternalProject_Get_Property(ANTLR SOURCE_DIR) |
|||
ExternalProject_Get_Property(ANTLR INSTALL_DIR) |
|||
|
|||
if (BUILD_JAR) |
|||
ExternalProject_Add( |
|||
ANTLR-jar |
|||
EXCLUDE_FROM_ALL 1 |
|||
DOWNLOAD_COMMAND "" |
|||
SOURCE_DIR "${SOURCE_DIR}" |
|||
BUILD_IN_SOURCE 1 |
|||
UPDATE_COMMAND "" |
|||
CONFIGURE_COMMAND mvn clean |
|||
BUILD_COMMAND mvn -DskipTests package -pl tool -am |
|||
INSTALL_COMMAND "" |
|||
) |
|||
endif() |
|||
|
|||
set(ANTLR-runtime_TARGETS "antlr4_shared") |
|||
|
|||
ExternalProject_Add( |
|||
ANTLR-runtime |
|||
DOWNLOAD_COMMAND "" |
|||
SOURCE_DIR "${SOURCE_DIR}" |
|||
UPDATE_COMMAND "" |
|||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=ON -DBUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> "<SOURCE_DIR>/runtime/Cpp" -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} |
|||
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target antlr4_shared |
|||
COMMAND ${CMAKE_COMMAND} --build . --target antlr4_static |
|||
BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/resources/lib/libantlr4-runtime${DYNAMIC_EXT} |
|||
) |
|||
|
|||
ExternalProject_Get_Property(ANTLR-runtime INSTALL_DIR) |
|||
|
|||
file(MAKE_DIRECTORY "${INSTALL_DIR}/include") |
|||
file(MAKE_DIRECTORY "${INSTALL_DIR}/include/antlr4-runtime") |
|||
|
|||
add_library(antlr4shared SHARED IMPORTED GLOBAL) |
|||
set_target_properties(antlr4shared PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/lib/libantlr4-runtime${DYNAMIC_EXT}) |
|||
set_target_properties(antlr4shared PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${INSTALL_DIR}/include;${INSTALL_DIR}/include/antlr4-runtime") |
|||
|
|||
add_library(antlr4static STATIC IMPORTED GLOBAL) |
|||
set_target_properties(antlr4static PROPERTIES IMPORTED_LOCATION ${INSTALL_DIR}/lib/libantlr4-runtime${STATIC_EXT}) |
|||
set_target_properties(antlr4static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${INSTALL_DIR}/include;${INSTALL_DIR}/include/antlr4-runtime") |
|||
|
|||
if (USE_SHIPPED_JAR) |
|||
add_dependencies(ANTLR-jar ANTLR) |
|||
endif() |
|||
add_dependencies(ANTLR-runtime ANTLR) |
|||
add_dependencies(antlr4shared ANTLR-runtime) |
|||
add_dependencies(antlr4static ANTLR-runtime) |
|||
|
|||
mark_as_advanced(MAVEN) |
@ -0,0 +1,71 @@ |
|||
# WARNING: |
|||
# add_custom_command makes the output files only visible in the same directory. |
|||
# Therefore, we cannot simply run this code here, but must export it as a function to be called in the right context. |
|||
|
|||
function(create_antlr_targets) |
|||
find_package(Java COMPONENTS Runtime) |
|||
|
|||
set(ANTLR_generated_sources "") |
|||
file(GLOB_RECURSE antlr_grammars "${CMAKE_SOURCE_DIR}/src/*.g4") |
|||
|
|||
set(ANTLR_generated_include "" PARENT_SCOPE) |
|||
set(ANTLR_generated_sources "" PARENT_SCOPE) |
|||
|
|||
set(ANTLR_JAR "${PROJECT_SOURCE_DIR}/resources/lib/antlr-${ANTLR_VERSION}-complete.jar") |
|||
|
|||
if (BUILD_JAR) |
|||
add_custom_command(OUTPUT ${ANTLR_JAR} |
|||
COMMAND ${CMAKE_COMMAND} --build . --target ANTLR-jar |
|||
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/lib/ |
|||
COMMAND cp ${SOURCE_DIR}/tool/target/antlr4-${ANTLR_VERSION}-complete.jar ${ANTLR_JAR} |
|||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
|||
) |
|||
endif() |
|||
|
|||
foreach(file ${antlr_grammars}) |
|||
get_filename_component(DIR ${file} DIRECTORY) |
|||
file(RELATIVE_PATH DIR ${CMAKE_SOURCE_DIR}/src "${DIR}") |
|||
get_filename_component(FILENAME ${file} NAME) |
|||
get_filename_component(GRAMMAR ${file} NAME_WE) |
|||
set(DESTDIR "${CMAKE_SOURCE_DIR}/src/generated/${DIR}") |
|||
|
|||
# https://github.com/antlr/antlr4/blob/master/doc/cpp-target.md |
|||
set(generated_sources |
|||
${DESTDIR}/${GRAMMAR}Lexer.cpp |
|||
${DESTDIR}/${GRAMMAR}Parser.cpp |
|||
${DESTDIR}/${GRAMMAR}Visitor.cpp |
|||
${DESTDIR}/${GRAMMAR}BaseVisitor.cpp |
|||
${DESTDIR}/${GRAMMAR}Listener.cpp |
|||
${DESTDIR}/${GRAMMAR}BaseListener.cpp |
|||
) |
|||
set(ANTLR_generated_sources "${ANTLR_generated_sources};${generated_sources}") |
|||
|
|||
add_custom_command( |
|||
OUTPUT ${generated_sources} |
|||
COMMAND ${CMAKE_COMMAND} -E make_directory ${DESTDIR} |
|||
COMMAND ${Java_JAVA_EXECUTABLE} -jar ${ANTLR_JAR} -Werror -Dlanguage=Cpp -listener -visitor -o ${DESTDIR} -package carlparser ${file} |
|||
DEPENDS ${file} ${ANTLR_JAR} |
|||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src |
|||
) |
|||
endforeach() |
|||
set(ANTLR_generated_include ${ANTLR_generated_include} "${CMAKE_SOURCE_DIR}/src/generated/" PARENT_SCOPE) |
|||
set(ANTLR_generated_sources ${ANTLR_generated_sources} "${generated_sources}" PARENT_SCOPE) |
|||
|
|||
endfunction() |
|||
|
|||
create_antlr_targets() |
|||
#set(CMAKE_DEBUG_TARGET_PROPERTIES INCLUDE_DIRECTORIES) |
|||
|
|||
add_library(carl-parser SHARED ${CMAKE_CURRENT_SOURCE_DIR}/carl-parser/ParseTreeVisitor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/carl-parser/Parser.cpp ${ANTLR_generated_sources}) |
|||
target_include_directories(carl-parser PUBLIC ${ANTLR_generated_include}) |
|||
target_link_libraries(carl-parser PUBLIC carl-shared PRIVATE antlr4shared) |
|||
|
|||
set(PARSER_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/) |
|||
list(APPEND PARSER_INCLUDES ${ANTLR_generated_include}) |
|||
|
|||
|
|||
|
|||
target_include_directories( carl-parser PUBLIC |
|||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/src> |
|||
"$<BUILD_INTERFACE:${PARSER_INCLUDES}>" |
|||
) |
@ -0,0 +1,463 @@ |
|||
#include "ParseTreeVisitor.h"
|
|||
|
|||
#include <carl/formula/Formula.h>
|
|||
|
|||
using namespace carl; |
|||
|
|||
namespace carlparser { |
|||
|
|||
template<typename Res, typename Pol> |
|||
class perform_addition: public boost::static_visitor<Res> { |
|||
public: |
|||
template<typename T, typename U> |
|||
Res operator()(const T& lhs, const U& rhs) const { |
|||
return Pol(lhs) + Pol(rhs); |
|||
} |
|||
|
|||
Res operator()(const typename Pol::CoeffType& lhs, const typename Pol::CoeffType& rhs) const { |
|||
return (lhs) + (rhs); |
|||
} |
|||
|
|||
Res operator()(const RationalFunction<Pol>& lhs, const Monomial::Arg& rhs) const { |
|||
return (lhs) + Pol(rhs); |
|||
} |
|||
|
|||
Res operator()(const RationalFunction<Pol>& lhs, const Term<typename Pol::CoeffType>& rhs) const { |
|||
return (lhs) + Pol(rhs); |
|||
} |
|||
|
|||
template<typename T> |
|||
Res operator()(const RationalFunction<Pol>& lhs, const T& rhs) const { |
|||
return (lhs) + (rhs); |
|||
} |
|||
|
|||
template<typename T> |
|||
Res operator()(const T& lhs, const RationalFunction<Pol>& rhs) const { |
|||
return (rhs) + Pol(lhs); |
|||
} |
|||
|
|||
Res operator()(const RationalFunction<Pol>& lhs, const RationalFunction<Pol>& rhs) const { |
|||
return (lhs) + (rhs); |
|||
} |
|||
}; |
|||
|
|||
template<typename Res, typename Pol> |
|||
class perform_subtraction: public boost::static_visitor<Res> { |
|||
public: |
|||
template<typename T, typename U> |
|||
Res operator()(const T& lhs, const U& rhs) const { |
|||
return Pol(lhs) - Pol(rhs); |
|||
} |
|||
|
|||
Res operator()(const typename Pol::CoeffType& lhs, const typename Pol::CoeffType& rhs) const { |
|||
return (lhs) - (rhs); |
|||
} |
|||
|
|||
Res operator()(const RationalFunction<Pol>& lhs, const Monomial::Arg& rhs) const { |
|||
return (lhs) - Pol(rhs); |
|||
} |
|||
|
|||
Res operator()(const RationalFunction<Pol>& lhs, const Term<typename Pol::CoeffType>& rhs) const { |
|||
return (lhs) - Pol(rhs); |
|||
} |
|||
|
|||
template<typename T> |
|||
Res operator()(const RationalFunction<Pol>& lhs, const T& rhs) const { |
|||
return (lhs) - (rhs); |
|||
} |
|||
|
|||
template<typename T> |
|||
Res operator()(const T& lhs, const RationalFunction<Pol>& rhs) const { |
|||
return (rhs) - Pol(lhs); |
|||
} |
|||
|
|||
Res operator()(const RationalFunction<Pol>& lhs, const RationalFunction<Pol>& rhs) const { |
|||
return (lhs) - (rhs); |
|||
} |
|||
}; |
|||
|
|||
template<typename Res, typename Pol> |
|||
class perform_unary_subtraction: public boost::static_visitor<Res> { |
|||
public: |
|||
template<typename T> |
|||
Res operator()(const T& lhs) const { |
|||
return -lhs; |
|||
} |
|||
|
|||
Res operator()(const Monomial::Arg& lhs) const { |
|||
return -Pol(lhs); |
|||
} |
|||
|
|||
Res operator()(const Variable& lhs) const { |
|||
return -Pol(lhs); |
|||
} |
|||
}; |
|||
|
|||
|
|||
template<typename Res, typename Pol> |
|||
class perform_multiplication: public boost::static_visitor<Res> { |
|||
public: |
|||
template<typename T, typename U> |
|||
Res operator()(const T& lhs, const U& rhs) const { |
|||
return lhs * rhs; |
|||
} |
|||
|
|||
template<typename T> |
|||
Res operator()(const T& lhs, const RationalFunction<Pol>& rhs) const { |
|||
return rhs * lhs; |
|||
} |
|||
|
|||
Res operator()(const RationalFunction<Pol>& lhs, const Monomial::Arg& rhs) const { |
|||
return (lhs) * Pol(rhs); |
|||
} |
|||
|
|||
Res operator()(const RationalFunction<Pol>& lhs, const Term<typename Pol::CoeffType>& rhs) const { |
|||
return (lhs) * Pol(rhs); |
|||
} |
|||
|
|||
Res operator()(const Monomial::Arg& lhs, const RationalFunction<Pol>& rhs) const { |
|||
return (rhs) * Pol(lhs); |
|||
} |
|||
|
|||
Res operator()(const Term<typename Pol::CoeffType>& lhs, const RationalFunction<Pol>& rhs) const { |
|||
return (rhs) * Pol(lhs); |
|||
} |
|||
}; |
|||
|
|||
template<typename Res, typename Pol> |
|||
class perform_division: public boost::static_visitor<Res> { |
|||
public: |
|||
Res operator()(const RationalFunction<Pol>& lhs, const typename Pol::CoeffType& rhs) const { |
|||
return lhs / rhs; |
|||
} |
|||
|
|||
template<typename T> |
|||
Res operator()(const RationalFunction<Pol>& lhs, const T& rhs) const { |
|||
return lhs / rhs; |
|||
} |
|||
|
|||
Res operator()(const RationalFunction<Pol>& lhs, const Monomial::Arg& rhs) const { |
|||
return lhs / Pol(rhs); |
|||
} |
|||
|
|||
Res operator()(const RationalFunction<Pol>& lhs, const Term<typename Pol::CoeffType>& rhs) const { |
|||
return lhs / Pol(rhs); |
|||
} |
|||
|
|||
Res operator()(const RationalFunction<Pol>& lhs, const RationalFunction<Pol>& rhs) const { |
|||
return lhs / rhs; |
|||
} |
|||
|
|||
template<typename T> |
|||
Res operator()(const T& lhs, const typename Pol::CoeffType& coeff) const { |
|||
return lhs * reciprocal(coeff); |
|||
} |
|||
|
|||
template<typename T> |
|||
Res operator()(const T& lhs, const RationalFunction<Pol>& rhs) const { |
|||
// TODO: Not extremely efficient probably
|
|||
return RationalFunction<Pol>(rhs.denominator(), rhs.nominator()) * Pol(lhs); |
|||
} |
|||
|
|||
template<typename T, typename U> |
|||
Res operator()(const T& lhs, const U& rhs) const { |
|||
return RationalFunction<Pol>(Pol(lhs), Pol(rhs)); |
|||
} |
|||
}; |
|||
|
|||
template<typename Pol> |
|||
class make_constraint: public boost::static_visitor<Constraint<Pol>> { |
|||
Relation m_rel; |
|||
public: |
|||
make_constraint(Relation rel) : m_rel(rel) {} |
|||
|
|||
template<typename T> |
|||
Constraint<Pol> operator()(T const& expr) const { |
|||
return Constraint<Pol>(Pol(expr), m_rel); |
|||
} |
|||
|
|||
Constraint<Pol> operator()(Pol const& expr) const { |
|||
return Constraint<Pol>(expr, m_rel); |
|||
} |
|||
|
|||
Constraint<Pol> operator()(RationalFunction<Pol> const& expr) const { |
|||
throw std::runtime_error("Cannot compare rational function"); |
|||
} |
|||
}; |
|||
|
|||
class to_antlr_any: public boost::static_visitor<antlrcpp::Any> { |
|||
public: |
|||
template<typename T> |
|||
antlrcpp::Any operator()(T const& expr) const { |
|||
return expr; |
|||
} |
|||
}; |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitStart(SerializationParser::StartContext *ctx) { |
|||
return ctx->carl_expr()->accept(this); |
|||
} |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitCarl_expr(SerializationParser::Carl_exprContext *ctx) { |
|||
if (ctx->formula_nary()) { |
|||
return ctx->formula_nary()->accept(this); |
|||
} else if (ctx->formula_unary()) { |
|||
return ctx->formula_unary()->accept(this); |
|||
} else if (ctx->constraint()) { |
|||
return ctx->constraint()->accept(this); |
|||
} else if (ctx->arith_nary()) { |
|||
return boost::apply_visitor(to_antlr_any(), ctx->arith_nary()->accept(this).template as<ArithType>()); |
|||
} else if (ctx->arith_unary()) { |
|||
return boost::apply_visitor(to_antlr_any(), ctx->arith_unary()->accept(this).template as<ArithType>()); |
|||
} else if (ctx->real_variable()) { |
|||
return boost::apply_visitor(to_antlr_any(), ctx->real_variable()->accept(this).template as<ArithType>()); |
|||
} else if (ctx->number()) { |
|||
return boost::apply_visitor(to_antlr_any(), ctx->number()->accept(this).template as<ArithType>()); |
|||
} else if (ctx->boolean()) { |
|||
return ctx->boolean()->accept(this).template as<Formula<Pol>>(); |
|||
} |
|||
throw std::runtime_error("Unknown formula rule"); |
|||
} |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitForm_expr(SerializationParser::Form_exprContext *ctx) { |
|||
if (ctx->formula_nary()) { |
|||
return ctx->formula_nary()->accept(this); |
|||
} else if (ctx->formula_unary()) { |
|||
return ctx->formula_unary()->accept(this); |
|||
} else if (ctx->constraint()) { |
|||
return Formula<Pol>(ctx->constraint()->accept(this).template as<Constraint<Pol>>()); |
|||
} else if (ctx->boolean()) { |
|||
return ctx->boolean()->accept(this); |
|||
} else if (ctx->bool_variable()) { |
|||
return ctx->bool_variable()->accept(this); |
|||
} |
|||
throw std::runtime_error("Unknown formula rule"); |
|||
} |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitFormula_nary(SerializationParser::Formula_naryContext *ctx) { |
|||
FormulaType type = ctx->form_op_nary()->accept(this).template as<FormulaType>(); |
|||
if (type == FormulaType::ITE) { |
|||
if (ctx->form_expr().size() != 3) { |
|||
throw std::runtime_error("ITE formula requires 3 subformulae"); |
|||
} |
|||
return Formula<Pol>(type, ctx->form_expr(0)->accept(this).template as<Formula<Pol>>(), |
|||
ctx->form_expr(1)->accept(this).template as<Formula<Pol>>(), |
|||
ctx->form_expr(2)->accept(this).template as<Formula<Pol>>()); |
|||
} else { |
|||
if (ctx->form_expr().size() < 2) { |
|||
if (type != FormulaType::AND && type != FormulaType::OR) { |
|||
throw std::runtime_error("formula requires >1 subformulae"); |
|||
} |
|||
return ctx->form_expr(0)->accept(this).template as<Formula<Pol>>(); |
|||
} |
|||
size_t index = 0; |
|||
Formula<Pol> form = ctx->form_expr(index)->accept(this).template as<Formula<Pol>>(); |
|||
++index; |
|||
for(; index < ctx->form_expr().size(); ++index) { |
|||
form = Formula<Pol>(type, form, ctx->form_expr(index)->accept(this).template as<Formula<Pol>>()); |
|||
} |
|||
return form; |
|||
} |
|||
} |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitForm_op_nary(SerializationParser::Form_op_naryContext *ctx) { |
|||
auto const& text = ctx->getText(); |
|||
if (text == "and") { |
|||
return FormulaType::AND; |
|||
} else if (text == "or") { |
|||
return FormulaType::OR; |
|||
} else if (text == "=") { |
|||
return FormulaType::IFF; |
|||
} else if (text == "xor") { |
|||
return FormulaType::XOR; |
|||
} else if (text == "=>") { |
|||
return FormulaType::IMPLIES; |
|||
} else if (text == "ite") { |
|||
return FormulaType::ITE; |
|||
} |
|||
throw std::runtime_error("Unknown formula operator"); |
|||
} |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitFormula_unary(SerializationParser::Formula_unaryContext *ctx) { |
|||
auto formula = ctx->form_expr()->accept(this).template as<Formula<Pol>>(); |
|||
return Formula<Pol>(FormulaType::NOT, formula); |
|||
} |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitConstraint(SerializationParser::ConstraintContext *ctx) { |
|||
auto const& text = ctx->token->getText(); |
|||
auto lhs = ctx->arith_expr(0)->accept(this).template as<ArithType>(); |
|||
auto rhs = ctx->arith_expr(1)->accept(this).template as<ArithType>(); |
|||
auto arith_expr = boost::apply_visitor(perform_subtraction<ArithType, Pol>(), lhs, rhs); |
|||
if (text == "=") { |
|||
return boost::apply_visitor(make_constraint<Pol>(Relation::EQ), arith_expr); |
|||
} else if (text == "!=") { |
|||
return boost::apply_visitor(make_constraint<Pol>(Relation::NEQ), arith_expr); |
|||
} else if (text == "<") { |
|||
return boost::apply_visitor(make_constraint<Pol>(Relation::LESS), arith_expr); |
|||
} else if (text == "<=") { |
|||
return boost::apply_visitor(make_constraint<Pol>(Relation::LEQ), arith_expr); |
|||
} else if (text == ">") { |
|||
return boost::apply_visitor(make_constraint<Pol>(Relation::GREATER), arith_expr); |
|||
} else if (text == ">=") { |
|||
return boost::apply_visitor(make_constraint<Pol>(Relation::GEQ), arith_expr); |
|||
} else { |
|||
throw std::runtime_error("Unknown constraint operator"); |
|||
} |
|||
} |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitArith_expr(SerializationParser::Arith_exprContext *ctx) { |
|||
if (ctx->arith_nary()) { |
|||
return ctx->arith_nary()->accept(this); |
|||
} else if (ctx->arith_unary()) { |
|||
return ctx->arith_unary()->accept(this); |
|||
} else if (ctx->number()) { |
|||
return ctx->number()->accept(this); |
|||
} else if (ctx->real_variable()) { |
|||
return ctx->real_variable()->accept(this); |
|||
} |
|||
throw std::runtime_error("Unknown arithmetic rule"); |
|||
} |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitArith_nary(SerializationParser::Arith_naryContext *ctx) { |
|||
auto const& text = ctx->token->getText(); |
|||
auto baseExpr = ctx->arith_expr(0)->accept(this).template as<ArithType>(); |
|||
if (text == "+") { |
|||
for(size_t i = 1; i < ctx->arith_expr().size(); ++i) { |
|||
auto nextExpr = ctx->arith_expr(i)->accept(this).template as<ArithType>(); |
|||
baseExpr = boost::apply_visitor(perform_addition<ArithType, Pol>(), baseExpr, nextExpr); |
|||
} |
|||
} else if (text == "-") { |
|||
for(size_t i = 1; i < ctx->arith_expr().size(); ++i) { |
|||
auto nextExpr = ctx->arith_expr(i)->accept(this); |
|||
baseExpr = boost::apply_visitor(perform_subtraction<ArithType, Pol>(), baseExpr, nextExpr.template as<ArithType>()); |
|||
} |
|||
} else if (text == "*") { |
|||
for(size_t i = 1; i < ctx->arith_expr().size(); ++i) { |
|||
auto nextExpr = ctx->arith_expr(i)->accept(this); |
|||
baseExpr = boost::apply_visitor(perform_multiplication<ArithType, Pol>(), baseExpr, nextExpr.template as<ArithType>()); |
|||
} |
|||
} else if (text == "/") { |
|||
for(size_t i = 1; i < ctx->arith_expr().size(); ++i) { |
|||
auto nextExpr = ctx->arith_expr(i)->accept(this); |
|||
baseExpr = boost::apply_visitor(perform_division<ArithType, Pol>(), baseExpr, nextExpr.template as<ArithType>()); |
|||
} |
|||
} else { |
|||
throw std::runtime_error("Unknown arithmetic operator"); |
|||
} |
|||
return baseExpr; |
|||
} |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitArith_unary(SerializationParser::Arith_unaryContext *ctx) { |
|||
auto const& text = ctx->token->getText(); |
|||
auto baseExpr = ctx->arith_expr()->accept(this).template as<ArithType>(); |
|||
if (text == "+") { |
|||
// Skip.
|
|||
} else if (text == "-") { |
|||
baseExpr = boost::apply_visitor(perform_unary_subtraction<ArithType, Pol>(), baseExpr); |
|||
} else { |
|||
throw std::runtime_error("Unknown arithmetic operator"); |
|||
} |
|||
return baseExpr; |
|||
} |
|||
|
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitBoolean(SerializationParser::BooleanContext *ctx) { |
|||
if (ctx->TRUE()) { |
|||
return carl::Formula<Pol>(FormulaType::TRUE); |
|||
} else if (ctx->FALSE()) { |
|||
return carl::Formula<Pol>(FormulaType::FALSE); |
|||
} |
|||
throw std::runtime_error("Unknown boolean"); |
|||
} |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitNumber(SerializationParser::NumberContext *ctx) { |
|||
Rational tmp; |
|||
if (ctx->NUMERAL()) { |
|||
bool suc = carl::try_parse<Rational>(ctx->NUMERAL()->getText(), tmp); |
|||
if(!suc) { |
|||
throw std::invalid_argument("Cannot translate " + ctx->NUMERAL()->getText() + " into a rational."); |
|||
} |
|||
return ArithType(tmp); |
|||
} else if (ctx->DECIMAL()) { |
|||
bool suc = carl::try_parse<Rational>(ctx->DECIMAL()->getText(), tmp); |
|||
if(!suc) { |
|||
throw std::invalid_argument("Cannot translate " + ctx->DECIMAL()->getText() + " into a rational."); |
|||
} |
|||
return ArithType(tmp); |
|||
} else if (ctx->HEXADECIMAL()) { |
|||
long v = std::stol(ctx->HEXADECIMAL()->getText().substr(2), nullptr, 16); |
|||
tmp = v; |
|||
return ArithType(tmp); |
|||
} else if (ctx->BINARY()) { |
|||
long v = std::stol(ctx->BINARY()->getText().substr(2), nullptr, 2); |
|||
tmp = v; |
|||
return ArithType(tmp); |
|||
} |
|||
throw std::runtime_error("Unknown number"); |
|||
} |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitBool_variable(SerializationParser::Bool_variableContext *ctx) { |
|||
std::string name = ctx->SYMBOL()->getSymbol()->getText(); |
|||
//try and generate new variable from pool
|
|||
Variable newVar; |
|||
auto &pool = VariablePool::getInstance(); |
|||
Variable res = pool.findVariableWithName(name); |
|||
if (res != Variable::NO_VARIABLE) { |
|||
newVar = res; |
|||
if (newVar.type() != VariableType::VT_BOOL) { |
|||
throw std::runtime_error("Expected Boolean variable"); |
|||
} |
|||
} else { |
|||
newVar = freshBooleanVariable(name); |
|||
} |
|||
|
|||
return Formula<Pol>(newVar); |
|||
} |
|||
|
|||
template<typename Pol> |
|||
antlrcpp::Any ParseTreeVisitor<Pol>::visitReal_variable(SerializationParser::Real_variableContext *ctx) { |
|||
std::string name = ctx->SYMBOL()->getSymbol()->getText(); |
|||
//try and generate new variable from pool
|
|||
Variable newVar; |
|||
auto &pool = VariablePool::getInstance(); |
|||
Variable res = pool.findVariableWithName(name); |
|||
if (res != Variable::NO_VARIABLE) { |
|||
newVar = res; |
|||
if (newVar.type() != VariableType::VT_REAL) { |
|||
throw std::runtime_error("Expected real variable"); |
|||
} |
|||
} else { |
|||
newVar = freshRealVariable(name); |
|||
} |
|||
|
|||
return ArithType(newVar); |
|||
} |
|||
|
|||
template |
|||
class ParseTreeVisitor<MultivariatePolynomial<mpq_class>>; |
|||
#ifdef USE_CLN_NUMBERS
|
|||
template |
|||
class ParseTreeVisitor<MultivariatePolynomial<cln::cl_RA>>; |
|||
#endif
|
|||
#ifdef USE_MPFR_FLOAT
|
|||
template |
|||
class ParseTreeVisitor<MultivariatePolynomial<FLOAT_T<mpfr_t>>>; |
|||
#endif
|
|||
#ifdef USE_Z3_NUMBERS
|
|||
template |
|||
class ParseTreeVisitor<MultivariatePolynomial<rational>>; |
|||
#endif
|
|||
|
|||
} |
@ -0,0 +1,55 @@ |
|||
#pragma once |
|||
|
|||
// generated files |
|||
#include "carl-parser/SerializationVisitor.h" |
|||
|
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
|
|||
#include <boost/variant.hpp> |
|||
|
|||
namespace carlparser { |
|||
|
|||
/** |
|||
* Visitor for the Serialization grammar that will build |
|||
* up the CARL data. |
|||
*/ |
|||
template<typename Pol> |
|||
class ParseTreeVisitor : public SerializationVisitor { |
|||
typedef typename Pol::CoeffType Rational; |
|||
|
|||
using ArithType = boost::variant<Rational, carl::Variable, carl::Monomial::Arg, |
|||
carl::Term<Rational>, Pol, carl::RationalFunction<Pol> >; |
|||
|
|||
public: |
|||
antlrcpp::Any visitStart(SerializationParser::StartContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitCarl_expr(SerializationParser::Carl_exprContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitForm_expr(SerializationParser::Form_exprContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitFormula_nary(SerializationParser::Formula_naryContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitForm_op_nary(SerializationParser::Form_op_naryContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitFormula_unary(SerializationParser::Formula_unaryContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitConstraint(SerializationParser::ConstraintContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitArith_expr(SerializationParser::Arith_exprContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitArith_nary(SerializationParser::Arith_naryContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitArith_unary(SerializationParser::Arith_unaryContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitBoolean(SerializationParser::BooleanContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitNumber(SerializationParser::NumberContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitBool_variable(SerializationParser::Bool_variableContext *ctx) override; |
|||
|
|||
antlrcpp::Any visitReal_variable(SerializationParser::Real_variableContext *ctx) override; |
|||
|
|||
}; |
|||
|
|||
} // namespace carl |
@ -0,0 +1,96 @@ |
|||
//
|
|||
// Created by Sebastian Junges on 29/06/2017.
|
|||
//
|
|||
#include "Parser.h"
|
|||
|
|||
// Generated files:
|
|||
#include "carl-parser/SerializationLexer.h"
|
|||
#include "carl-parser/SerializationParser.h"
|
|||
#include "carl-parser/SerializationVisitor.h"
|
|||
#include "ParseTreeVisitor.h"
|
|||
|
|||
#include <antlr4-runtime.h>
|
|||
|
|||
|
|||
using namespace antlr4; |
|||
|
|||
namespace carlparser { |
|||
class ErrorListener : public antlr4::ANTLRErrorListener { |
|||
public: |
|||
void syntaxError(antlr4::Recognizer *recognizer, antlr4::Token *offendingSymbol, size_t line, |
|||
size_t charPositionInLine, const std::string &msg, std::exception_ptr e) override { |
|||
throw std::runtime_error(std::string("Parser error: ") + msg); |
|||
} |
|||
|
|||
void reportAmbiguity(antlr4::Parser *recognizer, const antlr4::dfa::DFA &dfa, size_t startIndex, |
|||
size_t stopIndex, bool exact, const antlrcpp::BitSet &ambigAlts, |
|||
antlr4::atn::ATNConfigSet *configs) override { |
|||
throw std::runtime_error("Parser error"); |
|||
} |
|||
|
|||
void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, |
|||
const antlrcpp::BitSet &conflictingAlts, |
|||
antlr4::atn::ATNConfigSet *configs) override { |
|||
throw std::runtime_error("Parser error"); |
|||
} |
|||
|
|||
void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, |
|||
size_t prediction, atn::ATNConfigSet *configs) override { |
|||
throw std::runtime_error("Parser error"); |
|||
} |
|||
}; |
|||
|
|||
template<typename Pol> |
|||
parser_types<Pol> deserialize(std::string input) { |
|||
ANTLRInputStream input_stream(input); |
|||
SerializationLexer lexer(&input_stream); |
|||
CommonTokenStream tokens(&lexer); |
|||
SerializationParser parser(&tokens); |
|||
ParseTreeVisitor <Pol> visitor; |
|||
|
|||
auto errListener = ErrorListener(); |
|||
lexer.removeErrorListeners(); |
|||
lexer.addErrorListener(&errListener); |
|||
parser.removeErrorListeners(); |
|||
parser.addErrorListener(&errListener); |
|||
|
|||
tree::ParseTree *tree = parser.start(); |
|||
antlrcpp::Any resultData = tree->accept(&visitor); |
|||
|
|||
if (resultData.is < carl::Formula < Pol >> ()) { |
|||
return resultData.as < carl::Formula < Pol >> (); |
|||
} else if (resultData.is < carl::Constraint < Pol >> ()) { |
|||
return resultData.as < carl::Constraint < Pol >> (); |
|||
} else if (resultData.is < carl::RationalFunction < Pol >> ()) { |
|||
return resultData.as < carl::RationalFunction < Pol >> (); |
|||
} else if (resultData.is<Pol>()) { |
|||
return resultData.as<Pol>(); |
|||
} else if (resultData.is < carl::Term < typename Pol::CoeffType >> ()) { |
|||
return resultData.as < carl::Term < typename Pol::CoeffType >> (); |
|||
} else if (resultData.is<carl::Monomial::Arg>()) { |
|||
return resultData.as<carl::Monomial::Arg>(); |
|||
} else if (resultData.is<typename Pol::CoeffType>()) { |
|||
return resultData.as<typename Pol::CoeffType>(); |
|||
} else if (resultData.is<carl::Variable>()) { |
|||
return resultData.as<carl::Variable>(); |
|||
} else { |
|||
throw std::runtime_error("Unexpected parser result"); |
|||
} |
|||
} |
|||
|
|||
template |
|||
parser_types<carl::MultivariatePolynomial<mpq_class>> deserialize(std::string); |
|||
#ifdef USE_CLN_NUMBERS
|
|||
template |
|||
parser_types<carl::MultivariatePolynomial<cln::cl_RA>> deserialize(std::string); |
|||
#endif
|
|||
#ifdef USE_MPFR_FLOAT
|
|||
template |
|||
class ParseTreeVisitor<MultivariatePolynomial<FLOAT_T<mpfr_t>>>; |
|||
#endif
|
|||
#ifdef USE_Z3_NUMBERS
|
|||
template |
|||
class ParseTreeVisitor<MultivariatePolynomial<rational>>; |
|||
#endif
|
|||
|
|||
} |
@ -0,0 +1,64 @@ |
|||
// |
|||
// Created by hbruintjes on 19/06/17. |
|||
// |
|||
|
|||
#pragma once |
|||
|
|||
|
|||
#include <carl/formula/Formula.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
|
|||
#include <boost/variant.hpp> |
|||
|
|||
|
|||
namespace carlparser { |
|||
|
|||
|
|||
enum class ParserReturnType { |
|||
Rational, Variable, Monomial, Term, Polynomial, RationalFunction, Constraint, Formula |
|||
}; |
|||
|
|||
template<typename Pol> |
|||
class typechecker: public boost::static_visitor<ParserReturnType> { |
|||
public: |
|||
ParserReturnType operator()(const typename Pol::CoeffType&) const { |
|||
return ParserReturnType::Rational; |
|||
} |
|||
ParserReturnType operator()(const carl::Variable&) const { |
|||
return ParserReturnType::Variable; |
|||
} |
|||
ParserReturnType operator()(const carl::Monomial::Arg&) const { |
|||
return ParserReturnType::Monomial; |
|||
} |
|||
ParserReturnType operator()(const carl::Term<typename Pol::CoeffType>&) const { |
|||
return ParserReturnType::Term; |
|||
} |
|||
ParserReturnType operator()(const Pol&) const { |
|||
return ParserReturnType::Polynomial; |
|||
} |
|||
ParserReturnType operator()(const carl::RationalFunction<Pol>&) const { |
|||
return ParserReturnType::RationalFunction; |
|||
} |
|||
ParserReturnType operator()(const carl::Constraint<Pol>&) const { |
|||
return ParserReturnType::Constraint; |
|||
} |
|||
ParserReturnType operator()(const carl::Formula<Pol>&) const { |
|||
return ParserReturnType::Formula; |
|||
} |
|||
}; |
|||
|
|||
|
|||
template<typename Pol> |
|||
using parser_types = boost::variant< typename Pol::CoeffType, carl::Variable, carl::Monomial::Arg, |
|||
carl::Term<typename Pol::CoeffType>, Pol, carl::RationalFunction<Pol>, |
|||
carl::Constraint<Pol>, carl::Formula<Pol> >; |
|||
|
|||
template<typename Pol> |
|||
inline ParserReturnType check_type(const parser_types<Pol>& t) { |
|||
return boost::apply_visitor(typechecker<Pol>(), t); |
|||
} |
|||
|
|||
|
|||
template<typename Pol> |
|||
parser_types<Pol> deserialize(std::string input); |
|||
} |
@ -0,0 +1,103 @@ |
|||
/** |
|||
* Grammar used to represent formulas and all they can contain in CaRL, |
|||
* based on the SMTLIB 2.5 standard. |
|||
* In particular, it can parse a subset of Terms, and contains many |
|||
* a hardcoded symbol/qualifying identifier |
|||
*/ |
|||
|
|||
grammar Serialization; |
|||
|
|||
/////////////////////////////// |
|||
// Rules |
|||
/////////////////////////////// |
|||
start : carl_expr EOF ; |
|||
|
|||
carl_expr |
|||
: formula_nary |
|||
| formula_unary |
|||
| constraint |
|||
| arith_nary |
|||
| arith_unary |
|||
| boolean |
|||
| number |
|||
| real_variable |
|||
; |
|||
|
|||
form_expr |
|||
: formula_nary |
|||
| formula_unary |
|||
| constraint |
|||
| boolean |
|||
| bool_variable |
|||
; |
|||
|
|||
formula_nary : LPAREN form_op_nary form_expr+ RPAREN; |
|||
form_op_nary : 'and' | 'or' | '=' | 'xor' | '=>' | 'ite'; |
|||
|
|||
formula_unary : LPAREN token='not' form_expr RPAREN; |
|||
|
|||
// NEQ not directly written ( is not = ) |
|||
constraint : LPAREN token=('=' | '<' | '<=' | '>' | '>=' | '!=') left=arith_expr arith_expr RPAREN; |
|||
|
|||
arith_expr |
|||
: arith_nary |
|||
| arith_unary |
|||
| number |
|||
| real_variable |
|||
; |
|||
|
|||
arith_unary : LPAREN token=('+' | '-') arith_expr RPAREN; |
|||
arith_nary : LPAREN token=('+' | '-' | '*' | '/') arith_expr arith_expr+ RPAREN; |
|||
|
|||
|
|||
boolean : TRUE | FALSE; |
|||
number : NUMERAL | DECIMAL | HEXADECIMAL | BINARY; |
|||
real_variable : SYMBOL; |
|||
bool_variable : SYMBOL; |
|||
|
|||
//variable_type : 'Bool' | 'Real' | '?_Uninterpreted' | '?_Bitvector'; |
|||
|
|||
|
|||
/////////////////////////////// |
|||
// Tokens |
|||
/////////////////////////////// |
|||
TBINARY : 'BINARY'; |
|||
TDECIMAL : 'DECIMAL'; |
|||
THEXADECIMAL : 'HEXADECIMAL'; |
|||
TNUMERAL : 'NUMERAL'; |
|||
TSTRING : 'STRING'; |
|||
|
|||
LPAREN : '('; |
|||
RPAREN : ')'; |
|||
INDEXER : '_'; |
|||
ANNOTATION : '!'; |
|||
|
|||
AS : 'as'; |
|||
LET : 'let'; |
|||
EXISTS : 'exists'; |
|||
FORALL : 'forall'; |
|||
PAR : 'par'; |
|||
|
|||
TRUE : 'true'; |
|||
FALSE: 'false'; |
|||
|
|||
fragment DIGIT : [0-9]; |
|||
fragment LETTER : [A-Za-z]; |
|||
NUMERAL : '0' | '-'?([1-9]DIGIT*); |
|||
DECIMAL : NUMERAL '.' DIGIT+; |
|||
HEXADECIMAL : '#x' [0-9A-Fa-f]+; |
|||
BINARY: '#b' [0-1]+; |
|||
|
|||
STRING : '"' ( '""' | ~["] )* '"'; |
|||
|
|||
fragment SIMPLE_SYM : (LETTER | [~!@$%^&*_\-+=<>.?/]) (LETTER | DIGIT | [~!@$%^&*_\-+=<>.?/])*; |
|||
//TODO: Incomplete spec for QUOTED_SYM (printable char) |
|||
fragment QUOTED_SYM : '|' (LETTER | DIGIT)+ '|'; |
|||
|
|||
// QUOTED_SYM removed for simplification |
|||
SYMBOL : SIMPLE_SYM; // | QUOTED_SYM; |
|||
|
|||
KEYWORD : ':' SIMPLE_SYM; |
|||
|
|||
// Whitespace according to SMTLIB spec |
|||
WS: [ \n\t\r]+ -> skip; |
@ -0,0 +1,121 @@ |
|||
// |
|||
// Created by hbruintjes on 19/06/17. |
|||
// |
|||
|
|||
#ifndef CARL_SERIALIZER_H |
|||
#define CARL_SERIALIZER_H |
|||
|
|||
#include <string> |
|||
|
|||
#include <carl/core/Variable.h> |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
#include <carl/formula/Formula.h> |
|||
|
|||
namespace carlparser { |
|||
|
|||
std::string serialize(Variable const& v) { |
|||
return v.getName(); |
|||
} |
|||
|
|||
std::string serialize(mpq_class const& rational) { |
|||
return toString(rational); |
|||
} |
|||
|
|||
//std::string serialize(cln::RA const& rational); |
|||
|
|||
std::string serialize(Monomial::Arg const& v) { |
|||
if (v->isConstant()) { |
|||
return "0"; |
|||
} else if (v->isLinear()) { |
|||
return serialize(v->getSingleVariable()); |
|||
} |
|||
|
|||
std::string res = "(*"; |
|||
for(auto const& exp: *v) { |
|||
for(uint i = 0; i < exp.second; ++i) { |
|||
res += ' ' + exp.first.getName(); |
|||
} |
|||
} |
|||
res += ")"; |
|||
return res; |
|||
} |
|||
|
|||
template <typename CoeffType> |
|||
std::string serialize(Term<CoeffType> const& t) { |
|||
if (carl::isOne(t.coeff())) { |
|||
return serialize(t.monomial()); |
|||
} else { |
|||
std::string res = "(*" + serialize(t.coeff()); |
|||
for(auto const& exp: *t.monomial()) { |
|||
for(uint i = 0; i < exp.second; ++i) { |
|||
res += ' ' + exp.first.getName(); |
|||
} |
|||
} |
|||
res += ")"; |
|||
return res; |
|||
} |
|||
} |
|||
|
|||
template <typename CoeffType> |
|||
std::string serialize(MultivariatePolynomial<CoeffType> const& poly) { |
|||
if (poly.isConstant()) { |
|||
return serialize(poly.constantPart()); |
|||
} else if (poly.nrTerms() == 1) { |
|||
return serialize(*poly.begin()); |
|||
} else { |
|||
std::string res = "(+"; |
|||
for(auto const& term: poly) { |
|||
res += ' ' + serialize(term); |
|||
} |
|||
res += ")"; |
|||
return res; |
|||
} |
|||
} |
|||
|
|||
template <typename Poly> |
|||
std::string serialize(RationalFunction<Poly> const& rf) { |
|||
return std::string("(/ ") + serialize(rf.nominator()) + ' ' + serialize(rf.denominator()) + ")"; |
|||
} |
|||
|
|||
template <typename Poly> |
|||
std::string serialize(Constraint<Poly> const& c) { |
|||
return std::string("(") + relationToString(c.relation()) + ' ' + serialize(c.lhs()) + "0)"; |
|||
} |
|||
|
|||
template <typename Poly> |
|||
std::string serialize(Formula<Poly> const& f) { |
|||
switch(f.type()) { |
|||
case ITE: |
|||
return std::string("(ite ") + serialize(f.subformulas()[0]) + |
|||
' ' + serialize(f.subformulas()[1]) + |
|||
' ' + serialize(f.subformulas()[2])+ ")"; |
|||
case FormulaType::TRUE: |
|||
return "true"; |
|||
case FormulaType::FALSE: |
|||
return "true"; |
|||
case FormulaType::BOOL: |
|||
return f.boolean().getName(); |
|||
case FormulaType::NOT: |
|||
case FormulaType::IMPLIES: |
|||
case FormulaType::AND: |
|||
case FormulaType::OR: |
|||
case FormulaType::XOR: |
|||
case FormulaType::IFF: { |
|||
std::string res = "(" + formulaTypeToString(f.type()); |
|||
for (auto const &sub: f) { |
|||
res += ' ' + serialize(sub); |
|||
} |
|||
res += ')'; |
|||
return res; |
|||
} |
|||
case FormulaType::CONSTRAINT: |
|||
return serialize(f.constraint()); |
|||
default: |
|||
throw std::runtime_error("Unsupported formula type to serialize"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
#endif //CARL_SERIALIZER_H |
@ -0,0 +1,99 @@ |
|||
/** |
|||
* Grammar based on the SMTLIB 2.5 standard. |
|||
*/ |
|||
|
|||
grammar smtlib; |
|||
|
|||
/** |
|||
* 3.2 S-expr |
|||
*/ |
|||
spec_constant : NUMERAL | DECIMAL | HEXADECIMAL | BINARY | STRING; |
|||
s_expr : spec_constant | SYMBOL | KEYWORD | LPAREN s_expr* RPAREN; |
|||
|
|||
/** |
|||
* 3.3 identifiers |
|||
* Indexed removed for simplification |
|||
*/ |
|||
index : NUMERAL | SYMBOL; |
|||
identifier : SYMBOL | LPAREN INDEXER SYMBOL index+ RPAREN; |
|||
|
|||
/** 3.4 Attributes */ |
|||
attribute_value : spec_constant | SYMBOL | LPAREN s_expr* RPAREN; |
|||
attribute : KEYWORD attribute_value?; |
|||
|
|||
/** |
|||
* 3.5 Sorts |
|||
*/ |
|||
sort : identifier | LPAREN identifier sort+ RPAREN; |
|||
|
|||
/** |
|||
* 3.6 Terms |
|||
*/ |
|||
qual_identifier : identifier | LPAREN AS identifier sort RPAREN; |
|||
var_binding : LPAREN SYMBOL term RPAREN; |
|||
sorted_var : LPAREN SYMBOL sort RPAREN; |
|||
term : spec_constant | qual_identifier |
|||
| LPAREN qual_identifier term+ RPAREN |
|||
| LPAREN LET LPAREN var_binding+ RPAREN RPAREN |
|||
| LPAREN FORALL sorted_var+ LPAREN RPAREN RPAREN |
|||
| LPAREN EXISTS sorted_var+ LPAREN RPAREN RPAREN |
|||
| LPAREN ANNOTATION term attribute+ RPAREN |
|||
; |
|||
|
|||
/** |
|||
* 3.7 Theories |
|||
*/ |
|||
sort_symbol_decl : LPAREN identifier NUMERAL attribute* RPAREN; |
|||
meta_spec_constant : TNUMERAL | TDECIMAL | TSTRING; |
|||
fun_symbol_decl : LPAREN spec_constant sort attribute* RPAREN |
|||
| LPAREN meta_spec_constant sort attribute* RPAREN |
|||
| LPAREN identifier sort+ attribute* RPAREN |
|||
; |
|||
par_fun_symbol_decl : fun_symbol_decl |
|||
| LPAREN PAR LPAREN SYMBOL+ RPAREN |
|||
LPAREN identifier sort+ attribute* RPAREN RPAREN; |
|||
theory_attribute : attribute; |
|||
theory_decl : LPAREN 'theory' SYMBOL theory_attribute+ RPAREN; |
|||
|
|||
/** |
|||
* 3.1 Predefined tokens |
|||
* Should be complete w.r.t. SMTLIB, to avoid |
|||
* unparseable inputs |
|||
*/ |
|||
TBINARY : 'BINARY'; |
|||
TDECIMAL : 'DECIMAL'; |
|||
THEXADECIMAL : 'HEXADECIMAL'; |
|||
TNUMERAL : 'NUMERAL'; |
|||
TSTRING : 'STRING'; |
|||
|
|||
LPAREN : '('; |
|||
RPAREN : ')'; |
|||
INDEXER : '_'; |
|||
ANNOTATION : '!'; |
|||
|
|||
AS : 'as'; |
|||
LET : 'let'; |
|||
EXISTS : 'exists'; |
|||
FORALL : 'forall'; |
|||
PAR : 'par'; |
|||
|
|||
fragment DIGIT : [0-9]; |
|||
fragment LETTER : [A-Za-z]; |
|||
NUMERAL : '0' | [1-9]DIGIT*; |
|||
DECIMAL : NUMERAL '.' DIGIT+; |
|||
HEXADECIMAL : '#x' [0-9A-Fa-f]+; |
|||
BINARY: '#b' [0-1]+; |
|||
|
|||
STRING : '"' ( '""' | ~["] )* '"'; |
|||
|
|||
fragment SIMPLE_SYM : (LETTER | [~!@$%^&*_\-+=<>.?/]) (LETTER | DIGIT | [~!@$%^&*_\-+=<>.?/])*; |
|||
//TODO: Incomplete spec for QUOTED_SYM (printable char) |
|||
fragment QUOTED_SYM : '|' (LETTER | DIGIT)+ '|'; |
|||
|
|||
// QUOTED_SYM removed for simplification |
|||
SYMBOL : SIMPLE_SYM; // | QUOTED_SYM; |
|||
|
|||
KEYWORD : ':' SIMPLE_SYM; |
|||
|
|||
// Whitespace according to SMTLIB spec |
|||
WS: [ \n\t\r]+ -> skip; |
@ -0,0 +1,4 @@ |
|||
add_executable(carl-parser-test ${CMAKE_CURRENT_SOURCE_DIR}/test.cpp) |
|||
target_link_libraries(carl-parser-test PUBLIC carl-parser) |
|||
|
|||
add_test(NAME test COMMAND carl-parser-test) |
5697
carl-parser/test/doctest.h
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,24 @@ |
|||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
|||
#include "doctest.h"
|
|||
|
|||
#include "carl-parser/Parser.h"
|
|||
|
|||
using namespace carlparser; |
|||
|
|||
TEST_CASE("testing the parse") { |
|||
auto res = carlparser::deserialize<carl::MultivariatePolynomial<mpq_class>>("(/ 12 12)"); |
|||
DOCTEST_CHECK_EQ(check_type(res), carlparser::ParserReturnType::Rational); |
|||
res = carlparser::deserialize<carl::MultivariatePolynomial<mpq_class>>("x"); |
|||
DOCTEST_CHECK_EQ(check_type(res), carlparser::ParserReturnType::Variable); |
|||
res = carlparser::deserialize<carl::MultivariatePolynomial<mpq_class>>("-1"); |
|||
DOCTEST_CHECK_EQ(check_type(res), carlparser::ParserReturnType::Rational); |
|||
res = carlparser::deserialize<carl::MultivariatePolynomial<mpq_class>>("(+ x 1)"); |
|||
DOCTEST_CHECK_EQ(check_type(res), carlparser::ParserReturnType::Polynomial); |
|||
res = carlparser::deserialize<carl::MultivariatePolynomial<mpq_class>>("(< x 1)"); |
|||
DOCTEST_CHECK_EQ(check_type(res), carlparser::ParserReturnType::Constraint); |
|||
res = carlparser::deserialize<carl::MultivariatePolynomial<mpq_class>>("(<= (* (- 1) pL) 0)"); |
|||
DOCTEST_CHECK_EQ(check_type(res), carlparser::ParserReturnType::Constraint); |
|||
res = carlparser::deserialize<carl::MultivariatePolynomial<mpq_class>>("(!= pK 0)"); |
|||
DOCTEST_CHECK_EQ(check_type(res), carlparser::ParserReturnType::Constraint); |
|||
|
|||
} |
@ -0,0 +1,12 @@ |
|||
version: 1.0.{build} |
|||
image: Visual Studio 2017 |
|||
environment: |
|||
BOOST_ROOT: C:\Libraries\boost_1_64_0 |
|||
BOOST_LIBRARYDIR: C:\Libraries\boost_1_64_0\lib64-msvc-14.1 |
|||
CTEST_OUTPUT_ON_FAILURE: 1 |
|||
|
|||
cache: |
|||
- '%APPVEYOR_BUILD_FOLDER%\build\resources -> .appveyor.yml, resources/resources.cmake' |
|||
|
|||
build_script: |
|||
- ps: .ci\setup_appveyor.ps1 |
@ -0,0 +1,99 @@ |
|||
#!/usr/bin/env bash |
|||
|
|||
mkdir -p build || return 1 |
|||
cd build/ || return 1 |
|||
cmake -D DEVELOPER=ON -D THREAD_SAFE=ON -D USE_BLISS=ON -D USE_CLN_NUMBERS=ON -D USE_COCOA=ON -D USE_GINAC=ON ../ || return 1 |
|||
|
|||
function keep_waiting() { |
|||
while true; do |
|||
echo -e "." |
|||
sleep 60 |
|||
done |
|||
} |
|||
|
|||
if [ -z "$MAKE_PARALLEL" ]; then |
|||
MAKE_PARALLEL="-j2" |
|||
fi |
|||
|
|||
if [[ ${TASK} == "dependencies" ]]; then |
|||
|
|||
keep_waiting & |
|||
/usr/bin/time make ${MAKE_PARALLEL} resources || return 1 |
|||
kill $! |
|||
|
|||
elif [[ ${TASK} == "coverity" ]]; then |
|||
|
|||
keep_waiting & |
|||
/usr/bin/time make ${MAKE_PARALLEL} lib_carl || return 1 |
|||
/usr/bin/time make ${MAKE_PARALLEL} || return 1 |
|||
kill $! |
|||
|
|||
elif [[ ${TASK} == "sonarcloud" ]]; then |
|||
|
|||
cmake -D COVERAGE=ON ../ || return 1 |
|||
|
|||
WRAPPER="build-wrapper-linux-x86-64 --out-dir ../bw-output" |
|||
$WRAPPER make ${MAKE_PARALLEL} lib_carl || return 1 |
|||
$WRAPPER make ${MAKE_PARALLEL} || return 1 |
|||
make coverage-collect |
|||
|
|||
cd ../ && sonar-scanner -X -Dproject.settings=build/sonarcloud.properties && cd build/ |
|||
elif [[ ${TASK} == "doxygen" ]]; then |
|||
|
|||
cmake -D DOCUMENTATION_CREATE_PDF=ON -D BUILD_DOXYGEN=ON ../ |
|||
|
|||
make doc || return 1 |
|||
|
|||
git config --global user.email "gereon.kremer@cs.rwth-aachen.de" |
|||
git config --global user.name "Travis doxygen daemon" |
|||
|
|||
git clone https://${GH_TOKEN}@github.com/smtrat/smtrat.github.io.git |
|||
cd smtrat.github.io/ || return 1 |
|||
git branch -m master old_master |
|||
git checkout --orphan master |
|||
|
|||
# Update cloned copy |
|||
cp -r ../doc/html/* carl/ || return 1 |
|||
cp ../doc/*.pdf . || return 1 |
|||
|
|||
git add . || return 1 |
|||
|
|||
# Commit and push |
|||
git commit -q -m "Updated documentation for carl" || return 1 |
|||
git push -f origin master || return 1 |
|||
|
|||
elif [[ ${TASK} == "pycarl" ]]; then |
|||
|
|||
# Create a python virtual environment for local installation |
|||
virtualenv -p python3 pycarl-env |
|||
source pycarl-env/bin/activate |
|||
|
|||
/usr/bin/time make ${MAKE_PARALLEL} lib_carl || return 1 |
|||
|
|||
# Clone pycarl |
|||
git clone https://github.com/moves-rwth/pycarl.git |
|||
cd pycarl/ || return 1 |
|||
# Build bindings |
|||
python setup.py build_ext -j 1 develop || return 1 |
|||
# Run tests |
|||
python setup.py test || return 1 |
|||
|
|||
elif [[ ${TASK} == "tidy" ]]; then |
|||
|
|||
/usr/bin/time make tidy || return 1 |
|||
|
|||
elif [[ ${TASK} == "addons" ]]; then |
|||
|
|||
cmake -D BUILD_ADDONS=ON -D BUILD_ADDON_PARSER=ON -D BUILD_ADDON_PYCARL=ON -D DEVELOPER=ON -D USE_CLN_NUMBERS=ON -D USE_GINAC=ON -D USE_COCOA=ON ../ || return 1 |
|||
|
|||
/usr/bin/time make ${MAKE_PARALLEL} lib_carl || return 1 |
|||
/usr/bin/time make ${MAKE_PARALLEL} || return 1 |
|||
/usr/bin/time make -j1 CTEST_OUTPUT_ON_FAILURE=1 test || return 1 |
|||
|
|||
else |
|||
/usr/bin/time make ${MAKE_PARALLEL} lib_carl || return 1 |
|||
/usr/bin/time make ${MAKE_PARALLEL} || return 1 |
|||
/usr/bin/time make -j1 CTEST_OUTPUT_ON_FAILURE=1 test || return 1 |
|||
fi |
|||
|
|||
cd ../ |
@ -0,0 +1,13 @@ |
|||
echo "Looking for preinstalled Boost" |
|||
$env:PATH += ";$BOOST_ROOT" |
|||
$env:PATH += ";$BOOST_LIBRARYDIR" |
|||
|
|||
md build |
|||
cd build |
|||
|
|||
cmake -G "Visual Studio 14 2015 Win64" -DBUILD_STATIC="ON" -DBOOST_ROOT="$BOOST_ROOT" -DBOOST_LIBRARYDIR="$BOOST_LIBRARYDIR" -DCMAKE_BUILD_TYPE=DEBUG -DBoost_COMPILER="-vc141" -DLOGGING="ON" .. |
|||
cmake --build . --config Debug --target lib_carl |
|||
cmake --build . --config Debug --target lib_carl_static |
|||
cmake --build . --config Debug --target all-tests |
|||
.\bin\Debug\runCoreTests.exe |
|||
cmake --build . --config Debug --target RUN_TESTS |
@ -0,0 +1,34 @@ |
|||
#!/usr/bin/env bash |
|||
|
|||
git fetch --unshallow |
|||
|
|||
if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then |
|||
|
|||
mkdir -p ~/usr/bin/ |
|||
PREFIX=`cd ~/usr; pwd` |
|||
|
|||
if [ ! -f $PREFIX/bin/cmake ]; then |
|||
wget -nv https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.sh |
|||
chmod +x cmake-3.7.2-Linux-x86_64.sh |
|||
./cmake-3.7.2-Linux-x86_64.sh --prefix=$PREFIX --exclude-subdir --skip-license |
|||
fi |
|||
|
|||
export PATH="$PREFIX/bin:$PATH" |
|||
|
|||
elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then |
|||
|
|||
brew update --quiet |
|||
brew install llvm |
|||
|
|||
if [[ ${CXX} == "g++-5" ]]; then |
|||
brew install gcc@5 |
|||
brew link --overwrite gcc@5 |
|||
elif [[ ${CXX} == "g++-6" ]]; then |
|||
brew install gcc@6 |
|||
brew link --overwrite gcc@6 |
|||
fi |
|||
|
|||
fi |
|||
|
|||
export CC=$CC |
|||
export CXX=$CXX |
@ -0,0 +1,27 @@ |
|||
sonar.projectKey=${PROJECT_FULLNAME} |
|||
sonar.projectName=${${PROJECT_FULLNAME}_NAME} |
|||
sonar.projectVersion=${PROJECT_VERSION} |
|||
|
|||
# ===================================================== |
|||
# Meta-data for the project |
|||
# ===================================================== |
|||
|
|||
sonar.links.homepage=https://github.com/smtrat/carl |
|||
sonar.links.ci=https://travis-ci.org/smtract/carl |
|||
sonar.links.scm=https://github.com/smtrat/carl |
|||
sonar.links.issue=https://github.com/smtrat/carl/issues |
|||
|
|||
|
|||
# ===================================================== |
|||
# Properties that will be shared amongst all modules |
|||
# ===================================================== |
|||
|
|||
# SQ standard properties |
|||
sonar.language=cpp |
|||
sonar.sources=src/ |
|||
sonar.cpp.file.suffixes=.h,.tpp,.cpp |
|||
|
|||
# Properties specific to the C/C++ analyzer: |
|||
sonar.cfamily.build-wrapper-output=bw-output |
|||
sonar.cfamily.gcov.reportsPath=. |
|||
sonar.cfamily.llvm-cov.reportPath=build/coverage.txt |
@ -0,0 +1,92 @@ |
|||
language: generic |
|||
sudo: false |
|||
dist: trusty |
|||
|
|||
cache: |
|||
apt: true |
|||
directories: |
|||
{%- for cache in cached %} |
|||
- {{ cache }} |
|||
{%- endfor %} |
|||
|
|||
addons: |
|||
apt: |
|||
sources: &sources_base |
|||
- ubuntu-toolchain-r-test |
|||
packages: &packages_base |
|||
- texinfo |
|||
- time |
|||
- uuid-dev |
|||
|
|||
matrix: |
|||
include: |
|||
{%- for job in jobs %} |
|||
- stage: {{ job.stage }} |
|||
os: {{ job.os }} |
|||
{%- if job.osx_image %} |
|||
osx_image: {{ job.osx_image }} |
|||
{%- endif %} |
|||
{%- if job.compiler %} |
|||
compiler: {{ job.compiler }} |
|||
{%- endif %} |
|||
{%- if job.env|length > 0 %} |
|||
env: {{ job.env|join(' ') }} |
|||
{%- endif %} |
|||
{%- if job.script %} |
|||
script: {{ job.script|join(' ') }} |
|||
{%- endif %} |
|||
{%- if job.addons %} |
|||
addons: |
|||
{%- if job.addons.apt %} |
|||
{%- set sources = ["*sources_base"] + job.addons.apt.sources %} |
|||
{%- set packages = ["*packages_base"] + job.addons.apt.packages %} |
|||
apt: |
|||
sources: [{{ sources|join(', ') }}] |
|||
packages: [{{ packages|join(', ') }}] |
|||
{%- endif %} |
|||
{%- if job.addons.coverity_scan %} |
|||
coverity_scan: |
|||
project: |
|||
name: "{{ job.addons.coverity_scan.name }}" |
|||
description: "{{ job.addons.coverity_scan.description }}" |
|||
{%- for prop,value in job.addons.coverity_scan.properties.items() %} |
|||
{{ prop }}: "{{ value }}" |
|||
{%- endfor %} |
|||
{%- endif %} |
|||
{%- if job.addons.sonarcloud %} |
|||
sonarcloud: |
|||
organization: "{{ job.addons.sonarcloud.organization }}" |
|||
token: |
|||
secure: "{{ job.addons.sonarcloud.token }}" |
|||
{%- endif %} |
|||
{%- endif %} |
|||
{%- endfor %} |
|||
allow_failures: |
|||
{%- for job in jobs if job.allow_failure %} |
|||
- stage: {{ job.stage }} |
|||
os: {{ job.os }} |
|||
{%- if job.osx_image %} |
|||
osx_image: {{ job.osx_image}} |
|||
{%- endif %} |
|||
{%- if job.env|length > 0 %} |
|||
env: {{ job.env|join(' ') }} |
|||
{%- endif %} |
|||
{%- endfor %} |
|||
|
|||
before_install: |
|||
- cd .ci/ && source setup_travis.sh && cd ../ |
|||
|
|||
notifications: |
|||
email: |
|||
on_failure: always |
|||
on_success: change |
|||
irc: |
|||
channels: |
|||
- "chat.freenode.net#carl" |
|||
template: |
|||
- "Commit to %{repository_name}/%{branch} from %{author}" |
|||
- "%{commit_message}" |
|||
- "Build: %{message} %{duration} %{build_url}" |
|||
slack: |
|||
rooms: |
|||
secure: "mL8Ku2omjsseTL5P2R2P3ddCedg8u9qSTKRjKNBhOYRJvpKNrIWr9fouP1tGsah9GBF+HL/JFWlA2sckCL9pURx6TdICHSgik1V/48QhpPKrV+ZkCmKenw3+hdXQY3YP36Xpj/SCCSMyRovA6kacWL3k0gRGJ++dxZYrYF7oVd8ltwxNC6+1o9HCmJnueCME5GBCKCgtOhYOr7izkjQ9wtFJvCmxHcI9EZxMQjWXmcHfItaWD1YFhR0/7AbsxJ9xtYZD0OMJrOgRBau671wV603a0EctIPcv0uKzjSsvB3yLndGOcMRsA8x/OPrFoOHbpLZ9d4O9gY3lvW5oueV+KTbbvHMSxJtvB9q3F0ZJSDHoG7cn1E2xb4gOHRdu4FhwqYy9abUM0DVUI/f7GaL+DMgzKeTduLB6h4GhtGR7fcWaBpCJYN1k8o33Vf/OPwaoPVCeiDRQIFqrqjDRcBc7ONe096WAf61albpMW6iCr5cBHy/j9XqEAGHu6sYftogWm/YVRqSF9+vnZy41cfQU+SYlFtWusUepqX1X/Kei+MCwESuddBnWj+oX8N8nreI8ql2IHG79IQVeEZZKMowxmo2IMsNnvkMyRTQsOmFY2u4NMRGga71QRCSbNvl01KxQ2ilyQ8Gu9Kjbs1QJ76jhOutChCzwOBAgc5aREdNCaV0=" |
@ -0,0 +1,71 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
from travis_helper import * |
|||
|
|||
def addon_coverity(): |
|||
return { |
|||
"coverity_scan": { |
|||
"name": "smtrat/carl", |
|||
"description": "CArL", |
|||
"properties": { |
|||
"notification_email": "gereon.kremer@cs.rwth-aachen.de", |
|||
"build_command_prepend": "cov-configure --template --comptype clangcc --compiler $CXX", |
|||
"build_command": ".ci/build.sh", |
|||
"branch_pattern": "master", |
|||
} |
|||
} |
|||
} |
|||
return res |
|||
|
|||
def addon_sonarcloud(): |
|||
return { |
|||
"sonarcloud": { |
|||
"organization": "smtrat-github", |
|||
"token": "nIGn6M7vkwD6HAKgS94QZIIU+A+dWOgqXzJ7lnAdGLXUx3cStVMO1LuOANttGyeGSJNj8Fa+YzwCx5EMQDvZW/b8cuoRld+I4gbmszUB6BXwQ6JJvpFczHrPpwyeo2LKrBN549aBCtOaLzw7rVPDzcdC6T39IvxpPXVCMTTjoq7Mp12HSWS8Ra8YIsOnJfYKVSxjCwcY9ICac70zpA6uKuWBNL13EBM+IpLACLFDKMcaIdb2CGyRvtbt7u8BOU9mjulRtpg1Ndc3eGEIIJJXM8lQTA+iMB6iapGWYbMB5Gwifrwy59UTgNbdR/6sWP5E5kxBGxn1lyp9VP6ChSS/b3Szhh0jUWaqBxoAK0Kh4KBeW7eeLvaUALuPmoNneGUZACrbNDq6aVzHUgwEKQTxF0reDkG3ZaEU+1NCukvLaI58OBxenb5bMOlEWzUMSMMuNO0MgVKXc3Nvr4oEm0USP6Ixky1AUTKTVDY87HHuQ+kCM/L5MQUQTwtQPuWF1zkDry+6A2LNABySla9AAtxlUth7rGvLwaTz2o3yMOIohQb12r8LqXnjESVcENk0f0gbyqeqM7aPcXAyqc6YDW9LBDSsWWa9SqxEfwz2zktzsWfKfCZWi4Fn7CaPdHGsGlSaGsXGovrT1DbyQPiTND0R1cinfrOqZBgwjWOB6JTol+g=" |
|||
} |
|||
} |
|||
|
|||
properties.update({ |
|||
"addon.coverity": {"addons": addon_coverity()}, |
|||
"addon.sonarcloud": {"addons": addon_sonarcloud()}, |
|||
}) |
|||
|
|||
jobs = [ |
|||
job("0-clang", ["build", "linux", "clang-3.8", "build.sh"]), |
|||
job("0-clang", ["build", "linux", "clang-3.9", "build.sh"]), |
|||
job("0-clang", ["build", "linux", "clang-4.0", "build.sh"]), |
|||
job("0-clang", ["build", "linux", "clang-5.0", "build.sh"]), |
|||
job("0-clang", ["build", "linux", "clang-6.0", "build.sh"]), |
|||
job("1-gcc", ["dependencies", "linux", "g++-5", "build.sh"]), |
|||
job("1-gcc", ["build", "linux", "g++-5", "j1", "build.sh"]), |
|||
job("1-gcc", ["dependencies", "linux", "g++-6", "build.sh"]), |
|||
job("1-gcc", ["build", "linux", "g++-6", "j1", "build.sh"]), |
|||
job("1-gcc", ["dependencies", "linux", "g++-7", "build.sh"]), |
|||
job("1-gcc", ["build", "linux", "g++-7", "j1", "build.sh"]), |
|||
job("1-gcc", ["dependencies", "linux", "g++-8", "build.sh"]), |
|||
job("1-gcc", ["build", "linux", "g++-8", "j1", "build.sh"]), |
|||
job("2-macos", ["build", "xcode7.3", "build.sh"]), |
|||
job("2-macos", ["build", "xcode8.3", "build.sh"]), |
|||
job("2-macos", ["build", "xcode9", "build.sh"]), |
|||
job("2-macos", ["build", "xcode9.1", "build.sh"]), |
|||
job("2-macos", ["build", "xcode9.2", "build.sh"]), |
|||
job("2-macos", ["build", "xcode9.3", "build.sh"]), |
|||
job("3-docs", ["build", "linux", "g++-6", "task.doxygen", "j1", "build.sh"]), |
|||
job("4-tidy", ["build", "linux", "clang-5.0", "task.tidy", "build.sh", "mayfail"]), |
|||
job("5-checker", ["dependencies", "linux", "clang-5.0", "task.coverity", "build.sh"]), |
|||
job("5-checker", ["build", "linux", "clang-5.0", "task.coverity", "addon.coverity", "mayfail"]), |
|||
#job("5-checker", ["dependencies", "linux", "clang-6.0", "task.sonarcloud", "j1", "build.sh"]), |
|||
job("5-checker", ["build", "linux", "clang-5.0", "task.sonarcloud", "addon.sonarcloud", "build.sh", "mayfail"]), |
|||
job("6-addons", ["dependencies", "linux", "g++-6", "task.pycarl", "j1", "build.sh"]), |
|||
job("6-addons", ["build", "linux", "g++-6", "task.pycarl", "j1", "build.sh", "mayfail"]), |
|||
job("6-addons", ["dependencies", "linux", "g++-6", "task.addons", "j1", "build.sh"]), |
|||
job("6-addons", ["build", "linux", "g++-6", "task.addons", "j1", "build.sh", "mayfail"]), |
|||
] |
|||
|
|||
cached = [ |
|||
"$HOME/usr/", |
|||
"$HOME/.sonar/cache", |
|||
"build/resources", |
|||
] |
|||
|
|||
render_template(jobs, cached) |
@ -0,0 +1,93 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
from jinja2 import * |
|||
import os |
|||
|
|||
def datamerge(a, b): |
|||
"""Merges two lists or dictionaries.""" |
|||
if isinstance(a, list) and isinstance(b, list): |
|||
return a + b |
|||
elif isinstance(a, dict) and isinstance(b, dict): |
|||
res = a.copy() |
|||
for k,v in b.items(): |
|||
if k in res: |
|||
res[k] = datamerge(res[k], v) |
|||
else: |
|||
res[k] = v |
|||
return res |
|||
else: |
|||
return b |
|||
|
|||
|
|||
|
|||
def addon_apt(sources, packages): |
|||
"""Standard addon for apt.""" |
|||
return { |
|||
"apt": { |
|||
"sources": sources, |
|||
"packages": packages |
|||
} |
|||
} |
|||
|
|||
# List of predefined properties. |
|||
# Can be extended. |
|||
properties = { |
|||
"dependencies": {"stage": "dependencies", "script": ["TASK=dependencies"]}, |
|||
"build": {"stage": "build"}, |
|||
|
|||
"xcode7.3": {"os": "osx", "osx_image": "xcode7.3", "env": []}, |
|||
"xcode8.2": {"os": "osx", "osx_image": "xcode8.2", "env": []}, |
|||
"xcode8.3": {"os": "osx", "osx_image": "xcode8.3", "env": []}, |
|||
"xcode9": {"os": "osx", "osx_image": "xcode9", "env": []}, |
|||
"xcode9.1": {"os": "osx", "osx_image": "xcode9.1", "env": []}, |
|||
"xcode9.2": {"os": "osx", "osx_image": "xcode9.2", "env": []}, |
|||
"xcode9.3": {"os": "osx", "osx_image": "xcode9.3", "env": []}, |
|||
"linux": {"os": "linux"}, |
|||
|
|||
"clang-3.8": {"env": ["CC=clang-3.8 CXX=clang++-3.8"], "compiler": "clang++-3.8", "addons": addon_apt(["llvm-toolchain-precise-3.8"], ["clang-3.8", "libstdc++-6-dev"])}, |
|||
"clang-3.9": {"env": ["CC=clang-3.9 CXX=clang++-3.9"], "compiler": "clang++-3.9", "addons": addon_apt(["llvm-toolchain-trusty-3.9"], ["clang-3.9", "libstdc++-8-dev"])}, |
|||
"clang-4.0": {"env": ["CC=clang-4.0 CXX=clang++-4.0"], "compiler": "clang++-4.0", "addons": addon_apt(["llvm-toolchain-trusty-4.0"], ["clang-4.0", "libstdc++-8-dev"])}, |
|||
"clang-5.0": {"env": ["CC=clang-5.0 CXX=clang++-5.0"], "compiler": "clang++-5.0", "addons": addon_apt(["llvm-toolchain-trusty-5.0"], ["clang-5.0", "libstdc++-8-dev"])}, |
|||
"clang-6.0": {"env": ["CC=clang-6.0 CXX=clang++-6.0"], "compiler": "clang++-6.0", "addons": addon_apt(["llvm-toolchain-trusty-6.0"], ["clang-6.0", "libstdc++-8-dev"])}, |
|||
"g++-5": {"env": ["CC=gcc-5 CXX=g++-5"], "compiler": "g++-5", "addons": addon_apt([],["g++-5"])}, |
|||
"g++-6": {"env": ["CC=gcc-6 CXX=g++-6"], "compiler": "g++-6", "addons": addon_apt([],["g++-6"])}, |
|||
"g++-7": {"env": ["CC=gcc-7 CXX=g++-7"], "compiler": "g++-7", "addons": addon_apt([],["g++-7"])}, |
|||
"g++-8": {"env": ["CC=gcc-8 CXX=g++-8"], "compiler": "g++-8", "addons": addon_apt([],["g++-8"])}, |
|||
|
|||
"task.coverity": {"env": ["TASK=coverity"]}, |
|||
"task.sonarcloud": {"env": ["TASK=sonarcloud"]}, |
|||
"task.doxygen": {"env": ["TASK=doxygen"], "addons": addon_apt([],["doxygen", "ghostscript", "latex-xcolor", "pgf", "texinfo", "texlive", "texlive-font-utils", "texlive-latex-extra"])}, |
|||
"task.pycarl": {"env": ["TASK=pycarl"], "addons": addon_apt([],["python3"])}, |
|||
"task.addons": {"env": ["TASK=addons"]}, |
|||
"task.tidy": {"env": ["TASK=tidy"]}, |
|||
|
|||
"j1": {"script": ["MAKE_PARALLEL=-j1"]}, |
|||
"build.sh": {"script": ["source .ci/build.sh"]}, |
|||
"mayfail": {"allow_failure": True}, |
|||
} |
|||
|
|||
def propertymapper(j): |
|||
"""Merges the properties of a job into the job itself.""" |
|||
if "properties" not in j: return j |
|||
res = j.copy() |
|||
for p in j["properties"]: |
|||
res = datamerge(res, properties[p]) |
|||
return res |
|||
|
|||
def render_template(jobs, cached, template = "travis.yml.tpl", filename = "../.travis.yml"): |
|||
"""Applies the propertymapper to the list of jobs and renders the jobs into the given template.""" |
|||
jobs = map(propertymapper, jobs) |
|||
jobs = sorted(jobs, key = lambda x: (-len(x["stage"]),x["priority"])) |
|||
|
|||
j2_env = Environment(loader = FileSystemLoader(os.path.dirname(__file__)), keep_trailing_newline = True) |
|||
tpl = j2_env.get_template(template) |
|||
res = tpl.render(cached = cached, jobs = jobs) |
|||
|
|||
open(filename, "w").write(res) |
|||
|
|||
def job(priority, properties): |
|||
"""Creates a new job with the given priority and properties.""" |
|||
return { |
|||
"priority": priority, |
|||
"properties": properties, |
|||
} |
@ -0,0 +1,15 @@ |
|||
Language: Cpp |
|||
BasedOnStyle: LLVM |
|||
|
|||
AccessModifierOffset: -4 |
|||
AllowShortFunctionsOnASingleLine: Empty |
|||
AllowShortIfStatementsOnASingleLine: true |
|||
AlwaysBreakTemplateDeclarations: true |
|||
BreakStringLiterals: false |
|||
ColumnLimit: 0 |
|||
IndentWidth: 4 |
|||
PointerAlignment: Left |
|||
SpaceAfterTemplateKeyword: false |
|||
SpacesInContainerLiterals: false |
|||
TabWidth: 4 |
|||
UseTab: Always |
@ -0,0 +1,183 @@ |
|||
|
|||
# # # # # # # # # # # # # # # # # # # # # # |
|||
# A. Project properties. |
|||
# B. Options. |
|||
# C. Find system tools and libraries. |
|||
# D. Write information files. |
|||
# E. Invoke subdirectories. |
|||
# F. Export Compile Information |
|||
# G. CPack |
|||
# # # # # # # # # # # # # # # # # # # # # # |
|||
|
|||
cmake_minimum_required (VERSION 3.2 FATAL_ERROR) |
|||
|
|||
# # # # # # # # # # # # # # # # # # # # # # |
|||
# A. Project properties |
|||
# # # # # # # # # # # # # # # # # # # # # # |
|||
project(carl CXX) |
|||
|
|||
# path to find own modules |
|||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) |
|||
# Include own macros. |
|||
include( carlmacros ) |
|||
|
|||
set_version(18 08) |
|||
|
|||
set( PROJECT_FULLNAME "carl") |
|||
set( PROJECT_DESCRIPTION "Computer ARithmetic Library") |
|||
set( carl_NAME "CArL" ) |
|||
set( carl_DESCRIPTION ${PROJECT_DESCRIPTION} ) |
|||
|
|||
message(STATUS "Version: ${PROJECT_FULLNAME} ${PROJECT_VERSION_FULL}") |
|||
|
|||
# # # # # # # # # # # # # # # # # # # # # # |
|||
# B. Options |
|||
# # # # # # # # # # # # # # # # # # # # # # |
|||
|
|||
# options |
|||
option( DEVELOPER "Compile with extra warnings" OFF ) |
|||
option( ALLWARNINGS "Compile with even more warnings" OFF ) |
|||
option( LOGGING "Enable logging within the carl library" OFF ) |
|||
export_option(LOGGING) |
|||
option( LOGGING_DISABLE_INEFFICIENT "Disable log messages about inefficient methods" OFF ) |
|||
option( TIMING "Enable timing within the carl library" OFF ) |
|||
export_option(TIMING) |
|||
option( FORCE_SHIPPED_RESOURCES "Do not look in system for resources which are included" OFF ) |
|||
export_option(FORCE_SHIPPED_RESOURCES) |
|||
option( FORCE_SHIPPED_GMP "Do not look in system for lib gmp" OFF ) |
|||
export_option(FORCE_SHIPPED_GMP) |
|||
option( USE_GINAC "Compile with testing with the runtime and result comparisons of carl to ginac" OFF ) |
|||
export_option(USE_GINAC) |
|||
option( COMPARE_WITH_Z3 "Compile benchmarks that compare to z3" OFF ) |
|||
option( USE_Z3_NUMBERS "Make z3 rationals available in carl" OFF ) |
|||
option( USE_CLN_NUMBERS "Make cln rationals and integers available in carl" OFF ) |
|||
export_option(USE_CLN_NUMBERS) |
|||
option( USE_COCOA "Use CoCoALib" OFF ) |
|||
export_option(USE_COCOA) |
|||
option( USE_BLISS "Use bliss" OFF ) |
|||
export_option(USE_BLISS) |
|||
OPTION( USE_MPFR_FLOAT "Use the mpfr implementation of floating point numbers." OFF ) |
|||
export_option(USE_MPFR_FLOAT) |
|||
option( USE_COTIRE "Use cotire to generate and use precompiled headers" OFF ) |
|||
option( BUILD_STATIC "Build the static library as well" OFF ) |
|||
export_option(BUILD_STATIC) |
|||
option( BUILD_DOXYGEN "Build doxygen if not found" OFF ) |
|||
export_option(BUILD_DOXYGEN) |
|||
option( THREAD_SAFE "Use mutexing to assure thread safety" OFF ) |
|||
export_option(THREAD_SAFE) |
|||
option( PRUNE_MONOMIAL_POOL "Prune monomial pool" ON ) |
|||
option( EXCLUDE_TESTS_FROM_ALL "If set, tests will not be compiled by default" OFF ) |
|||
export_option(EXCLUDE_TESTS_FROM_ALL) |
|||
|
|||
set(CLANG_SANITIZER "none" CACHE STRING "Compile with the respective sanitizer") |
|||
set_property(CACHE CLANG_SANITIZER PROPERTY STRINGS none address memory thread) |
|||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
|||
|
|||
if (NOT CMAKE_BUILD_TYPE) |
|||
set(CMAKE_BUILD_TYPE "RELEASE" CACHE STRING "Build type." FORCE) |
|||
endif() |
|||
|
|||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "DEBUG" "RELEASE") |
|||
|
|||
set(CARL_LIBRARIES_DIR "${PROJECT_BINARY_DIR}/lib") |
|||
|
|||
# Offer the user the choice of overriding the installation directories |
|||
set(INCLUDE_INSTALL_DIR include/ CACHE PATH "Installation directory for header files" ) |
|||
set(LIB_INSTALL_DIR lib/ CACHE PATH "Installation directory for libraries") |
|||
#set(SYSCONFIG_INSTALL_DIR etc/carl/ CACHE PATH "Installation for system configuration files) |
|||
set(BIN_INSTALL_DIR lib/ CACHE PATH "Installation directory for executables") |
|||
|
|||
|
|||
if(WIN32 AND NOT CYGWIN) |
|||
set(DEF_INSTALL_CMAKE_DIR CMake) |
|||
else() |
|||
set(DEF_INSTALL_CMAKE_DIR lib/cmake/carl) |
|||
endif() |
|||
set(CMAKE_INSTALL_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") |
|||
|
|||
|
|||
foreach(p LIB BIN INCLUDE CMAKE) |
|||
set(var ${p}_INSTALL_DIR) |
|||
if(NOT IS_ABSOLUTE "${${var}}") |
|||
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") |
|||
endif() |
|||
endforeach() |
|||
|
|||
# path to put in the executables after building. |
|||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Directory for built executables") |
|||
|
|||
include(compiler-options) |
|||
|
|||
set(DYNAMIC_EXT ".so") |
|||
set(STATIC_EXT ".a") |
|||
if(APPLE) |
|||
set(DYNAMIC_EXT ".dylib") |
|||
set(STATIC_EXT ".a") |
|||
elseif (WIN32) |
|||
set(DYNAMIC_EXT ".dll") |
|||
set(STATIC_EXT ".lib") |
|||
endif() |
|||
|
|||
if(BUILD_STATIC) |
|||
message(STATUS "Building static: yes") |
|||
if (LOGGING) |
|||
message(WARNING "A static build with logging enabled will probably trigger a segfault!") |
|||
endif() |
|||
else() |
|||
message(STATUS "Building static: no") |
|||
endif() |
|||
|
|||
include(cotire) |
|||
|
|||
# RPATH settings |
|||
# don't skip the full RPATH for the build tree |
|||
SET(CMAKE_SKIP_BUILD_RPATH FALSE) |
|||
# when building, don't use the install RPATH already (but only when installing) |
|||
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) |
|||
# the RPATH to be used when installing |
|||
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") |
|||
# don't add the automatically determined parts of the RPATH |
|||
# which point to directories outside the build tree to the install RPATH |
|||
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) |
|||
|
|||
|
|||
# # # # # # # # # # # # # # # # # # # # # # |
|||
# C. Find system tools and libraries. |
|||
# |
|||
# 1. Required libraries for core. |
|||
# 2. Optional libraries for core. |
|||
# 3. Development and debug libraries. |
|||
# # # # # # # # # # # # # # # # # # # # # # |
|||
|
|||
# # # # # # # # # # # # # # # # # # # # # # |
|||
# C.1. Required libraries for core. |
|||
# # # # # # # # # # # # # # # # # # # # # # |
|||
|
|||
include(resources/resources.cmake) |
|||
|
|||
# we only search for this libraries in the system, if we do not force using the shipped resources. |
|||
|
|||
enable_testing() |
|||
|
|||
#dl must be linked LAST as this is required for the stacktrace in util/platform.h |
|||
if (NOT WIN32) |
|||
list(APPEND carl_LIBRARIES_DYNAMIC pthread dl) |
|||
endif() |
|||
|
|||
include(clang-tidy) |
|||
include(coverage) |
|||
|
|||
if (TARGET Doxygen::doxygen) |
|||
add_subdirectory(doxygen-conf) |
|||
endif() |
|||
add_subdirectory(src) |
|||
|
|||
include(export) |
|||
|
|||
if (BINDINGS_PYTHON) |
|||
add_subdirectory(bindings/pycarl) |
|||
endif() |
|||
|
|||
include(resources/addons/addons.cmake) |
|||
include(packaging) |
|||
include(prepare-ci) |
@ -0,0 +1,23 @@ |
|||
Copyright (c) 2015 Florian Corzilius <corzilius@cs.rwth-aachen.de>, |
|||
Gereon Kremer <gereon.kremer@cs.rwth-aachen.de>, |
|||
Sebastian Junges <sebastian.junges@cs.rwth-aachen.de>, |
|||
Stefan Schupp <stefan.schupp@cs.rwth-aachen.de>, |
|||
Erika Abraham <abraham@cs.rwth-aachen.de> |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in |
|||
all copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|||
THE SOFTWARE. |
@ -0,0 +1,10 @@ |
|||
This is the README for CArL - the Computer ARithmetic and Logic library. |
|||
|
|||
A getting started guide can be found at http://smtrat.github.io/carl/getting_started.html |
|||
|
|||
For more information, please checkout the docs. |
|||
|
|||
[](https://travis-ci.org/smtrat/carl) |
|||
[](https://ci.appveyor.com/project/smtrat/carl) |
|||
[](https://sonarcloud.io/dashboard/index/carl) |
|||
[](https://sonarcloud.io/dashboard?id=carl) |
@ -0,0 +1,113 @@ |
|||
find_package(Java REQUIRED COMPONENTS Runtime Development) |
|||
find_package(JNI REQUIRED) |
|||
find_package(SWIG 3.0 REQUIRED) |
|||
include(UseJava) |
|||
include(UseSWIG) |
|||
|
|||
|
|||
|
|||
file(GLOB_RECURSE i_files "swig/*.i") |
|||
foreach(file ${i_files}) |
|||
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES CPLUSPLUS 1) |
|||
endforeach() |
|||
|
|||
|
|||
#set(test_filenames "") |
|||
#file(GLOB_RECURSE test_files "test/*.java") |
|||
#foreach(file ${test_files}) |
|||
# get_filename_component(filename ${file} NAME_WE) |
|||
# IF (NOT (${filename} MATCHES "TestCarl")) |
|||
# set(test_filenames ${test_filenames} ${filename}) |
|||
# ENDIF () |
|||
#endforeach() |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
#enable_testing() |
|||
|
|||
#compile the tests |
|||
#ADD_CUSTOM_COMMAND( |
|||
#OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test/*.class |
|||
#COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test |
|||
#COMMAND ${Java_JAVAC_EXECUTABLE} -d ${CMAKE_CURRENT_BINARY_DIR}/test -cp "${CMAKE_CURRENT_BINARY_DIR}:${CMAKE_CURRENT_SOURCE_DIR}/test:${CMAKE_CURRENT_BINARY_DIR}/jcarl.jar:/usr/share/java/junit.jar" |
|||
#${CMAKE_CURRENT_SOURCE_DIR}/test/*java |
|||
#DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test/*.java |
|||
#) |
|||
|
|||
|
|||
#build the jar |
|||
ADD_CUSTOM_COMMAND( |
|||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/jcarl/jcarl.jar |
|||
COMMAND ${Java_JAVAC_EXECUTABLE} ./jcarl/*.java |
|||
COMMAND jar cvf jcarl.jar ./jcarl/*.class |
|||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/jcarl |
|||
) |
|||
|
|||
|
|||
|
|||
|
|||
#add_test(NAME jcarl COMMAND ${Java_JAVA_EXECUTABLE} -classpath .:/usr/share/java/junit.jar:/usr/share/java/hamcrest-core.jar:../ -Djava.library.path=../ org.junit.runner.JUnitCore ${test_filenames} |
|||
#WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test ) |
|||
|
|||
|
|||
|
|||
|
|||
set(CMAKE_JNI_TARGET TRUE) |
|||
|
|||
|
|||
|
|||
|
|||
#this is for swig |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${JAVA_AWT_INCLUDE_PATH} -I${JAVA_AWT_INCLUDE_PATH}/linux -I/usr/include/python2.7") |
|||
|
|||
set(CMAKE_SWIG_FLAGS -package jcarl) |
|||
set(CMAKE_SWIG_OUTDIR "jcarl/jcarl") |
|||
swig_add_module(jcarl java ${i_files}) |
|||
swig_link_libraries(jcarl lib_carl) |
|||
|
|||
|
|||
#For Python: Not working, however... |
|||
#set(CMAKE_SWIG_FLAGS "") |
|||
#set(CMAKE_SWIG_OUTDIR "pycarl/pycarl") |
|||
#swig_add_module(pycarl python ${i_files}) |
|||
#swig_link_libraries(pycarl lib_carl) |
|||
|
|||
|
|||
|
|||
|
|||
ADD_CUSTOM_TARGET(jcarl.jar |
|||
ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/jcarl/jcarl.jar jcarl) |
|||
|
|||
|
|||
|
|||
#ADD_CUSTOM_TARGET(tests |
|||
#ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/test/*.class ${CMAKE_CURRENT_BINARY_DIR}/jcarl.jar jcarl) |
|||
|
|||
|
|||
#find_package(PythonInterp) |
|||
|
|||
#if (PYTHONINTERP_FOUND) |
|||
# add_test( NAME pycarl COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/runAllTests.py) |
|||
#else() |
|||
# status(WARNING "Did not find a python interpreter, disabling pycarl tests.") |
|||
#endif() |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
# include dir: bindings/jcarl/example/ |
|||
# libraries: bindings/jcarl/*.jar / *.so |
|||
# javac test.java |
|||
# java -cp <jarfile>:. test |
|||
|
|||
#execute test from within test directory: java -Djava.library.path=../ -cp ../:. TestBindings |
@ -0,0 +1,4 @@ |
|||
setup.cfg |
|||
build/ |
|||
dist/ |
|||
lib/ |
@ -0,0 +1,140 @@ |
|||
|
|||
|
|||
%module ConstraintRationalT |
|||
%{ |
|||
#include <carl/formula/Constraint.h> |
|||
#include <carl/core/SimpleConstraint.h> |
|||
#include <carl/formula/Formula.h> |
|||
#include "gmpxx.h" |
|||
#include <carl/core/RationalFunction.h> |
|||
#include <carl/core/Relation.h> |
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
typedef carl::Monomial::Arg Monomial; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
%} |
|||
|
|||
%import "formula.i" |
|||
|
|||
%include "std_string.i" |
|||
%import "variable.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
%import "factorizedpolynomial.i" |
|||
%include "std_vector.i" |
|||
%include "std_map.i" |
|||
|
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
typedef carl::Monomial::Arg Monomial; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
|
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
enum class Relation { EQ = 0, NEQ = 1, LESS = 2, LEQ = 4, GREATER = 3, GEQ = 5 }; |
|||
|
|||
|
|||
|
|||
template<typename Pol> class Constraint { |
|||
public: |
|||
Constraint( bool _valid = true ); |
|||
|
|||
explicit Constraint( carl::Variable::Arg _var, carl::Relation _rel, const typename Pol::NumberType& _bound = constant_zero<typename Pol::NumberType>::get() ); |
|||
|
|||
explicit Constraint( const Pol& _lhs, carl::Relation _rel ); |
|||
|
|||
unsigned satisfiedBy( const std::map<Variable,Rational>& _assignment ) const; |
|||
|
|||
std::string toString( unsigned _unequalSwitch = 0, bool _infix = true, bool _friendlyVarNames = true ) const; |
|||
|
|||
const Pol& lhs() const; |
|||
|
|||
carl::Relation relation() const; |
|||
|
|||
//TODO: maybe find fix for the weird underscore names |
|||
%extend { |
|||
carl::Formula<Pol> not_() { |
|||
return carl::Formula<Pol>(carl::FormulaType::NOT, carl::Formula<Pol>(*$self)); |
|||
} |
|||
|
|||
carl::Formula<Pol> and_(const Constraint& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::AND, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs)); |
|||
} |
|||
|
|||
carl::Formula<Pol> and_(const carl::Formula<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::AND, carl::Formula<Pol>(*$self), rhs); |
|||
} |
|||
|
|||
carl::Formula<Pol> or_(const Constraint& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::OR, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs)); |
|||
} |
|||
|
|||
carl::Formula<Pol> or_(const carl::Formula<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::OR, carl::Formula<Pol>(*$self), rhs); |
|||
} |
|||
|
|||
carl::Formula<Pol> xor_(const Constraint& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::XOR, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs)); |
|||
} |
|||
|
|||
carl::Formula<Pol> xor_(const carl::Formula<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::XOR, carl::Formula<Pol>(*$self), rhs); |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
}; |
|||
|
|||
template<typename LhsType> class SimpleConstraint { |
|||
public: |
|||
SimpleConstraint(bool v) : mLhs(v ? 0 : 1), mRelation(carl::Relation::EQ) {} |
|||
SimpleConstraint(const LhsType& lhs, carl::Relation rel) : mLhs(lhs), mRelation(rel) |
|||
{} |
|||
|
|||
const LhsType& lhs() const {return mLhs;} |
|||
const carl::Relation& rel() const {return mRelation;} |
|||
|
|||
%extend { |
|||
std::string toString() { |
|||
std::stringstream ss; |
|||
ss << *$self; |
|||
return ss.str(); |
|||
} |
|||
} |
|||
|
|||
}; |
|||
} |
|||
|
|||
|
|||
%include "std_map.i" |
|||
|
|||
%template(ConstraintRational) carl::Constraint<Polynomial>; |
|||
%template(SimpleConstraintRational) carl::SimpleConstraint<Polynomial>; |
|||
%template(SimpleConstraintFunc) carl::SimpleConstraint<FactorizedRationalFunction>; |
@ -0,0 +1,140 @@ |
|||
|
|||
|
|||
%module ConstraintRationalT |
|||
%{ |
|||
#include <carl/formula/Constraint.h> |
|||
#include <carl/core/SimpleConstraint.h> |
|||
#include <carl/formula/Formula.h> |
|||
#include "gmpxx.h" |
|||
#include <carl/core/RationalFunction.h> |
|||
#include <carl/core/Relation.h> |
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
typedef carl::Monomial::Arg Monomial; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
%} |
|||
|
|||
%import "formula.i" |
|||
|
|||
%include "std_string.i" |
|||
%import "variable.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
%import "factorizedpolynomial.i" |
|||
%include "std_vector.i" |
|||
%include "std_map.i" |
|||
|
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
typedef carl::Monomial::Arg Monomial; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
|
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
enum Relation { EQ = 0, NEQ = 1, LESS = 2, LEQ = 4, GREATER = 3, GEQ = 5 }; |
|||
|
|||
|
|||
|
|||
template<typename Pol> class Constraint { |
|||
public: |
|||
Constraint( bool _valid = true ); |
|||
|
|||
explicit Constraint( carl::Variable::Arg _var, carl::Relation _rel, const typename Pol::NumberType& _bound = constant_zero<typename Pol::NumberType>::get() ); |
|||
|
|||
explicit Constraint( const Pol& _lhs, carl::Relation _rel ); |
|||
|
|||
unsigned satisfiedBy( const std::map<Variable,Rational>& _assignment ) const; |
|||
|
|||
std::string toString( unsigned _unequalSwitch = 0, bool _infix = true, bool _friendlyVarNames = true ) const; |
|||
|
|||
const Pol& lhs() const; |
|||
|
|||
carl::Relation relation() const; |
|||
|
|||
//TODO: maybe find fix for the weird underscore names |
|||
%extend { |
|||
carl::Formula<Pol> not_() { |
|||
return carl::Formula<Pol>(carl::FormulaType::NOT, carl::Formula<Pol>(*$self)); |
|||
} |
|||
|
|||
carl::Formula<Pol> and_(const Constraint& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::AND, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs)); |
|||
} |
|||
|
|||
carl::Formula<Pol> and_(const carl::Formula<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::AND, carl::Formula<Pol>(*$self), rhs); |
|||
} |
|||
|
|||
carl::Formula<Pol> or_(const Constraint& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::OR, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs)); |
|||
} |
|||
|
|||
carl::Formula<Pol> or_(const carl::Formula<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::OR, carl::Formula<Pol>(*$self), rhs); |
|||
} |
|||
|
|||
carl::Formula<Pol> xor_(const Constraint& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::XOR, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs)); |
|||
} |
|||
|
|||
carl::Formula<Pol> xor_(const carl::Formula<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::XOR, carl::Formula<Pol>(*$self), rhs); |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
}; |
|||
|
|||
template<typename LhsType> class SimpleConstraint { |
|||
public: |
|||
SimpleConstraint(bool v) : mLhs(v ? 0 : 1), mRelation(carl::Relation::EQ) {} |
|||
SimpleConstraint(const LhsType& lhs, carl::Relation rel) : mLhs(lhs), mRelation(rel) |
|||
{} |
|||
|
|||
const LhsType& lhs() const {return mLhs;} |
|||
const carl::Relation& rel() const {return mRelation;} |
|||
|
|||
%extend { |
|||
std::string toString() { |
|||
std::stringstream ss; |
|||
ss << *$self; |
|||
return ss.str(); |
|||
} |
|||
} |
|||
|
|||
}; |
|||
} |
|||
|
|||
|
|||
%include "std_map.i" |
|||
|
|||
%template(ConstraintRational) carl::Constraint<Polynomial>; |
|||
%template(SimpleConstraintRational) carl::SimpleConstraint<Polynomial>; |
|||
%template(SimpleConstraintFunc) carl::SimpleConstraint<FactorizedRationalFunction>; |
@ -0,0 +1,123 @@ |
|||
|
|||
|
|||
|
|||
|
|||
%module FactorizedPolynomialRationalT |
|||
%{ |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/FactorizedPolynomial.h> |
|||
#include "gmp.h" |
|||
#include "gmpxx.h" |
|||
|
|||
|
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
typedef unsigned int uint; |
|||
typedef std::pair<carl::Variable,uint> VarIntPair; |
|||
|
|||
|
|||
typedef FactorizedPolynomial::CACHE FactorizationCache; |
|||
|
|||
|
|||
%} |
|||
|
|||
%include "std_string.i" |
|||
%include "std_shared_ptr.i" |
|||
%shared_ptr(carl::Cache<FactorizationPair>); |
|||
|
|||
%import "variable.i" |
|||
%import "polynomial.i" |
|||
|
|||
typedef mpq_class Rational; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
typedef FactorizedPolynomial::CACHE FactorizationCache; |
|||
|
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
%rename(FactorizationCache) Cache<FactorizationPair>; |
|||
class Cache<FactorizationPair> { |
|||
public: |
|||
Cache( size_t _maxCacheSize = 10000, double _cacheReductionAmount = 0.2, double _decay = 0.98 ); |
|||
|
|||
}; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
template<typename P> |
|||
class FactorizedPolynomial { |
|||
public: |
|||
typedef typename P::CoeffType CoeffType; |
|||
typedef carl::Cache<carl::PolynomialFactorizationPair<P>> CACHE; |
|||
|
|||
|
|||
explicit FactorizedPolynomial( const CoeffType& ); |
|||
|
|||
explicit FactorizedPolynomial( const P& _polynomial, const std::shared_ptr<carl::FactorizedPolynomial::CACHE>&, bool = false ); |
|||
CoeffType constantPart() const; |
|||
template<typename SubstitutionType = CoeffType> |
|||
SubstitutionType evaluate(const std::map<carl::Variable, SubstitutionType>& substitutions) const; |
|||
|
|||
|
|||
|
|||
std::string toString( bool _infix = true, bool _friendlyVarNames = true ) const; |
|||
|
|||
%extend { |
|||
std::vector<carl::Variable> gatherVariables() const { |
|||
std::set<carl::Variable> asSet = $self->gatherVariables(); |
|||
return std::vector<carl::Variable>(asSet.begin(),asSet.end()); |
|||
} |
|||
|
|||
} |
|||
|
|||
%extend { |
|||
|
|||
carl::FactorizedPolynomial<P> add(const carl::FactorizedPolynomial<P>& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
carl::FactorizedPolynomial<P> sub(const carl::FactorizedPolynomial<P>& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
carl::FactorizedPolynomial<P> mul(const carl::FactorizedPolynomial<P>& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
bool equals(const carl::FactorizedPolynomial<P>& rhs) { |
|||
return *$self==rhs; |
|||
} |
|||
|
|||
bool notEquals(const carl::FactorizedPolynomial<P>& rhs) { |
|||
return *$self!=rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
}; |
|||
|
|||
%template(evaluate) carl::FactorizedPolynomial::evaluate<Rational>; |
|||
|
|||
} |
|||
|
|||
%template(FactorizedPolynomialRational) carl::FactorizedPolynomial<Polynomial>; |
|||
|
@ -0,0 +1,123 @@ |
|||
|
|||
|
|||
|
|||
|
|||
%module FactorizedPolynomialRational |
|||
%{ |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/FactorizedPolynomial.h> |
|||
#include "gmp.h" |
|||
#include "gmpxx.h" |
|||
|
|||
|
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
typedef unsigned int uint; |
|||
typedef std::pair<carl::Variable,uint> VarIntPair; |
|||
|
|||
|
|||
typedef FactorizedPolynomial::CACHE FactorizationCache; |
|||
|
|||
|
|||
%} |
|||
|
|||
%include "std_string.i" |
|||
%include "std_shared_ptr.i" |
|||
%shared_ptr(carl::Cache<FactorizationPair>); |
|||
|
|||
%import "variable.i" |
|||
%import "polynomial.i" |
|||
|
|||
typedef mpq_class Rational; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
typedef FactorizedPolynomial::CACHE FactorizationCache; |
|||
|
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
%rename(FactorizationCache) Cache<FactorizationPair>; |
|||
class Cache<FactorizationPair> { |
|||
public: |
|||
Cache( size_t _maxCacheSize = 10000, double _cacheReductionAmount = 0.2, double _decay = 0.98 ); |
|||
|
|||
}; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
template<typename P> |
|||
class FactorizedPolynomial { |
|||
public: |
|||
typedef typename P::CoeffType CoeffType; |
|||
typedef carl::Cache<carl::PolynomialFactorizationPair<P>> CACHE; |
|||
|
|||
|
|||
explicit FactorizedPolynomial( const CoeffType& ); |
|||
|
|||
explicit FactorizedPolynomial( const P& _polynomial, const std::shared_ptr<carl::FactorizedPolynomial::CACHE>&, bool = false ); |
|||
CoeffType constantPart() const; |
|||
template<typename SubstitutionType = CoeffType> |
|||
SubstitutionType evaluate(const std::map<carl::Variable, SubstitutionType>& substitutions) const; |
|||
|
|||
|
|||
|
|||
std::string toString( bool _infix = true, bool _friendlyVarNames = true ) const; |
|||
|
|||
%extend { |
|||
std::vector<carl::Variable> gatherVariables() const { |
|||
std::set<carl::Variable> asSet = $self->gatherVariables(); |
|||
return std::vector<carl::Variable>(asSet.begin(),asSet.end()); |
|||
} |
|||
|
|||
} |
|||
|
|||
%extend { |
|||
|
|||
carl::FactorizedPolynomial<P> add(const carl::FactorizedPolynomial<P>& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
carl::FactorizedPolynomial<P> sub(const carl::FactorizedPolynomial<P>& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
carl::FactorizedPolynomial<P> mul(const carl::FactorizedPolynomial<P>& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
bool equals(const carl::FactorizedPolynomial<P>& rhs) { |
|||
return *$self==rhs; |
|||
} |
|||
|
|||
bool notEquals(const carl::FactorizedPolynomial<P>& rhs) { |
|||
return *$self!=rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
}; |
|||
|
|||
%template(evaluate) carl::FactorizedPolynomial::evaluate<Rational>; |
|||
|
|||
} |
|||
|
|||
%template(FactorizedPolynomialRational) carl::FactorizedPolynomial<Polynomial>; |
|||
|
@ -0,0 +1,185 @@ |
|||
|
|||
|
|||
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE) |
|||
SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE) |
|||
|
|||
%module FormulaPolynomialT |
|||
%{ |
|||
#include <carl/formula/Formula.h> |
|||
#include <carl/formula/Constraint.h> |
|||
#include <carl/core/SimpleConstraint.h> |
|||
#include "gmpxx.h" |
|||
#include <carl/core/RationalFunction.h> |
|||
#include <carl/core/Relation.h> |
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
typedef carl::Monomial::Arg Monomial; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
typedef carl::Formula<Polynomial> FormulaPolynomial; |
|||
typedef std::vector<FormulaPolynomial> FormulaVector; |
|||
|
|||
|
|||
|
|||
|
|||
%} |
|||
|
|||
|
|||
|
|||
|
|||
%import "constraint.i" |
|||
|
|||
%include "std_string.i" |
|||
%import "variable.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
%import "factorizedpolynomial.i" |
|||
%include "std_vector.i" |
|||
%include "std_map.i" |
|||
|
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef std::vector<FormulaPolynomial> FormulaVector; |
|||
|
|||
|
|||
|
|||
%template(FormulaVector) std::vector<carl::Formula<carl::MultivariatePolynomial<Rational>>>; |
|||
|
|||
|
|||
typedef carl::Formula<Polynomial> FormulaPolynomial; |
|||
|
|||
|
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
typedef carl::Monomial::Arg Monomial; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
|
|||
enum FormulaType { |
|||
// Generic |
|||
ITE, EXISTS, FORALL, |
|||
|
|||
// Core Theory |
|||
TRUE, FALSE, |
|||
BOOL, |
|||
NOT, IMPLIES, AND, OR, XOR, |
|||
IFF, |
|||
|
|||
// Arithmetic Theory |
|||
CONSTRAINT, |
|||
|
|||
// Bitvector Theory |
|||
BITVECTOR, |
|||
|
|||
// Uninterpreted Theory |
|||
UEQ |
|||
}; |
|||
|
|||
|
|||
template<typename Pol> class Formula { |
|||
public: |
|||
explicit Formula( carl::Variable::Arg _booleanVar ): |
|||
Formula( carl::FormulaPool<Pol>::getInstance().create( _booleanVar ) ) |
|||
{} |
|||
|
|||
explicit Formula( const carl::Constraint<Pol>& _constraint ): |
|||
Formula( carl::FormulaPool<Pol>::getInstance().create( _constraint ) ) |
|||
{} |
|||
|
|||
explicit Formula( carl::FormulaType _type, const Formula& _subformula ): |
|||
Formula(carl::FormulaPool<Pol>::getInstance().create(_type, std::move(Formula(_subformula)))) |
|||
{} |
|||
|
|||
explicit Formula( carl::FormulaType _type, const std::vector<Formula<Pol>>& _subasts ): |
|||
Formula( carl::FormulaPool<Pol>::getInstance().create( _type, _subasts ) ) |
|||
{} |
|||
|
|||
//Apparently satisfiedBy no longer exists |
|||
//unsigned satisfiedBy( const carl::EvaluationMap<typename Pol::NumberType>& _assignment ) const; |
|||
|
|||
std::string toString( bool _withActivity = false, unsigned _resolveUnequal = 0, const std::string _init = "", bool _oneline = true, bool _infix = false, bool _friendlyNames = true, bool _withVariableDefinition = false ) const; |
|||
|
|||
size_t size() const; |
|||
|
|||
|
|||
|
|||
carl::FormulaType getType() const; |
|||
|
|||
|
|||
//TODO: maybe find fix for the weird underscore names |
|||
|
|||
%extend { |
|||
carl::Formula<Pol> not_() { |
|||
return carl::Formula<Pol>(carl::FormulaType::NOT, carl::Formula<Pol>(*$self)); |
|||
} |
|||
|
|||
carl::Formula<Pol> and_(const carl::Constraint<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::AND, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs)); |
|||
} |
|||
|
|||
carl::Formula<Pol> and_(const carl::Formula<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::AND, carl::Formula<Pol>(*$self), rhs); |
|||
} |
|||
|
|||
carl::Formula<Pol> or_(const carl::Constraint<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::OR, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs)); |
|||
} |
|||
|
|||
carl::Formula<Pol> or_(const carl::Formula<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::OR, carl::Formula<Pol>(*$self), rhs); |
|||
} |
|||
|
|||
carl::Formula<Pol> xor_(const carl::Constraint<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::XOR, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs)); |
|||
} |
|||
|
|||
carl::Formula<Pol> xor_(const carl::Formula<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::XOR, carl::Formula<Pol>(*$self), rhs); |
|||
} |
|||
|
|||
//instead of iterator |
|||
|
|||
carl::Formula<Pol> getItem(int i) { |
|||
return $self->subformulas().at(i); |
|||
} |
|||
|
|||
bool equals(const carl::Formula<Pol>& rhs) { |
|||
return *$self == rhs; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
}; |
|||
|
|||
} |
|||
|
|||
|
|||
%template(FormulaPolynomial) carl::Formula<Polynomial>; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,179 @@ |
|||
|
|||
|
|||
%module FormulaPolynomialT |
|||
%{ |
|||
#include <carl/formula/Formula.h> |
|||
#include <carl/formula/Constraint.h> |
|||
#include <carl/core/SimpleConstraint.h> |
|||
#include "gmpxx.h" |
|||
#include <carl/core/RationalFunction.h> |
|||
#include <carl/core/Relation.h> |
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
typedef carl::Monomial::Arg Monomial; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
typedef carl::Formula<Polynomial> FormulaPolynomial; |
|||
typedef std::vector<FormulaPolynomial> FormulaVector; |
|||
|
|||
|
|||
|
|||
|
|||
%} |
|||
|
|||
%import "constraint.i" |
|||
|
|||
%include "std_string.i" |
|||
%import "variable.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
%import "factorizedpolynomial.i" |
|||
%include "std_vector.i" |
|||
%include "std_map.i" |
|||
|
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef std::vector<FormulaPolynomial> FormulaVector; |
|||
|
|||
|
|||
|
|||
%template(FormulaVector) std::vector<carl::Formula<carl::MultivariatePolynomial<Rational>>>; |
|||
|
|||
|
|||
typedef carl::Formula<Polynomial> FormulaPolynomial; |
|||
|
|||
|
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
typedef carl::Monomial::Arg Monomial; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
|
|||
enum FormulaType { |
|||
// Generic |
|||
ITE, EXISTS, FORALL, |
|||
|
|||
// Core Theory |
|||
TRUE, FALSE, |
|||
BOOL, |
|||
NOT, IMPLIES, AND, OR, XOR, |
|||
IFF, |
|||
|
|||
// Arithmetic Theory |
|||
CONSTRAINT, |
|||
|
|||
// Bitvector Theory |
|||
BITVECTOR, |
|||
|
|||
// Uninterpreted Theory |
|||
UEQ |
|||
}; |
|||
|
|||
|
|||
template<typename Pol> class Formula { |
|||
public: |
|||
explicit Formula( carl::Variable::Arg _booleanVar ): |
|||
Formula( carl::FormulaPool<Pol>::getInstance().create( _booleanVar ) ) |
|||
{} |
|||
|
|||
explicit Formula( const carl::Constraint<Pol>& _constraint ): |
|||
Formula( carl::FormulaPool<Pol>::getInstance().create( _constraint ) ) |
|||
{} |
|||
|
|||
explicit Formula( carl::FormulaType _type, const Formula& _subformula ): |
|||
Formula(carl::FormulaPool<Pol>::getInstance().create(_type, std::move(Formula(_subformula)))) |
|||
{} |
|||
|
|||
//explicit Formula( carl::FormulaType _type, const std::vector<Formula<Pol>>& _subasts ): |
|||
// Formula( carl::FormulaPool<Pol>::getInstance().create( _type, _subasts ) ) |
|||
//{} |
|||
|
|||
//Apparently satisfiedBy no longer exists |
|||
//unsigned satisfiedBy( const carl::EvaluationMap<typename Pol::NumberType>& _assignment ) const; |
|||
|
|||
std::string toString( bool _withActivity = false, unsigned _resolveUnequal = 0, const std::string _init = "", bool _oneline = true, bool _infix = false, bool _friendlyNames = true, bool _withVariableDefinition = false ) const; |
|||
|
|||
size_t size() const; |
|||
|
|||
|
|||
|
|||
carl::FormulaType getType() const; |
|||
|
|||
|
|||
//TODO: maybe find fix for the weird underscore names |
|||
|
|||
%extend { |
|||
carl::Formula<Pol> not_() { |
|||
return carl::Formula<Pol>(carl::FormulaType::NOT, carl::Formula<Pol>(*$self)); |
|||
} |
|||
|
|||
carl::Formula<Pol> and_(const carl::Constraint<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::AND, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs)); |
|||
} |
|||
|
|||
carl::Formula<Pol> and_(const carl::Formula<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::AND, carl::Formula<Pol>(*$self), rhs); |
|||
} |
|||
|
|||
carl::Formula<Pol> or_(const carl::Constraint<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::OR, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs)); |
|||
} |
|||
|
|||
carl::Formula<Pol> or_(const carl::Formula<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::OR, carl::Formula<Pol>(*$self), rhs); |
|||
} |
|||
|
|||
carl::Formula<Pol> xor_(const carl::Constraint<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::XOR, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs)); |
|||
} |
|||
|
|||
carl::Formula<Pol> xor_(const carl::Formula<Pol>& rhs) { |
|||
return carl::Formula<Pol>(carl::FormulaType::XOR, carl::Formula<Pol>(*$self), rhs); |
|||
} |
|||
|
|||
//instead of iterator |
|||
|
|||
carl::Formula<Pol> getItem(int i) { |
|||
return $self->subformulas().at(i); |
|||
} |
|||
|
|||
bool equals(const carl::Formula<Pol>& rhs) { |
|||
return *$self == rhs; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
}; |
|||
|
|||
} |
|||
|
|||
|
|||
%template(FormulaPolynomial) carl::Formula<Polynomial>; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,213 @@ |
|||
|
|||
%module FormulaClasses |
|||
%{ |
|||
#include <carl/formula/Formula.h> |
|||
#include <carl/formula/Constraint.h> |
|||
#include <carl/core/SimpleConstraint.h> |
|||
#include "gmpxx.h" |
|||
#include <carl/core/RationalFunction.h> |
|||
#include <carl/core/Relation.h> |
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
typedef carl::Monomial::Arg Monomial; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
typedef carl::Formula<Polynomial> FormulaPoly; |
|||
typedef std::vector<FormulaPoly> FormulaVector; |
|||
|
|||
|
|||
|
|||
|
|||
%} |
|||
|
|||
|
|||
%include "std_string.i" |
|||
%import "variable.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
%import "factorizedpolynomial.i" |
|||
%include "std_vector.i" |
|||
%include "std_map.i" |
|||
|
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef std::vector<FormulaPoly> FormulaVector; |
|||
|
|||
|
|||
|
|||
%template(FormulaVector) std::vector<carl::Formula<carl::MultivariatePolynomial<Rational>>>; |
|||
|
|||
|
|||
typedef carl::Formula<Polynomial> FormulaPoly; |
|||
|
|||
|
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
typedef carl::Monomial::Arg Monomial; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction; |
|||
typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair; |
|||
|
|||
|
|||
|
|||
|
|||
/*%typemap(in) std::vector<FormulaPoly> { |
|||
|
|||
|
|||
}*/ |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
//typedef typename Polynomial::UnderlyingNumberType<Rational>::type Polynomial::NumberType; |
|||
|
|||
|
|||
enum FormulaType { |
|||
// Generic |
|||
ITE, EXISTS, FORALL, |
|||
|
|||
// Core Theory |
|||
TRUE, FALSE, |
|||
BOOL, |
|||
NOT, IMPLIES, AND, OR, XOR, |
|||
IFF, |
|||
|
|||
// Arithmetic Theory |
|||
CONSTRAINT, |
|||
|
|||
// Bitvector Theory |
|||
BITVECTOR, |
|||
|
|||
// Uninterpreted Theory |
|||
UEQ |
|||
}; |
|||
|
|||
enum Relation { EQ = 0, NEQ = 1, LESS = 2, LEQ = 4, GREATER = 3, GEQ = 5 }; |
|||
/* TODO: wrap this toString |
|||
inline std::ostream& operator<<(std::ostream& os, const Relation& r) { |
|||
switch (r) { |
|||
case Relation::EQ: os << "="; break; |
|||
case Relation::NEQ: os << "<>"; break; |
|||
case Relation::LESS: os << "<"; break; |
|||
case Relation::LEQ: os << "<="; break; |
|||
case Relation::GREATER: os << ">"; break; |
|||
case Relation::GEQ: os << ">="; break; |
|||
} |
|||
return os; |
|||
} */ |
|||
|
|||
template<typename Pol> class Constraint { |
|||
public: |
|||
Constraint( bool _valid = true ); |
|||
|
|||
explicit Constraint( carl::Variable::Arg _var, carl::Relation _rel, const typename Pol::NumberType & _bound = constant_zero<Rational>::get() ); |
|||
|
|||
explicit Constraint( const Pol& _lhs, carl::Relation _rel ); |
|||
|
|||
unsigned satisfiedBy( const std::map<Variable,Rational>& _assignment ) const; |
|||
|
|||
std::string toString( unsigned _unequalSwitch = 0, bool _infix = true, bool _friendlyVarNames = true ) const; |
|||
|
|||
const Pol& lhs() const; |
|||
|
|||
carl::Relation relation() const; |
|||
|
|||
//TODO: boolean connectives |
|||
|
|||
|
|||
}; |
|||
|
|||
template<typename LhsType> class SimpleConstraint { |
|||
public: |
|||
SimpleConstraint(bool v) : mLhs(v ? 0 : 1), mRelation(carl::Relation::EQ) {} |
|||
SimpleConstraint(const LhsType& lhs, carl::Relation rel) : mLhs(lhs), mRelation(rel) |
|||
{} |
|||
|
|||
const LhsType& lhs() const {return mLhs;} |
|||
const carl::Relation& rel() const {return mRelation;} |
|||
|
|||
%extend { |
|||
std::string toString() { |
|||
std::stringstream ss; |
|||
ss << *$self; |
|||
return ss.str(); |
|||
} |
|||
} |
|||
|
|||
}; |
|||
|
|||
|
|||
|
|||
//TODO: wrap EvaluationMap, Formulas, and the other types that are missing! |
|||
|
|||
template<typename Pol> class Formula { |
|||
|
|||
|
|||
public: |
|||
explicit Formula( carl::Variable::Arg _booleanVar ): |
|||
Formula( carl::FormulaPool<Pol>::getInstance().create( _booleanVar ) ) |
|||
{} |
|||
|
|||
explicit Formula( const carl::Constraint<Pol>& _constraint ): |
|||
Formula( carl::FormulaPool<Pol>::getInstance().create( _constraint ) ) |
|||
{} |
|||
|
|||
explicit Formula( carl::FormulaType _type, const Formula& _subformula ): |
|||
Formula(carl::FormulaPool<Pol>::getInstance().create(_type, std::move(Formula(_subformula)))) |
|||
{} |
|||
|
|||
explicit Formula( carl::FormulaType _type, const std::vector<Formula<Pol>>& _subasts ): |
|||
Formula( carl::FormulaPool<Pol>::getInstance().create( _type, _subasts ) ) |
|||
{} |
|||
|
|||
//Apparently satisfiedBy is no longer existent |
|||
//unsigned satisfiedBy( const carl::EvaluationMap<typename Pol::NumberType>& _assignment ) const; |
|||
|
|||
std::string toString( bool _withActivity = false, unsigned _resolveUnequal = 0, const std::string _init = "", bool _oneline = true, bool _infix = false, bool _friendlyNames = true, bool _withVariableDefinition = false ) const; |
|||
|
|||
size_t size() const; |
|||
|
|||
|
|||
|
|||
carl::FormulaType getType() const |
|||
{ |
|||
return mpContent->mType; |
|||
} |
|||
//TODO: operators and iterator! |
|||
|
|||
}; |
|||
} |
|||
|
|||
|
|||
%include "std_map.i" |
|||
|
|||
|
|||
|
|||
%template(FormulaPoly) carl::Formula<Polynomial>; |
|||
%template(ConstraintPoly) carl::Constraint<Polynomial>; |
|||
%template(SimpleConstraintPoly) carl::SimpleConstraint<Polynomial>; |
|||
%template(SimpleConstraintFunc) carl::SimpleConstraint<FactorizedRationalFunction>; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,244 @@ |
|||
|
|||
|
|||
|
|||
|
|||
%module IntervalRationalT |
|||
%{ |
|||
#include <carl/interval/Interval.h> |
|||
|
|||
typedef mpq_class Rational; |
|||
typedef unsigned int uint; |
|||
%} |
|||
|
|||
%import "rational.i" |
|||
|
|||
typedef unsigned int uint; |
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
|
|||
%include "enums.swg" |
|||
%javaconst(1); |
|||
|
|||
|
|||
enum class BoundType { |
|||
/// the given bound is compared by a strict ordering relation |
|||
STRICT=0, |
|||
/// the given bound is compared by a weak ordering relation |
|||
WEAK=1, |
|||
/// the given bound is interpreted as minus or plus infinity depending on whether it is the left or the right bound |
|||
INFTY=2 |
|||
}; |
|||
|
|||
|
|||
|
|||
template<typename Number> |
|||
class Interval |
|||
{ |
|||
public: |
|||
|
|||
Interval(const Number& n) : |
|||
mContent(n), |
|||
mLowerBoundType(BoundType::WEAK), |
|||
mUpperBoundType(BoundType::WEAK) { } |
|||
|
|||
Interval(const Number& lower, const Number& upper) |
|||
{ |
|||
|
|||
} |
|||
|
|||
Interval(const Number& lower, BoundType lowerBoundType, const Number& upper, BoundType upperBoundType) |
|||
{ |
|||
} |
|||
|
|||
|
|||
//BEWARE: in python sth with return value policy had to be changed here, so maybe problems will arise |
|||
|
|||
inline const Number& lower() const; |
|||
|
|||
inline const Number& upper() const; |
|||
|
|||
inline void setLower(const Number& n); |
|||
|
|||
inline void setUpper(const Number& n); |
|||
|
|||
inline bool isInfinite() const; |
|||
|
|||
inline bool isUnbounded() const; |
|||
|
|||
inline bool isHalfBounded() const; |
|||
|
|||
inline bool isEmpty() const; |
|||
|
|||
inline bool isPointInterval() const; |
|||
|
|||
inline bool isOpenInterval() const; |
|||
|
|||
inline bool isClosedInterval() const; |
|||
|
|||
inline bool isZero() const; |
|||
|
|||
inline bool isOne() const; |
|||
|
|||
inline bool isPositive() const; |
|||
|
|||
inline bool isNegative() const; |
|||
|
|||
inline bool isSemiPositive() const; |
|||
|
|||
inline bool isSemiNegative() const; |
|||
|
|||
Interval<Number> integralPart() const; |
|||
Number diameter() const; |
|||
//NOTE: this is now set for Number not being a float... needs to be changed in Interval.h otherwise |
|||
Number center() const; |
|||
Number sample(bool _includingBounds = true) const; |
|||
bool contains(const Number& val) const; |
|||
bool contains(const Interval<Number>& rhs) const; |
|||
bool meets(const Number& val) const; |
|||
bool isSubset(const Interval<Number>& rhs) const; |
|||
bool isProperSubset(const Interval<Number>& rhs) const; |
|||
|
|||
Interval<Number> div(const Interval<Number>& rhs) const; |
|||
Interval<Number> inverse() const; |
|||
Interval<Number> abs() const; |
|||
Interval<Number> pow(uint exp) const; |
|||
bool intersectsWith(const Interval<Number>& rhs) const; |
|||
|
|||
Interval<Number> intersect(const Interval<Number>& rhs) const; |
|||
bool unite(const Interval<Number>& rhs, Interval<Number>& resultA, Interval<Number>& resultB) const; |
|||
bool difference(const Interval<Number>& rhs, Interval<Number>& resultA, Interval<Number>& resultB) const; |
|||
bool complement(Interval<Number>& resultA, Interval<Number>& resultB) const; |
|||
bool symmetricDifference(const Interval<Number>& rhs, Interval<Number>& resultA, Interval<Number>& resultB) const; |
|||
|
|||
|
|||
|
|||
|
|||
std::string toString() const; |
|||
|
|||
%extend { |
|||
/* |
|||
static Interval<Number> pow(const Interval<Number>& _in, unsigned _exponent) |
|||
{ |
|||
return carl::pow(_in,_exponent); |
|||
} */ |
|||
|
|||
static Interval<Number> floor(const Interval<Number>& _in) { |
|||
return carl::floor(_in); |
|||
} |
|||
|
|||
static Interval<Number> ceil(const Interval<Number>& _in) { |
|||
return carl::ceil(_in); |
|||
} |
|||
|
|||
/* |
|||
static Interval<Number> abs(const Interval<Number>& _in) { |
|||
return carl::abs(_in); |
|||
} |
|||
|
|||
static Interval<Number> div(const Interval<Number>& _lhs, const Interval<Number>& _rhs) { |
|||
return carl::div(_lhs,_rhs); |
|||
} */ |
|||
|
|||
static Interval<Number> quotient(const Interval<Number>& _lhs, const Interval<Number>& _rhs) { |
|||
return carl::div(_lhs,_rhs); |
|||
} |
|||
|
|||
static bool isInteger(const Interval<Number>&) { |
|||
return false; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
Interval<Number> add(const Interval<Number>& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Interval<Number> add(const Rational& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Interval<Number> neg() { |
|||
return -*$self; |
|||
} |
|||
|
|||
Interval<Number> sub(const Interval<Number>& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Interval<Number> sub(const Rational& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Interval<Number> mul(const Interval<Number>& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
Interval<Number> mul(const Rational& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
Interval<Number> div(const Rational& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
|
|||
//The +=, -=, *= are missing now |
|||
|
|||
|
|||
|
|||
bool equals(const Interval<Number> rhs) { |
|||
return *$self==rhs; |
|||
} |
|||
|
|||
bool notEquals(const Interval<Number> rhs) { |
|||
return *$self!=rhs; |
|||
} |
|||
|
|||
bool lessEquals(const Interval<Number> rhs) { |
|||
return *$self<=rhs; |
|||
} |
|||
|
|||
bool lessEquals(const Rational rhs) { |
|||
return *$self<=rhs; |
|||
} |
|||
|
|||
bool greaterEquals(const Interval<Number> rhs) { |
|||
return *$self>=rhs; |
|||
} |
|||
|
|||
bool greaterEquals(const Rational rhs) { |
|||
return *$self>=rhs; |
|||
} |
|||
|
|||
|
|||
bool less(const Interval<Number> rhs) { |
|||
return *$self<rhs; |
|||
} |
|||
|
|||
bool less(const Rational rhs) { |
|||
return *$self<rhs; |
|||
} |
|||
|
|||
bool greater(const Interval<Number> rhs) { |
|||
return *$self>rhs; |
|||
} |
|||
|
|||
bool greater(const Rational rhs) { |
|||
return *$self>rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
}; |
|||
|
|||
} |
|||
%template(IntervalRational) carl::Interval<Rational>; |
|||
|
@ -0,0 +1,244 @@ |
|||
|
|||
|
|||
|
|||
|
|||
%module IntervalRationalT |
|||
%{ |
|||
#include <carl/interval/Interval.h> |
|||
|
|||
typedef mpq_class Rational; |
|||
typedef unsigned int uint; |
|||
%} |
|||
|
|||
%import "rational.i" |
|||
|
|||
typedef unsigned int uint; |
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
|
|||
//%include "enums.swg" |
|||
//%javaconst(1); |
|||
|
|||
|
|||
enum class BoundType { |
|||
/// the given bound is compared by a strict ordering relation |
|||
STRICT=0, |
|||
/// the given bound is compared by a weak ordering relation |
|||
WEAK=1, |
|||
/// the given bound is interpreted as minus or plus infinity depending on whether it is the left or the right bound |
|||
INFTY=2 |
|||
}; |
|||
|
|||
|
|||
|
|||
template<typename Number> |
|||
class Interval |
|||
{ |
|||
public: |
|||
|
|||
Interval(const Number& n) : |
|||
mContent(n), |
|||
mLowerBoundType(BoundType::WEAK), |
|||
mUpperBoundType(BoundType::WEAK) { } |
|||
|
|||
Interval(const Number& lower, const Number& upper) |
|||
{ |
|||
|
|||
} |
|||
|
|||
Interval(const Number& lower, BoundType lowerBoundType, const Number& upper, BoundType upperBoundType) |
|||
{ |
|||
} |
|||
|
|||
|
|||
//BEWARE: in python sth with return value policy had to be changed here, so maybe problems will arise |
|||
|
|||
inline const Number& lower() const; |
|||
|
|||
inline const Number& upper() const; |
|||
|
|||
inline void setLower(const Number& n); |
|||
|
|||
inline void setUpper(const Number& n); |
|||
|
|||
inline bool isInfinite() const; |
|||
|
|||
inline bool isUnbounded() const; |
|||
|
|||
inline bool isHalfBounded() const; |
|||
|
|||
inline bool isEmpty() const; |
|||
|
|||
inline bool isPointInterval() const; |
|||
|
|||
inline bool isOpenInterval() const; |
|||
|
|||
inline bool isClosedInterval() const; |
|||
|
|||
inline bool isZero() const; |
|||
|
|||
inline bool isOne() const; |
|||
|
|||
inline bool isPositive() const; |
|||
|
|||
inline bool isNegative() const; |
|||
|
|||
inline bool isSemiPositive() const; |
|||
|
|||
inline bool isSemiNegative() const; |
|||
|
|||
Interval<Number> integralPart() const; |
|||
Number diameter() const; |
|||
//NOTE: this is now set for Number not being a float... needs to be changed in Interval.h otherwise |
|||
Number center() const; |
|||
Number sample(bool _includingBounds = true) const; |
|||
bool contains(const Number& val) const; |
|||
bool contains(const Interval<Number>& rhs) const; |
|||
bool meets(const Number& val) const; |
|||
bool isSubset(const Interval<Number>& rhs) const; |
|||
bool isProperSubset(const Interval<Number>& rhs) const; |
|||
|
|||
Interval<Number> div(const Interval<Number>& rhs) const; |
|||
Interval<Number> inverse() const; |
|||
Interval<Number> abs() const; |
|||
Interval<Number> pow(uint exp) const; |
|||
bool intersectsWith(const Interval<Number>& rhs) const; |
|||
|
|||
Interval<Number> intersect(const Interval<Number>& rhs) const; |
|||
bool unite(const Interval<Number>& rhs, Interval<Number>& resultA, Interval<Number>& resultB) const; |
|||
bool difference(const Interval<Number>& rhs, Interval<Number>& resultA, Interval<Number>& resultB) const; |
|||
bool complement(Interval<Number>& resultA, Interval<Number>& resultB) const; |
|||
bool symmetricDifference(const Interval<Number>& rhs, Interval<Number>& resultA, Interval<Number>& resultB) const; |
|||
|
|||
|
|||
|
|||
|
|||
std::string toString() const; |
|||
|
|||
%extend { |
|||
/* |
|||
static Interval<Number> pow(const Interval<Number>& _in, unsigned _exponent) |
|||
{ |
|||
return carl::pow(_in,_exponent); |
|||
} */ |
|||
|
|||
static Interval<Number> floor(const Interval<Number>& _in) { |
|||
return carl::floor(_in); |
|||
} |
|||
|
|||
static Interval<Number> ceil(const Interval<Number>& _in) { |
|||
return carl::ceil(_in); |
|||
} |
|||
|
|||
/* |
|||
static Interval<Number> abs(const Interval<Number>& _in) { |
|||
return carl::abs(_in); |
|||
} |
|||
|
|||
static Interval<Number> div(const Interval<Number>& _lhs, const Interval<Number>& _rhs) { |
|||
return carl::div(_lhs,_rhs); |
|||
} */ |
|||
|
|||
static Interval<Number> quotient(const Interval<Number>& _lhs, const Interval<Number>& _rhs) { |
|||
return carl::div(_lhs,_rhs); |
|||
} |
|||
|
|||
static bool isInteger(const Interval<Number>&) { |
|||
return false; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
Interval<Number> add(const Interval<Number>& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Interval<Number> add(const Rational& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Interval<Number> neg() { |
|||
return -*$self; |
|||
} |
|||
|
|||
Interval<Number> sub(const Interval<Number>& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Interval<Number> sub(const Rational& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Interval<Number> mul(const Interval<Number>& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
Interval<Number> mul(const Rational& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
Interval<Number> div(const Rational& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
|
|||
//The +=, -=, *= are missing now |
|||
|
|||
|
|||
|
|||
bool equals(const Interval<Number> rhs) { |
|||
return *$self==rhs; |
|||
} |
|||
|
|||
bool notEquals(const Interval<Number> rhs) { |
|||
return *$self!=rhs; |
|||
} |
|||
|
|||
bool lessEquals(const Interval<Number> rhs) { |
|||
return *$self<=rhs; |
|||
} |
|||
|
|||
bool lessEquals(const Rational rhs) { |
|||
return *$self<=rhs; |
|||
} |
|||
|
|||
bool greaterEquals(const Interval<Number> rhs) { |
|||
return *$self>=rhs; |
|||
} |
|||
|
|||
bool greaterEquals(const Rational rhs) { |
|||
return *$self>=rhs; |
|||
} |
|||
|
|||
|
|||
bool less(const Interval<Number> rhs) { |
|||
return *$self<rhs; |
|||
} |
|||
|
|||
bool less(const Rational rhs) { |
|||
return *$self<rhs; |
|||
} |
|||
|
|||
bool greater(const Interval<Number> rhs) { |
|||
return *$self>rhs; |
|||
} |
|||
|
|||
bool greater(const Rational rhs) { |
|||
return *$self>rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
}; |
|||
|
|||
} |
|||
%template(IntervalRational) carl::Interval<Rational>; |
|||
|
@ -0,0 +1,263 @@ |
|||
|
|||
|
|||
|
|||
%module MonomialT |
|||
%{ |
|||
#include <carl/core/Monomial.h> |
|||
#include <carl/core/Term.h> |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
#include "gmp.h" |
|||
#include "gmpxx.h" |
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef unsigned int uint; |
|||
typedef std::pair<carl::Variable,uint> VarIntPair; |
|||
|
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
|
|||
%} |
|||
|
|||
%include "std_string.i" |
|||
//TODO: for 32 bit support this has to be changed.. |
|||
//%import <stddef> //for size_t maybe? |
|||
typedef long unsigned int size_t; //this should be okay for 64 bits at least |
|||
|
|||
typedef unsigned int uint; |
|||
|
|||
|
|||
%include "std_pair.i" |
|||
%include "std_vector.i" |
|||
|
|||
|
|||
|
|||
%import "variable.i" |
|||
%import "term.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
|
|||
|
|||
|
|||
|
|||
%include "std_shared_ptr.i" |
|||
%shared_ptr(carl::Monomial); |
|||
|
|||
typedef std::pair<carl::Variable,uint> VarIntPair; |
|||
namespace std { |
|||
%template(VarIntPair) pair<carl::Variable,uint>; |
|||
%template(VarIntPairVector) vector<VarIntPair>; |
|||
} |
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
%nodefaultctor carl::Monomial; |
|||
namespace carl { |
|||
|
|||
typedef unsigned int exponent; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
class Monomial { |
|||
public: |
|||
typedef std::shared_ptr<const carl::Monomial> Arg; |
|||
typedef std::vector<VarIntPair> Content; |
|||
|
|||
/* |
|||
explicit Monomial(Variable::Arg v, carl::exponent e = 1) : |
|||
mExponents(1, std::make_pair(v,e)), |
|||
mTotalDegree(e) |
|||
{ |
|||
} |
|||
*/ |
|||
|
|||
carl::exponent tdeg() const; |
|||
|
|||
const carl::Monomial::Content& exponents() const; |
|||
|
|||
|
|||
std::string toString(bool infix = true, bool friendlyVarNames = true) const; |
|||
|
|||
size_t nrVariables() const; |
|||
|
|||
|
|||
|
|||
%extend { |
|||
|
|||
|
|||
static carl::Monomial::Arg createMonomial(Variable::Arg v, carl::exponent e = 1) { |
|||
return carl::MonomialPool::getInstance().create(v, e); |
|||
} |
|||
|
|||
Polynomial add(const Polynomial& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Term& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Monomial::Arg& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return carl::operator+<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(ptr,rhs); |
|||
} |
|||
|
|||
Polynomial add(carl::Variable::Arg rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return carl::operator+<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(ptr,rhs); |
|||
} |
|||
|
|||
Polynomial add(const Rational& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr+rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
Polynomial sub(const Polynomial& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Term& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Monomial::Arg& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return carl::operator-<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(ptr,rhs); |
|||
} |
|||
|
|||
Polynomial sub(carl::Variable::Arg rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return carl::operator-<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(ptr,rhs); |
|||
} |
|||
|
|||
Polynomial sub(const Rational& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr-rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
Polynomial mul(const Polynomial& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return rhs*ptr; |
|||
} |
|||
|
|||
Term mul(const Term& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr*rhs; |
|||
} |
|||
|
|||
Polynomial mul(const Monomial::Arg& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
//const std::shared_ptr<const carl::Monomial> ptr2(rhs); |
|||
return carl::operator*(ptr,Polynomial(rhs)); |
|||
} |
|||
|
|||
Polynomial mul(carl::Variable::Arg rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return carl::operator*(ptr,Polynomial(rhs)); |
|||
} |
|||
|
|||
Term mul(const Rational& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr*rhs; |
|||
} |
|||
|
|||
|
|||
RationalFunction div(const RationalFunction& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return RationalFunction(Polynomial(ptr)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Polynomial& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return RationalFunction(Polynomial(ptr)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Term& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return RationalFunction(Polynomial(ptr)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Monomial::Arg& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return RationalFunction(Polynomial(ptr)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(carl::Variable::Arg rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return RationalFunction(Polynomial(ptr)) / rhs; |
|||
} |
|||
|
|||
Term div(const Rational& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return Term(ptr) / rhs; |
|||
} |
|||
|
|||
Term neg() { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr*Rational(-1); |
|||
} |
|||
|
|||
carl::Monomial::Arg pow(uint exp) { |
|||
return $self->pow(exp); |
|||
} |
|||
|
|||
|
|||
|
|||
VarIntPair getItem(std::size_t index) { |
|||
return *($self->begin()+index); |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
}; |
|||
|
|||
} |
@ -0,0 +1,263 @@ |
|||
|
|||
|
|||
|
|||
%module MonomialT |
|||
%{ |
|||
#include <carl/core/Monomial.h> |
|||
#include <carl/core/Term.h> |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
#include "gmp.h" |
|||
#include "gmpxx.h" |
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef unsigned int uint; |
|||
typedef std::pair<carl::Variable,uint> VarIntPair; |
|||
|
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
|
|||
%} |
|||
|
|||
%include "std_string.i" |
|||
//TODO: for 32 bit support this has to be changed.. |
|||
//%import <stddef> //for size_t maybe? |
|||
typedef long unsigned int size_t; //this should be okay for 64 bits at least |
|||
|
|||
typedef unsigned int uint; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
%import "variable.i" |
|||
%import "term.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
|
|||
|
|||
|
|||
|
|||
%include "std_shared_ptr.i" |
|||
%shared_ptr(carl::Monomial); |
|||
%include "std_pair.i" |
|||
%include "std_vector.i" |
|||
typedef std::pair<carl::Variable,uint> VarIntPair; |
|||
namespace std { |
|||
%template(VarIntPair) pair<carl::Variable,uint>; |
|||
%template(VarIntPairVector) vector<VarIntPair>; |
|||
} |
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
%nodefaultctor carl::Monomial; |
|||
namespace carl { |
|||
|
|||
typedef unsigned int exponent; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
class Monomial { |
|||
public: |
|||
typedef std::shared_ptr<const carl::Monomial> Arg; |
|||
typedef std::vector<VarIntPair> Content; |
|||
|
|||
/* |
|||
explicit Monomial(Variable::Arg v, carl::exponent e = 1) : |
|||
mExponents(1, std::make_pair(v,e)), |
|||
mTotalDegree(e) |
|||
{ |
|||
} |
|||
*/ |
|||
|
|||
carl::exponent tdeg() const; |
|||
|
|||
const carl::Monomial::Content& exponents() const; |
|||
|
|||
|
|||
std::string toString(bool infix = true, bool friendlyVarNames = true) const; |
|||
|
|||
size_t nrVariables() const; |
|||
|
|||
|
|||
|
|||
%extend { |
|||
|
|||
|
|||
static carl::Monomial::Arg createMonomial(Variable::Arg v, carl::exponent e = 1) { |
|||
return carl::MonomialPool::getInstance().create(v, e); |
|||
} |
|||
|
|||
Polynomial add(const Polynomial& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Term& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Monomial::Arg& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return carl::operator+<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(ptr,rhs); |
|||
} |
|||
|
|||
Polynomial add(carl::Variable::Arg rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return carl::operator+<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(ptr,rhs); |
|||
} |
|||
|
|||
Polynomial add(const Rational& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr+rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
Polynomial sub(const Polynomial& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Term& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Monomial::Arg& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return carl::operator-<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(ptr,rhs); |
|||
} |
|||
|
|||
Polynomial sub(carl::Variable::Arg rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return carl::operator-<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(ptr,rhs); |
|||
} |
|||
|
|||
Polynomial sub(const Rational& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr-rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
Polynomial mul(const Polynomial& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return rhs*ptr; |
|||
} |
|||
|
|||
Term mul(const Term& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr*rhs; |
|||
} |
|||
|
|||
Polynomial mul(const Monomial::Arg& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
//const std::shared_ptr<const carl::Monomial> ptr2(rhs); |
|||
return carl::operator*(ptr,Polynomial(rhs)); |
|||
} |
|||
|
|||
Polynomial mul(carl::Variable::Arg rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return carl::operator*(ptr,Polynomial(rhs)); |
|||
} |
|||
|
|||
Term mul(const Rational& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr*rhs; |
|||
} |
|||
|
|||
|
|||
RationalFunction div(const RationalFunction& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return RationalFunction(Polynomial(ptr)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Polynomial& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return RationalFunction(Polynomial(ptr)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Term& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return RationalFunction(Polynomial(ptr)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Monomial::Arg& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return RationalFunction(Polynomial(ptr)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(carl::Variable::Arg rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return RationalFunction(Polynomial(ptr)) / rhs; |
|||
} |
|||
|
|||
Term div(const Rational& rhs) { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return Term(ptr) / rhs; |
|||
} |
|||
|
|||
Term neg() { |
|||
carl::Monomial::Content exp($self->exponents()); |
|||
const std::shared_ptr<const carl::Monomial> ptr = std::make_shared<const carl::Monomial>(std::move(exp)); |
|||
return ptr*Rational(-1); |
|||
} |
|||
|
|||
carl::Monomial::Arg pow(uint exp) { |
|||
return $self->pow(exp); |
|||
} |
|||
|
|||
|
|||
|
|||
VarIntPair getItem(std::size_t index) { |
|||
return *($self->begin()+index); |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
}; |
|||
|
|||
} |
@ -0,0 +1,207 @@ |
|||
|
|||
|
|||
%module PolynomialT |
|||
%{ |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
#include "gmp.h" |
|||
#include "gmpxx.h" |
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
|
|||
typedef unsigned int uint; |
|||
typedef std::pair<carl::Variable,uint> VarIntPair; |
|||
%} |
|||
|
|||
|
|||
%include "std_string.i" |
|||
%include "std_vector.i" |
|||
|
|||
namespace std { |
|||
%template(VarVector) vector<carl::Variable>; |
|||
} |
|||
|
|||
//TODO: for 32 bit support this has to be changed.. |
|||
//%import <stddef> //for size_t maybe? |
|||
typedef long unsigned int size_t; //this should be okay for 64 bits at least |
|||
|
|||
%import "rational.i" |
|||
%import "variable.i" |
|||
%import "term.i" |
|||
%import "monomial.i" |
|||
%import "rationalfunction.i" |
|||
|
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
template<typename Coeff> |
|||
class MultivariatePolynomial |
|||
{ |
|||
public: |
|||
typedef Coeff CoeffType; |
|||
typedef Coeff NumberType; //ATTENTION: This is only correct if polynomials are never instantiated with a type that's not a number |
|||
explicit MultivariatePolynomial(const carl::Term<Coeff>& t); |
|||
explicit MultivariatePolynomial(const std::shared_ptr<const carl::Monomial>& m); |
|||
explicit MultivariatePolynomial(Variable::Arg v); |
|||
explicit MultivariatePolynomial(const Coeff& c); |
|||
const Coeff& constantPart() const; |
|||
template<typename SubstitutionType = Coeff> |
|||
SubstitutionType evaluate(const std::map<Variable, SubstitutionType>& substitutions) const; |
|||
std::size_t totalDegree() const; |
|||
std::size_t degree(Variable::Arg var) const; |
|||
size_t nrTerms() const; |
|||
std::string toString(bool infix=true, bool friendlyVarNames=true) const; |
|||
|
|||
size_t size() const; |
|||
|
|||
%extend{ |
|||
bool equals(const MultivariatePolynomial<Coeff>& other) { |
|||
return *$self == other; |
|||
} |
|||
|
|||
bool notEquals(const MultivariatePolynomial<Coeff>& other) { |
|||
return *$self != other; |
|||
} |
|||
|
|||
std::vector<carl::Variable> gatherVariables() const { |
|||
std::set<carl::Variable> asSet = $self->gatherVariables(); |
|||
return std::vector<carl::Variable>(asSet.begin(),asSet.end()); |
|||
} |
|||
|
|||
|
|||
Polynomial add(const Polynomial& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Term& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Monomial::Arg& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial add(carl::Variable::Arg rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Rational& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
Polynomial sub(const Polynomial& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Term& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Monomial::Arg& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial sub(carl::Variable::Arg rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Rational& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial mul(const Polynomial& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
Polynomial mul(const Term& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
Polynomial mul(const Monomial::Arg& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial mul(carl::Variable::Arg rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
Polynomial mul(const Rational& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
RationalFunction div(const RationalFunction& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Polynomial& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Term& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Monomial::Arg& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
|
|||
RationalFunction div(carl::Variable::Arg rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
Polynomial div(const Rational& rhs) { |
|||
return *$self / rhs; |
|||
} |
|||
|
|||
Polynomial pow(uint exp) { |
|||
return $self->pow(exp); |
|||
} |
|||
|
|||
Polynomial neg() { |
|||
return *$self*Rational(-1); |
|||
} |
|||
|
|||
|
|||
Term getItem(std::size_t index) { |
|||
return *($self->begin()+index); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
}; |
|||
} |
|||
|
|||
%include "std_map.i" |
|||
|
|||
namespace std { |
|||
%template(VarRationalMap) map<carl::Variable,Rational>; |
|||
} |
|||
|
|||
|
|||
%template(evaluate) carl::MultivariatePolynomial::evaluate<Rational>; |
|||
%template(Polynomial) carl::MultivariatePolynomial<Rational>; |
|||
|
@ -0,0 +1,207 @@ |
|||
|
|||
|
|||
%module PolynomialT |
|||
%{ |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
#include "gmp.h" |
|||
#include "gmpxx.h" |
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
|
|||
typedef unsigned int uint; |
|||
typedef std::pair<carl::Variable,uint> VarIntPair; |
|||
%} |
|||
|
|||
|
|||
%include "std_string.i" |
|||
|
|||
|
|||
|
|||
|
|||
//TODO: for 32 bit support this has to be changed.. |
|||
//%import <stddef> //for size_t maybe? |
|||
typedef long unsigned int size_t; //this should be okay for 64 bits at least |
|||
|
|||
%import "rational.i" |
|||
%import "variable.i" |
|||
%import "term.i" |
|||
%import "monomial.i" |
|||
%import "rationalfunction.i" |
|||
|
|||
|
|||
%include "std_vector.i" |
|||
typedef mpq_class Rational; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
namespace std { |
|||
%template(VarVector) vector<carl::Variable>; |
|||
} |
|||
|
|||
namespace carl { |
|||
|
|||
template<typename Coeff> |
|||
class MultivariatePolynomial |
|||
{ |
|||
public: |
|||
typedef Coeff CoeffType; |
|||
typedef Coeff NumberType; //ATTENTION: This is only correct if polynomials are never instantiated with a type that's not a number |
|||
explicit MultivariatePolynomial(const carl::Term<Coeff>& t); |
|||
explicit MultivariatePolynomial(const std::shared_ptr<const carl::Monomial>& m); |
|||
explicit MultivariatePolynomial(Variable::Arg v); |
|||
explicit MultivariatePolynomial(const Coeff& c); |
|||
const Coeff& constantPart() const; |
|||
template<typename SubstitutionType = Coeff> |
|||
SubstitutionType evaluate(const std::map<Variable, SubstitutionType>& substitutions) const; |
|||
std::size_t totalDegree() const; |
|||
std::size_t degree(Variable::Arg var) const; |
|||
size_t nrTerms() const; |
|||
std::string toString(bool infix=true, bool friendlyVarNames=true) const; |
|||
|
|||
size_t size() const; |
|||
|
|||
%extend{ |
|||
bool equals(const MultivariatePolynomial<Coeff>& other) { |
|||
return *$self == other; |
|||
} |
|||
|
|||
bool notEquals(const MultivariatePolynomial<Coeff>& other) { |
|||
return *$self != other; |
|||
} |
|||
|
|||
std::vector<carl::Variable> gatherVariables() const { |
|||
std::set<carl::Variable> asSet = $self->gatherVariables(); |
|||
return std::vector<carl::Variable>(asSet.begin(),asSet.end()); |
|||
} |
|||
|
|||
|
|||
Polynomial add(const Polynomial& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Term& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Monomial::Arg& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial add(carl::Variable::Arg rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Rational& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
Polynomial sub(const Polynomial& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Term& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Monomial::Arg& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial sub(carl::Variable::Arg rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Rational& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial mul(const Polynomial& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
Polynomial mul(const Term& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
Polynomial mul(const Monomial::Arg& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial mul(carl::Variable::Arg rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
Polynomial mul(const Rational& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
RationalFunction div(const RationalFunction& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Polynomial& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Term& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Monomial::Arg& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
|
|||
RationalFunction div(carl::Variable::Arg rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
Polynomial div(const Rational& rhs) { |
|||
return *$self / rhs; |
|||
} |
|||
|
|||
Polynomial pow(uint exp) { |
|||
return $self->pow(exp); |
|||
} |
|||
|
|||
Polynomial neg() { |
|||
return *$self*Rational(-1); |
|||
} |
|||
|
|||
|
|||
Term getItem(std::size_t index) { |
|||
return *($self->begin()+index); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
}; |
|||
} |
|||
|
|||
%include "std_map.i" |
|||
|
|||
namespace std { |
|||
%template(VarRationalMap) map<carl::Variable,Rational>; |
|||
} |
|||
|
|||
|
|||
%template(evaluate) carl::MultivariatePolynomial::evaluate<Rational>; |
|||
%template(Polynomial) carl::MultivariatePolynomial<Rational>; |
|||
|
@ -0,0 +1,238 @@ |
|||
|
|||
|
|||
%module RationalT |
|||
%{ |
|||
#include <carl/core/Monomial.h> |
|||
#include <carl/core/Term.h> |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
#include <carl/numbers/numbers.h> |
|||
#include "gmp.h" |
|||
#include "gmpxx.h" |
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
%} |
|||
|
|||
|
|||
|
|||
|
|||
%include "std_string.i" |
|||
%import "monomial.i" |
|||
%import "variable.i" |
|||
%import "term.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
|
|||
|
|||
namespace carl { |
|||
typedef long sint; |
|||
} |
|||
|
|||
|
|||
%rename(Rational) mpq_class; |
|||
|
|||
class mpq_class { |
|||
//NOTE: maybe change this to getDouble or whatever.. |
|||
%rename(toDouble) get_d; |
|||
public: |
|||
mpq_class(signed int i) { mpq_init(mp); mpq_set_si(mp, i, 1); } |
|||
mpq_class(double d) { mpq_init(mp); mpq_set_d(mp, d); } |
|||
explicit mpq_class(const std::string &s, int base = 0) |
|||
{ |
|||
mpq_init(mp); |
|||
if (mpq_set_str (mp, s.c_str(), base) != 0) |
|||
{ |
|||
mpq_clear (mp); |
|||
throw std::invalid_argument ("mpq_set_str"); |
|||
} |
|||
} |
|||
|
|||
double get_d() const; |
|||
|
|||
%extend{ |
|||
std::string toString() { |
|||
return carl::toString(*$self,true); |
|||
} |
|||
|
|||
|
|||
|
|||
int nominator() { |
|||
return carl::toInt<carl::sint>(carl::getNum(*$self)); |
|||
} |
|||
|
|||
int numerator() { |
|||
return carl::toInt<carl::sint>(carl::getNum(*$self)); |
|||
} |
|||
|
|||
int denominator() { |
|||
return carl::toInt<carl::sint>(carl::getDenom(*$self)); |
|||
} |
|||
|
|||
|
|||
carl::sint toInt() { |
|||
double d = carl::toDouble(*$self); |
|||
return static_cast<carl::sint>(d); |
|||
} |
|||
|
|||
|
|||
|
|||
Polynomial add(const Polynomial & rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Term& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Polynomial add(const carl::Monomial::Arg& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial add(carl::Variable::Arg rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
|
|||
Rational add(const Rational& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
Polynomial sub(const Polynomial & rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Term& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const carl::Monomial::Arg& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial sub(carl::Variable::Arg rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
|
|||
Rational sub(const Rational& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial mul(const Polynomial & rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
Term mul(const Term& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
Term mul(const carl::Monomial::Arg& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
Term mul(carl::Variable::Arg rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
Rational mul(const Rational& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
RationalFunction div(const RationalFunction& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Polynomial& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Term& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const carl::Monomial::Arg& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
|
|||
RationalFunction div(carl::Variable::Arg rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
|
|||
Rational div(const Rational& rhs) { |
|||
if (carl::isZero(rhs)) throw std::runtime_error("Div by zero"); |
|||
return *$self / rhs; |
|||
} |
|||
|
|||
Rational pow(std::size_t exp) { |
|||
return pow($self->get_d(),exp); |
|||
} |
|||
|
|||
Rational neg() { |
|||
return -(*$self); |
|||
} |
|||
|
|||
Rational abs() { |
|||
return abs(*$self); |
|||
} |
|||
|
|||
bool equals(const Rational& rhs) { |
|||
return *$self==rhs; |
|||
} |
|||
|
|||
bool notEquals(const Rational& rhs) { |
|||
return *$self!=rhs; |
|||
} |
|||
|
|||
|
|||
bool lessEquals(const Rational& rhs) { |
|||
return *$self<=rhs; |
|||
} |
|||
|
|||
bool greaterEquals(const Rational& rhs) { |
|||
return *$self>=rhs; |
|||
} |
|||
|
|||
|
|||
bool less(const Rational& rhs) { |
|||
return *$self<rhs; |
|||
} |
|||
|
|||
bool greater(const Rational& rhs) { |
|||
return *$self>rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
}; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
/* |
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; */ |
@ -0,0 +1,238 @@ |
|||
|
|||
|
|||
%module Rational |
|||
%{ |
|||
#include <carl/core/Monomial.h> |
|||
#include <carl/core/Term.h> |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
#include <carl/numbers/numbers.h> |
|||
#include "gmp.h" |
|||
#include "gmpxx.h" |
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
%} |
|||
|
|||
|
|||
|
|||
|
|||
%include "std_string.i" |
|||
%import "monomial.i" |
|||
%import "variable.i" |
|||
%import "term.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
|
|||
|
|||
namespace carl { |
|||
typedef long sint; |
|||
} |
|||
|
|||
|
|||
%rename(Rational) mpq_class; |
|||
|
|||
class mpq_class { |
|||
//NOTE: maybe change this to getDouble or whatever.. |
|||
%rename(toDouble) get_d; |
|||
public: |
|||
mpq_class(signed int i) { mpq_init(mp); mpq_set_si(mp, i, 1); } |
|||
mpq_class(double d) { mpq_init(mp); mpq_set_d(mp, d); } |
|||
explicit mpq_class(const std::string &s, int base = 0) |
|||
{ |
|||
mpq_init(mp); |
|||
if (mpq_set_str (mp, s.c_str(), base) != 0) |
|||
{ |
|||
mpq_clear (mp); |
|||
throw std::invalid_argument ("mpq_set_str"); |
|||
} |
|||
} |
|||
|
|||
double get_d() const; |
|||
|
|||
%extend{ |
|||
std::string toString() { |
|||
return carl::toString(*$self,true); |
|||
} |
|||
|
|||
|
|||
|
|||
int nominator() { |
|||
return carl::toInt<carl::sint>(carl::getNum(*$self)); |
|||
} |
|||
|
|||
int numerator() { |
|||
return carl::toInt<carl::sint>(carl::getNum(*$self)); |
|||
} |
|||
|
|||
int denominator() { |
|||
return carl::toInt<carl::sint>(carl::getDenom(*$self)); |
|||
} |
|||
|
|||
|
|||
carl::sint toInt() { |
|||
double d = carl::toDouble(*$self); |
|||
return static_cast<carl::sint>(d); |
|||
} |
|||
|
|||
|
|||
|
|||
Polynomial add(const Polynomial & rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Term& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
Polynomial add(const carl::Monomial::Arg& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial add(carl::Variable::Arg rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
|
|||
Rational add(const Rational& rhs) { |
|||
return *$self+rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
Polynomial sub(const Polynomial & rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Term& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const carl::Monomial::Arg& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial sub(carl::Variable::Arg rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
|
|||
Rational sub(const Rational& rhs) { |
|||
return *$self-rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial mul(const Polynomial & rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
Term mul(const Term& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
Term mul(const carl::Monomial::Arg& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
Term mul(carl::Variable::Arg rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
Rational mul(const Rational& rhs) { |
|||
return *$self*rhs; |
|||
} |
|||
|
|||
|
|||
RationalFunction div(const RationalFunction& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Polynomial& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Term& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const carl::Monomial::Arg& rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
|
|||
RationalFunction div(carl::Variable::Arg rhs) { |
|||
return RationalFunction(*$self) / rhs; |
|||
} |
|||
|
|||
|
|||
Rational div(const Rational& rhs) { |
|||
if (carl::isZero(rhs)) throw std::runtime_error("Div by zero"); |
|||
return *$self / rhs; |
|||
} |
|||
|
|||
Rational pow(std::size_t exp) { |
|||
return pow($self->get_d(),exp); |
|||
} |
|||
|
|||
Rational neg() { |
|||
return -(*$self); |
|||
} |
|||
|
|||
Rational abs() { |
|||
return abs(*$self); |
|||
} |
|||
|
|||
bool equals(const Rational& rhs) { |
|||
return *$self==rhs; |
|||
} |
|||
|
|||
bool notEquals(const Rational& rhs) { |
|||
return *$self!=rhs; |
|||
} |
|||
|
|||
|
|||
bool lessEquals(const Rational& rhs) { |
|||
return *$self<=rhs; |
|||
} |
|||
|
|||
bool greaterEquals(const Rational& rhs) { |
|||
return *$self>=rhs; |
|||
} |
|||
|
|||
|
|||
bool less(const Rational& rhs) { |
|||
return *$self<rhs; |
|||
} |
|||
|
|||
bool greater(const Rational& rhs) { |
|||
return *$self>rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
}; |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
/* |
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; */ |
@ -0,0 +1,248 @@ |
|||
|
|||
|
|||
%module ModRationalFunction |
|||
%{ |
|||
#include <carl/core/RationalFunction.h> |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/FactorizedPolynomial.h> |
|||
|
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction; |
|||
|
|||
|
|||
typedef unsigned int uint; |
|||
|
|||
%} |
|||
|
|||
|
|||
|
|||
%include "std_string.i" |
|||
//TODO: for 32 bit support this has to be changed.. |
|||
//%import <stddef> //for size_t maybe? |
|||
typedef long unsigned int size_t; //this should be okay for 64 bits at least |
|||
|
|||
|
|||
%import "rational.i" |
|||
%import "variable.i" |
|||
%import "monomial.i" |
|||
%import "term.i" |
|||
%import "polynomial.i" |
|||
%import "factorizedpolynomial.i" |
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial; |
|||
|
|||
typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction; |
|||
|
|||
|
|||
%rename(RationalFunction) carl::RationalFunction<Polynomial>; |
|||
%rename(FactorizedRationalFunction) carl::RationalFunction<FactorizedPolynomial>; |
|||
namespace carl { |
|||
|
|||
|
|||
|
|||
class RationalFunction<Polynomial> |
|||
{ |
|||
public: |
|||
typedef typename Rational CoeffType; |
|||
explicit RationalFunction(const Polynomial& nom, const Polynomial& denom): |
|||
mPolynomialQuotient(nullptr), |
|||
mNumberQuotient(), |
|||
mIsSimplified(false) |
|||
{ |
|||
} |
|||
|
|||
CoeffType evaluate(const std::map<Variable, CoeffType>& substitutions) const; |
|||
|
|||
inline Polynomial nominator() const; |
|||
|
|||
inline Polynomial denominator() const; |
|||
|
|||
|
|||
%extend { |
|||
std::string toString() { |
|||
std::stringstream ss; |
|||
ss << *$self; |
|||
return ss.str(); |
|||
} |
|||
|
|||
Polynomial numerator() const { |
|||
return $self->nominator(); |
|||
} |
|||
|
|||
std::vector<carl::Variable> gatherVariables() const { |
|||
std::set<carl::Variable> asSet = $self->gatherVariables(); |
|||
return std::vector<carl::Variable>(asSet.begin(),asSet.end()); |
|||
} |
|||
|
|||
|
|||
bool equals(const carl::RationalFunction<Polynomial>& other) { |
|||
return *$self == other; |
|||
} |
|||
bool notEquals(const carl::RationalFunction<Polynomial>& other) { |
|||
return *$self != other; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
carl::RationalFunction<Polynomial> add(const Polynomial& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
|
|||
carl::RationalFunction<Polynomial> add(const Term& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> add(const Monomial::Arg& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> add(carl::Variable::Arg rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> add(Rational rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
|
|||
carl::RationalFunction<Polynomial> sub(const Polynomial& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> sub(const Term& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> sub(const Monomial::Arg& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> sub(carl::Variable::Arg rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> sub(Rational rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
carl::RationalFunction<Polynomial> mul(const Polynomial& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial>mul(const Term& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> mul(const Monomial::Arg& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> mul(carl::Variable::Arg rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> mul(Rational rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> div(const Polynomial& rhs) { |
|||
return *($self)/rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> div(const Term& rhs) { |
|||
return *($self)/rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> div(const Monomial::Arg& rhs) { |
|||
return *($self)/rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> div(carl::Variable::Arg rhs) { |
|||
return *($self)/rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> div(Rational rhs) { |
|||
return *($self)/rhs; |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> div(const RationalFunction& rhs) { |
|||
return *($self)/rhs; |
|||
} |
|||
|
|||
|
|||
carl::RationalFunction<Polynomial> pow(uint exp) { |
|||
return carl::pow(*($self),exp); |
|||
} |
|||
|
|||
carl::RationalFunction<Polynomial> neg() { |
|||
return *$self*Rational(-1); |
|||
} |
|||
} |
|||
|
|||
}; |
|||
|
|||
|
|||
|
|||
class RationalFunction<FactorizedPolynomial> { |
|||
public: |
|||
typedef typename Rational CoeffType; |
|||
explicit RationalFunction(const FactorizedPolynomial& nom, const FactorizedPolynomial& denom): |
|||
mPolynomialQuotient(nullptr), |
|||
mNumberQuotient(), |
|||
mIsSimplified(false) |
|||
{ |
|||
} |
|||
|
|||
CoeffType evaluate(const std::map<Variable, CoeffType>& substitutions) const; |
|||
|
|||
inline FactorizedPolynomial nominator() const; |
|||
|
|||
inline FactorizedPolynomial denominator() const; |
|||
|
|||
|
|||
%extend { |
|||
std::string toString() { |
|||
std::stringstream ss; |
|||
ss << *$self; |
|||
return ss.str(); |
|||
} |
|||
|
|||
FactorizedPolynomial numerator() const { |
|||
return $self->nominator(); |
|||
} |
|||
|
|||
std::vector<carl::Variable> gatherVariables() const { |
|||
std::set<carl::Variable> asSet = $self->gatherVariables(); |
|||
return std::vector<carl::Variable>(asSet.begin(),asSet.end()); |
|||
} |
|||
|
|||
bool equals(const carl::RationalFunction<FactorizedPolynomial>& other) { |
|||
return *$self == other; |
|||
} |
|||
|
|||
} |
|||
}; |
|||
|
|||
} |
|||
|
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
|
|||
/* |
|||
%template(RationalFunctionPoly) carl::RationalFunction<Polynomial>; |
|||
%template(FactorizedRationalFunction) carl::RationalFunction<carl::FactorizedPolynomial<Polynomial>,false>; */ |
|||
|
@ -0,0 +1,155 @@ |
|||
|
|||
%module TermRationalT |
|||
%{ |
|||
#include <carl/core/Term.h> |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
#include "gmp.h" |
|||
#include "gmpxx.h" |
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
%} |
|||
|
|||
|
|||
%include "std_string.i" |
|||
%import "monomial.i" |
|||
%import "rational.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
typedef mpq_class Rational; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
|
|||
template<typename Coefficient> |
|||
class Term { |
|||
public: |
|||
Term(const Coefficient& c, const carl::Monomial::Arg& m); |
|||
|
|||
Coefficient& coeff(); |
|||
|
|||
inline const Monomial::Arg& monomial() const; |
|||
//template<typename C = Coefficient, DisableIf<is_interval<C>> = dummy> |
|||
//std::string toString(bool infix=true, bool friendlyVarNames=true) const; |
|||
|
|||
carl::Term<Coefficient> pow(uint exp) const; |
|||
|
|||
|
|||
%extend { |
|||
|
|||
std::string toString() const { |
|||
return $self->toString(); |
|||
} |
|||
|
|||
Polynomial add(const carl::Term<Coefficient>& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Polynomial& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Monomial::Arg& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
Polynomial add(carl::Variable::Arg rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Coefficient& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial sub(const carl::Term<Coefficient>& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Polynomial& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Monomial::Arg& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
Polynomial sub(carl::Variable::Arg rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Coefficient& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
|
|||
carl::Term<Coefficient> mul(const carl::Term<Coefficient>& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
Polynomial mul(const Polynomial& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
carl::Term<Coefficient> mul(const Monomial::Arg& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
carl::Term<Coefficient> mul(carl::Variable::Arg rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
carl::Term<Coefficient> mul(const Coefficient& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
|
|||
RationalFunction div(const RationalFunction& rhs) { |
|||
return RationalFunction(Polynomial(*($self))) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Polynomial& rhs) { |
|||
return RationalFunction(Polynomial(*($self))) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const carl::Term<Coefficient>& rhs) { |
|||
return RationalFunction(Polynomial(*($self))) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Monomial::Arg& rhs) { |
|||
return RationalFunction(Polynomial(*($self))) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(carl::Variable::Arg rhs) { |
|||
return RationalFunction(Polynomial(*($self))) / rhs; |
|||
} |
|||
|
|||
carl::Term<Coefficient> div(const Rational& rhs) { |
|||
return *$self / rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
carl::Term<Coefficient> neg() { |
|||
return *$self*Coefficient(-1); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
}; |
|||
} |
|||
|
|||
|
|||
%template(TermRational) carl::Term<Rational>; |
@ -0,0 +1,155 @@ |
|||
|
|||
%module TermRational |
|||
%{ |
|||
#include <carl/core/Term.h> |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
#include "gmp.h" |
|||
#include "gmpxx.h" |
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
%} |
|||
|
|||
|
|||
%include "std_string.i" |
|||
%import "monomial.i" |
|||
%import "rational.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
typedef mpq_class Rational; |
|||
typedef carl::Term<Rational> Term; |
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
|
|||
template<typename Coefficient> |
|||
class Term { |
|||
public: |
|||
Term(const Coefficient& c, const carl::Monomial::Arg& m); |
|||
|
|||
Coefficient& coeff(); |
|||
|
|||
inline const Monomial::Arg& monomial() const; |
|||
//template<typename C = Coefficient, DisableIf<is_interval<C>> = dummy> |
|||
//std::string toString(bool infix=true, bool friendlyVarNames=true) const; |
|||
|
|||
carl::Term<Coefficient> pow(uint exp) const; |
|||
|
|||
|
|||
%extend { |
|||
|
|||
std::string toString() const { |
|||
return $self->toString(); |
|||
} |
|||
|
|||
Polynomial add(const carl::Term<Coefficient>& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Polynomial& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Monomial::Arg& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
Polynomial add(carl::Variable::Arg rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Coefficient& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial sub(const carl::Term<Coefficient>& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Polynomial& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Monomial::Arg& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
Polynomial sub(carl::Variable::Arg rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Coefficient& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
|
|||
carl::Term<Coefficient> mul(const carl::Term<Coefficient>& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
Polynomial mul(const Polynomial& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
carl::Term<Coefficient> mul(const Monomial::Arg& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
carl::Term<Coefficient> mul(carl::Variable::Arg rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
carl::Term<Coefficient> mul(const Coefficient& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
|
|||
RationalFunction div(const RationalFunction& rhs) { |
|||
return RationalFunction(Polynomial(*($self))) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Polynomial& rhs) { |
|||
return RationalFunction(Polynomial(*($self))) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const carl::Term<Coefficient>& rhs) { |
|||
return RationalFunction(Polynomial(*($self))) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Monomial::Arg& rhs) { |
|||
return RationalFunction(Polynomial(*($self))) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(carl::Variable::Arg rhs) { |
|||
return RationalFunction(Polynomial(*($self))) / rhs; |
|||
} |
|||
|
|||
carl::Term<Coefficient> div(const Rational& rhs) { |
|||
return *$self / rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
carl::Term<Coefficient> neg() { |
|||
return *$self*Coefficient(-1); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
}; |
|||
} |
|||
|
|||
|
|||
%template(TermRational) carl::Term<Rational>; |
@ -0,0 +1,240 @@ |
|||
|
|||
%module VariableT |
|||
%{ |
|||
#include <carl/core/Variable.h> |
|||
#include <carl/core/Monomial.h> |
|||
#include <carl/core/Term.h> |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
%} |
|||
|
|||
|
|||
|
|||
%include "std_string.i" |
|||
|
|||
%import "monomial.i" |
|||
%import "term.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
|
|||
|
|||
|
|||
//TODO: for 32 bit support this has to be changed.. |
|||
//%import <stddef> //for size_t maybe? |
|||
typedef long unsigned int size_t; //this should be okay for 64 bits at least |
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
//typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
|
|||
%include "enums.swg" |
|||
%javaconst(1); |
|||
//maybe also define the toString for this enum, if needed |
|||
//enum VariableType { VT_BOOL = 0, VT_REAL = 1, VT_INT = 2, VT_UNINTERPRETED = 3, VT_BITVECTOR = 4, MIN_TYPE = VT_BOOL, MAX_TYPE = VT_BITVECTOR}; |
|||
|
|||
enum class VariableType { VT_BOOL = 0, VT_REAL = 1, VT_INT = 2, VT_UNINTERPRETED = 3, VT_BITVECTOR = 4, MIN_TYPE = VT_BOOL, MAX_TYPE = VT_BITVECTOR, TYPE_SIZE = MAX_TYPE - MIN_TYPE + 1 }; |
|||
|
|||
|
|||
|
|||
class Variable { |
|||
public: |
|||
#ifdef VARIABLE_PASS_BY_VALUE |
|||
/// Argument type for variables being function arguments. |
|||
typedef Variable Arg; |
|||
#else |
|||
/// Argument type for variables being function arguments. |
|||
typedef const Variable& Arg; |
|||
#endif |
|||
%extend { |
|||
Variable(std::string name, carl::VariableType type) { |
|||
//try and generate new variable from pool |
|||
carl::Variable newVar; |
|||
auto& pool = carl::VariablePool::getInstance(); |
|||
carl::Variable res = pool.findVariableWithName(name); |
|||
if (res != carl::Variable::NO_VARIABLE) { |
|||
newVar = res; |
|||
} else { |
|||
newVar = freshVariable(name, type); |
|||
} |
|||
return new carl::Variable(newVar); |
|||
} |
|||
|
|||
Variable(carl::VariableType type) { |
|||
carl::Variable newVar = freshVariable(type); |
|||
return new carl::Variable(newVar); |
|||
} |
|||
|
|||
|
|||
std::string toString() { |
|||
std::stringstream ss; |
|||
ss << *$self; |
|||
return ss.str(); |
|||
} |
|||
|
|||
} |
|||
|
|||
std::size_t getId() const; |
|||
|
|||
|
|||
VariableType getType() const; |
|||
|
|||
|
|||
std::string getName() const; |
|||
|
|||
|
|||
std::size_t getRank(); |
|||
|
|||
%extend { |
|||
bool equals(carl::Variable::Arg other) { |
|||
return *$self == other; |
|||
} |
|||
|
|||
bool notEquals(carl::Variable::Arg other) { |
|||
return *$self != other; |
|||
} |
|||
bool less(carl::Variable::Arg other) { |
|||
return *$self < other; |
|||
} |
|||
bool lessEquals(carl::Variable::Arg other) { |
|||
return *$self <= other; |
|||
} |
|||
bool greater(carl::Variable::Arg other) { |
|||
return *$self > other; |
|||
} |
|||
bool greaterEquals(carl::Variable::Arg other) { |
|||
return *$self >= other; |
|||
} |
|||
|
|||
|
|||
Polynomial add(const Polynomial& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Term& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial add(const carl::Monomial::Arg& rhs) { |
|||
return carl::operator+<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(*($self),rhs); |
|||
} |
|||
|
|||
Polynomial add(carl::Variable::Arg rhs) { |
|||
return carl::operator+<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(*($self),rhs); |
|||
} |
|||
|
|||
Polynomial add(const Rational& rhs) { |
|||
return *($self)+Term(rhs); |
|||
} |
|||
|
|||
|
|||
|
|||
Polynomial sub(const Polynomial& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Term& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const carl::Monomial::Arg& rhs) { |
|||
return carl::operator-<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(*($self),rhs); |
|||
} |
|||
|
|||
|
|||
Polynomial sub(carl::Variable::Arg rhs) { |
|||
return carl::operator-<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(*($self),rhs); |
|||
} |
|||
|
|||
Polynomial sub(const Rational& rhs) { |
|||
return *($self)-Term(rhs); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
Polynomial mul(const Polynomial& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
Term mul(const Term& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
Polynomial mul(const Monomial::Arg& rhs) { |
|||
//const std::shared_ptr<const carl::Monomial> ptr(rhs); |
|||
return carl::operator*(*($self),Polynomial(rhs)); |
|||
} |
|||
|
|||
Polynomial mul(carl::Variable::Arg rhs) { |
|||
return carl::operator*(*($self),Polynomial(rhs)); |
|||
} |
|||
|
|||
Term mul(const Rational& rhs) { |
|||
return *($self)*Term(rhs); |
|||
} |
|||
|
|||
|
|||
|
|||
RationalFunction div(const carl::RationalFunction<Polynomial>& rhs) { |
|||
return RationalFunction(*($self)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Polynomial& rhs) { |
|||
return RationalFunction(*($self)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Term& rhs) { |
|||
return RationalFunction(*($self)) / rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
RationalFunction div(const carl::Monomial::Arg& rhs) { |
|||
return RationalFunction(*($self)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(carl::Variable::Arg rhs) { |
|||
return RationalFunction(*($self)) / rhs; |
|||
} |
|||
|
|||
Polynomial div(const Rational& rhs) { |
|||
if (carl::isZero(rhs)) throw std::runtime_error("Div by zero"); |
|||
return Polynomial(*($self)) / rhs; |
|||
} |
|||
|
|||
Term neg() { |
|||
return *$self*Rational(-1); |
|||
} |
|||
|
|||
|
|||
|
|||
carl::Monomial::Arg pow(uint exp) { |
|||
carl::Monomial m(*$self); |
|||
return m.pow(exp); |
|||
} |
|||
|
|||
} |
|||
}; |
|||
|
|||
} |
|||
|
@ -0,0 +1,240 @@ |
|||
|
|||
%module VariableT |
|||
%{ |
|||
#include <carl/core/Variable.h> |
|||
#include <carl/core/Monomial.h> |
|||
#include <carl/core/Term.h> |
|||
#include <carl/core/MultivariatePolynomial.h> |
|||
#include <carl/core/RationalFunction.h> |
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
%} |
|||
|
|||
|
|||
|
|||
%include "std_string.i" |
|||
|
|||
%import "monomial.i" |
|||
%import "term.i" |
|||
%import "polynomial.i" |
|||
%import "rationalfunction.i" |
|||
|
|||
|
|||
|
|||
//TODO: for 32 bit support this has to be changed.. |
|||
//%import <stddef> //for size_t maybe? |
|||
typedef long unsigned int size_t; //this should be okay for 64 bits at least |
|||
|
|||
|
|||
typedef mpq_class Rational; |
|||
|
|||
|
|||
typedef carl::Term<Rational> Term; |
|||
|
|||
typedef carl::MultivariatePolynomial<Rational> Polynomial; |
|||
//typedef carl::RationalFunction<Polynomial> RationalFunction; |
|||
|
|||
|
|||
namespace carl { |
|||
|
|||
|
|||
//%include "enums.swg" |
|||
//%javaconst(1); |
|||
//maybe also define the toString for this enum, if needed |
|||
//enum VariableType { VT_BOOL = 0, VT_REAL = 1, VT_INT = 2, VT_UNINTERPRETED = 3, VT_BITVECTOR = 4, MIN_TYPE = VT_BOOL, MAX_TYPE = VT_BITVECTOR}; |
|||
|
|||
enum class VariableType { VT_BOOL = 0, VT_REAL = 1, VT_INT = 2, VT_UNINTERPRETED = 3, VT_BITVECTOR = 4, MIN_TYPE = VT_BOOL, MAX_TYPE = VT_BITVECTOR, TYPE_SIZE = MAX_TYPE - MIN_TYPE + 1 }; |
|||
|
|||
|
|||
|
|||
class Variable { |
|||
public: |
|||
#ifdef VARIABLE_PASS_BY_VALUE |
|||
/// Argument type for variables being function arguments. |
|||
typedef Variable Arg; |
|||
#else |
|||
/// Argument type for variables being function arguments. |
|||
typedef const Variable& Arg; |
|||
#endif |
|||
%extend { |
|||
Variable(std::string name, carl::VariableType type) { |
|||
//try and generate new variable from pool |
|||
carl::Variable newVar; |
|||
auto& pool = carl::VariablePool::getInstance(); |
|||
carl::Variable res = pool.findVariableWithName(name); |
|||
if (res != carl::Variable::NO_VARIABLE) { |
|||
newVar = res; |
|||
} else { |
|||
newVar = freshVariable(name, type); |
|||
} |
|||
return new carl::Variable(newVar); |
|||
} |
|||
|
|||
Variable(carl::VariableType type) { |
|||
carl::Variable newVar = freshVariable(type); |
|||
return new carl::Variable(newVar); |
|||
} |
|||
|
|||
|
|||
std::string toString() { |
|||
std::stringstream ss; |
|||
ss << *$self; |
|||
return ss.str(); |
|||
} |
|||
|
|||
} |
|||
|
|||
std::size_t getId() const; |
|||
|
|||
|
|||
VariableType getType() const; |
|||
|
|||
|
|||
std::string getName() const; |
|||
|
|||
|
|||
std::size_t getRank(); |
|||
|
|||
%extend { |
|||
bool equals(carl::Variable::Arg other) { |
|||
return *$self == other; |
|||
} |
|||
|
|||
bool notEquals(carl::Variable::Arg other) { |
|||
return *$self != other; |
|||
} |
|||
bool less(carl::Variable::Arg other) { |
|||
return *$self < other; |
|||
} |
|||
bool lessEquals(carl::Variable::Arg other) { |
|||
return *$self <= other; |
|||
} |
|||
bool greater(carl::Variable::Arg other) { |
|||
return *$self > other; |
|||
} |
|||
bool greaterEquals(carl::Variable::Arg other) { |
|||
return *$self >= other; |
|||
} |
|||
|
|||
|
|||
Polynomial add(const Polynomial& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
Polynomial add(const Term& rhs) { |
|||
return *($self)+rhs; |
|||
} |
|||
|
|||
|
|||
Polynomial add(const carl::Monomial::Arg& rhs) { |
|||
return carl::operator+<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(*($self),rhs); |
|||
} |
|||
|
|||
Polynomial add(carl::Variable::Arg rhs) { |
|||
return carl::operator+<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(*($self),rhs); |
|||
} |
|||
|
|||
Polynomial add(const Rational& rhs) { |
|||
return *($self)+Term(rhs); |
|||
} |
|||
|
|||
|
|||
|
|||
Polynomial sub(const Polynomial& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const Term& rhs) { |
|||
return *($self)-rhs; |
|||
} |
|||
|
|||
Polynomial sub(const carl::Monomial::Arg& rhs) { |
|||
return carl::operator-<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(*($self),rhs); |
|||
} |
|||
|
|||
|
|||
Polynomial sub(carl::Variable::Arg rhs) { |
|||
return carl::operator-<Rational,carl::GrLexOrdering,carl::StdMultivariatePolynomialPolicies<>>(*($self),rhs); |
|||
} |
|||
|
|||
Polynomial sub(const Rational& rhs) { |
|||
return *($self)-Term(rhs); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
Polynomial mul(const Polynomial& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
Term mul(const Term& rhs) { |
|||
return *($self)*rhs; |
|||
} |
|||
|
|||
Polynomial mul(const Monomial::Arg& rhs) { |
|||
//const std::shared_ptr<const carl::Monomial> ptr(rhs); |
|||
return carl::operator*(*($self),Polynomial(rhs)); |
|||
} |
|||
|
|||
Polynomial mul(carl::Variable::Arg rhs) { |
|||
return carl::operator*(*($self),Polynomial(rhs)); |
|||
} |
|||
|
|||
Term mul(const Rational& rhs) { |
|||
return *($self)*Term(rhs); |
|||
} |
|||
|
|||
|
|||
|
|||
RationalFunction div(const carl::RationalFunction<Polynomial>& rhs) { |
|||
return RationalFunction(*($self)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Polynomial& rhs) { |
|||
return RationalFunction(*($self)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(const Term& rhs) { |
|||
return RationalFunction(*($self)) / rhs; |
|||
} |
|||
|
|||
|
|||
|
|||
RationalFunction div(const carl::Monomial::Arg& rhs) { |
|||
return RationalFunction(*($self)) / rhs; |
|||
} |
|||
|
|||
RationalFunction div(carl::Variable::Arg rhs) { |
|||
return RationalFunction(*($self)) / rhs; |
|||
} |
|||
|
|||
Polynomial div(const Rational& rhs) { |
|||
if (carl::isZero(rhs)) throw std::runtime_error("Div by zero"); |
|||
return Polynomial(*($self)) / rhs; |
|||
} |
|||
|
|||
Term neg() { |
|||
return *$self*Rational(-1); |
|||
} |
|||
|
|||
|
|||
|
|||
carl::Monomial::Arg pow(uint exp) { |
|||
carl::Monomial m(*$self); |
|||
return m.pow(exp); |
|||
} |
|||
|
|||
} |
|||
}; |
|||
|
|||
} |
|||
|
@ -0,0 +1,36 @@ |
|||
# Include dir |
|||
find_path(BLISS_INCLUDE_DIR |
|||
NAMES bliss/bliss_C.h |
|||
PATHS |
|||
/usr/include |
|||
/usr/local/include |
|||
) |
|||
|
|||
# Library files |
|||
find_library(BLISS_LIBRARY |
|||
NAMES bliss |
|||
PATHS |
|||
/usr/lib |
|||
/usr/local/lib |
|||
) |
|||
|
|||
if(BLISS_INCLUDE_DIR AND BLISS_LIBRARY) |
|||
set(BLISS_FOUND TRUE) |
|||
|
|||
# Version |
|||
file(STRINGS ${BLISS_INCLUDE_DIR}/bliss/defs.hh BLISS_VERSION REGEX "const version = \".*\";") |
|||
string(REGEX MATCH "[0-9]+\\.[0-9]+" BLISS_VERSION "${BLISS_VERSION}") |
|||
|
|||
if(BLISS_FIND_VERSION VERSION_GREATER BLISS_VERSION) |
|||
message(WARNING "Required bliss ${BLISS_FIND_VERSION} but found only bliss ${BLISS_VERSION}.") |
|||
return() |
|||
endif() |
|||
endif() |
|||
|
|||
# Cleanup |
|||
mark_as_advanced( |
|||
BLISS_FOUND |
|||
BLISS_INCLUDE_DIR |
|||
BLISS_LIBRARY |
|||
BLISS_VERSION |
|||
) |
@ -0,0 +1,38 @@ |
|||
# Include dir |
|||
find_path(CLN_INCLUDE_DIR |
|||
NAMES cln/cln.h |
|||
HINTS ${CLN_PKGCONF_INCLUDE_DIRS} |
|||
PATHS |
|||
/usr/include |
|||
/usr/local/include |
|||
) |
|||
|
|||
# Library files |
|||
find_library(CLN_LIBRARY |
|||
NAMES cln |
|||
HINTS ${CLN_PKGCONF_LIBRARY_DIRS} |
|||
PATHS |
|||
/usr/lib |
|||
/usr/local/lib |
|||
) |
|||
|
|||
if(CLN_INCLUDE_DIR AND CLN_LIBRARY) |
|||
set(CLN_FOUND TRUE) |
|||
|
|||
# Version |
|||
file(STRINGS ${CLN_INCLUDE_DIR}/cln/version.h CLN_VERSION REGEX "^#define[\t ]+CL_VERSION .*") |
|||
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CLN_VERSION "${CLN_VERSION}") |
|||
|
|||
if(CLN_FIND_VERSION VERSION_GREATER CLN_VERSION) |
|||
message(WARNING "Required CLN ${CLN_FIND_VERSION} but found only CLN ${CLN_VERSION}.") |
|||
return() |
|||
endif() |
|||
endif() |
|||
|
|||
# Cleanup |
|||
mark_as_advanced( |
|||
CLN_FOUND |
|||
CLN_INCLUDE_DIR |
|||
CLN_LIBRARY |
|||
CLN_VERSION |
|||
) |
@ -0,0 +1,39 @@ |
|||
# Include dir |
|||
find_path(COCOA_INCLUDE_DIR |
|||
NAMES CoCoA/library.H |
|||
PATHS |
|||
/usr/include/ |
|||
/usr/local/include/ |
|||
DOC "Include directory for CoCoA" |
|||
) |
|||
|
|||
find_library(COCOA_LIBRARY |
|||
NAMES cocoa |
|||
PATHS |
|||
/usr/lib |
|||
/usr/local/lib |
|||
) |
|||
|
|||
if(COCOA_INCLUDE_DIR AND COCOA_LIBRARY) |
|||
set(COCOA_FOUND TRUE) |
|||
|
|||
# Version |
|||
function(GetVersion OUTPUT FILENAME) |
|||
file(STRINGS ${FILENAME} RES REGEX "CoCoALib version .*") |
|||
string(REGEX MATCH "[0-9]+\.[0-9]+" RES "${RES}") |
|||
set(${OUTPUT} "${RES}" PARENT_SCOPE) |
|||
endfunction() |
|||
GetVersion(COCOA_VERSION "${COCOA_INCLUDE_DIR}/CoCoA/library.H") |
|||
|
|||
if(COCOA_FIND_VERSION VERSION_GREATER COCOA_VERSION) |
|||
message(WARNING "Required CoCoA ${COCOA_FIND_VERSION} but found only CoCoA ${COCOA_VERSION}.") |
|||
return() |
|||
endif() |
|||
endif() |
|||
|
|||
mark_as_advanced( |
|||
COCOA_FOUND |
|||
COCOA_INCLUDE_DIR |
|||
COCOA_LIBRARY |
|||
COCOA_VERSION |
|||
) |
@ -0,0 +1,80 @@ |
|||
# - Try to find EIGEN3 lib |
|||
# |
|||
# This module supports requiring a minimum version, e.g. you can do |
|||
# find_package(EIGEN3 3.1.2) |
|||
# to require version 3.1.2 or newer of EIGEN3. |
|||
# |
|||
# Once done this will define |
|||
# |
|||
# EIGEN3_FOUND - system has eigen lib with correct version |
|||
# EIGEN3_INCLUDE_DIR - the eigen include directory |
|||
# EIGEN3_VERSION - eigen version |
|||
|
|||
# Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org> |
|||
# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr> |
|||
# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> |
|||
# Redistribution and use is allowed according to the terms of the 2-clause BSD license. |
|||
|
|||
if(NOT EIGEN3_FIND_VERSION) |
|||
if(NOT EIGEN3_FIND_VERSION_MAJOR) |
|||
set(EIGEN3_FIND_VERSION_MAJOR 2) |
|||
endif(NOT EIGEN3_FIND_VERSION_MAJOR) |
|||
if(NOT EIGEN3_FIND_VERSION_MINOR) |
|||
set(EIGEN3_FIND_VERSION_MINOR 91) |
|||
endif(NOT EIGEN3_FIND_VERSION_MINOR) |
|||
if(NOT EIGEN3_FIND_VERSION_PATCH) |
|||
set(EIGEN3_FIND_VERSION_PATCH 0) |
|||
endif(NOT EIGEN3_FIND_VERSION_PATCH) |
|||
|
|||
set(EIGEN3_FIND_VERSION "${EIGEN3_FIND_VERSION_MAJOR}.${EIGEN3_FIND_VERSION_MINOR}.${EIGEN3_FIND_VERSION_PATCH}") |
|||
endif(NOT EIGEN3_FIND_VERSION) |
|||
|
|||
macro(_eigen3_check_version) |
|||
file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header) |
|||
|
|||
string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}") |
|||
set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}") |
|||
string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}") |
|||
set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}") |
|||
string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}") |
|||
set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}") |
|||
|
|||
set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION}) |
|||
if(${EIGEN3_VERSION} VERSION_LESS ${EIGEN3_FIND_VERSION}) |
|||
set(EIGEN3_VERSION_OK FALSE) |
|||
else(${EIGEN3_VERSION} VERSION_LESS ${EIGEN3_FIND_VERSION}) |
|||
set(EIGEN3_VERSION_OK TRUE) |
|||
endif(${EIGEN3_VERSION} VERSION_LESS ${EIGEN3_FIND_VERSION}) |
|||
|
|||
if(NOT EIGEN3_VERSION_OK) |
|||
|
|||
message(STATUS "EIGEN3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, " |
|||
"but at least version ${EIGEN3_FIND_VERSION} is required") |
|||
endif(NOT EIGEN3_VERSION_OK) |
|||
endmacro(_eigen3_check_version) |
|||
|
|||
if (EIGEN3_INCLUDE_DIR) |
|||
|
|||
# in cache already |
|||
_eigen3_check_version() |
|||
set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) |
|||
|
|||
else (EIGEN3_INCLUDE_DIR) |
|||
|
|||
find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library |
|||
PATHS |
|||
${CMAKE_INSTALL_PREFIX}/include |
|||
${KDE4_INCLUDE_DIR} |
|||
PATH_SUFFIXES eigen3 eigen |
|||
) |
|||
|
|||
if(EIGEN3_INCLUDE_DIR) |
|||
_eigen3_check_version() |
|||
endif(EIGEN3_INCLUDE_DIR) |
|||
|
|||
include(FindPackageHandleStandardArgs) |
|||
find_package_handle_standard_args(EIGEN3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) |
|||
|
|||
mark_as_advanced(EIGEN3_INCLUDE_DIR) |
|||
|
|||
endif(EIGEN3_INCLUDE_DIR) |
@ -0,0 +1,42 @@ |
|||
# Include dir |
|||
find_path(GINAC_INCLUDE_DIR |
|||
NAMES ginac.h |
|||
PATHS |
|||
/usr/include/ginac |
|||
/usr/local/include/ginac |
|||
DOC "Include directory for GiNaC" |
|||
) |
|||
|
|||
find_library(GINAC_LIBRARY |
|||
NAMES ginac |
|||
PATHS |
|||
/usr/lib |
|||
/usr/local/lib |
|||
) |
|||
|
|||
if(GINAC_INCLUDE_DIR AND GINAC_LIBRARY) |
|||
set(GINAC_FOUND TRUE) |
|||
|
|||
# Version |
|||
function(GetVersionPart OUTPUT FILENAME DESC) |
|||
file(STRINGS ${FILENAME} RES REGEX "^#define GINACLIB_${DESC}_VERSION[ \\t]+.*") |
|||
string(REGEX MATCH "[0-9]+" RES "${RES}") |
|||
set(${OUTPUT} "${RES}" PARENT_SCOPE) |
|||
endfunction() |
|||
GetVersionPart(MAJOR "${GINAC_INCLUDE_DIR}/version.h" "MAJOR") |
|||
GetVersionPart(MINOR "${GINAC_INCLUDE_DIR}/version.h" "MINOR") |
|||
GetVersionPart(MICRO "${GINAC_INCLUDE_DIR}/version.h" "MICRO") |
|||
set(GINAC_VERSION "${MAJOR}.${MINOR}.${MICRO}") |
|||
|
|||
if(GINAC_FIND_VERSION VERSION_GREATER GINAC_VERSION) |
|||
message(WARNING "Required GiNaC ${GINAC_FIND_VERSION} but found only GiNaC ${GINAC_VERSION}.") |
|||
return() |
|||
endif() |
|||
endif() |
|||
|
|||
mark_as_advanced( |
|||
GINAC_FOUND |
|||
GINAC_INCLUDE_DIR |
|||
GINAC_LIBRARY |
|||
GINAC_VERSION |
|||
) |
@ -0,0 +1,54 @@ |
|||
# Include dir |
|||
STRING(REPLACE ":" ";" CPATH "$ENV{CPATH}") |
|||
find_path(GMP_INCLUDE_DIR |
|||
NAMES gmp.h |
|||
HINTS ${CPATH} |
|||
DOC "Include directory for GMP" |
|||
) |
|||
|
|||
# Library files |
|||
STRING(REPLACE ":" ";" LIBRARY_PATH "$ENV{LIBRARY_PATH}") |
|||
find_library(GMP_LIBRARY |
|||
NAMES gmp |
|||
HINTS ${LIBRARY_PATH} |
|||
PATHS /usr/local/lib |
|||
) |
|||
|
|||
# Version |
|||
function(GetVersionPart OUTPUT FILENAME DESC) |
|||
file(STRINGS ${FILENAME} RES REGEX "^#define __GNU_MP_${DESC}[ \\t]+.*") |
|||
string(REGEX MATCH "[0-9]+" RES "${RES}") |
|||
set(${OUTPUT} "${RES}" PARENT_SCOPE) |
|||
endfunction() |
|||
function(GetVersion OUTPUT FILENAME) |
|||
GetVersionPart(MAJOR "${FILENAME}" "VERSION") |
|||
GetVersionPart(MINOR "${FILENAME}" "VERSION_MINOR") |
|||
GetVersionPart(PATCH "${FILENAME}" "VERSION_PATCHLEVEL") |
|||
set(${OUTPUT} "${MAJOR}.${MINOR}.${PATCH}" PARENT_SCOPE) |
|||
endfunction() |
|||
|
|||
if(GMP_INCLUDE_DIR AND GMP_LIBRARY) |
|||
set(GMP_FOUND TRUE) |
|||
|
|||
if (EXISTS "${GMP_INCLUDE_DIR}/gmp-x86_64.h") |
|||
GetVersion(GMP_VERSION "${GMP_INCLUDE_DIR}/gmp-x86_64.h") |
|||
else() |
|||
GetVersion(GMP_VERSION "${GMP_INCLUDE_DIR}/gmp.h") |
|||
endif() |
|||
|
|||
if(GMP_FIND_VERSION VERSION_GREATER GMP_VERSION) |
|||
message(WARNING "Required GMP ${GMP_FIND_VERSION} but found only GMP ${GMP_VERSION}.") |
|||
unset(GMP_FOUND) |
|||
unset(GMP_INCLUDE_DIR) |
|||
unset(GMP_LIBRARY) |
|||
unset(GMP_VERSION) |
|||
return() |
|||
endif() |
|||
endif() |
|||
|
|||
mark_as_advanced( |
|||
GMP_FOUND |
|||
GMP_INCLUDE_DIR |
|||
GMP_LIBRARY |
|||
GMP_VERSION |
|||
) |
@ -0,0 +1,29 @@ |
|||
find_package(GMP ${GMPXX_FIND_VERSION} QUIET) |
|||
|
|||
if(GMP_FOUND) |
|||
# Include dir |
|||
find_path(GMPXX_INCLUDE_DIR |
|||
NAMES gmpxx.h |
|||
HINTS ${GMP_INCLUDE_DIR} |
|||
DOC "Include directory for GMPXX" |
|||
) |
|||
|
|||
# Library files |
|||
get_filename_component(GMP_LIB_PATH ${GMP_LIBRARY} DIRECTORY) |
|||
find_library(GMPXX_LIBRARY |
|||
NAMES gmpxx |
|||
HINTS ${GMP_LIB_PATH} |
|||
) |
|||
|
|||
if(GMPXX_INCLUDE_DIR AND GMPXX_LIBRARY) |
|||
set(GMPXX_FOUND TRUE) |
|||
endif() |
|||
|
|||
mark_as_advanced( |
|||
GMPXX_FOUND |
|||
GMPXX_INCLUDE_DIR |
|||
GMPXX_LIBRARY |
|||
) |
|||
else() |
|||
message(STATUS "Did not search for GMPXX, GMP is missing.") |
|||
endif() |
@ -0,0 +1,35 @@ |
|||
# Copyright (c) 2008-2010 Kent State University |
|||
# Copyright (c) 2011-2012 Texas A&M University |
|||
# |
|||
# This file is distributed under the MIT License. See the accompanying file |
|||
# LICENSE.txt or http://www.opensource.org/licenses/mit-license.php for terms |
|||
# and conditions. |
|||
|
|||
# FIXME: How do I find the version of MPFR that I want to use? |
|||
# What versions are available? |
|||
|
|||
# NOTE: MPFR prefix is understood to be the path to the root of the MPFR |
|||
# installation library. |
|||
set(MPFR_PREFIX "" CACHE PATH "The path to the previx of an MPFR installation") |
|||
|
|||
find_path(MPFR_INCLUDE_DIR mpfr.h |
|||
PATHS ${MPFR_PREFIX}/include /usr/include /usr/local/include) |
|||
|
|||
find_library(MPFR_LIBRARY NAMES mpfr |
|||
PATHS ${MPFR_PREFIX}/lib /usr/lib /usr/local/lib) |
|||
|
|||
if(MPFR_INCLUDE_DIR AND MPFR_LIBRARIES) |
|||
get_filename_component(MPFR_LIBRARIES_DIR ${MPFR_LIBRARY} PATH) |
|||
set(MPFR_FOUND TRUE) |
|||
endif() |
|||
|
|||
|
|||
if(MPFR_FOUND) |
|||
if(NOT MPFR_FIND_QUIETLY) |
|||
MESSAGE(STATUS "Found MPFR: ${MPFR_LIBRARY}") |
|||
endif() |
|||
elseif(MPFR_FOUND) |
|||
if(MPFR_FIND_REQUIRED) |
|||
message(FATAL_ERROR "Could not find MPFR") |
|||
endif() |
|||
endif() |
@ -0,0 +1,42 @@ |
|||
# - Try to find libz3 |
|||
# Once done this will define |
|||
# LIBZ3_FOUND - System has libz3 |
|||
# LIBZ3_INCLUDE_DIRS - The libz3 include directories |
|||
# LIBZ3_LIBRARIES - The libraries needed to use libz3 |
|||
|
|||
# dependencies |
|||
# -- TODO -- needed? |
|||
|
|||
# find include dir by searching for a concrete file, which definetely must be in it |
|||
find_path(Z3_INCLUDE_DIR |
|||
NAMES src/util/z3_exception.h #exemplary file, should only be available in z3 |
|||
PATHS ENV PATH INCLUDE |
|||
PATH_SUFFIXES z3 |
|||
) |
|||
|
|||
# find library |
|||
find_library(Z3_LIBRARY |
|||
NAMES z3 |
|||
PATHS /usr/local/include/z3/build ENV PATH INCLUDE |
|||
) |
|||
|
|||
# set up the final variables |
|||
set(Z3_LIBRARIES ${Z3_LIBRARY}) |
|||
set(Z3_INCLUDE_DIRS ${Z3_INCLUDE_DIR}/src/util) |
|||
|
|||
# set the LIBZ3_FOUND variable by utilizing the following macro |
|||
# (which also handles the REQUIRED and QUIET arguments) |
|||
include(FindPackageHandleStandardArgs) |
|||
find_package_handle_standard_args(z3 DEFAULT_MSG |
|||
Z3_LIBRARY Z3_INCLUDE_DIR) |
|||
|
|||
IF (NOT Z3_FIND_QUIETLY) |
|||
MESSAGE(STATUS "Found Z3: ${Z3_LIBRARY}") |
|||
ENDIF (NOT Z3_FIND_QUIETLY) |
|||
|
|||
# debug output to see if everything went well |
|||
#message(${Z3_INCLUDE_DIR}) |
|||
#message(${Z3_LIBRARY}) |
|||
|
|||
# make the set variables only visible in advanced mode |
|||
mark_as_advanced(Z3_LIBRARY Z3_INCLUDE_DIR ) |
@ -0,0 +1,26 @@ |
|||
set(carl_VERSION @PROJECT_VERSION_FULL@) |
|||
|
|||
set( carl_VERSION_MAJOR @PROJECT_VERSION_MAJOR@) |
|||
set( carl_VERSION_MINOR @PROJECT_VERSION_MINOR@) |
|||
set( carl_VERSION_PATCH @PROJECT_VERSION_PATCH_FULL@) |
|||
set( carl_MINORYEARVERSION @PROJECT_VERSION_MAJOR@) |
|||
set( carl_MINORMONTHVERSION @PROJECT_VERSION_MINOR@) |
|||
set( carl_MAINTENANCEVERSION @PROJECT_VERSION_PATCH_FULL@) |
|||
|
|||
get_filename_component(carl_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) |
|||
|
|||
@DEP_TARGETS@ |
|||
|
|||
@EXP_OPTIONS@ |
|||
|
|||
# Our library dependencies (contains definitions for IMPORTED targets) |
|||
if(NOT TARGET lib_carl AND NOT carl_BINARY_DIR) |
|||
include("${carl_CMAKE_DIR}/carlTargets.cmake") |
|||
endif() |
|||
|
|||
@PACKAGE_INIT@ |
|||
|
|||
set(carl_INCLUDE_DIR "@CONF_INCLUDE_DIRS@") |
|||
|
|||
set(carl_LIBRARIES lib_carl) |
|||
check_required_components(carl) |
@ -0,0 +1,11 @@ |
|||
set(PACKAGE_VERSION "@PROJECT_VERSION@") |
|||
|
|||
# Check whether the requested PACKAGE_FIND_VERSION is compatible |
|||
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") |
|||
set(PACKAGE_VERSION_COMPATIBLE FALSE) |
|||
else() |
|||
set(PACKAGE_VERSION_COMPATIBLE TRUE) |
|||
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") |
|||
set(PACKAGE_VERSION_EXACT TRUE) |
|||
endif() |
|||
endif() |
@ -0,0 +1,201 @@ |
|||
# File: macros.cmake |
|||
# Authors: Igor N. Bongartz |
|||
# Erstellt: 2015-06-11 |
|||
# Version: 2015-06-11 |
|||
# |
|||
# This file contains several macros which are used in this project. Notice that several are copied straight from web ressources. |
|||
|
|||
function(set_version major minor) |
|||
execute_process( |
|||
COMMAND git describe |
|||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
|||
OUTPUT_VARIABLE GIT_VERSION |
|||
OUTPUT_STRIP_TRAILING_WHITESPACE |
|||
) |
|||
set(patch "") |
|||
if (GIT_VERSION MATCHES "([0-9]+)\.([0-9]+)(-?.*)") |
|||
set(major ${CMAKE_MATCH_1}) |
|||
set(minor ${CMAKE_MATCH_2}) |
|||
if (CMAKE_MATCH_3 MATCHES "-([0-9]+)-(g[0-9a-f]+)") |
|||
set(patch_full "${CMAKE_MATCH_1}-${CMAKE_MATCH_2}") |
|||
set(patch "${CMAKE_MATCH_1}") |
|||
endif() |
|||
else() |
|||
message(STATUS "Could not parse version from git, using default ${major}.${minor}") |
|||
endif() |
|||
|
|||
set(PROJECT_VERSION_MAJOR ${major} PARENT_SCOPE) |
|||
set(PROJECT_VERSION_MINOR ${minor} PARENT_SCOPE) |
|||
set(PROJECT_VERSION_PATCH ${patch} PARENT_SCOPE) |
|||
if(patch) |
|||
set(PROJECT_VERSION_FULL "${major}.${minor}.${patch_full}" PARENT_SCOPE) |
|||
set(PROJECT_VERSION "${major}.${minor}.${patch}" PARENT_SCOPE) |
|||
else() |
|||
set(PROJECT_VERSION_FULL "${major}.${minor}" PARENT_SCOPE) |
|||
set(PROJECT_VERSION "${major}.${minor}" PARENT_SCOPE) |
|||
endif() |
|||
endfunction(set_version) |
|||
|
|||
function(add_imported_library_interface name include) |
|||
add_library(${name} INTERFACE IMPORTED) |
|||
set_target_properties(${name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${include}") |
|||
endfunction(add_imported_library_interface) |
|||
|
|||
function(add_imported_library name type lib include) |
|||
# Workaround from https://cmake.org/Bug/view.php?id=15052 |
|||
file(MAKE_DIRECTORY "${include}") |
|||
if("${lib}" STREQUAL "") |
|||
if("${type}" STREQUAL "SHARED") |
|||
add_library(${name} INTERFACE IMPORTED) |
|||
set_target_properties(${name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${include}") |
|||
endif() |
|||
else() |
|||
set(lib_list "${lib}") |
|||
list(LENGTH lib_list NumFiles) |
|||
if(NumFiles GREATER 1) |
|||
add_library(${name}_${type} INTERFACE IMPORTED GLOBAL) |
|||
set(shortnames "${ARGN}") |
|||
set(libs "") |
|||
math(EXPR range "${NumFiles}-1") |
|||
foreach(index RANGE ${range}) |
|||
list(GET lib_list ${index} l) |
|||
list(GET shortnames ${index} shortname) |
|||
add_imported_library("${name}_${shortname}" ${type} ${l} ${include}) |
|||
list(APPEND libs "${name}_${shortname}_${type}") |
|||
# only from cmake 3.3 https://github.com/ceph/ceph/pull/7128 |
|||
#add_dependencies(${name}_${type} ${name}_${shortname}_${type}) |
|||
endforeach() |
|||
set_target_properties(${name}_${type} PROPERTIES INTERFACE_LINK_LIBRARIES "${libs}") |
|||
set_target_properties(${name}_${type} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${include}") |
|||
else() |
|||
add_library(${name}_${type} ${type} IMPORTED GLOBAL) |
|||
set_target_properties(${name}_${type} PROPERTIES IMPORTED_LOCATION "${lib}") |
|||
set_target_properties(${name}_${type} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${include}") |
|||
if(WIN32) |
|||
string(REPLACE "dll" "lib" IMPLIB ${lib}) |
|||
set_target_properties(${name}_${type} PROPERTIES IMPORTED_IMPLIB "${IMPLIB}") |
|||
endif() |
|||
endif() |
|||
endif() |
|||
endfunction(add_imported_library) |
|||
|
|||
function(export_option name) |
|||
list(APPEND EXPORTED_OPTIONS "${name}") |
|||
set(EXPORTED_OPTIONS "${EXPORTED_OPTIONS}" PARENT_SCOPE) |
|||
endfunction(export_option) |
|||
|
|||
function(_export_target_add_exec output TARGET) |
|||
set(${output} "${${output}} |
|||
add_executable(${TARGET} IMPORTED)" PARENT_SCOPE) |
|||
endfunction(_export_target_add_exec) |
|||
function(_export_target_add_lib output TARGET TYPE) |
|||
set(${output} "${${output}} |
|||
add_library(${TARGET} ${TYPE} IMPORTED)" PARENT_SCOPE) |
|||
endfunction(_export_target_add_lib) |
|||
function(_export_target_start output TARGET) |
|||
set(${output} "${${output}} |
|||
|
|||
if(NOT TARGET ${TARGET})" PARENT_SCOPE) |
|||
endfunction(_export_target_start) |
|||
function(_export_target_end output) |
|||
set(${output} "${${output}} |
|||
endif()" PARENT_SCOPE) |
|||
endfunction(_export_target_end) |
|||
|
|||
macro(_export_target_set_prop output TARGET REQUIRED PROPERTY) |
|||
get_target_property(VALUE ${TARGET} ${PROPERTY}) |
|||
set(extra_args ${ARGN}) |
|||
list(GET extra_args 0 NEWPROPERTY) |
|||
if(NOT NEWPROPERTY) |
|||
set(NEWPROPERTY ${PROPERTY}) |
|||
endif() |
|||
if(VALUE) |
|||
set(${output} "${${output}} |
|||
set_target_properties(${TARGET} PROPERTIES ${NEWPROPERTY} \"${VALUE}\")") |
|||
elseif(${REQUIRED}) |
|||
message(STATUS "Did not find ${PROPERTY} of ${TARGET} for export.") |
|||
endif() |
|||
endmacro(_export_target_set_prop) |
|||
|
|||
macro(export_target output target) |
|||
if(TARGET ${target}) |
|||
get_target_property(TYPE ${target} TYPE) |
|||
_export_target_start(${output} ${target}) |
|||
if(TYPE STREQUAL "EXECUTABLE") |
|||
_export_target_add_exec(${output} ${target}) |
|||
_export_target_set_prop(${output} ${target} TRUE IMPORTED_LOCATION) |
|||
elseif(TYPE STREQUAL "SHARED_LIBRARY") |
|||
_export_target_add_lib(${output} ${target} SHARED) |
|||
_export_target_set_prop(${output} ${target} TRUE IMPORTED_LOCATION) |
|||
_export_target_set_prop(${output} ${target} FALSE INTERFACE_INCLUDE_DIRECTORIES) |
|||
_export_target_set_prop(${output} ${target} FALSE LINK_INTERFACE_LIBRARIES) |
|||
elseif(TYPE STREQUAL "STATIC_LIBRARY") |
|||
_export_target_add_lib(${output} ${target} STATIC) |
|||
_export_target_set_prop(${output} ${target} TRUE IMPORTED_LOCATION) |
|||
_export_target_set_prop(${output} ${target} FALSE INTERFACE_INCLUDE_DIRECTORIES) |
|||
_export_target_set_prop(${output} ${target} FALSE LINK_INTERFACE_LIBRARIES IMPORTED_LINK_INTERFACE_LIBRARIES) |
|||
elseif(TYPE STREQUAL "INTERFACE_LIBRARY") |
|||
_export_target_add_lib(${output} ${target} INTERFACE) |
|||
_export_target_set_prop(${output} ${target} TRUE INTERFACE_INCLUDE_DIRECTORIES) |
|||
_export_target_set_prop(${output} ${target} FALSE INTERFACE_LINK_LIBRARIES) |
|||
else() |
|||
message(STATUS "Unknown type ${TYPE}") |
|||
endif() |
|||
if(NOT "${ARGN}" STREQUAL "") |
|||
set(${output} "${${output}} |
|||
set_target_properties(${target} PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES \"${ARGN}\")") |
|||
endif() |
|||
_export_target_end(${output}) |
|||
endif() |
|||
endmacro(export_target) |
|||
|
|||
macro(export_target_recursive output target RECURSE_ON) |
|||
export_target(${output} ${target}) |
|||
get_target_property(deps ${target} ${RECURSE_ON}) |
|||
foreach(d ${deps}) |
|||
export_target(${output} ${d}) |
|||
endforeach() |
|||
endmacro(export_target_recursive) |
|||
|
|||
macro(load_library group name version) |
|||
string(TOUPPER ${name} LIBNAME) |
|||
set(CMAKE_FIND_LIBRARY_SUFFIXES "${DYNAMIC_EXT};${STATIC_EXT}") |
|||
set(Boost_USE_STATIC_LIBS OFF) |
|||
find_package(${name} ${version} ${ARGN} QUIET) |
|||
if(${name}_FOUND OR ${LIBNAME}_FOUND) |
|||
if (${name}_FOUND) |
|||
set(LIBNAME ${name}) |
|||
endif() |
|||
|
|||
if(LIBNAME MATCHES "Boost") |
|||
add_imported_library(${LIBNAME} SHARED "${${LIBNAME}_LIBRARIES}" "${${LIBNAME}_INCLUDE_DIR}" "${BOOST_COMPONENTS}") |
|||
else() |
|||
add_imported_library(${LIBNAME} SHARED "${${LIBNAME}_LIBRARY}" "${${LIBNAME}_INCLUDE_DIR}") |
|||
endif() |
|||
|
|||
unset(${LIBNAME}_FOUND CACHE) |
|||
unset(${LIBNAME}_INCLUDE_DIR CACHE) |
|||
unset(${LIBNAME}_LIBRARY CACHE) |
|||
|
|||
set(CMAKE_FIND_LIBRARY_SUFFIXES "${STATIC_EXT};${DYNAMIC_EXT}") |
|||
set(Boost_USE_STATIC_LIBS ON) |
|||
if (ARGN) |
|||
list(REMOVE_ITEM ARGN "REQUIRED") |
|||
endif() |
|||
find_package(${name} ${version} ${ARGN} QUIET) |
|||
if(${LIBNAME}_FOUND) |
|||
if(LIBNAME MATCHES "Boost") |
|||
add_imported_library(${LIBNAME} STATIC "${${LIBNAME}_LIBRARIES}" "${${LIBNAME}_INCLUDE_DIR}" "${BOOST_COMPONENTS}") |
|||
else() |
|||
add_imported_library(${LIBNAME} STATIC "${${LIBNAME}_LIBRARY}" "${${LIBNAME}_INCLUDE_DIR}") |
|||
endif() |
|||
endif() |
|||
|
|||
unset(${LIBNAME}_LIBRARY CACHE) |
|||
endif() |
|||
endmacro(load_library) |
|||
|
|||
macro(get_include_dir var name) |
|||
get_target_property(INCLUDE_DIR ${name} INTERFACE_INCLUDE_DIRECTORIES) |
|||
set(${var} ${${var}}:${INCLUDE_DIR}) |
|||
endmacro(get_include_dir) |
@ -0,0 +1,50 @@ |
|||
find_program(CLANG_TIDY clang-tidy) |
|||
if(NOT CLANG_TIDY) |
|||
message(STATUS "Did not find clang-tidy, target tidy is disabled.") |
|||
else() |
|||
message(STATUS "Found clang-tidy, use \"make tidy\" to run it.") |
|||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # Matches "Clang" and "AppleClang" |
|||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5) |
|||
message(STATUS "Please enable readability-redundant-member-init (disabled due to #32966)") |
|||
endif() |
|||
endif() |
|||
|
|||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
|||
set(CLANG_TIDY_CHECKS "*") |
|||
|
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-llvm-header-guard") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-llvm-include-order") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-llvm-namespace-comment") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-readability-else-after-return") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-misc-macro-parentheses") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-clang-analyzer-alpha.core.CastToStruct") |
|||
# Modernize |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-modernize-raw-string-literal") |
|||
# CPP Core Guidelines |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-bounds-array-to-pointer-decay") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-bounds-constant-array-index") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-bounds-pointer-arithmetic") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-type-member-init") # as of https://llvm.org/bugs/show_bug.cgi?id=31039 |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-type-reinterpret-cast") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-type-vararg") |
|||
# Google |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-readability-namespace-comments") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-readability-braces-around-statements,-readability-braces-around-statements") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-readability-todo") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-runtime-int") |
|||
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-runtime-references") |
|||
set(CLANG_TIDY_CHECKS "-checks='${CLANG_TIDY_CHECKS}'") |
|||
#message(STATUS "Enabled checks for clang-tidy: ${CLANG_TIDY_CHECKS}") |
|||
endif() |
|||
|
|||
find_program(CLANG_FORMAT clang-format) |
|||
if(NOT CLANG_FORMAT) |
|||
message(STATUS "Did not find clang-format, target format is disabled.") |
|||
else() |
|||
message(STATUS "Found clang-format, use \"make format\" to run it.") |
|||
|
|||
add_custom_target(format |
|||
COMMAND find ./ -iname "*.h" -o -iname "*.tpp" -o -iname "*.cpp" | xargs ${CLANG_FORMAT} -style=file -i -verbose |
|||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/ |
|||
) |
|||
endif() |
@ -0,0 +1,76 @@ |
|||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # Matches "Clang" and "AppleClang" |
|||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5) |
|||
message(FATAL_ERROR " clang version must be at least 3.5!") |
|||
endif() |
|||
if (APPLE) |
|||
message(STATUS "Using clang ${CMAKE_CXX_COMPILER_VERSION} on apple") |
|||
set(CMAKE_MACOSX_RPATH 1) |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -stdlib=libc++ -pthread") |
|||
else() |
|||
message(STATUS "Using clang ${CMAKE_CXX_COMPILER_VERSION}") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread") |
|||
endif() |
|||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -fomit-frame-pointer -msse -msse2 -funroll-loops") |
|||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1") |
|||
if (NOT "${CLANG_SANITIZER}" STREQUAL "none") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${CLANG_SANITIZER}") |
|||
endif() |
|||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
|||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) |
|||
message(FATAL_ERROR " g++ version must be at least 4.9!") |
|||
endif() |
|||
message(STATUS "Using g++ ${CMAKE_CXX_COMPILER_VERSION}") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wunknown-pragmas") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -fmax-errors=5 -fdiagnostics-color=auto") |
|||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") |
|||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1") |
|||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
|||
message("-- Using Visual Studio C++ ${CMAKE_CXX_COMPILER_VERSION}") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP1 /D_SCL_SECURE_NO_WARNINGS") |
|||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /MT") |
|||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /bigobj") |
|||
else() |
|||
message(WARNING "Possibly unsupported compiler ${CMAKE_CXX_COMPILER_ID}") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
|||
endif() |
|||
|
|||
if(DEVELOPER) |
|||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall") |
|||
else() |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wconversion -Wno-deprecated-declarations") |
|||
endif() |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG -ftemplate-backtrace-limit=0") |
|||
#set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -print-search-dirs") |
|||
|
|||
if (ALLWARNINGS) |
|||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat -Wno-c++98-compat-pedantic") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-old-style-cast") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reserved-id-macro") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-newline-eof") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-documentation") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-vtables") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-global-constructors") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-exit-time-destructors") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch-enum") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-covered-switch-default") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-padded") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-float-equal") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedef") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-variable-declarations") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory") |
|||
endif() |
|||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weffc++") |
|||
endif() |
|||
endif() |
|||
|
|||
set(CMAKE_BUILD_TYPE "DEBUG") |
|||
endif() |
|||
|
|||
message(STATUS "CXX Flags: ${CMAKE_CXX_FLAGS}") |
|||
message(STATUS "CXX Debug Flags: ${CMAKE_CXX_FLAGS_DEBUG}") |
|||
message(STATUS "CXX Release Flags: ${CMAKE_CXX_FLAGS_RELEASE}") |
|||
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") |
3334
carl/cmake/cotire.cmake
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,19 @@ |
|||
#!/bin/sh |
|||
|
|||
CMAKE_BINARY_DIR=$1 |
|||
|
|||
mkdir -p ${CMAKE_BINARY_DIR}/coverage |
|||
mkdir -p ${CMAKE_BINARY_DIR}/coverage-out |
|||
rm -f ${CMAKE_BINARY_DIR}/coverage/* |
|||
rm -f ${CMAKE_BINARY_DIR}/coverage-out/* |
|||
|
|||
make |
|||
make test LLVM_PROFILE_FILE=${CMAKE_BINARY_DIR}/coverage/%p.profraw |
|||
|
|||
llvm-profdata merge -sparse ${CMAKE_BINARY_DIR}/coverage/*.profraw -o ${CMAKE_BINARY_DIR}/llvm.profdata |
|||
|
|||
llvm-cov show -instr-profile llvm.profdata libcarl.so > coverage-out/coverage.txt |
|||
for f in `ls bin/` ; do |
|||
llvm-cov show -instr-profile llvm.profdata bin/$f > coverage-out/coverage-$f.txt |
|||
done |
|||
cat coverage-out/*.txt > coverage.txt |
@ -0,0 +1,28 @@ |
|||
option( COVERAGE "Enable collection of coverage statistics" OFF ) |
|||
|
|||
if (COVERAGE) |
|||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
|||
#message(SEND_ERROR "Coverage collection with clang is not supported yet.") |
|||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -g -O0") |
|||
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping") |
|||
|
|||
add_custom_target(coverage-collect |
|||
COMMAND ${CMAKE_SOURCE_DIR}/cmake/coverage-clang.sh ${CMAKE_BINARY_DIR} |
|||
WORKING_DIRECTORY ${CMAKE_BUILD_DIR} |
|||
) |
|||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage --coverage -g -O0") |
|||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov") |
|||
|
|||
add_custom_target(coverage-collect |
|||
COMMAND lcov --directory . --zerocounters |
|||
COMMAND make test |
|||
COMMAND lcov --directory . --base-directory . --capture -o coverage.info |
|||
COMMAND lcov --remove coverage.info '/usr/*' 'build/resources/*' 'src/tests/*' --output-file coverage.info |
|||
COMMAND genhtml coverage.info -o "coverage/" |
|||
WORKING_DIRECTORY ${CMAKE_BUILD_DIR} |
|||
) |
|||
endif() |
|||
|
|||
endif() |
@ -0,0 +1,71 @@ |
|||
option(EXPORT_TO_CMAKE "Export the project to CMake for easy inclusion" ON) |
|||
|
|||
# Add all targets to the build-tree export set |
|||
export(TARGETS ${CARL_TARGETS} FILE "${PROJECT_BINARY_DIR}/carlTargets.cmake") |
|||
|
|||
|
|||
# Export the package for use from the build-tree |
|||
# (this registers the build-tree with a global CMake-registry) |
|||
if(EXPORT_TO_CMAKE) |
|||
message(STATUS "Registered with cmake") |
|||
export(PACKAGE carl) |
|||
endif() |
|||
|
|||
set(DEP_TARGETS "") |
|||
if(USE_BLISS) |
|||
export_target(DEP_TARGETS BLISS_SHARED) |
|||
export_target(DEP_TARGETS BLISS_STATIC) |
|||
endif() |
|||
if(USE_CLN_NUMBERS) |
|||
export_target(DEP_TARGETS CLN_SHARED) |
|||
export_target(DEP_TARGETS CLN_STATIC GMP_STATIC) |
|||
endif() |
|||
if(USE_GINAC) |
|||
export_target(DEP_TARGETS GINAC_SHARED CLN_SHARED) |
|||
export_target(DEP_TARGETS GINAC_STATIC CLN_STATIC) |
|||
endif() |
|||
if(USE_COCOA) |
|||
export_target(DEP_TARGETS COCOA_SHARED GMPXX_SHARED GMP_SHARED pthread) |
|||
export_target(DEP_TARGETS COCOA_STATIC GMPXX_STATIC GMP_STATIC pthread) |
|||
endif() |
|||
export_target(DEP_TARGETS GMP_SHARED) |
|||
export_target(DEP_TARGETS GMP_STATIC) |
|||
export_target(DEP_TARGETS GMPXX_SHARED) |
|||
export_target(DEP_TARGETS GMPXX_STATIC GMP_STATIC) |
|||
export_target(DEP_TARGETS EIGEN3) |
|||
|
|||
export_target_recursive(DEP_TARGETS Boost_SHARED INTERFACE_LINK_LIBRARIES) |
|||
export_target_recursive(DEP_TARGETS Boost_STATIC INTERFACE_LINK_LIBRARIES) |
|||
|
|||
export_target(DEP_TARGETS Doxygen::doxygen) |
|||
|
|||
set(EXP_OPTIONS "") |
|||
foreach(option ${EXPORTED_OPTIONS}) |
|||
set(EXP_OPTIONS "${EXP_OPTIONS}\nset(CARL_${option} \"${${option}}\")") |
|||
endforeach() |
|||
|
|||
include(CMakePackageConfigHelpers) |
|||
|
|||
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/carlConfigVersion.cmake |
|||
COMPATIBILITY AnyNewerVersion |
|||
) |
|||
|
|||
# ... for the build tree |
|||
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src") # TODO looks not correct, this would be hypro_INCLUDE_DIR |
|||
|
|||
configure_package_config_file( |
|||
cmake/carlConfig.cmake.in |
|||
${PROJECT_BINARY_DIR}/carlConfig.cmake |
|||
INSTALL_DESTINATION ${PROJECT_BINARY_DIR} |
|||
PATH_VARS INCLUDE_INSTALL_DIR #SYSCONFIG_INSTALL_DIR |
|||
) |
|||
# ... for the install tree |
|||
file(RELATIVE_PATH REL_INCLUDE_DIR "${CMAKE_INSTALL_DIR}" "${INCLUDE_INSTALL_DIR}") |
|||
set(CONF_INCLUDE_DIRS "\${carl_CMAKE_DIR}/${REL_INCLUDE_DIR}") |
|||
|
|||
configure_package_config_file( |
|||
cmake/carlConfig.cmake.in |
|||
${PROJECT_BINARY_DIR}/carlConfig.install.cmake |
|||
INSTALL_DESTINATION ${CMAKE_INSTALL_DIR} |
|||
PATH_VARS INCLUDE_INSTALL_DIR #SYSCONFIG_INSTALL_DIR |
|||
) |
@ -0,0 +1,34 @@ |
|||
|
|||
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER 3.0) |
|||
|
|||
include(GNUInstallDirs) |
|||
|
|||
install( |
|||
DIRECTORY ${CMAKE_SOURCE_DIR}/src/carl/ |
|||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/carl |
|||
FILES_MATCHING REGEX ".*\.(h|tpp)$" |
|||
) |
|||
|
|||
install( |
|||
TARGETS lib_carl |
|||
EXPORT carl_Targets |
|||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
|||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
|||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
|||
) |
|||
|
|||
if(BUILD_STATIC) |
|||
install( |
|||
TARGETS lib_carl_static |
|||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
|||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
|||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
|||
) |
|||
endif() |
|||
|
|||
install(FILES ${CMAKE_BINARY_DIR}/carlConfig.install.cmake DESTINATION ${CMAKE_INSTALL_DIR} RENAME carlConfig.cmake) |
|||
install(FILES ${CMAKE_BINARY_DIR}/carlConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_DIR}) |
|||
install(EXPORT carl_Targets FILE carlTargets.cmake DESTINATION ${CMAKE_INSTALL_DIR}) |
|||
else() |
|||
message(STATUS "Disabled install target due to cmake version less than 3.1") |
|||
endif() |
Some files were not shown because too many files changed in this diff
Reference in new issue