Compare commits
428 Commits
v3.0.2-rc.
...
develop
Author | SHA1 | Date | |
---|---|---|---|
af325e3991 | |||
31542c6adc | |||
2d0e4b09fa | |||
2288fa891e | |||
7c02b46f7c | |||
1c44dfcda7 | |||
b93e41d5bc | |||
0ff78f43e6 | |||
0f039f0837 | |||
9d04996b0a | |||
b2280c155a | |||
f7e089042d | |||
ce4fe6a113 | |||
3e2adf6db4 | |||
8ff87985f5 | |||
9fde2b8e1b | |||
c283adc42a | |||
9281592c39 | |||
6889e97f47 | |||
23130134bb | |||
5af0c26650 | |||
39410ac98b | |||
5621820fe4 | |||
9e9040cac0 | |||
0cf84dd5ca | |||
b063f5047e | |||
08a2eebe2c | |||
010e7bf41e | |||
|
a1a80332ca | ||
f0e553df23 | |||
0d0a4337a2 | |||
b21b4f47bf | |||
3a7b61de68 | |||
|
efee22a655 | ||
4faa8813e4 | |||
dd1b2f9636 | |||
a31d8638e7 | |||
6af0d4ec7a | |||
021e6c439c | |||
e87f86af95 | |||
ca7ae883ee | |||
72fc7493b2 | |||
1631a70a0b | |||
27f773e091 | |||
6d07fcbd6c | |||
6415f871d7 | |||
feaef5a3fa | |||
624ddc38aa | |||
9803710ff3 | |||
4d8525f52d | |||
d0b7f89925 | |||
032fa14f61 | |||
8b487b0a82 | |||
f6eed53550 | |||
cb61f7cc5e | |||
5ec4dd2aaf | |||
b8bd42d361 | |||
89edafb586 | |||
0d5245b48b | |||
d20b30d34d | |||
b99e7c198a | |||
c3b6d6939f | |||
868c220e42 | |||
cde892c771 | |||
974c94fbb0 | |||
2be3f4256a | |||
5427876e36 | |||
abdc4e31dc | |||
db7ea6f2fe | |||
d8b2aa9720 | |||
63c4da8fad | |||
3fe2886925 | |||
86486207b8 | |||
569b170aba | |||
f6c9e19a60 | |||
6b891fcb8e | |||
|
8b6c4beed8 | ||
|
5e0c8a695c | ||
46cd4de854 | |||
871d3fcdb3 | |||
4ad9355e47 | |||
1dee4655a7 | |||
0a104d222c | |||
80167fd21b | |||
7de9980c10 | |||
89f3eb0306 | |||
716b4801aa | |||
9199b68080 | |||
|
a24ce91acb | ||
|
9ab1ea1c23 | ||
8b232e0155 | |||
aec16f4407 | |||
b2ac47c2d3 | |||
31cf6d287d | |||
b282225363 | |||
95c03396d0 | |||
a5038535f4 | |||
d82ae8544b | |||
0caef2e81c | |||
cb333fd420 | |||
f61cfa532d | |||
39b885c47c | |||
da85683f7c | |||
0beab67bd4 | |||
4622f31fa4 | |||
0eff8e5dcf | |||
1516561a58 | |||
5c93840f85 | |||
ea50cffac9 | |||
8a48a5043a | |||
cc90ef3ec6 | |||
31e5ead21e | |||
d451d2d548 | |||
729ecc9475 | |||
6c9ca0ccb8 | |||
6b1d079f69 | |||
6e858ff52f | |||
ca02b8ce62 | |||
2b0b6570ea | |||
909949ff22 | |||
436933f73f | |||
4d59732263 | |||
12efe41551 | |||
362222c882 | |||
fcb9aa0a76 | |||
d9bae984b2 | |||
994801525a | |||
939c2c735c | |||
287e1041bd | |||
9845c5ae9e | |||
7ae2734e9f | |||
d5dd8e849f | |||
079e2ac539 | |||
aeb8132fc7 | |||
dd51f2b4fd | |||
d7e0beabdf | |||
9d1a8f4c0f | |||
e4f4b5e066 | |||
19f2c2ebf8 | |||
2851f8d286 | |||
9360ad3487 | |||
c0b71290a4 | |||
3d9bf2582f | |||
cbc9c86edd | |||
480da6ff09 | |||
834209d506 | |||
ef606f3d9b | |||
b5131fa00d | |||
768afa9bf5 | |||
59dc239c67 | |||
ec546758a8 | |||
e93085d88a | |||
595891f040 | |||
b7b4d926b4 | |||
12e55da662 | |||
08c55adfbd | |||
ec8007125f | |||
17985e3b5a | |||
002f875c53 | |||
39c0e27cb2 | |||
97c6e58355 | |||
7162fa76f6 | |||
f5a73f09f8 | |||
ee56a105b3 | |||
19f2ad19b0 | |||
178a55d29e | |||
ff782a8642 | |||
e345fd60fd | |||
9c7532bd9d | |||
9d906a195a | |||
2d44ca7955 | |||
799c9ce2fb | |||
c35faab104 | |||
ce812d449b | |||
17b8306394 | |||
df2359712f | |||
de648fbb1d | |||
d0d141ef99 | |||
40b43217fc | |||
c6c36273b5 | |||
586e93190c | |||
9fe489de53 | |||
60d8b9ba77 | |||
1379c24362 | |||
bbf2a7d02d | |||
4c0583c91f | |||
04dffdb09e | |||
dd7fb31309 | |||
268fa84c9e | |||
b9b987490b | |||
230844c3ae | |||
6ce4eecb18 | |||
e364d01cf4 | |||
04ded5e8b8 | |||
83a36003b1 | |||
fc48b8f694 | |||
b0db73ab2f | |||
195cffbf88 | |||
bfb382de52 | |||
101f33df6e | |||
615167e7cd | |||
dde277cc3e | |||
7ead2277e8 | |||
da2a3eefa4 | |||
3877012274 | |||
e0aca18b38 | |||
19c81effbe | |||
f83f9edbef | |||
f90009b6d1 | |||
fbcb790611 | |||
8c98548dbc | |||
20c687a787 | |||
d376c1a993 | |||
10e658a922 | |||
9c30e27875 | |||
14c498c539 | |||
f4c1d65365 | |||
34d9c7a1c2 | |||
0d3cb152f9 | |||
63e15d37e8 | |||
51249fd678 | |||
0de5b9eb56 | |||
8288345bcb | |||
f349b5e351 | |||
de69003105 | |||
c84cafda18 | |||
78b4636028 | |||
9fbe0db567 | |||
1876d1fe0b | |||
30a092b365 | |||
464550cb5b | |||
a6babf3e90 | |||
62b9da844a | |||
fa9fd0935b | |||
1e77a6b043 | |||
216decafc1 | |||
849faad134 | |||
9642bab0c8 | |||
517698475c | |||
0b8da69394 | |||
a7c4fdb242 | |||
06b9632b70 | |||
94dd209e5e | |||
5d65cc3100 | |||
2042d6329d | |||
ff1d582605 | |||
b3fd49ef97 | |||
8a103ea89d | |||
29f8ee0778 | |||
5f240b632a | |||
d711fcd0f1 | |||
e312a91632 | |||
c10187f6ba | |||
d7db0d8ccd | |||
d2f9e55e68 | |||
ebcf263abd | |||
27c6b69874 | |||
386e5356af | |||
88cb8f4516 | |||
9c9995380e | |||
|
ff8dc0e85f | ||
|
1b94053542 | ||
|
d1f1f9230c | ||
|
59e95c7097 | ||
|
18f4a87dd7 | ||
|
664762fdec | ||
|
1458d93408 | ||
33e61beb4f | |||
0b31d8d56c | |||
cb2db2cadf | |||
f1d2c4e532 | |||
a07d105906 | |||
31182b6de9 | |||
586f53a788 | |||
1561aa5eb9 | |||
f4672a5b50 | |||
a5f1ebdc09 | |||
8587aa23c4 | |||
66cb09c8e4 | |||
6355921e59 | |||
4172d320e4 | |||
a8ba375e36 | |||
2334686c59 | |||
ebab65e233 | |||
692d3fe83a | |||
3b110c0b8a | |||
443c126b88 | |||
eb4798df4e | |||
c1340f6297 | |||
9e1cdaaa51 | |||
cfce6b1bbd | |||
c4e19dddae | |||
9b49b8ebe7 | |||
8b069d8149 | |||
f4efb4f3d4 | |||
180cc33ded | |||
431b33a4da | |||
58e784408c | |||
91b2a23c78 | |||
cbbe942dfd | |||
8bab1e19cb | |||
c80688b241 | |||
|
b1e98bd091 | ||
|
367f49253e | ||
|
6f1a64a705 | ||
|
f12ac1c839 | ||
|
03c83702ad | ||
|
e2c38b5459 | ||
|
7f62503237 | ||
e1e9efde25 | |||
fb3f847f6a | |||
|
888f12d88d | ||
|
b8357629a2 | ||
1b56e9ed9b | |||
ba63a9fb05 | |||
2585f726c5 | |||
|
dadb1801aa | ||
37732f35dd | |||
|
2f6255a4e8 | ||
5d8c143e60 | |||
0b94e315b4 | |||
4a422795d9 | |||
1a27a21fa1 | |||
bba069599f | |||
ba751f8c35 | |||
1f7ee57889 | |||
d4faaf428c | |||
a163278fb5 | |||
1e2573d3e7 | |||
5c5f0665e8 | |||
0ca51236bd | |||
a62cc8b3b9 | |||
cc0b9726ed | |||
bec63898af | |||
9cccba42e0 | |||
4fc9b35c13 | |||
34496a7158 | |||
e0ed145716 | |||
2e52357dd2 | |||
104f7165cd | |||
edbc8770e3 | |||
31068bf89c | |||
ad6b3d60eb | |||
bd2ef96216 | |||
faa920e1ad | |||
eb28ed3938 | |||
f4f0e07bc1 | |||
ca6664feb2 | |||
6f3769f364 | |||
0c5936ad38 | |||
263b611a7b | |||
79d449d0df | |||
dd621fcd5c | |||
c2af84a800 | |||
3fa7b93d44 | |||
4d72c20d9b | |||
97ad4268d7 | |||
ed2d64c1c9 | |||
c9ecd0c020 | |||
6aaf7c039d | |||
7aa20a5820 | |||
9afabacde3 | |||
f10f4ac29c | |||
da88a8816c | |||
63de1891af | |||
23e851ccef | |||
5f406e6b18 | |||
9aad139aae | |||
4fb2c331f3 | |||
1a96c3ec72 | |||
b084a1f727 | |||
56ce55677f | |||
c528626fe9 | |||
8361f3767b | |||
b72a17c190 | |||
6842bff04b | |||
6bec233e23 | |||
873ccef4ff | |||
4706d2915f | |||
1d59ad20c1 | |||
b4f7e4f102 | |||
e664fe8470 | |||
28b9d22a4c | |||
be376a9ffb | |||
76f8df13fc | |||
9447912fbf | |||
87717606b2 | |||
|
348bc32cef | ||
|
fcdb0b65c2 | ||
|
0fb79d1268 | ||
|
69757e50ac | ||
06feeab244 | |||
568945c7a8 | |||
dd33e47dd9 | |||
|
7dfe760285 | ||
|
d7b8cec50d | ||
|
92f3018b89 | ||
3806fba9c2 | |||
b44c04d3c0 | |||
220b9959a3 | |||
f8ec341015 | |||
3ceeb3ae40 | |||
56f0091f1e | |||
ec886e345b | |||
786eabb748 | |||
fa18dc7979 | |||
136f9ed00a | |||
e312740629 | |||
31d0a1fb38 | |||
ca30f8a815 | |||
21c337e0fa | |||
8251652445 | |||
5e28dd046b | |||
363070b579 | |||
63ed1299ec | |||
7bd483cd7e | |||
91019f52aa | |||
69a26cb22f | |||
cdb06fa5bf | |||
9c76ce7174 | |||
676dc44619 | |||
b8a3019e5b | |||
e0a15849df | |||
ef57f27c6a | |||
169c5ae8e9 | |||
760143a4a2 | |||
b100bcd446 | |||
04ddbaabae |
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -4,3 +4,4 @@
|
||||
.travis.yml export-ignore
|
||||
|
||||
tests/data/* linguist-documentation
|
||||
instances/* linguist-documentation
|
||||
|
16
.gitmodules
vendored
16
.gitmodules
vendored
@ -1,4 +1,12 @@
|
||||
[submodule "tests/googletest"]
|
||||
path = tests/googletest
|
||||
url = https://github.com/google/googletest.git
|
||||
ignore = dirty
|
||||
[submodule "lib/catch"]
|
||||
path = lib/catch
|
||||
url = https://github.com/catchorg/Catch2
|
||||
[submodule "lib/variant"]
|
||||
path = lib/variant
|
||||
url = https://github.com/mapbox/variant
|
||||
[submodule "tests/data/pddl-instances"]
|
||||
path = tests/data/pddl-instances
|
||||
url = https://github.com/potassco/pddl-instances.git
|
||||
[submodule "lib/cxxopts"]
|
||||
path = lib/cxxopts
|
||||
url = https://github.com/jarro2783/cxxopts
|
||||
|
34
.travis.yml
34
.travis.yml
@ -1,25 +1,29 @@
|
||||
# Use container-based distribution
|
||||
sudo: false
|
||||
language: c++
|
||||
addons:
|
||||
apt:
|
||||
sources: &default_sources
|
||||
- ubuntu-toolchain-r-test
|
||||
matrix:
|
||||
include:
|
||||
- compiler: gcc
|
||||
- env: COMPILER_NAME=g++ _CXX=g++-6
|
||||
os: linux
|
||||
language: cpp
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- boost-latest
|
||||
- *default_sources
|
||||
packages:
|
||||
- g++-5
|
||||
- libboost-program-options1.55-dev
|
||||
- libboost-iostreams1.55-dev
|
||||
- libboost-system1.55-dev
|
||||
- libboost-filesystem1.55-dev
|
||||
env: COMPILER=g++-5
|
||||
- g++-6
|
||||
script:
|
||||
- git submodule init
|
||||
- git submodule update
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$COMPILER
|
||||
- make -j3 && make -j3 run-tests
|
||||
- if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
|
||||
CMAKE_URL="http://www.cmake.org/files/v3.9/cmake-3.9.4-Linux-x86_64.tar.gz";
|
||||
mkdir cmake-bin && wget --quiet --no-check-certificate -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake-bin;
|
||||
export PATH=${PWD}/cmake-bin/bin:${PATH};
|
||||
fi
|
||||
- git submodule update --recursive --init
|
||||
- mkdir -p build/debug
|
||||
- cd build/debug
|
||||
- cmake ../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$_CXX -DTOKENIZE_BUILD_TESTS=ON -DPDDL_BUILD_TESTS=ON -DPLASP_BUILD_TESTS=ON
|
||||
- make -j3 plasp-app && make -j3 run-tokenize-tests && make -j3 run-pddl-tests && make -j3 run-tests
|
||||
|
60
CHANGELOG.md
60
CHANGELOG.md
@ -1,19 +1,67 @@
|
||||
# Change Log
|
||||
# Changelog
|
||||
|
||||
## (unreleased)
|
||||
|
||||
Features:
|
||||
## 3.1.1 (2017-11-25)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fixes ASP syntax issues caused by hyphens in variable names by replacing all user-defined variables with `X1`, `X2`, etc.
|
||||
|
||||
## 3.1.0 (2017-11-17)
|
||||
|
||||
### Changes
|
||||
|
||||
* new command-line interface based on `plasp` commands:
|
||||
* `plasp translate`: translate PDDL and SAS to ASP facts (replaces former, plain `plasp` calls)
|
||||
* `plasp normalize`: normalize PDDL to plasp’s custom PDDL format
|
||||
* `plasp check-syntax`: check the syntax of PDDL specifications
|
||||
* `plasp beautify`: cleanly format PDDL specifications
|
||||
* new output format to accommodate for new PDDL features
|
||||
|
||||
### Features
|
||||
|
||||
* extended PDDL 3.1 support:
|
||||
* arbitrarily nested expressions in preconditions, effects, and goal description (via derived predicates)
|
||||
* universal and existential quantifiers
|
||||
* disjunctions
|
||||
* conditional effects
|
||||
* implications
|
||||
* equality (parser only)
|
||||
* new output option `--log-level` to control which status messages to show
|
||||
* new basic option `--warnings-as-errors` to abort program execution upon warnings (replaces `--warning-level`)
|
||||
* new compatibility mode for parser to support more legacy domains
|
||||
* new parser option `--parsing-mode` to specify whether to apply strict or compatibility parsing rules
|
||||
|
||||
### Internal
|
||||
|
||||
* PDDL parser reimplemented from scratch in stand-alone `pddl` library
|
||||
* removes dependency to Boost
|
||||
|
||||
## 3.0.3 (2016-09-02)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fixes incorrect output format of conditional effects with SAS
|
||||
* fixes parsing issue with unexpected whitespaces in SAS files
|
||||
|
||||
## 3.0.2 (2016-08-18)
|
||||
|
||||
### Features
|
||||
|
||||
* unified translation format for SAS and PDDL files
|
||||
* documentation of `plasp`’s output format
|
||||
* improved output syntax highlighting
|
||||
* uses ASP string literals to avoid escaping PDDL identifiers
|
||||
|
||||
Bug Fixes:
|
||||
### Bug Fixes
|
||||
|
||||
* fixes minor formatting issues in SAS translation
|
||||
* fixes issue with unsupported expression negations
|
||||
|
||||
## 3.0.1 (2016-06-14)
|
||||
|
||||
Features:
|
||||
### Features
|
||||
|
||||
* basic support for parsing PDDL 3.1 domains and problems
|
||||
* limited support for translating PDDL 3.1 domains and problems to ASP facts
|
||||
@ -24,13 +72,13 @@ Features:
|
||||
* new command-line option `--warning-level` to treat warnings as errors or to ignore warnings
|
||||
* new command-line option `--color` to autodetect, enable, or disable color output
|
||||
|
||||
Bug Fixes:
|
||||
### Bug Fixes
|
||||
|
||||
* fixes bug in translation of SAS axiom rules
|
||||
|
||||
## 3.0.0 (2016-05-24)
|
||||
|
||||
Features:
|
||||
### Features
|
||||
|
||||
* parses [SAS](http://www.fast-downward.org/TranslatorOutputFormat) files created with [Fast Downward](http://www.fast-downward.org/)
|
||||
* experimental translation from SAS to ASP facts
|
||||
|
@ -1,20 +1,40 @@
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
project(plasp CXX)
|
||||
|
||||
find_package(Boost 1.55.0 COMPONENTS program_options iostreams system filesystem REQUIRED)
|
||||
option(PLASP_BUILD_TESTS "Build unit tests" OFF)
|
||||
option(PLASP_BUILD_STATIC "Build static binaries" OFF)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
add_definitions(-std=c++14)
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Werror ${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g ${CMAKE_CXX_FLAGS_DEBUG}")
|
||||
|
||||
option(BUILD_TESTS "Build unit tests" ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
if(PLASP_BUILD_STATIC)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-static")
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS)
|
||||
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
|
||||
endif()
|
||||
|
||||
if (CMAKE_GENERATOR STREQUAL "Ninja" AND
|
||||
((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR
|
||||
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)))
|
||||
# Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support.
|
||||
# Rationale in https://github.com/ninja-build/ninja/issues/814
|
||||
set(CMAKE_CXX_FLAGS "-fdiagnostics-color=always ${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
|
||||
add_subdirectory(lib/tokenize)
|
||||
add_subdirectory(lib/colorlog)
|
||||
add_subdirectory(lib/pddl)
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(apps)
|
||||
if(BUILD_TESTS)
|
||||
add_subdirectory(app)
|
||||
if(PLASP_BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif(BUILD_TESTS)
|
||||
endif(PLASP_BUILD_TESTS)
|
||||
|
20
KNOWN-ISSUES.md
Normal file
20
KNOWN-ISSUES.md
Normal file
@ -0,0 +1,20 @@
|
||||
# Known Issues
|
||||
|
||||
## Parser
|
||||
|
||||
- multiple PDDL features are not yet supported (see list of PDDL features supported by `plasp`)
|
||||
- several error messages obtained with syntax errors are misleading
|
||||
|
||||
## Translator
|
||||
|
||||
- in compatibility mode, the outdated `vars` sections within action definitions are handled just like `parameters`, which is semantically incorrect
|
||||
- equality expressions currently partly supported by parser but not the translator
|
||||
|
||||
## ASP Output Format
|
||||
|
||||
- SAS axiom rules and `plasp`’s derived predicates (obtained through normalization) are semantically similar, but differently represented
|
||||
|
||||
## Encodings
|
||||
|
||||
- the [simple example encoding](encodings/sequential-horizon.lp) does not SAS axiom rules
|
||||
- [multiple encodings](encodings/outdated) are outdated and need to be adapted to the output format introduced with `plasp` 3.1.0
|
85
README.md
85
README.md
@ -1,74 +1,87 @@
|
||||
# plasp—Translate PDDL to ASP
|
||||
# plasp [![GitHub Release](https://img.shields.io/github/release/potassco/plasp.svg?maxAge=3600)](https://github.com/potassco/plasp/releases) [![Build Status](https://img.shields.io/travis/potassco/plasp/master.svg?maxAge=3600&label=build%20%28master%29)](https://travis-ci.org/potassco/plasp?branch=master) [![Build Status](https://img.shields.io/travis/potassco/plasp/develop.svg?maxAge=3600&label=build%20%28develop%29)](https://travis-ci.org/potassco/plasp?branch=develop)
|
||||
|
||||
[![GitHub Release](https://img.shields.io/github/release/potassco/plasp.svg?maxAge=3600)](https://github.com/potassco/plasp/releases)
|
||||
[![Build Status](https://img.shields.io/travis/potassco/plasp/develop.svg?maxAge=3600&label=build (master))](https://travis-ci.org/potassco/plasp?branch=master)
|
||||
[![Build Status](https://img.shields.io/travis/potassco/plasp/develop.svg?maxAge=3600&label=build (develop))](https://travis-ci.org/potassco/plasp?branch=develop)
|
||||
> ASP planning tools for PDDL
|
||||
|
||||
`plasp` 3 is in early development and not intended for productive use yet.
|
||||
## Overview
|
||||
|
||||
`plasp` translates planning problem instances to ASP facts.
|
||||
`plasp` 3 supports the input languages [PDDL 3.1](https://helios.hud.ac.uk/scommv/IPC-14/software.html) (only basic features currently) and [SAS](http://www.fast-downward.org/TranslatorOutputFormat) (full support of SAS 3), which is used by [Fast Downward](http://www.fast-downward.org/).
|
||||
`plasp` is a tool collection for planning in [*answer set programming*](https://en.wikipedia.org/wiki/Answer_set_programming).
|
||||
`plasp` 3 supports the input languages [PDDL 3.1](https://helios.hud.ac.uk/scommv/IPC-14/software.html) (except for advanced features such as durative actions, numerical fluents, and preferences) and [SAS](http://www.fast-downward.org/TranslatorOutputFormat) (full support of SAS 3), which is used by [Fast Downward](http://www.fast-downward.org/).
|
||||
|
||||
Please get in touch with [Patrick Lühne](https://www.luehne.de) if you have any suggestions.
|
||||
The most notable tool provided by `plasp` is `plasp translate`, which translates PDDL descriptions to ASP facts.
|
||||
|
||||
## Usage
|
||||
|
||||
### Translating PDDL to ASP Facts
|
||||
## Translating PDDL to ASP Facts
|
||||
|
||||
PDDL instances are translated to ASP facts as follows:
|
||||
|
||||
```bash
|
||||
$ plasp domain.pddl problem.pddl
|
||||
```sh
|
||||
plasp translate domain.pddl problem.pddl
|
||||
```
|
||||
|
||||
Alternatively, PDDL instances may first be translated to SAS, the output format of [Fast Downward](http://www.fast-downward.org/).
|
||||
|
||||
```bash
|
||||
$ ./fast-downward.py --translate --build=release64 domain.pddl problem.pddl
|
||||
```sh
|
||||
./fast-downward.py --translate --build=release64 domain.pddl problem.pddl
|
||||
```
|
||||
|
||||
This creates a file called `output.sas`, which may now be translated by `plasp`.
|
||||
This creates a file called `output.sas`, which may now be translated by `plasp` as well.
|
||||
|
||||
```bash
|
||||
$ plasp output.sas
|
||||
```sh
|
||||
plasp translate output.sas
|
||||
```
|
||||
|
||||
### Solving the Translated Instance
|
||||
|
||||
The translated instance can finally be solved incrementally with `clingo` and a meta encoding, for instance, `pddl-meta-sequential-incremental.lp`:
|
||||
The translated instance can finally be solved with `clingo` and a meta encoding, for instance, [`sequential-horizon.lp`](encodings/sequential-horizon.lp):
|
||||
|
||||
```bash
|
||||
$ plasp domain.pddl problem.pddl > instance.lp
|
||||
$ clingo encodings/pddl-meta-sequential-incremental.lp instance.lp
|
||||
```sh
|
||||
plasp translate domain.pddl problem.pddl > instance.lp
|
||||
clingo encodings/sequential-horizon.lp -c horizon=10 instance.lp
|
||||
```
|
||||
|
||||
## Command-Line Interface
|
||||
### Translator Output Format
|
||||
|
||||
```bash
|
||||
$ plasp [files] [options]
|
||||
`plasp translate` provides a uniform output format for SAS and PDDL input problems.
|
||||
See [output format](doc/output-format.md) for more details.
|
||||
|
||||
If you want to write your own meta encoding for `plasp translate`’s output, this [simple example encoding](encodings/sequential-horizon.lp) gets you started.
|
||||
|
||||
## Provided Tools
|
||||
|
||||
```sh
|
||||
plasp <command> [<option>...] [<input file>...]
|
||||
```
|
||||
|
||||
`plasp` automatically detects the language of the input program.
|
||||
Aside from translating PDDL to ASP facts, `plasp` provides the following commands:
|
||||
|
||||
See [command-line interface](doc/command-line-interface.md) for more detail.
|
||||
| command | description |
|
||||
|---|---|
|
||||
| `translate` | Translate PDDL and SAS to ASP facts |
|
||||
| `normalize` | Normalize PDDL to plasp’s custom PDDL format |
|
||||
| `check-syntax` | Check the syntax of PDDL specifications |
|
||||
| `beautify` | Cleanly format PDDL specifications |
|
||||
| `help` | Display help message |
|
||||
| `version` | Display version information |
|
||||
|
||||
## Output Format
|
||||
`plasp help` shows a list of all commands provided by `plasp`.
|
||||
To list all available options of a command, call `plasp <command> --help` or `plasp help <command>`.
|
||||
|
||||
`plasp` provides a uniform output format for SAS and PDDL input problems.
|
||||
|
||||
See [output format](doc/output-format.md) for more detail.
|
||||
|
||||
If you want to write your own meta encoding for `plasp`’s output, this [simple example encoding](encodings/sequential-incremental.lp) gets you started.
|
||||
`plasp` automatically detects the language (PDDL or SAS) of the input descriptions.
|
||||
|
||||
## Building
|
||||
|
||||
`plasp` requires `boost` and is built via CMake and a C++ compiler.
|
||||
`plasp` is built with CMake and a C++ compiler.
|
||||
See [building](doc/building.md) for more details.
|
||||
|
||||
See [building instructions](doc/building-instructions.md) for more detail.
|
||||
## PDDL Feature Support
|
||||
|
||||
`plasp` supports a subset of PDDL 3.1.
|
||||
See [PDDL feature support](doc/pddl-feature-support.md) for a list of supported and unsupported PDDL 3.1 features.
|
||||
|
||||
## Contributors
|
||||
|
||||
* [Patrick Lühne](https://www.luehne.de) (`plasp` 3)
|
||||
* [Patrick Lühne](https://www.luehne.de)
|
||||
* Martin Gebser (encodings)
|
||||
* Torsten Schaub (encodings)
|
||||
|
||||
### Earlier Versions
|
||||
|
||||
|
1
app/CMakeLists.txt
Normal file
1
app/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
add_subdirectory(src)
|
71
app/include/plasp-app/Command.h
Normal file
71
app/include/plasp-app/Command.h
Normal file
@ -0,0 +1,71 @@
|
||||
#ifndef __PLASP_APP__COMMAND_H
|
||||
#define __PLASP_APP__COMMAND_H
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#include <cxxopts.hpp>
|
||||
|
||||
#include <plasp-app/Utils.h>
|
||||
#include <plasp-app/Version.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived, class... OptionGroups>
|
||||
class Command
|
||||
{
|
||||
public:
|
||||
void printHelp()
|
||||
{
|
||||
const auto numberOfOptionGroups = std::tuple_size<std::decay_t<decltype(m_optionGroups)>>();
|
||||
|
||||
std::vector<std::string> optionGroupNames;
|
||||
optionGroupNames.reserve(numberOfOptionGroups + 1);
|
||||
optionGroupNames.emplace_back("");
|
||||
|
||||
forEach(m_optionGroups,
|
||||
[&](auto &optionGroup)
|
||||
{
|
||||
optionGroupNames.emplace_back(optionGroup.Name);
|
||||
});
|
||||
|
||||
std::cout << m_options.help(optionGroupNames) << std::endl;
|
||||
}
|
||||
|
||||
protected:
|
||||
Command()
|
||||
: m_options(std::string("plasp ") + Derived::Name, std::string(Derived::Description) + ".")
|
||||
{
|
||||
forEach(m_optionGroups,
|
||||
[&](auto &optionGroup)
|
||||
{
|
||||
optionGroup.addTo(m_options);
|
||||
});
|
||||
}
|
||||
|
||||
void parseOptions(int argc, char **argv)
|
||||
{
|
||||
const auto parseResult = m_options.parse(argc, argv);
|
||||
|
||||
forEach(m_optionGroups,
|
||||
[&](auto &optionGroup)
|
||||
{
|
||||
optionGroup.read(parseResult);
|
||||
});
|
||||
}
|
||||
|
||||
static void printVersion()
|
||||
{
|
||||
std::cout << Version << std::endl;
|
||||
}
|
||||
|
||||
cxxopts::Options m_options;
|
||||
std::tuple<OptionGroups...> m_optionGroups;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
67
app/include/plasp-app/CommandType.h
Normal file
67
app/include/plasp-app/CommandType.h
Normal file
@ -0,0 +1,67 @@
|
||||
#ifndef __PLASP_APP__COMMAND_TYPE_H
|
||||
#define __PLASP_APP__COMMAND_TYPE_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <plasp-app/commands/CommandBeautify.h>
|
||||
#include <plasp-app/commands/CommandCheckSyntax.h>
|
||||
#include <plasp-app/commands/CommandHelp.h>
|
||||
#include <plasp-app/commands/CommandNormalize.h>
|
||||
#include <plasp-app/commands/CommandTranslate.h>
|
||||
#include <plasp-app/commands/CommandVersion.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Type
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class CommandType
|
||||
{
|
||||
Help,
|
||||
Version,
|
||||
CheckSyntax,
|
||||
Requirements,
|
||||
Beautify,
|
||||
Normalize,
|
||||
Translate
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const std::map<std::string, CommandType> commandNames =
|
||||
{
|
||||
{"help", CommandType::Help},
|
||||
{"-h", CommandType::Help},
|
||||
{"--help", CommandType::Help},
|
||||
{"version", CommandType::Version},
|
||||
{"-v", CommandType::Version},
|
||||
{"--version", CommandType::Version},
|
||||
{"check-syntax", CommandType::CheckSyntax},
|
||||
{"requirements", CommandType::Requirements},
|
||||
{"beautify", CommandType::Beautify},
|
||||
{"normalize", CommandType::Normalize},
|
||||
{"translate", CommandType::Translate},
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const auto parseCommandType =
|
||||
[](const std::string &commandString)
|
||||
{
|
||||
const auto matchingCommand = commandNames.find(commandString);
|
||||
|
||||
if (matchingCommand == commandNames.cend())
|
||||
throw std::runtime_error(std::string("“") + commandString + "” is not a plasp command");
|
||||
|
||||
return matchingCommand->second;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using AvailableCommands = std::tuple<CommandTranslate, CommandNormalize, CommandCheckSyntax, CommandBeautify, CommandHelp, CommandVersion>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
69
app/include/plasp-app/OptionGroups.h
Normal file
69
app/include/plasp-app/OptionGroups.h
Normal file
@ -0,0 +1,69 @@
|
||||
#ifndef __PLASP_APP__OPTION_GROUPS_H
|
||||
#define __PLASP_APP__OPTION_GROUPS_H
|
||||
|
||||
#include <cxxopts.hpp>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
#include <colorlog/Priority.h>
|
||||
|
||||
#include <pddl/Exception.h>
|
||||
#include <pddl/Mode.h>
|
||||
|
||||
#include <plasp/Language.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Option Groups
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class OptionException : public pddl::Exception
|
||||
{
|
||||
public:
|
||||
using Exception::Exception;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct OptionGroupBasic
|
||||
{
|
||||
static constexpr const auto Name = "basic";
|
||||
|
||||
void addTo(cxxopts::Options &options);
|
||||
void read(const cxxopts::ParseResult &parseResult);
|
||||
|
||||
bool help = false;
|
||||
bool version = false;
|
||||
bool warningsAsErrors = false;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct OptionGroupOutput
|
||||
{
|
||||
static constexpr const auto Name = "output";
|
||||
|
||||
void addTo(cxxopts::Options &options);
|
||||
void read(const cxxopts::ParseResult &parseResult);
|
||||
|
||||
colorlog::ColorStream::ColorPolicy colorPolicy = colorlog::ColorStream::ColorPolicy::Auto;
|
||||
colorlog::Priority logPriority = colorlog::Priority::Info;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct OptionGroupParser
|
||||
{
|
||||
static constexpr const auto Name = "parser";
|
||||
|
||||
void addTo(cxxopts::Options &options);
|
||||
void read(const cxxopts::ParseResult &parseResult);
|
||||
|
||||
std::vector<std::string> inputFiles;
|
||||
pddl::Mode parsingMode = pddl::Mode::Strict;
|
||||
plasp::Language::Type language = plasp::Language::Type::Automatic;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
46
app/include/plasp-app/Utils.h
Normal file
46
app/include/plasp-app/Utils.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef __PLASP_APP__UTILS_H
|
||||
#define __PLASP_APP__UTILS_H
|
||||
|
||||
#include <cxxopts.hpp>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <std::size_t... Index>
|
||||
auto makeIndexDispatcher(std::index_sequence<Index...>)
|
||||
{
|
||||
return
|
||||
[](auto &&f)
|
||||
{
|
||||
(f(std::integral_constant<std::size_t, Index>{}), ...);
|
||||
};
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <std::size_t N>
|
||||
auto makeIndexDispatcher()
|
||||
{
|
||||
return makeIndexDispatcher(std::make_index_sequence<N>{});
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename Tuple, typename Functor>
|
||||
void forEach(Tuple &&tuple, Functor &&functor)
|
||||
{
|
||||
constexpr auto n = std::tuple_size<std::decay_t<Tuple>>::value;
|
||||
auto dispatcher = makeIndexDispatcher<n>();
|
||||
dispatcher(
|
||||
[&functor, &tuple](auto index)
|
||||
{
|
||||
functor(std::get<index>(std::forward<Tuple>(tuple)));
|
||||
});
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
14
app/include/plasp-app/Version.h
Normal file
14
app/include/plasp-app/Version.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef __PLASP_APP__VERSION_H
|
||||
#define __PLASP_APP__VERSION_H
|
||||
|
||||
#include <string>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static constexpr const auto Version = "plasp version 3.1.1-git";
|
||||
|
||||
#endif
|
25
app/include/plasp-app/commands/CommandBeautify.h
Normal file
25
app/include/plasp-app/commands/CommandBeautify.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __PLASP_APP__COMMANDS__COMMAND_BEAUTIFY_H
|
||||
#define __PLASP_APP__COMMANDS__COMMAND_BEAUTIFY_H
|
||||
|
||||
#include <plasp-app/Command.h>
|
||||
#include <plasp-app/OptionGroups.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Beautify
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CommandBeautify : public Command<CommandBeautify, OptionGroupBasic, OptionGroupOutput, OptionGroupParser>
|
||||
{
|
||||
public:
|
||||
static constexpr auto Name = "beautify";
|
||||
static constexpr auto Description = "Cleanly format PDDL specifications";
|
||||
|
||||
public:
|
||||
int run(int argc, char **argv);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
25
app/include/plasp-app/commands/CommandCheckSyntax.h
Normal file
25
app/include/plasp-app/commands/CommandCheckSyntax.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __PLASP_APP__COMMANDS__COMMAND_CHECK_SYNTAX_H
|
||||
#define __PLASP_APP__COMMANDS__COMMAND_CHECK_SYNTAX_H
|
||||
|
||||
#include <plasp-app/Command.h>
|
||||
#include <plasp-app/OptionGroups.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Check Syntax
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CommandCheckSyntax : public Command<CommandCheckSyntax, OptionGroupBasic, OptionGroupOutput, OptionGroupParser>
|
||||
{
|
||||
public:
|
||||
static constexpr auto Name = "check-syntax";
|
||||
static constexpr auto Description = "Check the syntax of PDDL specifications";
|
||||
|
||||
public:
|
||||
int run(int argc, char **argv);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
25
app/include/plasp-app/commands/CommandHelp.h
Normal file
25
app/include/plasp-app/commands/CommandHelp.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __PLASP_APP__COMMANDS__COMMAND_HELP_H
|
||||
#define __PLASP_APP__COMMANDS__COMMAND_HELP_H
|
||||
|
||||
#include <plasp-app/Command.h>
|
||||
#include <plasp-app/OptionGroups.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Help
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CommandHelp : public Command<CommandHelp>
|
||||
{
|
||||
public:
|
||||
static constexpr auto Name = "help";
|
||||
static constexpr auto Description = "Display this help message";
|
||||
|
||||
public:
|
||||
int run(int argc, char **argv);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
25
app/include/plasp-app/commands/CommandNormalize.h
Normal file
25
app/include/plasp-app/commands/CommandNormalize.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __PLASP_APP__COMMANDS__COMMAND_NORMALIZE_H
|
||||
#define __PLASP_APP__COMMANDS__COMMAND_NORMALIZE_H
|
||||
|
||||
#include <plasp-app/Command.h>
|
||||
#include <plasp-app/OptionGroups.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Normalize
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CommandNormalize : public Command<CommandNormalize, OptionGroupBasic, OptionGroupOutput, OptionGroupParser>
|
||||
{
|
||||
public:
|
||||
static constexpr auto Name = "normalize";
|
||||
static constexpr auto Description = "Normalize PDDL to plasp’s custom PDDL format";
|
||||
|
||||
public:
|
||||
int run(int argc, char **argv);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
25
app/include/plasp-app/commands/CommandTranslate.h
Normal file
25
app/include/plasp-app/commands/CommandTranslate.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __PLASP_APP__COMMANDS__COMMAND_TRANSLATE_H
|
||||
#define __PLASP_APP__COMMANDS__COMMAND_TRANSLATE_H
|
||||
|
||||
#include <plasp-app/Command.h>
|
||||
#include <plasp-app/OptionGroups.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Translate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CommandTranslate : public Command<CommandTranslate, OptionGroupBasic, OptionGroupOutput, OptionGroupParser>
|
||||
{
|
||||
public:
|
||||
static constexpr auto Name = "translate";
|
||||
static constexpr auto Description = "Translate PDDL and SAS to ASP facts";
|
||||
|
||||
public:
|
||||
int run(int argc, char **argv);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
25
app/include/plasp-app/commands/CommandVersion.h
Normal file
25
app/include/plasp-app/commands/CommandVersion.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __PLASP_APP__COMMANDS__COMMAND_VERSION_H
|
||||
#define __PLASP_APP__COMMANDS__COMMAND_VERSION_H
|
||||
|
||||
#include <plasp-app/Command.h>
|
||||
#include <plasp-app/OptionGroups.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Version
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CommandVersion : public Command<CommandVersion>
|
||||
{
|
||||
public:
|
||||
static constexpr auto Name = "version";
|
||||
static constexpr auto Description = "Display version information";
|
||||
|
||||
public:
|
||||
int run(int argc, char **argv);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
34
app/src/CMakeLists.txt
Normal file
34
app/src/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
||||
set(target plasp-app)
|
||||
|
||||
file(GLOB core_sources "plasp-app/*.cpp")
|
||||
file(GLOB core_headers "../include/plasp-app/*.h")
|
||||
|
||||
file(GLOB commands_sources "plasp-app/commands/*.cpp")
|
||||
file(GLOB commands_headers "../include/plasp-app/commands/*.h")
|
||||
|
||||
set(includes
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
${PROJECT_SOURCE_DIR}/lib/tokenize/include
|
||||
${PROJECT_SOURCE_DIR}/lib/colorlog/include
|
||||
${PROJECT_SOURCE_DIR}/lib/variant/include
|
||||
${PROJECT_SOURCE_DIR}/lib/pddl/include
|
||||
${PROJECT_SOURCE_DIR}/lib/cxxopts/include
|
||||
${PROJECT_SOURCE_DIR}/app/include
|
||||
)
|
||||
|
||||
set(sources
|
||||
${core_sources}
|
||||
${core_headers}
|
||||
${commands_sources}
|
||||
${commands_headers}
|
||||
)
|
||||
|
||||
set(libraries
|
||||
stdc++fs
|
||||
plasp
|
||||
)
|
||||
|
||||
add_executable(${target} ${sources})
|
||||
target_include_directories(${target} PRIVATE ${includes})
|
||||
target_link_libraries(${target} ${libraries})
|
||||
set_target_properties(${target} PROPERTIES OUTPUT_NAME plasp)
|
108
app/src/plasp-app/OptionGroups.cpp
Normal file
108
app/src/plasp-app/OptionGroups.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
#include <plasp-app/OptionGroups.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Option Groups
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Nasty workaround needed for GCC prior to version 7
|
||||
constexpr decltype(OptionGroupBasic::Name) OptionGroupBasic::Name;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void OptionGroupBasic::addTo(cxxopts::Options &options)
|
||||
{
|
||||
options.add_options(Name)
|
||||
("h,help", "Display this help message")
|
||||
("v,version", "Display version information")
|
||||
("warnings-as-errors", "Treat warnings as errors");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void OptionGroupBasic::read(const cxxopts::ParseResult &parseResult)
|
||||
{
|
||||
help = (parseResult.count("help") > 0);
|
||||
version = (parseResult.count("version") > 0);
|
||||
warningsAsErrors = (parseResult.count("warnings-as-errors") > 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Nasty workaround needed for GCC prior to version 7
|
||||
constexpr decltype(OptionGroupOutput::Name) OptionGroupOutput::Name;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void OptionGroupOutput::addTo(cxxopts::Options &options)
|
||||
{
|
||||
options.add_options(Name)
|
||||
("color", "Colorize output (always, never, auto)", cxxopts::value<std::string>()->default_value("auto"))
|
||||
("p,log-priority", "Log messages starting from this priority (debug, info, warning, error)", cxxopts::value<std::string>()->default_value("info"));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void OptionGroupOutput::read(const cxxopts::ParseResult &parseResult)
|
||||
{
|
||||
const auto colorPolicyString = parseResult["color"].as<std::string>();
|
||||
|
||||
if (colorPolicyString == "auto")
|
||||
colorPolicy = colorlog::ColorStream::ColorPolicy::Auto;
|
||||
else if (colorPolicyString == "never")
|
||||
colorPolicy = colorlog::ColorStream::ColorPolicy::Never;
|
||||
else if (colorPolicyString == "always")
|
||||
colorPolicy = colorlog::ColorStream::ColorPolicy::Always;
|
||||
else
|
||||
throw OptionException("unknown color policy “" + colorPolicyString + "”");
|
||||
|
||||
const auto logPriorityString = parseResult["log-priority"].as<std::string>();
|
||||
|
||||
try
|
||||
{
|
||||
logPriority = colorlog::priorityFromName(logPriorityString.c_str());
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
throw OptionException(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Nasty workaround needed for GCC prior to version 7
|
||||
constexpr decltype(OptionGroupParser::Name) OptionGroupParser::Name;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void OptionGroupParser::addTo(cxxopts::Options &options)
|
||||
{
|
||||
options.add_options(Name)
|
||||
("i,input", "Input files (in PDDL or SAS format)", cxxopts::value<std::vector<std::string>>())
|
||||
("parsing-mode", "Parsing mode (strict, compatibility)", cxxopts::value<std::string>()->default_value("strict"))
|
||||
("l,language", "Input language (pddl, sas, auto)", cxxopts::value<std::string>()->default_value("auto"));
|
||||
options.parse_positional("input");
|
||||
options.positional_help("[<input file...>]");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void OptionGroupParser::read(const cxxopts::ParseResult &parseResult)
|
||||
{
|
||||
const auto parsingModeString = parseResult["parsing-mode"].as<std::string>();
|
||||
|
||||
if (parsingModeString == "compatibility")
|
||||
parsingMode = pddl::Mode::Compatibility;
|
||||
else if (parsingModeString != "strict")
|
||||
throw OptionException("unknown parsing mode “" + parsingModeString + "”");
|
||||
|
||||
if (parseResult.count("input"))
|
||||
inputFiles = parseResult["input"].as<std::vector<std::string>>();
|
||||
|
||||
const auto languageName = parseResult["language"].as<std::string>();
|
||||
language = plasp::Language::fromString(languageName);
|
||||
|
||||
if (language == plasp::Language::Type::Unknown)
|
||||
throw OptionException("unknown input language “" + languageName + "”");
|
||||
}
|
145
app/src/plasp-app/commands/CommandBeautify.cpp
Normal file
145
app/src/plasp-app/commands/CommandBeautify.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
#include <plasp-app/commands/CommandBeautify.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <cxxopts.hpp>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
#include <colorlog/Logger.h>
|
||||
#include <colorlog/Priority.h>
|
||||
|
||||
#include <pddl/AST.h>
|
||||
#include <pddl/ASTOutput.h>
|
||||
#include <pddl/Exception.h>
|
||||
#include <pddl/Mode.h>
|
||||
#include <pddl/Parse.h>
|
||||
|
||||
#include <plasp/LanguageDetection.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Beautify
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int CommandBeautify::run(int argc, char **argv)
|
||||
{
|
||||
parseOptions(argc, argv);
|
||||
|
||||
const auto &basicOptions = std::get<OptionGroupBasic>(m_optionGroups);
|
||||
const auto &outputOptions = std::get<OptionGroupOutput>(m_optionGroups);
|
||||
const auto &parserOptions = std::get<OptionGroupParser>(m_optionGroups);
|
||||
|
||||
if (basicOptions.help)
|
||||
{
|
||||
printHelp();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (basicOptions.version)
|
||||
{
|
||||
printVersion();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
colorlog::Logger logger;
|
||||
logger.setColorPolicy(outputOptions.colorPolicy);
|
||||
logger.setLogPriority(outputOptions.logPriority);
|
||||
|
||||
if (basicOptions.warningsAsErrors)
|
||||
logger.setAbortPriority(colorlog::Priority::Warning);
|
||||
|
||||
const auto printCompatibilityInfo =
|
||||
[&]()
|
||||
{
|
||||
if (parserOptions.parsingMode != pddl::Mode::Compatibility)
|
||||
logger.log(colorlog::Priority::Info, "try using --parsing-mode=compatibility for extended legacy feature support");
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
tokenize::Tokenizer<tokenize::CaseInsensitiveTokenizerPolicy> tokenizer;
|
||||
|
||||
if (!parserOptions.inputFiles.empty())
|
||||
std::for_each(parserOptions.inputFiles.cbegin(), parserOptions.inputFiles.cend(),
|
||||
[&](const auto &inputFile)
|
||||
{
|
||||
tokenizer.read(inputFile);
|
||||
});
|
||||
else
|
||||
{
|
||||
logger.log(colorlog::Priority::Info, "reading from stdin");
|
||||
tokenizer.read("std::cin", std::cin);
|
||||
}
|
||||
|
||||
const auto detectLanguage =
|
||||
[&]()
|
||||
{
|
||||
if (parserOptions.language == plasp::Language::Type::Automatic)
|
||||
return plasp::detectLanguage(tokenizer);
|
||||
|
||||
return parserOptions.language;
|
||||
};
|
||||
|
||||
switch (detectLanguage())
|
||||
{
|
||||
case plasp::Language::Type::Automatic:
|
||||
case plasp::Language::Type::Unknown:
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, "unknown input language");
|
||||
std::cout << std::endl;
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// TODO: get rid of unknown language type, use exception instead
|
||||
case plasp::Language::Type::PDDL:
|
||||
{
|
||||
const auto logWarning =
|
||||
[&](const auto &location, const auto &warning)
|
||||
{
|
||||
logger.log(colorlog::Priority::Warning, location, warning);
|
||||
};
|
||||
|
||||
auto context = pddl::Context(std::move(tokenizer), logWarning);
|
||||
context.mode = parserOptions.parsingMode;
|
||||
auto description = pddl::parseDescription(context);
|
||||
logger.outputStream() << description;
|
||||
break;
|
||||
}
|
||||
|
||||
case plasp::Language::Type::SAS:
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, "Beautification is only supported for PDDL specifications");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const tokenize::TokenizerException &e)
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, e.location(), e.message().c_str());
|
||||
|
||||
printCompatibilityInfo();
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const pddl::ParserException &e)
|
||||
{
|
||||
if (e.location())
|
||||
logger.log(colorlog::Priority::Error, e.location().value(), e.message().c_str());
|
||||
else
|
||||
logger.log(colorlog::Priority::Error, e.message().c_str());
|
||||
|
||||
printCompatibilityInfo();
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, e.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
145
app/src/plasp-app/commands/CommandCheckSyntax.cpp
Normal file
145
app/src/plasp-app/commands/CommandCheckSyntax.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
#include <plasp-app/commands/CommandCheckSyntax.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <cxxopts.hpp>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
#include <colorlog/Logger.h>
|
||||
#include <colorlog/Priority.h>
|
||||
|
||||
#include <pddl/AST.h>
|
||||
#include <pddl/ASTOutput.h>
|
||||
#include <pddl/Exception.h>
|
||||
#include <pddl/Mode.h>
|
||||
#include <pddl/Parse.h>
|
||||
|
||||
#include <plasp/LanguageDetection.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Check Syntax
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int CommandCheckSyntax::run(int argc, char **argv)
|
||||
{
|
||||
parseOptions(argc, argv);
|
||||
|
||||
const auto &basicOptions = std::get<OptionGroupBasic>(m_optionGroups);
|
||||
const auto &outputOptions = std::get<OptionGroupOutput>(m_optionGroups);
|
||||
const auto &parserOptions = std::get<OptionGroupParser>(m_optionGroups);
|
||||
|
||||
if (basicOptions.help)
|
||||
{
|
||||
printHelp();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (basicOptions.version)
|
||||
{
|
||||
printVersion();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
colorlog::Logger logger;
|
||||
logger.setColorPolicy(outputOptions.colorPolicy);
|
||||
logger.setLogPriority(outputOptions.logPriority);
|
||||
|
||||
if (basicOptions.warningsAsErrors)
|
||||
logger.setAbortPriority(colorlog::Priority::Warning);
|
||||
|
||||
const auto printCompatibilityInfo =
|
||||
[&]()
|
||||
{
|
||||
if (parserOptions.parsingMode != pddl::Mode::Compatibility)
|
||||
logger.log(colorlog::Priority::Info, "try using --parsing-mode=compatibility for extended legacy feature support");
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
tokenize::Tokenizer<tokenize::CaseInsensitiveTokenizerPolicy> tokenizer;
|
||||
|
||||
if (!parserOptions.inputFiles.empty())
|
||||
std::for_each(parserOptions.inputFiles.cbegin(), parserOptions.inputFiles.cend(),
|
||||
[&](const auto &inputFile)
|
||||
{
|
||||
tokenizer.read(inputFile);
|
||||
});
|
||||
else
|
||||
{
|
||||
logger.log(colorlog::Priority::Info, "reading from stdin");
|
||||
tokenizer.read("std::cin", std::cin);
|
||||
}
|
||||
|
||||
const auto detectLanguage =
|
||||
[&]()
|
||||
{
|
||||
if (parserOptions.language == plasp::Language::Type::Automatic)
|
||||
return plasp::detectLanguage(tokenizer);
|
||||
|
||||
return parserOptions.language;
|
||||
};
|
||||
|
||||
switch (detectLanguage())
|
||||
{
|
||||
case plasp::Language::Type::Automatic:
|
||||
case plasp::Language::Type::Unknown:
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, "unknown input language");
|
||||
std::cout << std::endl;
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// TODO: get rid of unknown language type, use exception instead
|
||||
case plasp::Language::Type::PDDL:
|
||||
{
|
||||
const auto logWarning =
|
||||
[&](const auto &location, const auto &warning)
|
||||
{
|
||||
logger.log(colorlog::Priority::Warning, location, warning);
|
||||
};
|
||||
|
||||
auto context = pddl::Context(std::move(tokenizer), logWarning);
|
||||
context.mode = parserOptions.parsingMode;
|
||||
auto description = pddl::parseDescription(context);
|
||||
logger.log(colorlog::Priority::Info, "no syntax errors found");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
case plasp::Language::Type::SAS:
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, "Syntax checking is only supported for PDDL specifications");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const tokenize::TokenizerException &e)
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, e.location(), e.message().c_str());
|
||||
|
||||
printCompatibilityInfo();
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const pddl::ParserException &e)
|
||||
{
|
||||
if (e.location())
|
||||
logger.log(colorlog::Priority::Error, e.location().value(), e.message().c_str());
|
||||
else
|
||||
logger.log(colorlog::Priority::Error, e.message().c_str());
|
||||
|
||||
printCompatibilityInfo();
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, e.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
87
app/src/plasp-app/commands/CommandHelp.cpp
Normal file
87
app/src/plasp-app/commands/CommandHelp.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
#include <plasp-app/commands/CommandHelp.h>
|
||||
|
||||
#include <colorlog/Logger.h>
|
||||
|
||||
#include <plasp-app/CommandType.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Help
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int CommandHelp::run(int argc, char **argv)
|
||||
{
|
||||
colorlog::Logger logger;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (parseCommandType(argv[1]))
|
||||
{
|
||||
case CommandType::Help:
|
||||
case CommandType::Version:
|
||||
break;
|
||||
|
||||
case CommandType::Translate:
|
||||
CommandTranslate().printHelp();
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
case CommandType::Normalize:
|
||||
CommandNormalize().printHelp();
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
case CommandType::Beautify:
|
||||
CommandBeautify().printHelp();
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
case CommandType::CheckSyntax:
|
||||
CommandCheckSyntax().printHelp();
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
default:
|
||||
logger.log(colorlog::Priority::Error, std::string("command “") + argv[1] + "” not yet implemented");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
catch (std::exception &exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
std::cout
|
||||
<< "ASP planning tools for PDDL." << std::endl
|
||||
<< "Usage:" << std::endl
|
||||
<< " plasp <command> [<arguments>]" << std::endl << std::endl
|
||||
<< " available commands:" << std::endl;
|
||||
|
||||
AvailableCommands availableCommands;
|
||||
|
||||
size_t lengthOfLongestCommandName = 0;
|
||||
|
||||
forEach(availableCommands,
|
||||
[&](const auto &command)
|
||||
{
|
||||
lengthOfLongestCommandName = std::max(lengthOfLongestCommandName, std::strlen(command.Name));
|
||||
});
|
||||
|
||||
const auto printSpaces =
|
||||
[](const auto numberOfSpaces)
|
||||
{
|
||||
for (auto i = static_cast<decltype(numberOfSpaces)>(0); i < numberOfSpaces; i++)
|
||||
std::cout << " ";
|
||||
};
|
||||
|
||||
forEach(availableCommands,
|
||||
[&](const auto &command)
|
||||
{
|
||||
const auto lengthOfCommandName = std::strlen(command.Name);
|
||||
|
||||
std::cout << " " << command.Name;
|
||||
printSpaces(lengthOfLongestCommandName - lengthOfCommandName + 2);
|
||||
std::cout << command.Description << std::endl;
|
||||
});
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
148
app/src/plasp-app/commands/CommandNormalize.cpp
Normal file
148
app/src/plasp-app/commands/CommandNormalize.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
#include <plasp-app/commands/CommandNormalize.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <cxxopts.hpp>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
#include <colorlog/Logger.h>
|
||||
#include <colorlog/Priority.h>
|
||||
|
||||
#include <pddl/AST.h>
|
||||
#include <pddl/Exception.h>
|
||||
#include <pddl/Mode.h>
|
||||
#include <pddl/Normalize.h>
|
||||
#include <pddl/NormalizedASTOutput.h>
|
||||
#include <pddl/Parse.h>
|
||||
#include <pddl/detail/normalization/Reduction.h>
|
||||
|
||||
#include <plasp/LanguageDetection.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Normalize
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int CommandNormalize::run(int argc, char **argv)
|
||||
{
|
||||
parseOptions(argc, argv);
|
||||
|
||||
const auto &basicOptions = std::get<OptionGroupBasic>(m_optionGroups);
|
||||
const auto &outputOptions = std::get<OptionGroupOutput>(m_optionGroups);
|
||||
const auto &parserOptions = std::get<OptionGroupParser>(m_optionGroups);
|
||||
|
||||
if (basicOptions.help)
|
||||
{
|
||||
printHelp();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (basicOptions.version)
|
||||
{
|
||||
printVersion();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
colorlog::Logger logger;
|
||||
logger.setColorPolicy(outputOptions.colorPolicy);
|
||||
logger.setLogPriority(outputOptions.logPriority);
|
||||
|
||||
if (basicOptions.warningsAsErrors)
|
||||
logger.setAbortPriority(colorlog::Priority::Warning);
|
||||
|
||||
const auto printCompatibilityInfo =
|
||||
[&]()
|
||||
{
|
||||
if (parserOptions.parsingMode != pddl::Mode::Compatibility)
|
||||
logger.log(colorlog::Priority::Info, "try using --parsing-mode=compatibility for extended legacy feature support");
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
tokenize::Tokenizer<tokenize::CaseInsensitiveTokenizerPolicy> tokenizer;
|
||||
|
||||
if (!parserOptions.inputFiles.empty())
|
||||
std::for_each(parserOptions.inputFiles.cbegin(), parserOptions.inputFiles.cend(),
|
||||
[&](const auto &inputFile)
|
||||
{
|
||||
tokenizer.read(inputFile);
|
||||
});
|
||||
else
|
||||
{
|
||||
logger.log(colorlog::Priority::Info, "reading from stdin");
|
||||
tokenizer.read("std::cin", std::cin);
|
||||
}
|
||||
|
||||
const auto detectLanguage =
|
||||
[&]()
|
||||
{
|
||||
if (parserOptions.language == plasp::Language::Type::Automatic)
|
||||
return plasp::detectLanguage(tokenizer);
|
||||
|
||||
return parserOptions.language;
|
||||
};
|
||||
|
||||
switch (detectLanguage())
|
||||
{
|
||||
case plasp::Language::Type::Automatic:
|
||||
case plasp::Language::Type::Unknown:
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, "unknown input language");
|
||||
std::cout << std::endl;
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// TODO: get rid of unknown language type, use exception instead
|
||||
case plasp::Language::Type::PDDL:
|
||||
{
|
||||
const auto logWarning =
|
||||
[&](const auto &location, const auto &warning)
|
||||
{
|
||||
logger.log(colorlog::Priority::Warning, location, warning);
|
||||
};
|
||||
|
||||
auto context = pddl::Context(std::move(tokenizer), logWarning);
|
||||
context.mode = parserOptions.parsingMode;
|
||||
auto description = pddl::parseDescription(context);
|
||||
auto normalizedDescription = pddl::normalize(std::move(description));
|
||||
logger.outputStream() << normalizedDescription;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
case plasp::Language::Type::SAS:
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, "Normalization is only supported for PDDL specifications");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const tokenize::TokenizerException &e)
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, e.location(), e.message().c_str());
|
||||
|
||||
printCompatibilityInfo();
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const pddl::ParserException &e)
|
||||
{
|
||||
if (e.location())
|
||||
logger.log(colorlog::Priority::Error, e.location().value(), e.message().c_str());
|
||||
else
|
||||
logger.log(colorlog::Priority::Error, e.message().c_str());
|
||||
|
||||
printCompatibilityInfo();
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, e.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
161
app/src/plasp-app/commands/CommandTranslate.cpp
Normal file
161
app/src/plasp-app/commands/CommandTranslate.cpp
Normal file
@ -0,0 +1,161 @@
|
||||
#include <plasp-app/commands/CommandTranslate.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <cxxopts.hpp>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
#include <colorlog/Logger.h>
|
||||
#include <colorlog/Priority.h>
|
||||
|
||||
#include <pddl/AST.h>
|
||||
#include <pddl/Exception.h>
|
||||
#include <pddl/Mode.h>
|
||||
#include <pddl/Normalize.h>
|
||||
#include <pddl/NormalizedASTOutput.h>
|
||||
#include <pddl/Parse.h>
|
||||
#include <pddl/detail/normalization/Reduction.h>
|
||||
|
||||
#include <plasp/LanguageDetection.h>
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/TranslatorASP.h>
|
||||
#include <plasp/sas/Description.h>
|
||||
#include <plasp/sas/TranslatorASP.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Translate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int CommandTranslate::run(int argc, char **argv)
|
||||
{
|
||||
parseOptions(argc, argv);
|
||||
|
||||
const auto &basicOptions = std::get<OptionGroupBasic>(m_optionGroups);
|
||||
const auto &outputOptions = std::get<OptionGroupOutput>(m_optionGroups);
|
||||
const auto &parserOptions = std::get<OptionGroupParser>(m_optionGroups);
|
||||
|
||||
if (basicOptions.help)
|
||||
{
|
||||
printHelp();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (basicOptions.version)
|
||||
{
|
||||
printVersion();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
colorlog::Logger logger;
|
||||
logger.setColorPolicy(outputOptions.colorPolicy);
|
||||
logger.setLogPriority(outputOptions.logPriority);
|
||||
|
||||
if (basicOptions.warningsAsErrors)
|
||||
logger.setAbortPriority(colorlog::Priority::Warning);
|
||||
|
||||
const auto printCompatibilityInfo =
|
||||
[&]()
|
||||
{
|
||||
if (parserOptions.parsingMode != pddl::Mode::Compatibility)
|
||||
logger.log(colorlog::Priority::Info, "try using --parsing-mode=compatibility for extended legacy feature support");
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
tokenize::Tokenizer<tokenize::CaseInsensitiveTokenizerPolicy> tokenizer;
|
||||
|
||||
if (!parserOptions.inputFiles.empty())
|
||||
std::for_each(parserOptions.inputFiles.cbegin(), parserOptions.inputFiles.cend(),
|
||||
[&](const auto &inputFile)
|
||||
{
|
||||
tokenizer.read(inputFile);
|
||||
});
|
||||
else
|
||||
{
|
||||
logger.log(colorlog::Priority::Info, "reading from stdin");
|
||||
tokenizer.read("std::cin", std::cin);
|
||||
}
|
||||
|
||||
const auto detectLanguage =
|
||||
[&]()
|
||||
{
|
||||
if (parserOptions.language == plasp::Language::Type::Automatic)
|
||||
return plasp::detectLanguage(tokenizer);
|
||||
|
||||
return parserOptions.language;
|
||||
};
|
||||
|
||||
switch (detectLanguage())
|
||||
{
|
||||
case plasp::Language::Type::Automatic:
|
||||
case plasp::Language::Type::Unknown:
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, "unknown input language");
|
||||
std::cout << std::endl;
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// TODO: get rid of unknown language type, use exception instead
|
||||
case plasp::Language::Type::PDDL:
|
||||
{
|
||||
const auto logWarning =
|
||||
[&](const auto &location, const auto &warning)
|
||||
{
|
||||
logger.log(colorlog::Priority::Warning, location, warning);
|
||||
};
|
||||
|
||||
auto context = pddl::Context(std::move(tokenizer), logWarning);
|
||||
context.mode = parserOptions.parsingMode;
|
||||
auto description = pddl::parseDescription(context);
|
||||
auto normalizedDescription = pddl::normalize(std::move(description));
|
||||
const auto translator = plasp::pddl::TranslatorASP(std::move(normalizedDescription), logger.outputStream());
|
||||
translator.translate();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
case plasp::Language::Type::SAS:
|
||||
{
|
||||
const auto description = plasp::sas::Description::fromTokenizer(std::move(tokenizer));
|
||||
const auto translator = plasp::sas::TranslatorASP(description, logger.outputStream());
|
||||
translator.translate();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const tokenize::TokenizerException &e)
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, e.location(), e.message().c_str());
|
||||
|
||||
printCompatibilityInfo();
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const pddl::ParserException &e)
|
||||
{
|
||||
if (e.location())
|
||||
logger.log(colorlog::Priority::Error, e.location().value(), e.message().c_str());
|
||||
else
|
||||
logger.log(colorlog::Priority::Error, e.message().c_str());
|
||||
|
||||
printCompatibilityInfo();
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const plasp::TranslatorException &e)
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, e.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, e.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
14
app/src/plasp-app/commands/CommandVersion.cpp
Normal file
14
app/src/plasp-app/commands/CommandVersion.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include <plasp-app/commands/CommandVersion.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Command Version
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int CommandVersion::run(int, char **)
|
||||
{
|
||||
printVersion();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
69
app/src/plasp-app/main.cpp
Normal file
69
app/src/plasp-app/main.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <cxxopts.hpp>
|
||||
|
||||
#include <colorlog/Logger.h>
|
||||
#include <colorlog/Priority.h>
|
||||
|
||||
#include <plasp-app/Command.h>
|
||||
#include <plasp-app/CommandType.h>
|
||||
#include <plasp-app/Version.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Main
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
colorlog::Logger logger;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
CommandHelp().run(argc - 1, &argv[1]);
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
switch (parseCommandType(argv[1]))
|
||||
{
|
||||
case CommandType::Help:
|
||||
return CommandHelp().run(argc - 1, &argv[1]);
|
||||
|
||||
case CommandType::Version:
|
||||
return CommandVersion().run(argc - 1, &argv[1]);
|
||||
|
||||
case CommandType::Translate:
|
||||
return CommandTranslate().run(argc - 1, &argv[1]);
|
||||
|
||||
case CommandType::Normalize:
|
||||
return CommandNormalize().run(argc - 1, &argv[1]);
|
||||
|
||||
case CommandType::Beautify:
|
||||
return CommandBeautify().run(argc - 1, &argv[1]);
|
||||
|
||||
case CommandType::CheckSyntax:
|
||||
return CommandCheckSyntax().run(argc - 1, &argv[1]);
|
||||
|
||||
default:
|
||||
logger.log(colorlog::Priority::Error, std::string("command “") + argv[1] + "” not yet implemented");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
catch (std::exception &exception)
|
||||
{
|
||||
logger.log(colorlog::Priority::Error, exception.what());
|
||||
std::cout << std::endl;
|
||||
|
||||
CommandHelp().run(argc - 1, &argv[1]);
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
@ -1 +0,0 @@
|
||||
add_subdirectory(plasp-app)
|
@ -1,23 +0,0 @@
|
||||
set(target plasp_app)
|
||||
|
||||
file(GLOB core_sources "*.cpp")
|
||||
file(GLOB core_headers "*.h")
|
||||
|
||||
include_directories(
|
||||
${Boost_INCLUDE_DIRS}
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
set(sources
|
||||
${core_sources}
|
||||
${core_headers}
|
||||
)
|
||||
|
||||
set(libraries
|
||||
${Boost_LIBRARIES}
|
||||
plasp
|
||||
)
|
||||
|
||||
add_executable(${target} ${sources})
|
||||
target_link_libraries(${target} ${libraries})
|
||||
set_target_properties(plasp_app PROPERTIES OUTPUT_NAME plasp)
|
@ -1,175 +0,0 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include <plasp/LanguageDetection.h>
|
||||
#include <plasp/pddl/Description.h>
|
||||
#include <plasp/pddl/TranslatorASP.h>
|
||||
#include <plasp/sas/Description.h>
|
||||
#include <plasp/sas/TranslatorASP.h>
|
||||
#include <plasp/utils/LogStream.h>
|
||||
#include <plasp/utils/TranslatorException.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
namespace po = boost::program_options;
|
||||
|
||||
po::options_description description("Allowed options");
|
||||
description.add_options()
|
||||
("help,h", "Display this help message.")
|
||||
("version,v", "Display version information.")
|
||||
("input,i", po::value<std::vector<std::string>>(), "Specify the PDDL or SAS input file.")
|
||||
("language,l", po::value<std::string>(), "Specify the input language (sas or pddl). Omit for automatic detection.")
|
||||
("warning-level", po::value<std::string>()->default_value("normal"), "Specify whether to output warnings normally (normal), to treat them as critical errors (error), or to ignore them (ignore).")
|
||||
("color", po::value<std::string>()->default_value("auto"), "Specify whether to colorize the output (always, never, or auto).");
|
||||
|
||||
po::positional_options_description positionalOptionsDescription;
|
||||
positionalOptionsDescription.add("input", -1);
|
||||
|
||||
po::variables_map variablesMap;
|
||||
|
||||
const auto printHelp =
|
||||
[&]()
|
||||
{
|
||||
std::cout << "Usage: plasp [files] [options]" << std::endl;
|
||||
std::cout << "Translate PDDL instances to ASP facts." << std::endl << std::endl;
|
||||
|
||||
std::cout << description;
|
||||
};
|
||||
|
||||
plasp::utils::Logger logger;
|
||||
|
||||
try
|
||||
{
|
||||
po::store(po::command_line_parser(argc, argv)
|
||||
.options(description)
|
||||
.positional(positionalOptionsDescription)
|
||||
.run(),
|
||||
variablesMap);
|
||||
po::notify(variablesMap);
|
||||
}
|
||||
catch (const po::error &e)
|
||||
{
|
||||
logger.logError(e.what());
|
||||
std::cout << std::endl;
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (variablesMap.count("help"))
|
||||
{
|
||||
printHelp();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (variablesMap.count("version"))
|
||||
{
|
||||
std::cout << "plasp version 3.0.2-rc.1" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
const auto warningLevel = variablesMap["warning-level"].as<std::string>();
|
||||
|
||||
if (warningLevel == "error")
|
||||
logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Error);
|
||||
else if (warningLevel == "ignore")
|
||||
logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Ignore);
|
||||
else if (warningLevel == "normal")
|
||||
logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Normal);
|
||||
else
|
||||
{
|
||||
logger.logError("unknown warning level “" + warningLevel + "”");
|
||||
std::cout << std::endl;
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
const auto colorPolicy = variablesMap["color"].as<std::string>();
|
||||
|
||||
if (colorPolicy == "auto")
|
||||
logger.setColorPolicy(plasp::utils::LogStream::ColorPolicy::Auto);
|
||||
else if (colorPolicy == "never")
|
||||
logger.setColorPolicy(plasp::utils::LogStream::ColorPolicy::Never);
|
||||
else if (colorPolicy == "always")
|
||||
logger.setColorPolicy(plasp::utils::LogStream::ColorPolicy::Always);
|
||||
else
|
||||
{
|
||||
logger.logError("unknown color policy “" + colorPolicy + "”");
|
||||
std::cout << std::endl;
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
plasp::utils::Parser<plasp::utils::CaseInsensitiveParserPolicy> parser;
|
||||
|
||||
if (variablesMap.count("input"))
|
||||
{
|
||||
const auto &inputFiles = variablesMap["input"].as<std::vector<std::string>>();
|
||||
|
||||
std::for_each(inputFiles.cbegin(), inputFiles.cend(),
|
||||
[&](const auto &inputFile)
|
||||
{
|
||||
parser.read(inputFile);
|
||||
});
|
||||
}
|
||||
else
|
||||
parser.read("std::cin", std::cin);
|
||||
|
||||
const auto detectLanguage =
|
||||
[&]()
|
||||
{
|
||||
if (variablesMap.count("language") == 0)
|
||||
return plasp::detectLanguage(parser);
|
||||
|
||||
const auto languageName = variablesMap["language"].as<std::string>();
|
||||
|
||||
return plasp::Language::fromString(languageName);
|
||||
};
|
||||
|
||||
const auto language = detectLanguage();
|
||||
|
||||
if (language == plasp::Language::Type::Unknown)
|
||||
{
|
||||
logger.logError("unknown input language");
|
||||
std::cout << std::endl;
|
||||
printHelp();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (language == plasp::Language::Type::PDDL)
|
||||
{
|
||||
auto pddlLogger = logger;
|
||||
auto context = plasp::pddl::Context(std::move(parser), std::move(pddlLogger));
|
||||
auto description = plasp::pddl::Description::fromContext(std::move(context));
|
||||
const auto translator = plasp::pddl::TranslatorASP(description, description.context().logger.outputStream());
|
||||
translator.translate();
|
||||
}
|
||||
else if (language == plasp::Language::Type::SAS)
|
||||
{
|
||||
const auto description = plasp::sas::Description::fromParser(std::move(parser));
|
||||
const auto translator = plasp::sas::TranslatorASP(description, logger.outputStream());
|
||||
translator.translate();
|
||||
}
|
||||
}
|
||||
catch (const plasp::utils::ParserException &e)
|
||||
{
|
||||
logger.logError(e.coordinate(), e.message());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const plasp::utils::TranslatorException &e)
|
||||
{
|
||||
logger.logError(e.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
logger.logError(e.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
# Building Instructions
|
||||
|
||||
`plasp` requires a C++14 compiler (preferrably GCC ≥ 6.1 or clang ≥ 3.8), the `boost` libraries (≥ 1.55), and CMake for building.
|
||||
|
||||
```bash
|
||||
$ git clone https://github.com/potassco/plasp.git
|
||||
$ cd plasp
|
||||
$ mkdir -p build/release
|
||||
$ cd build/release
|
||||
$ cmake ../.. -DCMAKE_BUILD_TYPE=Release
|
||||
$ make
|
||||
```
|
||||
|
||||
The built `plasp` binary is then located at `plasp/build/release/bin/plasp`.
|
||||
|
||||
To update `plasp` to the most recent version, perform the following steps:
|
||||
|
||||
```bash
|
||||
$ cd plasp
|
||||
$ git pull
|
||||
$ cd build/release
|
||||
$ cmake .
|
||||
$ make
|
||||
```
|
||||
|
||||
## Running the Tests
|
||||
|
||||
`plasp` provides unit tests written using the [Google Test](https://github.com/google/googletest) framework.
|
||||
Before building and running the tests, make sure you have fetched the Google Test git submodule:
|
||||
|
||||
```bash
|
||||
$ git submodule init
|
||||
$ git submodule update
|
||||
```
|
||||
|
||||
Afterward, build and run the tests as follows:
|
||||
|
||||
```bash
|
||||
$ make run-tests
|
||||
```
|
47
doc/building.md
Normal file
47
doc/building.md
Normal file
@ -0,0 +1,47 @@
|
||||
# Building
|
||||
|
||||
`plasp` requires a C++17 compiler (preferably GCC ≥ 6.1 or clang ≥ 3.8) and CMake for building.
|
||||
|
||||
```sh
|
||||
git clone https://github.com/potassco/plasp.git
|
||||
cd plasp
|
||||
mkdir -p build/release
|
||||
cd build/release
|
||||
cmake ../.. -DCMAKE_BUILD_TYPE=Release
|
||||
make
|
||||
```
|
||||
|
||||
The built `plasp` binary is then located at `plasp/build/release/bin/plasp`.
|
||||
|
||||
To update `plasp` to the most recent version, perform the following steps:
|
||||
|
||||
```sh
|
||||
cd plasp
|
||||
git checkout master
|
||||
git pull
|
||||
cd build/release
|
||||
cmake .
|
||||
make
|
||||
```
|
||||
|
||||
## Running the Tests
|
||||
|
||||
`plasp` provides unit tests written with [Catch2](https://github.com/catchorg/Catch2).
|
||||
Before building and running the tests, make sure you have fetched the Catch submodule:
|
||||
|
||||
```sh
|
||||
git submodule init
|
||||
git submodule update
|
||||
```
|
||||
|
||||
Afterward, enable the flag `BUILD_TESTS` in your CMake configuration.
|
||||
Finally, build and run the tests as follows:
|
||||
|
||||
```sh
|
||||
make run-tokenize-tests
|
||||
make run-pddl-tests
|
||||
make run-tests
|
||||
```
|
||||
|
||||
After updating `plasp`, make sure to execute CMake again in order for the tests to run correctly.
|
||||
Else, external files required by the test suite may be reported missing.
|
@ -1,18 +0,0 @@
|
||||
# Command-Line Interface
|
||||
|
||||
```bash
|
||||
$ plasp [files] [options]
|
||||
```
|
||||
|
||||
`plasp` automatically detects the language of the input files.
|
||||
|
||||
Multiple files may be provided in an arbitrary order.
|
||||
`[files]` may also be omitted, in which case the input is read from `std::cin`.
|
||||
|
||||
`plasp` supports the following options:
|
||||
|
||||
| **option** | **explanation** |
|
||||
|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `-l` [ `--language` ] | Specify the input language (`sas` or `pddl`). Omit for automatic detection. |
|
||||
| `--warning-level` arg (=`normal`) | Specify whether to output warnings normally (`normal`), to treat them as critical errors (`error`), or to ignore them (`ignore`). |
|
||||
| `--color` arg (=`auto`) | Specify whether to colorize the output (`always`, `never`, or `auto`). |
|
@ -15,33 +15,63 @@ Actions are modeled exactly as PDDL actions and SAS operators.
|
||||
|
||||
## In a Nutshell
|
||||
|
||||
The following illustrates `plasp`’s output format for the problem of turning switches on and off.
|
||||
Consider the following, simplistic PDDL problem of turning a switch on:
|
||||
|
||||
```lisp
|
||||
; simplistic example of turning a switch on
|
||||
(define (domain switch)
|
||||
(:requirements :typing)
|
||||
(:types switch)
|
||||
(:predicates
|
||||
(on ?x - switch))
|
||||
(:action turn-on
|
||||
:parameters
|
||||
(?x - switch)
|
||||
:precondition
|
||||
(not (on ?x))
|
||||
:effect
|
||||
(on ?x)))
|
||||
|
||||
; example problem with one switch
|
||||
(define (problem switch-problem)
|
||||
(:domain switch)
|
||||
(:objects a - switch)
|
||||
(:init
|
||||
(not (on a)))
|
||||
(:goal
|
||||
(on a)))
|
||||
```
|
||||
|
||||
This is translated by `plasp translate` into the following output format (slightly restructured for clarity):
|
||||
|
||||
```prolog
|
||||
% declares the type "type(switch)"
|
||||
type(type(switch)).
|
||||
% declares the type “type("switch")”
|
||||
type(type("switch")).
|
||||
|
||||
% introduces a switch "constant(a)"
|
||||
constant(constant(a)).
|
||||
has(constant(a), type(switch)).
|
||||
% introduces a switch “constant("a")”
|
||||
constant(constant("a")).
|
||||
has(constant("a"), type("switch")).
|
||||
|
||||
% declares a variable "variable(on(X))" for switches X
|
||||
variable(variable(on(X))) :- has(X, type(switch)).
|
||||
% declares a variable “variable(on(X))” for switches X
|
||||
variable(variable(("on", X))) :- has(X, type("switch")).
|
||||
|
||||
% the variable may be true or false
|
||||
contains(variable(on(X)), value(on(X)), true)) :- has(X, type(switch)).
|
||||
contains(variable(on(X)), value(on(X)), false)) :- has(X, type(switch)).
|
||||
% variables may have the values true and false
|
||||
boolean(true).
|
||||
boolean(false).
|
||||
contains(X, value(X, B)) :- variable(X), boolean(B).
|
||||
|
||||
% declares the action "action(turnOn(X))", which requires switch X to be off and then turns it on
|
||||
action(action(turnOn(X))) :- has(X, type(switch)).
|
||||
precondition(action(turnOn(X)), variable(on(X)), value(on(X), false)) :- has(X, type(switch)).
|
||||
postcondition(action(turnOn(X)), effect(0), variable(on(X)), value(on(X), true)) :- has(X, type(switch)).
|
||||
% declares the action “action(turnOn(X))”, which requires switch X to be off and then turns it on
|
||||
action(action(("turn-on", X))) :- has(X, type("switch")).
|
||||
precondition(action(("turn-on", X)), variable(("on", X)), value(variable(("on", X)), false))
|
||||
:- action(action(("turn-on", X))).
|
||||
postcondition(action(("turn-on", X)), effect(unconditional), variable(("on", X)), value(variable(("on", X)), true))
|
||||
:- action(action(("turn-on", X))).
|
||||
|
||||
% initially, the switch is off
|
||||
initialState(variable(on(constant(a))), value(on(constant(a)), false)).
|
||||
initialState(variable(("on", constant("a"))), value(variable(("on", constant("a"))), false)).
|
||||
|
||||
% in the end, the switch should be on
|
||||
goal(variable(on(constant(a))), value(on(constant(a)), true)).
|
||||
goal(variable(("on", constant("a"))), value(variable(("on", constant("a"))), true)).
|
||||
```
|
||||
|
||||
## Syntax and Semantics
|
||||
@ -55,7 +85,7 @@ goal(variable(on(constant(a))), value(on(constant(a)), true)).
|
||||
requires(feature(<name>)).
|
||||
```
|
||||
|
||||
`plasp` recognizes and declares advanced features used by the input problem, such as conditional effects, [mutex groups](#mutex-groups) and [axiom rules](#axiom-rules) (currently only SAS).
|
||||
`plasp` recognizes and declares advanced features used by the input problem, such as [conditional effects](#actions), [mutex groups](#mutex-groups) and [axiom rules](#axiom-rules) (currently only SAS).
|
||||
See the [full list of supported features](feature-requirements.md) for more information.
|
||||
|
||||
The feature requirement predicates may be used in meta encodings to warn about unsupported features.
|
||||
@ -66,12 +96,17 @@ The feature requirement predicates may be used in meta encodings to warn about u
|
||||
% declares a <type>
|
||||
type(type(<name>)).
|
||||
|
||||
% specifies <constant> to be of type type(<name>)
|
||||
has(<constant>, type(<name>)).
|
||||
% specifies that <type 1> inherits <type 2>
|
||||
inherits(<type 1>, <type 2>).
|
||||
|
||||
% specifies <constant> to have type <type>
|
||||
has(<constant>, <type>).
|
||||
```
|
||||
|
||||
[Variables](#variables), [constants](#constants-objects), and [objects](#constants-objects) may be typed. Types are only available with PDDL and if typing is enabled.
|
||||
|
||||
`plasp` automatically generates all matching `has` predicates for objects with types that inherit other types.
|
||||
|
||||
### Variables
|
||||
|
||||
```prolog
|
||||
@ -88,12 +123,30 @@ Variables are linked to the problem's [objects](#constants-objects) and [constan
|
||||
`plasp`’s variables are multivalued, and each variable has exactly one value at each point in time.
|
||||
|
||||
With SAS, variable names are numbers starting at 0, `variable(<number>)`.
|
||||
SAS variables are inherently multivalued, which results in two or more values of the form `value(<SAS predicate>, <bool>)` for each variable.
|
||||
SAS variables are inherently multivalued, which results in two or more values of the form `value(<SAS predicate>, <SAS value>)` for each variable.
|
||||
|
||||
With PDDL, Boolean variables are created from the PDDL predicates.
|
||||
Variables ared named after the PDDL predicates, `variable(<PDDL predicate>).`
|
||||
Each variable contains exactly two values (one `true`, one `false`) of the form `value(<PDDL predicate>, <bool>)`.
|
||||
Note that with PDDL, variables and values are named identically.
|
||||
Variables are named after the PDDL predicate signatures, `variable(<PDDL predicate>).`
|
||||
Each variable contains exactly two values (one `true`, one `false`) of the form `value(<variable>, <bool>)`.
|
||||
Note that with PDDL, values contain the corresponding variables as the first argument to make the format consistent with the multi-valued variables obtained with SAS input.
|
||||
|
||||
### Derived Variables
|
||||
|
||||
```prolog
|
||||
% declares a <derived variable>
|
||||
derivedVariable(derivedVariable(<name>)).
|
||||
|
||||
% adds a <value> to the domain of a <derived variable>
|
||||
contains(<derived variable>, <value>).
|
||||
```
|
||||
|
||||
Derived variables are introduced whenever the translator needs to use [derived predicates](#derived-predicates).
|
||||
When the preconditions of a [derived predicate](#derived-predicates) are met, the corresponding derived variable (named after the derived predicate) is set as an effect.
|
||||
|
||||
Derived variables are analogously defined to common variables and may also be referenced in preconditions, conditions of conditional effects, and goal descriptions, just as variables.
|
||||
|
||||
In contrast to common variables, derived variables *are not subject to inertia rules.*
|
||||
In other words, derived variables are computed for each time step separately, and reset when going to the next time step (their values don’t automatically carry over to the next time step).
|
||||
|
||||
### Actions
|
||||
|
||||
@ -101,20 +154,22 @@ Note that with PDDL, variables and values are named identically.
|
||||
% declares an <action>
|
||||
action(action(<name>)).
|
||||
|
||||
% defines that as a precondition to <action>, <variable> must have value <value>
|
||||
% defines that as a precondition to <action>, <variable> and <derived variable> must have value <value>
|
||||
precondition(<action>, <variable>, <value>).
|
||||
precondition(<action>, <derived variable>, <value>).
|
||||
|
||||
% defines that after applying <action>, <variable> is assigned <value>
|
||||
postcondition(<action>, effect(<number>), <variable>, <value>).
|
||||
|
||||
% defines the condition of a conditional effect
|
||||
precondition(effect(<number>), <variable>, <value>).
|
||||
precondition(effect(<number>), <derived variable>, <value>).
|
||||
|
||||
% specifies the costs of applying <action>
|
||||
costs(<action>, <number>).
|
||||
```
|
||||
|
||||
Actions may require certain variables to have specific values in order to be executed.
|
||||
Actions may require certain [variables](#variables) (or [derived variables](#derived-variables)) to have specific values in order to be executed.
|
||||
After applying an action, variables get new values according to the action's postconditions.
|
||||
|
||||
Actions may have *conditional effects*, that is, certain postconditions are only applied if additional conditions are satisfied.
|
||||
@ -127,13 +182,43 @@ Conditional effects are currently only supported with SAS input problems.
|
||||
|
||||
Actions may also have *action costs* required to apply them. Action costs are currently supported for SAS only.
|
||||
|
||||
### Derived Predicates
|
||||
|
||||
```prolog
|
||||
% declares a <derived predicate> of with conjunctive (type(and)) or disjunctive (type(or)) preconditions
|
||||
derivedPredicate(derivedPredicate(<name>), type(<and/or>)).
|
||||
|
||||
% defines that as a precondition to <derived predicate>, <variable> and <derived variable> must have value <value>
|
||||
precondition(<derived predicate>, type(<and/or>), <variable>, <value>).
|
||||
precondition(<derived predicate>, type(<and/or>), <derived variable>, <value>).
|
||||
|
||||
% defines that after applying <action>, <derived variable> is assigned <value>
|
||||
postcondition(<derived predicate>, type(<and/or>), effect(<number>), <derived variable>, <value>).
|
||||
|
||||
% defines the condition of a conditional effect
|
||||
precondition(effect(<number>), <variable>, <value>).
|
||||
precondition(effect(<number>), <derived variable>, <value>).
|
||||
|
||||
% specifies the costs of applying <action>
|
||||
costs(<action>, <number>).
|
||||
```
|
||||
|
||||
Derived predicates are introduced by the translator when there are nested expressions or disjunctions in action preconditions, conditions of conditional effects, or goal descriptions.
|
||||
Derived predicates operate on [derived variables](#derived-variables) of the same name.
|
||||
|
||||
Like actions, derived predicates must satisfy preconditions in order for their effect to be applicable.
|
||||
The effect of all derived predicates is to set the corresponding [derived variables](#derived-variables) to `true` or `false`.
|
||||
|
||||
In contrast to actions, however, derived predicates specify whether their preconditions are to be interpreted as a *conjunction* (`type(and)`) or as a *disjunction* (`type(or)`).
|
||||
Encoding authors need to ensure that derived predicate preconditions are interpreted in the correct way.
|
||||
|
||||
### Constants/Objects
|
||||
|
||||
```prolog
|
||||
% declares a <constant> or object
|
||||
constant(constant(<name>)).
|
||||
|
||||
% specifies <constant> to be of type type(<name>)
|
||||
% specifies <constant> to have type type(<name>)
|
||||
has(<constant>, <type>).
|
||||
```
|
||||
|
||||
@ -151,16 +236,17 @@ initialState(<variable>, <value>).
|
||||
|
||||
The initial state contains all [variable](#variables) assignments that hold before executing any [actions](#actions).
|
||||
|
||||
Note that with PDDL, the initial state might not assign values to all variables. Instead, unassigned values have to be assigned `false` manually.
|
||||
Note that with PDDL, `plasp` sets all unspecified initial state variables to `false` in order to make the initial state total.
|
||||
|
||||
### Goal
|
||||
|
||||
```prolog
|
||||
% specifies that <variable> shall obtain <value> in the end
|
||||
% specifies that <variable> and <derived variable> shall obtain a respective <value> in the end
|
||||
goal(<variable>, <value>).
|
||||
goal(<derived variable>, <value>).
|
||||
```
|
||||
|
||||
The goal specifies all variable assignments that have to be fulfilled after executing the plan.
|
||||
The goal specifies all assignments of [variables](#variables) and [derived variables](#derived-variables) that have to be fulfilled after executing the action sequence.
|
||||
|
||||
### Mutex Groups
|
||||
|
||||
@ -190,12 +276,14 @@ axiomRule(axiomRule(<number>)).
|
||||
precondition(<axiom rule>, <variable>, <value>).
|
||||
|
||||
% defines that after applying <axiom rule>, <variable> is assigned <value>
|
||||
postcondition(<axiom rule>, <variable>, <value>).
|
||||
postcondition(<axiom rule>, effect(unconditional), <variable>, <value>).
|
||||
```
|
||||
|
||||
Axiom rules are similar to [actions](#actions) in that they modify [variables](#variables) if certain preconditions are satisfied.
|
||||
However, axiom rules must be applied *immediately* as soon as their preconditions are satisfied.
|
||||
|
||||
The second argument of `postcondition`, `effect(unconditional)`, is not used and exists only for consistency with [actions](#actions).
|
||||
|
||||
Axiom rule facts are only present with SAS input programs and not PDDL.
|
||||
|
||||
Axiom rules contain essential information in order to find plans correctly.
|
||||
|
27
doc/pddl-feature-support.md
Normal file
27
doc/pddl-feature-support.md
Normal file
@ -0,0 +1,27 @@
|
||||
# PDDL Feature Support
|
||||
|
||||
This document describes the PDDL features are currently supported by `plasp`’s very own translator.
|
||||
|
||||
This doesn’t cover PDDL feature support through SAS conversion with [Fast Downward](http://www.fast-downward.org/) (please refer to [Fast Downward’s homepage](http://www.fast-downward.org/) for more information).
|
||||
|
||||
The table below lists the features of PDDL 3.1 and whether or not they are supported by `plasp`.
|
||||
Unless otherwise noted, this refers to `plasp`’s parser, normalizer, translator, and ASP output format.
|
||||
|
||||
| PDDL feature | description | supported by `plasp` |
|
||||
|---|---|---|
|
||||
| STRIPS | basic STRIPS functionality, the general PDDL sections (`:domain`, `:problem`, `:predicates`, `:action`) | yes |
|
||||
| typing | typed variables and constants, type inheritance | yes (except for `either` type directives) |
|
||||
| negative preconditions | typed variables and constants, type inheritance | yes |
|
||||
| disjunctive preconditions | `or` expressions in preconditions | yes |
|
||||
| existential preconditions | `exists` expressions in preconditions | yes |
|
||||
| universal preconditions | `forall` expressions in preconditions | yes |
|
||||
| conditional effects | `when` expressions in action effects | yes |
|
||||
| universal effects | `forall` expressions in effects | yes |
|
||||
| equality | `=` expressions for atomic formulas | no (parser support only) |
|
||||
| numeric fluents | numeric function definitions in `:functions` section, assignment operators, arithmetic preconditions | no |
|
||||
| action costs | actions are assigned costs through numeric fluents | no |
|
||||
| durative actions | temporal planning with action durations | no |
|
||||
| derived predicates | predicates whose truth value is defined by a formula | no (`plasp` introduces *custom* derived predicates to support nested expressions, but derived predicates specified in the PDDL input are currently not supported) |
|
||||
| timed initial literals | initial state may specify literals that become true at a specified time point | no |
|
||||
| preferences | preferences in action preconditions and goals | no |
|
||||
| constraints | additional constraints for domain and problem | no |
|
27
encodings/outdated/pddl-sequential-horizon-boolean.lp
Normal file
27
encodings/outdated/pddl-sequential-horizon-boolean.lp
Normal file
@ -0,0 +1,27 @@
|
||||
#const horizon=1.
|
||||
|
||||
step(0..horizon).
|
||||
|
||||
precondition(Action,variable(Fluent),Value) :- precondition(Action, variable(Fluent),value(Fluent,Value)).
|
||||
postcondition(Action,variable(Fluent),Value) :- postcondition(Action,effect(unconditional),variable(Fluent),value(Fluent,Value)).
|
||||
|
||||
holds(variable(Fluent),0) :- initialState(variable(Fluent),value(Fluent,true)).
|
||||
|
||||
{ occurs(Action,T) : action(Action) } = 1 :- step(T), T>0.
|
||||
|
||||
:- occurs(Action,T), precondition(Action,Fluent,true), not holds(Fluent,T-1).
|
||||
:- occurs(Action,T), precondition(Action,Fluent,false), holds(Fluent,T-1).
|
||||
|
||||
caused(Fluent,T) :- occurs(Action,T), postcondition(Action,Fluent,true).
|
||||
|
||||
holds(Fluent,T) :- caused(Fluent,T).
|
||||
holds(Fluent,T) :- holds(Fluent,T-1), not occurs(Action,T) : postcondition(Action,Fluent,false); T<=horizon.
|
||||
|
||||
goalAt(T) :- holds(variable(Variable),T) : goal(variable(Variable), value(Variable,true));
|
||||
not holds(variable(Variable),T) : goal(variable(Variable), value(Variable,false));
|
||||
T=horizon.
|
||||
|
||||
:- not goalAt(horizon).
|
||||
|
||||
#show occurs/2.
|
||||
% #show holds/2.
|
30
encodings/outdated/pddl-sequential-incremental-boolean.lp
Normal file
30
encodings/outdated/pddl-sequential-incremental-boolean.lp
Normal file
@ -0,0 +1,30 @@
|
||||
#include <incmode>.
|
||||
|
||||
#program base.
|
||||
|
||||
precondition(Action,variable(Fluent),Value) :- precondition(Action, variable(Fluent),value(Fluent,Value)).
|
||||
postcondition(Action,variable(Fluent),Value) :- postcondition(Action,effect(unconditional),variable(Fluent),value(Fluent,Value)).
|
||||
|
||||
holds(variable(Fluent),0) :- initialState(variable(Fluent),value(Fluent,true)).
|
||||
|
||||
#program step(t).
|
||||
|
||||
{ occurs(Action,t) : action(Action) } = 1.
|
||||
|
||||
:- occurs(Action,t), precondition(Action,Fluent,true), not holds(Fluent,t-1).
|
||||
:- occurs(Action,t), precondition(Action,Fluent,false), holds(Fluent,t-1).
|
||||
|
||||
caused(Fluent,t) :- occurs(Action,t), postcondition(Action,Fluent,true).
|
||||
|
||||
holds(Fluent,t) :- caused(Fluent,t).
|
||||
holds(Fluent,t) :- holds(Fluent,t-1), not occurs(Action,t) : postcondition(Action,Fluent,false).
|
||||
|
||||
#program check(t).
|
||||
|
||||
goalAt(t) :- holds(variable(Variable),t) : goal(variable(Variable), value(Variable,true));
|
||||
not holds(variable(Variable),t) : goal(variable(Variable), value(Variable,false)).
|
||||
|
||||
:- not goalAt(t), query(t).
|
||||
|
||||
#show occurs/2.
|
||||
% #show holds/2.
|
@ -0,0 +1,52 @@
|
||||
#include <incmode>.
|
||||
|
||||
% Check feature requirements
|
||||
% :- requires(feature(actionCosts)).
|
||||
|
||||
#program base.
|
||||
|
||||
% Establish initial state
|
||||
holds(Variable, Value, 0) :- initialState(Variable, Value), not stateVariable(Variable).
|
||||
|
||||
% Identify (head and) state variables
|
||||
headVariable(Rule,Variable) :- variable(Variable), axiomRule(Rule), postcondition(Rule,_,Variable,_).
|
||||
stateVariable(Variable) :- headVariable(_,Variable).
|
||||
|
||||
#program step(t). % t=1,2,...
|
||||
|
||||
% Perform actions
|
||||
1 {occurs(Action, t) : action(Action)} 1.
|
||||
|
||||
% Check preconditions
|
||||
:- occurs(Action, t), precondition(Action, Variable, Value), not holds(Variable, Value, t - 1).
|
||||
|
||||
% Apply effects
|
||||
caused(Variable, Value, t) :- occurs(Action, t), postcondition(Action, Effect, Variable, Value),
|
||||
holds(Variable', Value', t - 1) : precondition(Effect, Variable', Value').
|
||||
changed(Variable, t) :- caused(Variable, Value, t).
|
||||
|
||||
holds(Variable, Value, t) :- caused(Variable, Value, t).
|
||||
holds(Variable, Value, t) :- holds(Variable, Value, t - 1), not changed(Variable, t), not stateVariable(Variable).
|
||||
|
||||
#program check(t). % t=0,1,...
|
||||
|
||||
% Check that variables have unique values
|
||||
:- variable(Variable), {holds(Variable, Value, t) : contains(Variable, Value)} != 1.
|
||||
|
||||
% Check mutexes
|
||||
:- mutexGroup(MutexGroup), {holds(Variable, Value, t) : contains(MutexGroup, Variable, Value)} > 1.
|
||||
|
||||
% Apply axioms
|
||||
derived(Variable, Value, t) :- axiomRule(Rule), postcondition(Rule,_,Variable,Value),
|
||||
holds(Variable', Value', t) : precondition(Rule, Variable', Value'), not headVariable(Rule,Variable').
|
||||
|
||||
modified(Variable, t) :- derived(Variable, Value, t).
|
||||
|
||||
holds(Variable, Value, t) :- derived(Variable, Value, t), stateVariable(Variable).
|
||||
holds(Variable, Value, t) :- not modified(Variable, t), stateVariable(Variable), initialState(Variable, Value).
|
||||
|
||||
% Verify that goal is met
|
||||
:- query(t), goal(Variable, Value), not holds(Variable, Value, t).
|
||||
|
||||
#show occurs/2.
|
||||
% #show holds/3.
|
@ -1,18 +1,15 @@
|
||||
#include <incmode>.
|
||||
|
||||
% Check feature requirements
|
||||
:- requiresFeature(actionCosts).
|
||||
:- requiresFeature(axiomRules).
|
||||
:- requiresFeature(conditionalEffects).
|
||||
:- requires(feature(actionCosts)).
|
||||
:- requires(feature(axiomRules)).
|
||||
:- requires(feature(conditionalEffects)).
|
||||
|
||||
#program base.
|
||||
|
||||
% Establish initial state
|
||||
holds(Variable, Value, 0) :- initialState(Variable, Value).
|
||||
|
||||
% Make unspecified initial state variables false by default (for PDDL)
|
||||
holds(variable(Variable), value(Variable, false), 0) :- variable(variable(Variable)), {initialState(variable(Variable), _)} 0.
|
||||
|
||||
#program step(t).
|
||||
|
||||
% Perform actions
|
71
encodings/sequential-horizon.lp
Normal file
71
encodings/sequential-horizon.lp
Normal file
@ -0,0 +1,71 @@
|
||||
#const horizon=1.
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Horizon, must be defined externally
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
time(0..horizon).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Establish initial state
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
holds(Variable, Value, 0) :- initialState(Variable, Value).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Compute derived predicates
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% conjunctive preconditions
|
||||
satisfied(DerivedPredicate, type(and), T) :- derivedPredicate(DerivedPredicate, type(and)), holds(Variable, Value, T) : precondition(DerivedPredicate, type(and), Variable, Value); time(T).
|
||||
|
||||
% disjunctive preconditions
|
||||
satisfied(DerivedPredicate, type(or), T) :- precondition(DerivedPredicate, type(or), Variable, Value), holds(Variable, Value, T), time(T).
|
||||
|
||||
holds(DerivedVariable, Value, T) :- satisfied(DerivedPredicate, Type, T), postcondition(DerivedPredicate, Type, effect(unconditional), DerivedVariable, Value).
|
||||
|
||||
holds(derivedVariable(DerivedVariable), value(DerivedVariable, false), T) :- derivedVariable(DerivedVariable), not holds(derivedVariable(DerivedVariable), value(DerivedVariable, true), T), time(T).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Perform actions
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
1 {occurs(Action, T) : action(Action)} 1 :- time(T), T > 0.
|
||||
|
||||
% Check preconditions
|
||||
:- occurs(Action, T), precondition(Action, Variable, Value), not holds(Variable, Value, T - 1).
|
||||
|
||||
% Apply effects
|
||||
caused(Variable, Value, T) :-
|
||||
occurs(Action, T),
|
||||
postcondition(Action, Effect, Variable, Value),
|
||||
holds(VariablePre, ValuePre, T - 1) : precondition(Effect, VariablePre, ValuePre).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Inertia rules
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
modified(Variable, T) :- caused(Variable, Value, T).
|
||||
|
||||
holds(Variable, Value, T) :- caused(Variable, Value, T).
|
||||
holds(variable(V), Value, T) :- holds(variable(V), Value, T - 1), not modified(variable(V), T), time(T).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Variables and mutex groups
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
% Check that variables have unique values
|
||||
:- variable(Variable), not 1 {holds(Variable, Value, T) : contains(Variable, Value)} 1, time(T).
|
||||
|
||||
% Check mutexes
|
||||
:- mutexGroup(MutexGroup), not {holds(Variable, Value, T) : contains(MutexGroup, Variable, Value)} 1, time(T).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Verify that goal is met
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
:- goal(Variable, Value), not holds(Variable, Value, horizon).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
#show occurs/2.
|
73
encodings/strips/README.md
Normal file
73
encodings/strips/README.md
Normal file
@ -0,0 +1,73 @@
|
||||
# Incremental STRIPS Planning Encodings
|
||||
|
||||
This suite of incremental STRIPS planning encodings implements diverse methods.
|
||||
The included encoding files provide the following functionalities:
|
||||
|
||||
## Encodings
|
||||
|
||||
### [incmode.lp](incmode.lp): include built-in “iclingo“ script for incremental grounding and solving
|
||||
|
||||
### [preprocess.lp](preprocess.lp): static analysis of potentially relevant actions
|
||||
|
||||
* Parameter: `_closure` (default value: `3`)
|
||||
* Value `1`: forward chaining of effects w.r.t. initial variable values
|
||||
* Value `2`: backward regression of effects w.r.t. goal variable values
|
||||
* Value `3`: both forward chaining and backward regression of effects
|
||||
* Otherwise: off (simply take all actions as given)
|
||||
|
||||
### [strips-incremental.lp](strips-incremental.lp): sequential and parallel planning encoding variants
|
||||
* Parameter: `_parallel` (default value: `0`)
|
||||
* Value `1`: “forall” parallel actions that can be arranged in any sequence
|
||||
* Value `2`: “exists” parallel actions that can be arranged in some sequence
|
||||
* Value `3`: “exists“ parallel actions omitting achievement of preconditions
|
||||
* Value `4`: “exists“ parallel actions like `3` implemented by acyclicity
|
||||
* Otherwise: sequential actions
|
||||
* Parameter: `planner_on` (default value: `0`)
|
||||
* Value `0`: no compatibility to ASP-based planner (no idle steps permitted)
|
||||
* Otherwise: compatibility to ASP-based planner (idle steps permitted)
|
||||
|
||||
### [redundancy.lp](redundancy.lp): enforcement of ‘redundant’ actions to constrain parallel plans
|
||||
* Remarks:
|
||||
* Only relevant together with parallel actions not implemented by acyclicity
|
||||
* Encoded constraints seem rather ineffective though
|
||||
* Heavy space overhead in combination with “exists” parallel actions
|
||||
|
||||
### [postprocess.lp](postprocess.lp): plan feasibility checking and conversion to sequential plan
|
||||
|
||||
## Usage Examples
|
||||
|
||||
Some example invocations (using `clingo` 5.1.0) are as follows:
|
||||
|
||||
```bash
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp -c _closure=0
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp -c _closure=1
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp -c _closure=2
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp -c _parallel=1
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp -c _parallel=2
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp -c _parallel=3
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp -c _parallel=4
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp -c _parallel=1 redundancy.lp
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp -c _parallel=2 redundancy.lp
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp -c _parallel=3 redundancy.lp
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp --outf=1 | grep -A1 -e "ANSWER" | tail -n1 | clingo - postprocess.lp <(plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl)
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp --outf=1 -c _parallel=1 | grep -A1 -e "ANSWER" | tail -n1 | clingo - postprocess.lp <(plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl)
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp --outf=1 -c _parallel=2 | grep -A1 -e "ANSWER" | tail -n1 | clingo - postprocess.lp <(plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl)
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp --outf=1 -c _parallel=3 | grep -A1 -e "ANSWER" | tail -n1 | clingo - postprocess.lp <(plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl)
|
||||
|
||||
plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl | clingo - incmode.lp preprocess.lp strips-incremental.lp --outf=1 -c _parallel=4 | grep -A1 -e "ANSWER" | tail -n1 | clingo - postprocess.lp <(plasp ../../instances/PDDL/ipc-2000-elevator-m10-strips/domain.pddl ../../instances/PDDL/ipc-2000-elevator-m10-strips/problem-04-00.pddl)
|
||||
```
|
3
encodings/strips/incmode.lp
Normal file
3
encodings/strips/incmode.lp
Normal file
@ -0,0 +1,3 @@
|
||||
% Include built-in "iclingo" script for incremental grounding and solving
|
||||
|
||||
#include <incmode>.
|
58
encodings/strips/postprocess.lp
Normal file
58
encodings/strips/postprocess.lp
Normal file
@ -0,0 +1,58 @@
|
||||
% Convert a plan (possibly with parallel actions), given by atoms over occurs/2,
|
||||
% to a sequential plan, expressed by atoms over sequence/2
|
||||
|
||||
time(T) :- occurs(A,T).
|
||||
time :- time(T).
|
||||
|
||||
:- goal(X,V), not initialState(X,V), not time.
|
||||
|
||||
last(T2) :- time, T2 = #max{T1 : time(T1)}.
|
||||
|
||||
offset(T2,M) :- time(T2), M = #count{A,T1 : occurs(A,T1), T1 < T2}.
|
||||
finish(T,M+N) :- offset(T,M), N = #count{A : occurs(A,T)}.
|
||||
index(T,M+1..N) :- offset(T,M), finish(T,N).
|
||||
|
||||
postcondition(A,X,V) :- postcondition(A,E,X,V), occurs(A,T).
|
||||
postcondition(A,X) :- postcondition(A,X,V).
|
||||
|
||||
before(A1,A2,T) :- occurs(A1,T), occurs(A2,T), A1 != A2,
|
||||
precondition(A1,X,V), postcondition(A2,X), not postcondition(A2,X,V).
|
||||
|
||||
order(A1,A2,T) :- occurs(A1,T), occurs(A2,T), A1 < A2, A <= A1 : occurs(A,T), A < A2.
|
||||
first(A2,T) :- occurs(A2,T), #false : order(A1,A2,T).
|
||||
|
||||
undone(A,T,M) :- occurs(A,T), offset(T,M).
|
||||
undone(A,T,N) :- undone(A,T,N-1), select(A1,T,N), A != A1, index(T,N+1).
|
||||
|
||||
done(A,T,N) :- select(A,T,N).
|
||||
done(A,T,N) :- done(A,T,N-1), index(T,N).
|
||||
|
||||
:- finish(T,N), occurs(A,T), not done(A,T,N).
|
||||
|
||||
hold(X,V,0) :- initialState(X,V).
|
||||
hold(X,V,N) :- select(A,T,N), postcondition(A,X,V).
|
||||
hold(X,V,N) :- select(A,T,N), hold(X,V,N-1), not postcondition(A,X).
|
||||
|
||||
:- last(T), finish(T,N), goal(X,V), not hold(X,V,N).
|
||||
|
||||
hold(X,N) :- hold(X,V,N).
|
||||
|
||||
:- hold(X,N), #count{V : hold(X,V,N)} > 1.
|
||||
|
||||
preconditions(A,T,N) :- undone(A,T,N), hold(X,V,N) : precondition(A,X,V).
|
||||
applicable(A,T,N) :- preconditions(A,T,N), done(A1,T,N) : before(A1,A,T).
|
||||
|
||||
inapplicable(A,T,N) :- done(A,T,N), index(T,N+1).
|
||||
inapplicable(A,T,N) :- undone(A,T,N), precondition(A,X,V1), hold(X,V2,N), V1 != V2.
|
||||
inapplicable(A,T,N) :- undone(A1,T,N), before(A1,A,T).
|
||||
|
||||
continue(A2,T,N) :- order(A1,A2,T), inapplicable(A1,T,N), first(A1,T).
|
||||
continue(A2,T,N) :- order(A1,A2,T), inapplicable(A1,T,N), continue(A1,T,N).
|
||||
|
||||
select(A,T,N+1) :- applicable(A,T,N), first(A,T).
|
||||
select(A,T,N+1) :- applicable(A,T,N), continue(A,T,N).
|
||||
|
||||
% DISPLAY PART
|
||||
|
||||
#show.
|
||||
#show sequence(A,N) : select(A,T,N).
|
50
encodings/strips/preprocess.lp
Normal file
50
encodings/strips/preprocess.lp
Normal file
@ -0,0 +1,50 @@
|
||||
% Constant '_closure' to (de)activate analysis of potentially relevant actions
|
||||
% - value '1': forward chaining of effects w.r.t. initial variable values
|
||||
% - value '2': backward regression of effects w.r.t. goal variable values
|
||||
% - value '3': both forward chaining and backward regression of effects
|
||||
% - otherwise: off
|
||||
|
||||
#const _closure = 3.
|
||||
|
||||
% BASE PROGRAM
|
||||
|
||||
% Check feature requirements
|
||||
|
||||
:- requires(feature(actionCosts)).
|
||||
:- requires(feature(axiomRules)).
|
||||
:- requires(feature(conditionalEffects)).
|
||||
|
||||
% Basic redundancy check for actions
|
||||
|
||||
postcondition(A,X,V) :- postcondition(A,E,X,V).
|
||||
|
||||
has_condition(A,X,0) :- action(A), precondition(A,X,V).
|
||||
has_condition(A,X,1) :- action(A), postcondition(A,X,V).
|
||||
|
||||
inconsistent(A) :- has_condition(A,X,P),
|
||||
#count{V : precondition(A,X,V), P = 0;
|
||||
V : postcondition(A,X,V), P = 1} > 1.
|
||||
consistent(A) :- action(A), not inconsistent(A).
|
||||
irredundant(A) :- consistent(A), postcondition(A,X,V), not precondition(A,X,V).
|
||||
|
||||
% Forward chaining of effects w.r.t. initial variable values
|
||||
|
||||
feasible(X,V) :- initialState(X,V).
|
||||
feasible(X,V) :- possible(A), postcondition(A,X,V).
|
||||
|
||||
possible(A) :- irredundant(A), feasible(X,V) : precondition(A,X,V).
|
||||
possible(A) :- irredundant(A), _closure != 1, _closure != 3.
|
||||
|
||||
:- goal(X,V), not feasible(X,V).
|
||||
|
||||
% Backward regression of effects w.r.t. goal variable values
|
||||
|
||||
produce(X,V) :- goal(X,V), not initialState(X,V).
|
||||
produce(X,V) :- active(A), precondition(A,X,V), not initialState(X,V).
|
||||
produce(X,V) :- persist(X,V), active(A), has_condition(A,X,1), not postcondition(A,X,V).
|
||||
|
||||
persist(X,V) :- goal(X,V), initialState(X,V).
|
||||
persist(X,V) :- active(A), precondition(A,X,V), initialState(X,V).
|
||||
|
||||
active(A) :- possible(A), postcondition(A,X,V), produce(X,V).
|
||||
active(A) :- possible(A), _closure != 2, _closure != 3.
|
50
encodings/strips/redundancy.lp
Normal file
50
encodings/strips/redundancy.lp
Normal file
@ -0,0 +1,50 @@
|
||||
% Additional rules for enforcing the inclusion of parallel actions in plans,
|
||||
% whenever such 'redundant' actions are compatible with states and other actions
|
||||
|
||||
% BASE PROGRAM
|
||||
|
||||
selfdefeat(A) :- selfdefeat(A,X).
|
||||
disjoin(A,A1) :- active(A), has_condition(A,X,P), selfdefeat(A1,X), not selfdefeat(A).
|
||||
|
||||
compatible(A,A1) :- active(A), active(A1), A != A1, 1 < _parallel, _parallel < 4,
|
||||
not diverge(A,A1), not exclude(A,A1), not disable(A,A1) : disable(A1,A).
|
||||
compatible(A) :- compatible(A,A1).
|
||||
compatible(A) :- active(A), active(A1), A != A1, _parallel = 1, not selfdefeat(A),
|
||||
not diverge(A,A1), not exclude(A,A1), not disjoin(A,A1).
|
||||
|
||||
disable(A,A1,A2) :- compatible(A,A1), compatible(A,A2), compatible(A1,A2),
|
||||
disable(A1,A2), not disable(A1,A).
|
||||
|
||||
disabled(A,A1) :- compatible(A), disable(A,A1).
|
||||
disabled(A,A2) :- simulate(A,A1), disable(A,A1,A2).
|
||||
|
||||
simulate(A,A1) :- compatible(A,A1), not disable(A1,A), disabled(A,A1).
|
||||
simulate(A,A1) :- compatible(A,A1), not disable(A1,A), scope(X,V),
|
||||
postcondition(A1,X,V), not precondition(A1,X,V).
|
||||
|
||||
% STEP PROGRAM
|
||||
|
||||
#program step(t).
|
||||
|
||||
defeated(A,t) :- compatible(A), postcondition(A,X,V), fluent(X), not holds(X,V,t).
|
||||
|
||||
defeated(A,t) :- compatible(A), precondition(A,X,V), not holds(X,V,t-1), _parallel != 2.
|
||||
defeated(A,t) :- compatible(A), precondition(A,X,V), not has_condition(A,X,1), not holds(X,V,t),
|
||||
_parallel = 1.
|
||||
defeated(A,t) :- compatible(A), has_condition(A,X,1), not has_condition(A,X,0), single(X,t).
|
||||
|
||||
proceed(A,X,V,t) :- compatible(A), holds(X,V,t-1), scope(X,V).
|
||||
proceed(A,X,V,t) :- simulate(A,A1), perform(A,A1,t), occurs(A1,t), scope(X,V),
|
||||
postcondition(A1,X,V), not precondition(A1,X,V).
|
||||
|
||||
perform(A,A1,t) :- simulate(A,A1),
|
||||
proceed(A,X,V,t) : precondition(A1,X,V), _parallel = 2;
|
||||
alright(A,A2,t) : disable(A,A1,A2).
|
||||
|
||||
alright(A,A1,t) :- disabled(A,A1), not occurs(A1,t).
|
||||
alright(A,A1,t) :- disabled(A,A1), perform(A,A1,t).
|
||||
|
||||
defeated(A,t) :- compatible(A), precondition(A,X,V), not proceed(A,X,V,t), _parallel = 2.
|
||||
defeated(A,t) :- compatible(A), disable(A,A1), not alright(A,A1,t).
|
||||
|
||||
:- compatible(A), not occurs(A,t), not defeated(A,t), 0 < _parallel, _parallel < 4.
|
143
encodings/strips/strips-incremental.lp
Normal file
143
encodings/strips/strips-incremental.lp
Normal file
@ -0,0 +1,143 @@
|
||||
% Constant '_parallel' to enable parallel actions
|
||||
% - value '0': parallel actions *without* checking for mutual disablement
|
||||
% - value '1': "forall" parallel actions that can be arranged in any sequence
|
||||
% - value '2': "exists" parallel actions that can be arranged in some sequence
|
||||
% - value '3': "exists" parallel actions omitting achievement of preconditions
|
||||
% - value '4': "exists" parallel actions like '3' implemented by acyclicity
|
||||
% - otherwise: sequential actions
|
||||
|
||||
#const _parallel = 5.
|
||||
|
||||
% Constant '_shallow' to cheaply approximate mutually disabling parallel actions
|
||||
% - value '0': detect incompatible pre/postconditions to reduce parallel actions
|
||||
% - otherwise: over-approximate parallel actions (in testing mutual disablement)
|
||||
|
||||
#const _shallow = 0.
|
||||
|
||||
% Constant '_inertia' to choose flat or tiered format for transition constraints
|
||||
% - value '0': use flat rules (integrity constraints) for transition constraints
|
||||
% - otherwise: use rules that provide auxiliary atoms for transition constraints
|
||||
|
||||
#const _inertia = 0.
|
||||
|
||||
% Constant 'planner_on' to enable encoding support for ASP-based planner
|
||||
% - value '0': no compatibility to ASP-based planner (no idle steps permitted)
|
||||
% - otherwise: compatibility to ASP-based planner (idle steps permitted)
|
||||
|
||||
#const planner_on = 0.
|
||||
|
||||
% BASE PROGRAM
|
||||
|
||||
% Define auxiliary predicates for actions w.r.t. parallel mode
|
||||
|
||||
selfdefeat(A,X) :- active(A), precondition(A,X,V), _parallel = 1,
|
||||
has_condition(A,X,1), not postcondition(A,X,V).
|
||||
|
||||
diverge(A1,A2,X) :- active(A1), active(A2), postcondition(A1,X,V),
|
||||
has_condition(A2,X,1), not postcondition(A2,X,V),
|
||||
0 <= _parallel, _parallel < 5, _shallow = 0.
|
||||
diverge(A1,A2) :- diverge(A1,A2,X).
|
||||
|
||||
exclude(A1,A2) :- active(A1), active(A2), precondition(A1,X,V),
|
||||
has_condition(A2,X,0), not precondition(A2,X,V),
|
||||
0 <= _parallel, _parallel < 5, _parallel != 2, _shallow = 0.
|
||||
|
||||
disable(A1,A2) :- active(A1), active(A2), A1 != A2, postcondition(A1,X,V),
|
||||
has_condition(A2,X,0), not precondition(A2,X,V),
|
||||
not diverge(A1,A2), not exclude(A1,A2),
|
||||
1 < _parallel, _parallel < 5.
|
||||
|
||||
disable :- _parallel = 4, #sum{1,A1 : disable(A1,A2); -1,A2 : disable(A1,A2)} > 0.
|
||||
|
||||
scope(X,V) :- active(A), precondition(A,X,V), _parallel = 2.
|
||||
|
||||
% Define relevant fluents w.r.t. parallel mode
|
||||
|
||||
fluent(X,V) :- produce(X,V).
|
||||
fluent(X,V) :- persist(X,V).
|
||||
fluent(X,V) :- initialState(X,V), fluent(X).
|
||||
fluent(X,V) :- active(A), postcondition(A,X,V), fluent(X).
|
||||
fluent(X) :- fluent(X,V).
|
||||
fluent(X) :- diverge(A1,A2,X), not exclude(A1,A2).
|
||||
fluent(X) :- active(A), has_condition(A,X,1), 0 <= _parallel, _parallel < 5, _shallow != 0.
|
||||
|
||||
% Define unsubsumed mutexes
|
||||
|
||||
mutex(G,X) :- mutexGroup(G), contains(G,X,V), fluent(X,V).
|
||||
mutex(G) :- mutexGroup(G), #count{X : mutex(G,X)} > 1.
|
||||
|
||||
% Define initial state
|
||||
|
||||
holds(X,V,0) :- initialState(X,V), fluent(X).
|
||||
|
||||
:- fluent(X), #count{V : holds(X,V,0)} > 1.
|
||||
:- mutex(G), #count{X,V : holds(X,V,0), contains(G,X,V)} > 1.
|
||||
|
||||
% STEP PROGRAM
|
||||
|
||||
#program step(t).
|
||||
|
||||
% Generate successor state
|
||||
|
||||
1 {holds(X,V,t) : fluent(X,V)} 1 :- fluent(X).
|
||||
|
||||
:- mutex(G), #count{X,V : holds(X,V,t), contains(G,X,V)} > 1.
|
||||
|
||||
change(X,t) :- holds(X,V,t-1), not holds(X,V,t), _inertia != 0.
|
||||
|
||||
% Generate actions
|
||||
|
||||
{occurs(A,t)} :- active(A).
|
||||
|
||||
:- planner_on = 0, not occurs(A,t) : active(A).
|
||||
|
||||
:- occurs(A,t), postcondition(A,X,V), fluent(X), not holds(X,V,t).
|
||||
|
||||
effect(X,t) :- occurs(A,t), postcondition(A,X,V), fluent(X), not precondition(A,X,V),
|
||||
_inertia != 0.
|
||||
|
||||
:- change(X,t), not effect(X,t).
|
||||
|
||||
:- _inertia = 0, holds(X,V,t), not holds(X,V,t-1),
|
||||
not occurs(A,t) : active(A), postcondition(A,X,V), not precondition(A,X,V).
|
||||
|
||||
% Checks w.r.t. parallel mode
|
||||
|
||||
:- _parallel != 0, _parallel != 1, _parallel != 2, _parallel != 3, _parallel != 4,
|
||||
#count{A : occurs(A,t)} > 1.
|
||||
|
||||
:- _parallel != 2, occurs(A,t), precondition(A,X,V), not holds(X,V,t-1).
|
||||
|
||||
:- _parallel = 1, occurs(A,t), precondition(A,X,V), not has_condition(A,X,1), not holds(X,V,t).
|
||||
|
||||
single(X,t) :- occurs(A,t), selfdefeat(A,X).
|
||||
|
||||
:- single(X,t), #count{A : occurs(A,t), postcondition(A,X,V), not precondition(A,X,V)} > 1.
|
||||
|
||||
proceed(X,V,t) :- holds(X,V,t-1), scope(X,V).
|
||||
proceed(X,V,t) :- perform(A,t), scope(X,V), postcondition(A,X,V), not precondition(A,X,V),
|
||||
occurs(A,t).
|
||||
|
||||
perform(A,t) :- active(A), 1 < _parallel, _parallel < 4,
|
||||
proceed(X,V,t) : precondition(A,X,V), _parallel = 2;
|
||||
alright(A1,t) : disable(A,A1).
|
||||
|
||||
alright(A,t) :- active(A), 1 < _parallel, _parallel < 4, not occurs(A,t).
|
||||
alright(A,t) :- perform(A,t).
|
||||
|
||||
:- 1 < _parallel, _parallel < 4, active(A), not alright(A,t).
|
||||
|
||||
#edge((A1,t),(A2,t)) : disable(A1,A2), occurs(A1,t), _parallel = 4, not disable.
|
||||
#edge((A1,t),(A2,t)) : disable(A1,A2), occurs(A2,t), disable.
|
||||
|
||||
% CHECK PROGRAM
|
||||
|
||||
#program check(t).
|
||||
|
||||
% Check goal conditions
|
||||
|
||||
:- query(t), goal(X,V), not holds(X,V,t).
|
||||
|
||||
% DISPLAY PART
|
||||
|
||||
#show occurs/2.
|
@ -1,7 +1,7 @@
|
||||
#ifndef __PLASP__LANGUAGE_H
|
||||
#define __PLASP__LANGUAGE_H
|
||||
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <string>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -18,11 +18,11 @@ class Language
|
||||
enum class Type
|
||||
{
|
||||
Unknown,
|
||||
Automatic,
|
||||
PDDL,
|
||||
SAS
|
||||
};
|
||||
|
||||
static std::string toString(Type language);
|
||||
static Language::Type fromString(const std::string &languageName);
|
||||
|
||||
public:
|
||||
|
@ -1,8 +1,9 @@
|
||||
#ifndef __PLASP__LANGUAGE_DETECTION_H
|
||||
#define __PLASP__LANGUAGE_DETECTION_H
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/Language.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -13,32 +14,34 @@ namespace plasp
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Language::Type detectLanguage(utils::Parser<utils::CaseInsensitiveParserPolicy> &parser)
|
||||
inline Language::Type detectLanguage(tokenize::Tokenizer<tokenize::CaseInsensitiveTokenizerPolicy> &tokenizer)
|
||||
{
|
||||
parser.skipWhiteSpace();
|
||||
tokenizer.skipWhiteSpace();
|
||||
|
||||
// SAS begins with "begin_version"
|
||||
if (parser.testAndSkip<std::string>("begin"))
|
||||
if (tokenizer.testAndSkip<std::string>("begin"))
|
||||
{
|
||||
parser.seek(0);
|
||||
tokenizer.seek(0);
|
||||
return Language::Type::SAS;
|
||||
}
|
||||
|
||||
// Skip potential PDDL comments
|
||||
while (parser.currentCharacter() == ';')
|
||||
while (tokenizer.currentCharacter() == ';')
|
||||
{
|
||||
parser.skipLine();
|
||||
parser.skipWhiteSpace();
|
||||
tokenizer.skipLine();
|
||||
tokenizer.skipWhiteSpace();
|
||||
}
|
||||
|
||||
// PDDL contains sections starting with "(define"
|
||||
if (parser.testAndSkip<std::string>("(") && parser.testAndSkip<std::string>("define"))
|
||||
// PDDL contains sections starting with “(define”
|
||||
// Some legacy domains contain “in-package” sections, however
|
||||
if (tokenizer.testAndSkip<std::string>("(")
|
||||
&& (tokenizer.testAndSkip<std::string>("define") || tokenizer.testAndSkip<std::string>("in-package")))
|
||||
{
|
||||
parser.seek(std::ios::beg);
|
||||
tokenizer.seek(std::ios::beg);
|
||||
return Language::Type::PDDL;
|
||||
}
|
||||
|
||||
parser.seek(std::ios::beg);
|
||||
tokenizer.seek(std::ios::beg);
|
||||
return Language::Type::Unknown;
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,11 @@
|
||||
#ifndef __PLASP__UTILS__TRANSLATOR_EXCEPTION_H
|
||||
#define __PLASP__UTILS__TRANSLATOR_EXCEPTION_H
|
||||
#ifndef __PLASP__TRANSLATOR_EXCEPTION_H
|
||||
#define __PLASP__TRANSLATOR_EXCEPTION_H
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -50,7 +48,6 @@ class TranslatorException: public std::exception
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,48 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__ACTION_H
|
||||
#define __PLASP__PDDL__ACTION_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/expressions/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Action
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Action
|
||||
{
|
||||
public:
|
||||
static void parseDeclaration(Context &context, Domain &domain);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
|
||||
const expressions::Variables ¶meters() const;
|
||||
const Expression *precondition() const;
|
||||
const Expression *effect() const;
|
||||
|
||||
private:
|
||||
Action() = default;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
expressions::Variables m_parameters;
|
||||
std::unique_ptr<Expression> m_precondition;
|
||||
std::unique_ptr<Expression> m_effect;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,57 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__CONSISTENCY_EXCEPTION_H
|
||||
#define __PLASP__PDDL__CONSISTENCY_EXCEPTION_H
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ConsistencyException
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ConsistencyException: public std::exception
|
||||
{
|
||||
public:
|
||||
explicit ConsistencyException()
|
||||
: ConsistencyException("unspecified consistency error")
|
||||
{
|
||||
}
|
||||
|
||||
explicit ConsistencyException(const char *message)
|
||||
: ConsistencyException(static_cast<std::string>(message))
|
||||
{
|
||||
}
|
||||
|
||||
explicit ConsistencyException(const std::string &message)
|
||||
: m_message{message}
|
||||
{
|
||||
}
|
||||
|
||||
~ConsistencyException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
const char *what() const throw()
|
||||
{
|
||||
if (m_message.empty())
|
||||
return "unspecified consistency error";
|
||||
|
||||
return m_message.c_str();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_message;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,70 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__CONTEXT_H
|
||||
#define __PLASP__PDDL__CONTEXT_H
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/pddl/Parser.h>
|
||||
#include <plasp/utils/Logger.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Context
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Context
|
||||
{
|
||||
public:
|
||||
Context() = default;
|
||||
~Context() = default;
|
||||
|
||||
explicit Context(Parser &&otherParser)
|
||||
: parser{std::move(otherParser)}
|
||||
{
|
||||
}
|
||||
|
||||
explicit Context(utils::Logger &&otherLogger)
|
||||
: logger{std::move(otherLogger)}
|
||||
{
|
||||
}
|
||||
|
||||
explicit Context(Parser &&otherParser, utils::Logger &&otherLogger)
|
||||
: parser{std::move(otherParser)},
|
||||
logger{std::move(otherLogger)}
|
||||
{
|
||||
}
|
||||
|
||||
Context(const Context &other) = delete;
|
||||
Context &operator=(const Context &other) = delete;
|
||||
|
||||
Context(Context &&other)
|
||||
: parser(std::move(other.parser)),
|
||||
logger(std::move(other.logger))
|
||||
{
|
||||
}
|
||||
|
||||
Context &operator=(Context &&other)
|
||||
{
|
||||
parser = std::move(other.parser);
|
||||
logger = std::move(other.logger);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Parser parser;
|
||||
utils::Logger logger;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,59 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__DESCRIPTION_H
|
||||
#define __PLASP__PDDL__DESCRIPTION_H
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <plasp/pddl/Domain.h>
|
||||
#include <plasp/pddl/Problem.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Description
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Description
|
||||
{
|
||||
public:
|
||||
static Description fromContext(Context &&context);
|
||||
static Description fromStream(std::istream &istream);
|
||||
static Description fromFile(const std::string &path);
|
||||
static Description fromFiles(const std::vector<std::string> &paths);
|
||||
|
||||
public:
|
||||
Context &context();
|
||||
const Context &context() const;
|
||||
|
||||
const Domain &domain() const;
|
||||
|
||||
bool containsProblem() const;
|
||||
const Problem &problem() const;
|
||||
|
||||
private:
|
||||
Description();
|
||||
|
||||
void parse();
|
||||
void findSections();
|
||||
|
||||
void checkConsistency();
|
||||
|
||||
Context m_context;
|
||||
|
||||
utils::Stream::Position m_domainPosition;
|
||||
std::unique_ptr<Domain> m_domain;
|
||||
utils::Stream::Position m_problemPosition;
|
||||
std::unique_ptr<Problem> m_problem;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,93 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__DOMAIN_H
|
||||
#define __PLASP__PDDL__DOMAIN_H
|
||||
|
||||
#include <plasp/pddl/Action.h>
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/Parser.h>
|
||||
#include <plasp/pddl/Requirement.h>
|
||||
#include <plasp/pddl/expressions/Constant.h>
|
||||
#include <plasp/pddl/expressions/PredicateDeclaration.h>
|
||||
#include <plasp/pddl/expressions/PrimitiveType.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Domain
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Domain
|
||||
{
|
||||
public:
|
||||
Domain(Context &context);
|
||||
|
||||
public:
|
||||
void findSections();
|
||||
void parse();
|
||||
|
||||
void setName(std::string name);
|
||||
const std::string &name() const;
|
||||
|
||||
const Requirements &requirements() const;
|
||||
bool hasRequirement(Requirement::Type requirementType) const;
|
||||
void checkRequirement(Requirement::Type requirementType) const;
|
||||
|
||||
expressions::PrimitiveTypes &types();
|
||||
const expressions::PrimitiveTypes &types() const;
|
||||
|
||||
expressions::Constants &constants();
|
||||
const expressions::Constants &constants() const;
|
||||
|
||||
expressions::PredicateDeclarations &predicates();
|
||||
const expressions::PredicateDeclarations &predicates() const;
|
||||
|
||||
std::vector<std::unique_ptr<Action>> &actions();
|
||||
const std::vector<std::unique_ptr<Action>> &actions() const;
|
||||
|
||||
void checkConsistency();
|
||||
|
||||
private:
|
||||
void parseSection();
|
||||
|
||||
void parseRequirementSection();
|
||||
void computeDerivedRequirements();
|
||||
|
||||
void parseTypeSection();
|
||||
|
||||
void parseConstantSection();
|
||||
|
||||
void parsePredicateSection();
|
||||
|
||||
void parseActionSection();
|
||||
|
||||
Context &m_context;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
utils::Stream::Position m_requirementsPosition;
|
||||
Requirements m_requirements;
|
||||
|
||||
utils::Stream::Position m_typesPosition;
|
||||
expressions::PrimitiveTypes m_types;
|
||||
|
||||
utils::Stream::Position m_constantsPosition;
|
||||
expressions::Constants m_constants;
|
||||
|
||||
utils::Stream::Position m_predicatesPosition;
|
||||
expressions::PredicateDeclarations m_predicates;
|
||||
|
||||
std::vector<utils::Stream::Position> m_actionPositions;
|
||||
std::vector<std::unique_ptr<Action>> m_actions;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,130 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSION_H
|
||||
#define __PLASP__PDDL__EXPRESSION_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Expression
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Context;
|
||||
class Domain;
|
||||
class ExpressionContext;
|
||||
class ExpressionVisitor;
|
||||
class Problem;
|
||||
|
||||
class Expression;
|
||||
using ExpressionPointer = std::unique_ptr<Expression>;
|
||||
using Expressions = std::vector<ExpressionPointer>;
|
||||
|
||||
namespace expressions
|
||||
{
|
||||
class And;
|
||||
using AndPointer = std::unique_ptr<And>;
|
||||
|
||||
class At;
|
||||
using AtPointer = std::unique_ptr<At>;
|
||||
|
||||
class Constant;
|
||||
using ConstantPointer = std::unique_ptr<Constant>;
|
||||
using Constants = std::vector<ConstantPointer>;
|
||||
|
||||
class Either;
|
||||
using EitherPointer = std::unique_ptr<Either>;
|
||||
|
||||
class Imply;
|
||||
using ImplyPointer = std::unique_ptr<Imply>;
|
||||
|
||||
class Not;
|
||||
using NotPointer = std::unique_ptr<Not>;
|
||||
|
||||
class Or;
|
||||
using OrPointer = std::unique_ptr<Or>;
|
||||
|
||||
class Predicate;
|
||||
using PredicatePointer = std::unique_ptr<Predicate>;
|
||||
using Predicates = std::vector<PredicatePointer>;
|
||||
|
||||
class PredicateDeclaration;
|
||||
using PredicateDeclarationPointer = std::unique_ptr<PredicateDeclaration>;
|
||||
using PredicateDeclarations = std::vector<PredicateDeclarationPointer>;
|
||||
|
||||
class PrimitiveType;
|
||||
using PrimitiveTypePointer = std::unique_ptr<PrimitiveType>;
|
||||
using PrimitiveTypes = std::vector<PrimitiveTypePointer>;
|
||||
|
||||
class Unsupported;
|
||||
using UnsupportedPointer = std::unique_ptr<Unsupported>;
|
||||
|
||||
class Variable;
|
||||
using VariablePointer = std::unique_ptr<Variable>;
|
||||
using Variables = std::vector<VariablePointer>;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Expression
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
And,
|
||||
At,
|
||||
Binary,
|
||||
Constant,
|
||||
Either,
|
||||
Imply,
|
||||
Not,
|
||||
Or,
|
||||
PredicateDeclaration,
|
||||
Predicate,
|
||||
PrimitiveType,
|
||||
Unsupported,
|
||||
Variable
|
||||
};
|
||||
|
||||
public:
|
||||
virtual ~Expression() = default;
|
||||
|
||||
virtual Type expressionType() const = 0;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
class ExpressionCRTP: public Expression
|
||||
{
|
||||
public:
|
||||
Type expressionType() const override final
|
||||
{
|
||||
return Derived::ExpressionType;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer parseLiteral(Context &context, ExpressionContext &expressionContext);
|
||||
ExpressionPointer parseAtomicFormula(Context &context, ExpressionContext &expressionContext);
|
||||
|
||||
ExpressionPointer parsePreconditionExpression(Context &context,
|
||||
ExpressionContext &expressionContext);
|
||||
ExpressionPointer parseExpression(Context &context, ExpressionContext &expressionContext);
|
||||
|
||||
ExpressionPointer parseEffectExpression(Context &context,
|
||||
ExpressionContext &expressionContext);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,38 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSION_CONTEXT_H
|
||||
#define __PLASP__PDDL__EXPRESSION_CONTEXT_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/Requirement.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ExpressionContext
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ExpressionContext
|
||||
{
|
||||
public:
|
||||
ExpressionContext(Domain &domain, expressions::Variables ¶meters);
|
||||
ExpressionContext(Domain &domain, Problem *problem, expressions::Variables ¶meters);
|
||||
|
||||
bool hasRequirement(Requirement::Type requirementType) const;
|
||||
void checkRequirement(Requirement::Type requirementType) const;
|
||||
|
||||
Domain &domain;
|
||||
Problem *problem;
|
||||
|
||||
expressions::Variables ¶meters;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,35 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__INITIAL_STATE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__INITIAL_STATE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// InitialState
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class InitialState
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<InitialState> parseDeclaration(Context &context,
|
||||
ExpressionContext &expressionContext);
|
||||
|
||||
public:
|
||||
const Expressions &facts() const;
|
||||
|
||||
private:
|
||||
Expressions m_facts;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,49 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__PARSER_H
|
||||
#define __PLASP__PDDL__PARSER_H
|
||||
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Parser
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PDDLParserPolicy
|
||||
{
|
||||
public:
|
||||
static char transformCharacter(char c) noexcept
|
||||
{
|
||||
return std::tolower(c);
|
||||
}
|
||||
|
||||
static bool isWhiteSpaceCharacter(char c)
|
||||
{
|
||||
return std::iswspace(c);
|
||||
}
|
||||
|
||||
static bool isIdentifierCharacter(char c)
|
||||
{
|
||||
return c != '?'
|
||||
&& c != '('
|
||||
&& c != ')'
|
||||
&& c != ';'
|
||||
&& std::isgraph(c);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using Parser = utils::Parser<PDDLParserPolicy>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,85 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__PROBLEM_H
|
||||
#define __PLASP__PDDL__PROBLEM_H
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/InitialState.h>
|
||||
#include <plasp/pddl/Parser.h>
|
||||
#include <plasp/pddl/Requirement.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Problem
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Problem
|
||||
{
|
||||
public:
|
||||
Problem(Context &context, Domain &domain);
|
||||
|
||||
void findSections();
|
||||
void parse();
|
||||
|
||||
Domain &domain();
|
||||
const Domain &domain() const;
|
||||
|
||||
const std::string &name() const;
|
||||
|
||||
const Requirements &requirements() const;
|
||||
bool hasRequirement(Requirement::Type requirementType) const;
|
||||
void checkRequirement(Requirement::Type requirementType) const;
|
||||
|
||||
expressions::Constants &objects();
|
||||
const expressions::Constants &objects() const;
|
||||
|
||||
InitialState &initialState();
|
||||
const InitialState &initialState() const;
|
||||
|
||||
const Expression &goal() const;
|
||||
|
||||
void checkConsistency();
|
||||
|
||||
private:
|
||||
void parseRequirementSection();
|
||||
void computeDerivedRequirements();
|
||||
|
||||
void parseDomainSection();
|
||||
|
||||
void parseObjectSection();
|
||||
|
||||
void parseInitialStateSection();
|
||||
|
||||
void parseGoalSection();
|
||||
|
||||
Context &m_context;
|
||||
Domain &m_domain;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
utils::Stream::Position m_domainPosition;
|
||||
|
||||
utils::Stream::Position m_requirementsPosition;
|
||||
Requirements m_requirements;
|
||||
|
||||
utils::Stream::Position m_objectsPosition;
|
||||
expressions::Constants m_objects;
|
||||
|
||||
utils::Stream::Position m_initialStatePosition;
|
||||
std::unique_ptr<InitialState> m_initialState;
|
||||
|
||||
utils::Stream::Position m_goalPosition;
|
||||
ExpressionPointer m_goal;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,72 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__REQUIREMENT_H
|
||||
#define __PLASP__PDDL__REQUIREMENT_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Requirement
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Requirement;
|
||||
using Requirements = std::vector<Requirement>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Requirement
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
STRIPS,
|
||||
Typing,
|
||||
NegativePreconditions,
|
||||
DisjunctivePreconditions,
|
||||
Equality,
|
||||
ExistentialPreconditions,
|
||||
UniversalPreconditions,
|
||||
QuantifiedPreconditions,
|
||||
ConditionalEffects,
|
||||
Fluents,
|
||||
NumericFluents,
|
||||
ObjectFluents,
|
||||
ADL,
|
||||
DurativeActions,
|
||||
DurationInequalities,
|
||||
ContinuousEffects,
|
||||
DerivedPredicates,
|
||||
TimedInitialLiterals,
|
||||
Preferences,
|
||||
Constraints,
|
||||
ActionCosts,
|
||||
GoalUtilities
|
||||
};
|
||||
|
||||
static Requirement parse(Context &context);
|
||||
|
||||
public:
|
||||
Requirement(Type type);
|
||||
|
||||
Type type() const;
|
||||
|
||||
std::string toPDDL() const;
|
||||
std::string toASP() const;
|
||||
|
||||
private:
|
||||
Type m_type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,9 +1,10 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATOR_ASP_H
|
||||
#define __PLASP__PDDL__TRANSLATOR_ASP_H
|
||||
|
||||
#include <plasp/pddl/Description.h>
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
#include <iosfwd>
|
||||
#include <pddl/NormalizedASTForward.h>
|
||||
#include <pddl/Parse.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -19,28 +20,25 @@ namespace pddl
|
||||
class TranslatorASP
|
||||
{
|
||||
public:
|
||||
explicit TranslatorASP(const Description &description, utils::LogStream &outputStream);
|
||||
explicit TranslatorASP(const ::pddl::normalizedAST::Description &description, colorlog::ColorStream &outputStream);
|
||||
|
||||
void translate() const;
|
||||
|
||||
private:
|
||||
void translateDomain() const;
|
||||
void translateUtils() const;
|
||||
void translateTypes() const;
|
||||
void translatePredicates() const;
|
||||
void translateDerivedPredicates(const ::pddl::normalizedAST::DerivedPredicateDeclarations &derivedPredicates) const;
|
||||
void translateActions() const;
|
||||
|
||||
void translateProblem() const;
|
||||
void translateInitialState() const;
|
||||
void translateGoal() const;
|
||||
void translateConstants(const std::string &heading, const ::pddl::ast::ConstantDeclarations &constants) const;
|
||||
|
||||
void translateConstants(const std::string &heading, const expressions::Constants &constants) const;
|
||||
void translateVariablesHead(const expressions::Variables &variables) const;
|
||||
void translateVariablesBody(const expressions::Variables &variables) const;
|
||||
void translateLiteral(const Expression &literal) const;
|
||||
void translatePredicate(const expressions::Predicate &predicate) const;
|
||||
|
||||
const Description &m_description;
|
||||
utils::LogStream &m_outputStream;
|
||||
const ::pddl::normalizedAST::Description &m_description;
|
||||
colorlog::ColorStream &m_outputStream;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1,105 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__AT_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__AT_H
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// At
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class At: public ExpressionCRTP<At>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::At;
|
||||
|
||||
template<typename ExpressionParser>
|
||||
static AtPointer parse(Context &context, ExpressionContext &expressionContext,
|
||||
ExpressionParser parseExpression);
|
||||
|
||||
static const size_t TimePointStart = std::numeric_limits<size_t>::max();
|
||||
static const size_t TimePointEnd = std::numeric_limits<size_t>::max() - 1;
|
||||
|
||||
public:
|
||||
At();
|
||||
|
||||
size_t timePoint() const;
|
||||
|
||||
const Expression *argument() const;
|
||||
|
||||
private:
|
||||
void setArgument(const Expression *argument);
|
||||
void setArgument(ExpressionPointer &&argument);
|
||||
|
||||
size_t m_timePoint;
|
||||
|
||||
const Expression *m_argument;
|
||||
ExpressionPointer m_argumentStorage;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename ExpressionParser>
|
||||
AtPointer At::parse(Context &context, ExpressionContext &expressionContext,
|
||||
ExpressionParser parseExpression)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
||||
const auto position = parser.position();
|
||||
|
||||
if (!parser.testAndSkip<std::string>("(")
|
||||
|| !parser.testIdentifierAndSkip("at"))
|
||||
{
|
||||
parser.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t timePoint;
|
||||
|
||||
const auto timePointPosition = parser.position();
|
||||
|
||||
if (parser.testIdentifierAndSkip("start"))
|
||||
timePoint = TimePointStart;
|
||||
else if (parser.testIdentifierAndSkip("end"))
|
||||
timePoint = TimePointEnd;
|
||||
else if (parser.probeNumber())
|
||||
{
|
||||
parser.seek(timePointPosition);
|
||||
timePoint = parser.parse<size_t>();
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto expression = std::make_unique<At>(At());
|
||||
|
||||
expression->m_timePoint = timePoint;
|
||||
|
||||
context.parser.skipWhiteSpace();
|
||||
|
||||
// Parse argument
|
||||
expression->setArgument(parseExpression(context, expressionContext));
|
||||
|
||||
parser.expect<std::string>(")");
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,111 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__BINARY_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__BINARY_H
|
||||
|
||||
#include <plasp/pddl/ConsistencyException.h>
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/expressions/Variable.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Binary
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
class Binary: public ExpressionCRTP<Derived>
|
||||
{
|
||||
public:
|
||||
template<typename ExpressionParser>
|
||||
static std::unique_ptr<Derived> parse(Context &context,
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
const std::array<const Expression *, 2> &arguments() const;
|
||||
|
||||
private:
|
||||
template<size_t i>
|
||||
void setArgument(const Expression *argument);
|
||||
template<size_t i>
|
||||
void setArgument(ExpressionPointer &&argument);
|
||||
|
||||
std::array<const Expression *, 2> m_arguments;
|
||||
std::array<ExpressionPointer, 2> m_argumentStorage;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
template<typename ExpressionParser>
|
||||
std::unique_ptr<Derived> Binary<Derived>::parse(Context &context,
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
||||
const auto position = parser.position();
|
||||
|
||||
if (!parser.testAndSkip<std::string>("(")
|
||||
|| !parser.testIdentifierAndSkip(Derived::Identifier))
|
||||
{
|
||||
parser.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto expression = std::make_unique<Derived>();
|
||||
|
||||
// Assume that expression identifier (imply, exists, etc.) is already parsed
|
||||
// Parse arguments of the expression
|
||||
expression->Binary<Derived>::setArgument<0>(parseExpression(context, expressionContext));
|
||||
expression->Binary<Derived>::setArgument<1>(parseExpression(context, expressionContext));
|
||||
|
||||
parser.expect<std::string>(")");
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
template<size_t i>
|
||||
void Binary<Derived>::setArgument(const Expression *expression)
|
||||
{
|
||||
static_assert(i <= 2, "Index out of range");
|
||||
|
||||
m_argumentStorage[i] = nullptr;
|
||||
m_arguments[i] = expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
template<size_t i>
|
||||
void Binary<Derived>::setArgument(ExpressionPointer &&expression)
|
||||
{
|
||||
static_assert(i <= 2, "Index out of range");
|
||||
|
||||
m_argumentStorage[i] = std::move(expression);
|
||||
m_arguments[i] = m_argumentStorage[i].get();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
const std::array<const Expression *, 2> &Binary<Derived>::arguments() const
|
||||
{
|
||||
return m_arguments;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,64 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__CONSTANT_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__CONSTANT_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Constant
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Constant: public ExpressionCRTP<Constant>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Constant;
|
||||
|
||||
static void parseTypedDeclaration(Context &context, Domain &domain);
|
||||
static void parseTypedDeclarations(Context &context, Domain &domain);
|
||||
static void parseTypedDeclaration(Context &context, Problem &problem);
|
||||
static void parseTypedDeclarations(Context &context, Problem &problem);
|
||||
|
||||
static Constant *parseAndFind(Context &context, const Domain &domain);
|
||||
static Constant *parseAndFind(Context &context, const Problem &problem);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const PrimitiveType *type() const;
|
||||
|
||||
private:
|
||||
static ConstantPointer parseDeclaration(Context &context);
|
||||
static void parseTypedDeclaration(Context &context, Domain &domain, Constants &constants);
|
||||
|
||||
static Constant *parseAndFind(const std::string &constantName, const Constants &constants);
|
||||
|
||||
Constant();
|
||||
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
void setType(const PrimitiveType *parentType);
|
||||
|
||||
bool m_isDirty;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
const PrimitiveType *m_type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,33 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__EITHER_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__EITHER_H
|
||||
|
||||
#include <plasp/pddl/expressions/NAry.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Either
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Either: public NAry<Either>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Either;
|
||||
|
||||
static const std::string Identifier;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,117 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__N_ARY_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__N_ARY_H
|
||||
|
||||
#include <plasp/pddl/ConsistencyException.h>
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/pddl/expressions/Variable.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// NAry
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
class NAry: public ExpressionCRTP<Derived>
|
||||
{
|
||||
public:
|
||||
template<typename ExpressionParser>
|
||||
static std::unique_ptr<Derived> parse(Context &context,
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
const std::vector<const Expression *> &arguments() const;
|
||||
|
||||
private:
|
||||
void addArgument(const Expression *argument);
|
||||
void addArgument(ExpressionPointer &&argument);
|
||||
|
||||
std::vector<const Expression *> m_arguments;
|
||||
Expressions m_argumentStorage;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
template<typename ExpressionParser>
|
||||
std::unique_ptr<Derived> NAry<Derived>::parse(Context &context,
|
||||
ExpressionContext &expressionContext, ExpressionParser parseExpression)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
||||
const auto position = parser.position();
|
||||
|
||||
if (!parser.testAndSkip<std::string>("(")
|
||||
|| !parser.testIdentifierAndSkip(Derived::Identifier))
|
||||
{
|
||||
parser.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto expression = std::make_unique<Derived>();
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
// Assume that expression identifier (and, or, etc.) is already parsed
|
||||
// Parse arguments of the expression
|
||||
while (parser.currentCharacter() != ')')
|
||||
{
|
||||
expression->addArgument(parseExpression(context, expressionContext));
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
}
|
||||
|
||||
if (expression->m_arguments.empty())
|
||||
context.logger.logWarning(parser.coordinate(), "“" + Derived::Identifier + "” expressions should not be empty");
|
||||
|
||||
parser.expect<std::string>(")");
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
void NAry<Derived>::addArgument(const Expression *argument)
|
||||
{
|
||||
if (!argument)
|
||||
return;
|
||||
|
||||
m_arguments.emplace_back(argument);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
void NAry<Derived>::addArgument(ExpressionPointer &&argument)
|
||||
{
|
||||
if (!argument)
|
||||
return;
|
||||
|
||||
m_argumentStorage.emplace_back(std::move(argument));
|
||||
m_arguments.emplace_back(m_argumentStorage.back().get());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Derived>
|
||||
const std::vector<const Expression *> &NAry<Derived>::arguments() const
|
||||
{
|
||||
return m_arguments;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,77 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__NOT_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__NOT_H
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Not
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Not: public ExpressionCRTP<Not>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Not;
|
||||
|
||||
template<typename ExpressionParser>
|
||||
static NotPointer parse(Context &context, ExpressionContext &expressionContext,
|
||||
ExpressionParser parseExpression);
|
||||
|
||||
public:
|
||||
Not();
|
||||
|
||||
const Expression *argument() const;
|
||||
|
||||
private:
|
||||
void setArgument(const Expression *argument);
|
||||
void setArgument(ExpressionPointer &&argument);
|
||||
|
||||
const Expression *m_argument;
|
||||
ExpressionPointer m_argumentStorage;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename ExpressionParser>
|
||||
NotPointer Not::parse(Context &context, ExpressionContext &expressionContext,
|
||||
ExpressionParser parseExpression)
|
||||
{
|
||||
auto &parser = context.parser;
|
||||
|
||||
const auto position = parser.position();
|
||||
|
||||
if (!parser.testAndSkip<std::string>("(")
|
||||
|| !parser.testIdentifierAndSkip("not"))
|
||||
{
|
||||
parser.seek(position);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto expression = std::make_unique<Not>(Not());
|
||||
|
||||
context.parser.skipWhiteSpace();
|
||||
|
||||
// Parse argument
|
||||
expression->setArgument(parseExpression(context, expressionContext));
|
||||
|
||||
parser.expect<std::string>(")");
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,50 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__PREDICATE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__PREDICATE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Predicate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Predicate: public ExpressionCRTP<Predicate>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Predicate;
|
||||
|
||||
static PredicatePointer parse(Context &context, ExpressionContext &expressionContext);
|
||||
static PredicatePointer parse(Context &context, const Problem &problem);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const std::vector<const Expression *> &arguments() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
private:
|
||||
Predicate();
|
||||
|
||||
void setDeclared();
|
||||
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
std::vector<const Expression *> m_arguments;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,49 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__PREDICATE_DECLARATION_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__PREDICATE_DECLARATION_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PredicateDeclaration
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PredicateDeclaration: public ExpressionCRTP<PredicateDeclaration>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::PredicateDeclaration;
|
||||
|
||||
static void parse(Context &context, Domain &domain);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const Variables &arguments() const;
|
||||
|
||||
bool isDeclared() const;
|
||||
|
||||
private:
|
||||
PredicateDeclaration();
|
||||
|
||||
void setDeclared();
|
||||
|
||||
bool m_isDeclared;
|
||||
|
||||
std::string m_name;
|
||||
Variables m_parameters;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,55 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__PRIMITIVE_TYPE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__PRIMITIVE_TYPE_H
|
||||
|
||||
#include <plasp/pddl/ConsistencyException.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PrimitiveType
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class PrimitiveType: public ExpressionCRTP<PrimitiveType>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::PrimitiveType;
|
||||
|
||||
static void parseDeclaration(Context &context, Domain &domain);
|
||||
static void parseTypedDeclaration(Context &context, Domain &domain);
|
||||
|
||||
static PrimitiveType *parseAndFind(Context &context, Domain &domain);
|
||||
|
||||
public:
|
||||
PrimitiveType();
|
||||
PrimitiveType(std::string name);
|
||||
|
||||
const std::string &name() const;
|
||||
const std::vector<const PrimitiveType *> &parentTypes() const;
|
||||
|
||||
private:
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
bool m_isDirty;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
std::vector<const PrimitiveType *> m_parentTypes;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,40 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__UNSUPPORTED_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__UNSUPPORTED_H
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Unsupported
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Unsupported: public ExpressionCRTP<Unsupported>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Unsupported;
|
||||
|
||||
static UnsupportedPointer parse(Context &context);
|
||||
|
||||
public:
|
||||
const std::string &type() const;
|
||||
|
||||
private:
|
||||
std::string m_type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,61 +0,0 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__VARIABLE_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__VARIABLE_H
|
||||
|
||||
#include <plasp/pddl/Expression.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Variable
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Variable: public ExpressionCRTP<Variable>
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Variable;
|
||||
|
||||
static void parseTypedDeclaration(Context &context, ExpressionContext &expressionContext);
|
||||
static void parseTypedDeclarations(Context &context, ExpressionContext &expressionContext);
|
||||
|
||||
static const Variable *parseAndFind(Context &context,
|
||||
const ExpressionContext &expressionContext);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
const Expression *type() const;
|
||||
|
||||
void setDirty(bool isDirty = true);
|
||||
bool isDirty() const;
|
||||
|
||||
void setType(const Expression *type);
|
||||
|
||||
private:
|
||||
static void parseDeclaration(Context &context, Variables ¶meters);
|
||||
|
||||
private:
|
||||
Variable();
|
||||
|
||||
bool m_isDirty;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
const Expression *m_type;
|
||||
|
||||
// Stores "either" expression if necessary
|
||||
ExpressionPointer m_eitherExpression;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
110
include/plasp/pddl/translation/ConditionalEffect.h
Normal file
110
include/plasp/pddl/translation/ConditionalEffect.h
Normal file
@ -0,0 +1,110 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__CONDITIONAL_EFFECT_H
|
||||
#define __PLASP__PDDL__TRANSLATION__CONDITIONAL_EFFECT_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddl/NormalizedAST.h>
|
||||
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
#include <plasp/pddl/translation/Variables.h>
|
||||
#include <plasp/pddl/translation/VariableStack.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ConditionalEffect
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename PrintObjectName>
|
||||
inline void translateConditionalEffect(colorlog::ColorStream &outputStream,
|
||||
const ::pddl::normalizedAST::ConditionalEffect &conditionalEffect,
|
||||
PrintObjectName printObjectName, VariableStack &variableStack,
|
||||
size_t &numberOfConditionalEffects, VariableIDMap &variableIDs)
|
||||
{
|
||||
const auto handlePredicate =
|
||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
||||
{
|
||||
outputStream << std::endl << colorlog::Function("postcondition") << "(";
|
||||
printObjectName();
|
||||
outputStream
|
||||
<< ", " << colorlog::Keyword("effect") << "("
|
||||
<< colorlog::Number<size_t>(numberOfConditionalEffects) << ")"
|
||||
<< ", ";
|
||||
translatePredicateToVariable(outputStream, *predicate, variableIDs, isPositive);
|
||||
outputStream << ") :- " << colorlog::Function("action") << "(";
|
||||
printObjectName();
|
||||
outputStream << ")";
|
||||
|
||||
if (!variableStack.layers.empty())
|
||||
for (const auto &layer : variableStack.layers)
|
||||
{
|
||||
if (!layer->empty())
|
||||
outputStream << ", ";
|
||||
|
||||
translateVariablesForRuleBody(outputStream, *layer, variableIDs);
|
||||
}
|
||||
|
||||
outputStream << ".";
|
||||
};
|
||||
|
||||
const auto handleNegatedPredicate =
|
||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate)
|
||||
{
|
||||
handlePredicate(predicate, false);
|
||||
};
|
||||
|
||||
const auto handleDerivedPredicate =
|
||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &, bool = true)
|
||||
{
|
||||
// TODO: refactor as to exclude derived predicates from the Effect variant
|
||||
throw TranslatorException("derived predicates should not appear in effects, please report to the bug tracker");
|
||||
};
|
||||
|
||||
const auto handleNegatedDerivedPredicate =
|
||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate)
|
||||
{
|
||||
handleDerivedPredicate(derivedPredicate, false);
|
||||
};
|
||||
|
||||
const auto handleAtomicFormula =
|
||||
[&](const ::pddl::normalizedAST::AtomicFormula &atomicFormula)
|
||||
{
|
||||
atomicFormula.match(handlePredicate, handleDerivedPredicate);
|
||||
};
|
||||
|
||||
const auto handleNot =
|
||||
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> ¬_)
|
||||
{
|
||||
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
|
||||
};
|
||||
|
||||
const auto handleLiteral =
|
||||
[&](const ::pddl::normalizedAST::Literal &literal)
|
||||
{
|
||||
literal.match(handleAtomicFormula, handleNot);
|
||||
};
|
||||
|
||||
const auto handleAnd =
|
||||
[&](const ::pddl::normalizedAST::AndPointer<::pddl::normalizedAST::Literal> &and_)
|
||||
{
|
||||
for (const auto &argument : and_->arguments)
|
||||
handleLiteral(argument);
|
||||
};
|
||||
|
||||
conditionalEffect.match(handleAnd, handleLiteral);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
127
include/plasp/pddl/translation/DerivedPredicate.h
Normal file
127
include/plasp/pddl/translation/DerivedPredicate.h
Normal file
@ -0,0 +1,127 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__DERIVED_PREDICATE_H
|
||||
#define __PLASP__PDDL__TRANSLATION__DERIVED_PREDICATE_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddl/NormalizedAST.h>
|
||||
#include <pddl/Parse.h>
|
||||
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
#include <plasp/pddl/translation/Variables.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DerivedPredicate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void translateDerivedPredicate(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::DerivedPredicate &derivedPredicate, VariableIDMap &variableIDs);
|
||||
void translateDerivedPredicateDeclaration(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::DerivedPredicateDeclaration &derivedPredicateDeclaration, VariableIDMap &variableIDs);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: avoid code duplication with translatePredicate
|
||||
inline void translateDerivedPredicate(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::DerivedPredicate &derivedPredicate, VariableIDMap &variableIDs)
|
||||
{
|
||||
const auto &arguments = derivedPredicate.arguments;
|
||||
|
||||
if (arguments.empty())
|
||||
{
|
||||
outputStream << *derivedPredicate.declaration;
|
||||
return;
|
||||
}
|
||||
|
||||
outputStream << "(" << *derivedPredicate.declaration;
|
||||
|
||||
for (const auto &argument : arguments)
|
||||
{
|
||||
outputStream << ", ";
|
||||
|
||||
const auto handleConstant =
|
||||
[&](const ::pddl::normalizedAST::ConstantPointer &constant)
|
||||
{
|
||||
outputStream << colorlog::Keyword("constant") << "(" << *constant << ")";
|
||||
};
|
||||
|
||||
const auto handleVariable =
|
||||
[&](const ::pddl::normalizedAST::VariablePointer &variable)
|
||||
{
|
||||
translateVariable(outputStream, *variable, variableIDs);
|
||||
};
|
||||
|
||||
argument.match(handleConstant, handleVariable);
|
||||
}
|
||||
|
||||
outputStream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translateDerivedPredicateDeclaration(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::DerivedPredicateDeclaration &derivedPredicateDeclaration, VariableIDMap &variableIDs)
|
||||
{
|
||||
outputStream << colorlog::Keyword("derivedVariable") << "(";
|
||||
|
||||
if (derivedPredicateDeclaration.parameters.empty())
|
||||
{
|
||||
outputStream << derivedPredicateDeclaration << ")";
|
||||
return;
|
||||
}
|
||||
|
||||
outputStream << "(" << derivedPredicateDeclaration;
|
||||
translateVariablesForRuleHead(outputStream, derivedPredicateDeclaration.parameters, variableIDs);
|
||||
outputStream << "))";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translateDerivedPredicateToVariable(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::DerivedPredicate &derivedPredicate, VariableIDMap &variableIDs, bool isPositive = true)
|
||||
{
|
||||
outputStream << colorlog::Keyword("derivedVariable") << "(";
|
||||
|
||||
translateDerivedPredicate(outputStream, derivedPredicate, variableIDs);
|
||||
|
||||
outputStream
|
||||
<< "), "
|
||||
<< colorlog::Keyword("value") << "("
|
||||
<< colorlog::Keyword("derivedVariable") << "(";
|
||||
|
||||
translateDerivedPredicate(outputStream, derivedPredicate, variableIDs);
|
||||
|
||||
outputStream << "), ";
|
||||
|
||||
if (isPositive)
|
||||
outputStream << colorlog::Boolean("true");
|
||||
else
|
||||
outputStream << colorlog::Boolean("false");
|
||||
|
||||
outputStream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translateDerivedPredicateDeclarationToVariable(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::DerivedPredicateDeclaration &derivedPredicateDeclaration, VariableIDMap &variableIDs, bool isPositive = true)
|
||||
{
|
||||
translateDerivedPredicateDeclaration(outputStream, derivedPredicateDeclaration, variableIDs);
|
||||
outputStream << ", " << colorlog::Keyword("value") << "(";
|
||||
translateDerivedPredicateDeclaration(outputStream, derivedPredicateDeclaration, variableIDs);
|
||||
outputStream << ", ";
|
||||
|
||||
if (isPositive)
|
||||
outputStream << colorlog::Boolean("true");
|
||||
else
|
||||
outputStream << colorlog::Boolean("false");
|
||||
|
||||
outputStream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
106
include/plasp/pddl/translation/DerivedPredicatePrecondition.h
Normal file
106
include/plasp/pddl/translation/DerivedPredicatePrecondition.h
Normal file
@ -0,0 +1,106 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__DERIVED_PREDICATE_PRECONDITION_H
|
||||
#define __PLASP__PDDL__TRANSLATION__DERIVED_PREDICATE_PRECONDITION_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddl/NormalizedAST.h>
|
||||
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/DerivedPredicate.h>
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DerivedPredicatePrecondition
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename PrintObjectName>
|
||||
inline void translateDerivedPredicatePrecondition(colorlog::ColorStream &outputStream,
|
||||
const ::pddl::normalizedAST::DerivedPredicatePrecondition &derivedPredicatePrecondition,
|
||||
const std::string &objectType, PrintObjectName printObjectName, VariableIDMap &variableIDs)
|
||||
{
|
||||
const auto handlePredicate =
|
||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
||||
{
|
||||
outputStream << std::endl << colorlog::Function("precondition") << "(";
|
||||
printObjectName();
|
||||
outputStream << ", ";
|
||||
translatePredicateToVariable(outputStream, *predicate, variableIDs, isPositive);
|
||||
outputStream << ") :- " << colorlog::Function(objectType.c_str()) << "(";
|
||||
printObjectName();
|
||||
outputStream << ").";
|
||||
};
|
||||
|
||||
const auto handleNegatedPredicate =
|
||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate)
|
||||
{
|
||||
handlePredicate(predicate, false);
|
||||
};
|
||||
|
||||
const auto handleDerivedPredicate =
|
||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate, bool isPositive = true)
|
||||
{
|
||||
outputStream << std::endl << colorlog::Function("precondition") << "(";
|
||||
printObjectName();
|
||||
outputStream << ", ";
|
||||
translateDerivedPredicateToVariable(outputStream, *derivedPredicate, variableIDs, isPositive);
|
||||
outputStream << ") :- " << colorlog::Function(objectType.c_str()) << "(";
|
||||
printObjectName();
|
||||
outputStream << ").";
|
||||
};
|
||||
|
||||
const auto handleNegatedDerivedPredicate =
|
||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate)
|
||||
{
|
||||
handleDerivedPredicate(derivedPredicate, false);
|
||||
};
|
||||
|
||||
const auto handleAtomicFormula =
|
||||
[&](const ::pddl::normalizedAST::AtomicFormula &atomicFormula)
|
||||
{
|
||||
atomicFormula.match(handlePredicate, handleDerivedPredicate);
|
||||
};
|
||||
|
||||
const auto handleNot =
|
||||
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> ¬_)
|
||||
{
|
||||
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
|
||||
};
|
||||
|
||||
const auto handleLiteral =
|
||||
[&](const ::pddl::normalizedAST::Literal &literal)
|
||||
{
|
||||
literal.match(handleAtomicFormula, handleNot);
|
||||
};
|
||||
|
||||
const auto handleAnd =
|
||||
[&](const ::pddl::normalizedAST::AndPointer<::pddl::normalizedAST::Literal> &and_)
|
||||
{
|
||||
for (const auto &argument : and_->arguments)
|
||||
handleLiteral(argument);
|
||||
};
|
||||
|
||||
const auto handleOr =
|
||||
[&](const ::pddl::normalizedAST::OrPointer<::pddl::normalizedAST::Literal> &or_)
|
||||
{
|
||||
for (const auto &argument : or_->arguments)
|
||||
handleLiteral(argument);
|
||||
};
|
||||
|
||||
derivedPredicatePrecondition.match(handleLiteral, handleAnd, handleOr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
172
include/plasp/pddl/translation/Effect.h
Normal file
172
include/plasp/pddl/translation/Effect.h
Normal file
@ -0,0 +1,172 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__EFFECT_H
|
||||
#define __PLASP__PDDL__TRANSLATION__EFFECT_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddl/NormalizedAST.h>
|
||||
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/ConditionalEffect.h>
|
||||
#include <plasp/pddl/translation/Precondition.h>
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
#include <plasp/pddl/translation/Variables.h>
|
||||
#include <plasp/pddl/translation/VariableStack.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Effect
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename PrintObjectName>
|
||||
inline void translateEffect(colorlog::ColorStream &outputStream,
|
||||
const ::pddl::normalizedAST::Effect &effect, PrintObjectName printObjectName,
|
||||
VariableStack &variableStack, size_t &numberOfConditionalEffects, VariableIDMap &variableIDs)
|
||||
{
|
||||
const auto handlePredicate =
|
||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
||||
{
|
||||
outputStream << std::endl << colorlog::Function("postcondition") << "(";
|
||||
printObjectName();
|
||||
outputStream
|
||||
<< ", " << colorlog::Keyword("effect") << "("
|
||||
<< colorlog::Reserved("unconditional") << ")"
|
||||
<< ", ";
|
||||
translatePredicateToVariable(outputStream, *predicate, variableIDs, isPositive);
|
||||
outputStream << ") :- " << colorlog::Function("action") << "(";
|
||||
printObjectName();
|
||||
outputStream << ")";
|
||||
|
||||
if (!variableStack.layers.empty())
|
||||
for (const auto &layer : variableStack.layers)
|
||||
{
|
||||
if (!layer->empty())
|
||||
outputStream << ", ";
|
||||
|
||||
translateVariablesForRuleBody(outputStream, *layer, variableIDs);
|
||||
}
|
||||
|
||||
outputStream << ".";
|
||||
};
|
||||
|
||||
const auto handleNegatedPredicate =
|
||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate)
|
||||
{
|
||||
handlePredicate(predicate, false);
|
||||
};
|
||||
|
||||
const auto handleDerivedPredicate =
|
||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &, bool = true)
|
||||
{
|
||||
// TODO: refactor as to exclude derived predicates from the Effect variant
|
||||
throw TranslatorException("derived predicates should not appear in effects, please report to the bug tracker");
|
||||
};
|
||||
|
||||
const auto handleNegatedDerivedPredicate =
|
||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate)
|
||||
{
|
||||
handleDerivedPredicate(derivedPredicate, false);
|
||||
};
|
||||
|
||||
const auto handleAtomicFormula =
|
||||
[&](const ::pddl::normalizedAST::AtomicFormula &atomicFormula)
|
||||
{
|
||||
atomicFormula.match(handlePredicate, handleDerivedPredicate);
|
||||
};
|
||||
|
||||
const auto handleNot =
|
||||
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> ¬_)
|
||||
{
|
||||
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
|
||||
};
|
||||
|
||||
const auto handleLiteral =
|
||||
[&](const ::pddl::normalizedAST::Literal &literal)
|
||||
{
|
||||
literal.match(handleAtomicFormula, handleNot);
|
||||
};
|
||||
|
||||
const auto handleAnd =
|
||||
[&](const ::pddl::normalizedAST::AndPointer<::pddl::normalizedAST::Effect> &and_)
|
||||
{
|
||||
for (const auto &argument : and_->arguments)
|
||||
translateEffect(outputStream, argument, printObjectName, variableStack,
|
||||
numberOfConditionalEffects, variableIDs);
|
||||
};
|
||||
|
||||
const auto handleForAll =
|
||||
[&](const ::pddl::normalizedAST::ForAllPointer<::pddl::normalizedAST::Effect> &forAll)
|
||||
{
|
||||
variableStack.push(&forAll->parameters);
|
||||
|
||||
translateEffect(outputStream, forAll->argument, printObjectName,
|
||||
variableStack, numberOfConditionalEffects, variableIDs);
|
||||
|
||||
variableStack.pop();
|
||||
};
|
||||
|
||||
const auto handleWhen =
|
||||
[&](const ::pddl::normalizedAST::WhenPointer<::pddl::normalizedAST::Precondition,
|
||||
::pddl::normalizedAST::ConditionalEffect> &when)
|
||||
{
|
||||
numberOfConditionalEffects++;
|
||||
|
||||
const auto printConditionalEffectIdentifier =
|
||||
[&]()
|
||||
{
|
||||
outputStream << colorlog::Keyword("effect") << "("
|
||||
<< colorlog::Number<size_t>(numberOfConditionalEffects) << ")";
|
||||
};
|
||||
|
||||
const auto printPreconditionRuleBody =
|
||||
[&]()
|
||||
{
|
||||
outputStream << " :- " << colorlog::Function("action") << "(";
|
||||
printObjectName();
|
||||
outputStream << ")";
|
||||
|
||||
for (const auto &layer : variableStack.layers)
|
||||
{
|
||||
if (!layer->empty())
|
||||
outputStream << ", ";
|
||||
|
||||
translateVariablesForRuleBody(outputStream, *layer, variableIDs);
|
||||
}
|
||||
};
|
||||
|
||||
translatePrecondition(outputStream, when->argumentLeft,
|
||||
printConditionalEffectIdentifier, printPreconditionRuleBody, variableIDs);
|
||||
|
||||
translateConditionalEffect(outputStream, when->argumentRight, printObjectName,
|
||||
variableStack, numberOfConditionalEffects, variableIDs);
|
||||
};
|
||||
|
||||
effect.match(handleAnd, handleForAll, handleLiteral, handleWhen);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename PrintObjectName>
|
||||
inline void translateEffect(colorlog::ColorStream &outputStream,
|
||||
const ::pddl::normalizedAST::Effect &effect, PrintObjectName printObjectName,
|
||||
size_t &numberOfConditionalEffects, VariableIDMap &variableIDs)
|
||||
{
|
||||
VariableStack variableStack;
|
||||
|
||||
translateEffect(outputStream, effect, printObjectName, variableStack,
|
||||
numberOfConditionalEffects, variableIDs);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
73
include/plasp/pddl/translation/Fact.h
Normal file
73
include/plasp/pddl/translation/Fact.h
Normal file
@ -0,0 +1,73 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__FACT_H
|
||||
#define __PLASP__PDDL__TRANSLATION__FACT_H
|
||||
|
||||
#include <pddl/NormalizedAST.h>
|
||||
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Fact
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translateFact(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Fact &fact)
|
||||
{
|
||||
outputStream << std::endl << colorlog::Function("initialState") << "(";
|
||||
|
||||
VariableIDMap variableIDs;
|
||||
|
||||
const auto handlePredicate =
|
||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
||||
{
|
||||
translatePredicateToVariable(outputStream, *predicate, variableIDs, isPositive);
|
||||
};
|
||||
|
||||
const auto handleNegatedPredicate =
|
||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate)
|
||||
{
|
||||
return handlePredicate(predicate, false);
|
||||
};
|
||||
|
||||
const auto handleDerivedPredicate =
|
||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &, bool = true)
|
||||
{
|
||||
throw TranslatorException("derived predicates should not occur in initial state");
|
||||
};
|
||||
|
||||
const auto handleNegatedDerivedPredicate =
|
||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate)
|
||||
{
|
||||
return handleDerivedPredicate(derivedPredicate, false);
|
||||
};
|
||||
|
||||
const auto handleAtomicFormula =
|
||||
[&](const ::pddl::normalizedAST::AtomicFormula &atomicFormula)
|
||||
{
|
||||
atomicFormula.match(handlePredicate, handleDerivedPredicate);
|
||||
};
|
||||
|
||||
const auto handleNot =
|
||||
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> ¬_)
|
||||
{
|
||||
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
|
||||
};
|
||||
|
||||
fact.match(handleAtomicFormula, handleNot);
|
||||
|
||||
outputStream << ").";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
102
include/plasp/pddl/translation/Goal.h
Normal file
102
include/plasp/pddl/translation/Goal.h
Normal file
@ -0,0 +1,102 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__GOAL_H
|
||||
#define __PLASP__PDDL__TRANSLATION__GOAL_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddl/NormalizedAST.h>
|
||||
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/DerivedPredicate.h>
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Goal
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translateGoal(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Goal &goal)
|
||||
{
|
||||
VariableIDMap variableIDs;
|
||||
|
||||
const auto ensureNoVariables =
|
||||
[](const auto &predicate)
|
||||
{
|
||||
for (const auto &argument : predicate->arguments)
|
||||
if (argument.template is<::pddl::normalizedAST::VariablePointer>())
|
||||
throw TranslatorException("goal descriptions must be variable-free");
|
||||
};
|
||||
|
||||
const auto handlePredicate =
|
||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
||||
{
|
||||
ensureNoVariables(predicate);
|
||||
|
||||
outputStream << std::endl << colorlog::Function("goal") << "(";
|
||||
translatePredicateToVariable(outputStream, *predicate, variableIDs, isPositive);
|
||||
outputStream << ").";
|
||||
};
|
||||
|
||||
const auto handleNegatedPredicate =
|
||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate)
|
||||
{
|
||||
handlePredicate(predicate, false);
|
||||
};
|
||||
|
||||
const auto handleDerivedPredicate =
|
||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate, bool isPositive = true)
|
||||
{
|
||||
ensureNoVariables(derivedPredicate);
|
||||
|
||||
outputStream << std::endl << colorlog::Function("goal") << "(";
|
||||
translateDerivedPredicateToVariable(outputStream, *derivedPredicate, variableIDs, isPositive);
|
||||
outputStream << ").";
|
||||
};
|
||||
|
||||
const auto handleNegatedDerivedPredicate =
|
||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate)
|
||||
{
|
||||
handleDerivedPredicate(derivedPredicate, false);
|
||||
};
|
||||
|
||||
const auto handleAtomicFormula =
|
||||
[&](const ::pddl::normalizedAST::AtomicFormula &atomicFormula)
|
||||
{
|
||||
atomicFormula.match(handlePredicate, handleDerivedPredicate);
|
||||
};
|
||||
|
||||
const auto handleNot =
|
||||
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> ¬_)
|
||||
{
|
||||
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
|
||||
};
|
||||
|
||||
const auto handleLiteral =
|
||||
[&](const ::pddl::normalizedAST::Literal &literal)
|
||||
{
|
||||
literal.match(handleAtomicFormula, handleNot);
|
||||
};
|
||||
|
||||
const auto handleAnd =
|
||||
[&](const ::pddl::normalizedAST::AndPointer<::pddl::normalizedAST::Literal> &and_)
|
||||
{
|
||||
for (const auto &argument : and_->arguments)
|
||||
handleLiteral(argument);
|
||||
};
|
||||
|
||||
goal.match(handleLiteral, handleAnd);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
99
include/plasp/pddl/translation/Precondition.h
Normal file
99
include/plasp/pddl/translation/Precondition.h
Normal file
@ -0,0 +1,99 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__PRECONDITION_H
|
||||
#define __PLASP__PDDL__TRANSLATION__PRECONDITION_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddl/NormalizedAST.h>
|
||||
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
#include <plasp/pddl/translation/DerivedPredicate.h>
|
||||
#include <plasp/pddl/translation/Predicate.h>
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Precondition
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename PrintObjectName, typename PrintRuleBody>
|
||||
inline void translatePrecondition(colorlog::ColorStream &outputStream,
|
||||
const ::pddl::normalizedAST::Precondition &precondition, PrintObjectName printObjectName,
|
||||
PrintRuleBody printRuleBody, VariableIDMap &variableIDs)
|
||||
{
|
||||
const auto handlePredicate =
|
||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
||||
{
|
||||
outputStream << std::endl << colorlog::Function("precondition") << "(";
|
||||
printObjectName();
|
||||
outputStream << ", ";
|
||||
translatePredicateToVariable(outputStream, *predicate, variableIDs, isPositive);
|
||||
outputStream << ")";
|
||||
printRuleBody();
|
||||
outputStream << ".";
|
||||
};
|
||||
|
||||
const auto handleNegatedPredicate =
|
||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate)
|
||||
{
|
||||
handlePredicate(predicate, false);
|
||||
};
|
||||
|
||||
const auto handleDerivedPredicate =
|
||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate, bool isPositive = true)
|
||||
{
|
||||
outputStream << std::endl << colorlog::Function("precondition") << "(";
|
||||
printObjectName();
|
||||
outputStream << ", ";
|
||||
translateDerivedPredicateToVariable(outputStream, *derivedPredicate, variableIDs, isPositive);
|
||||
outputStream << ")";
|
||||
printRuleBody();
|
||||
outputStream << ".";
|
||||
};
|
||||
|
||||
const auto handleNegatedDerivedPredicate =
|
||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate)
|
||||
{
|
||||
handleDerivedPredicate(derivedPredicate, false);
|
||||
};
|
||||
|
||||
const auto handleAtomicFormula =
|
||||
[&](const ::pddl::normalizedAST::AtomicFormula &atomicFormula)
|
||||
{
|
||||
atomicFormula.match(handlePredicate, handleDerivedPredicate);
|
||||
};
|
||||
|
||||
const auto handleNot =
|
||||
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> ¬_)
|
||||
{
|
||||
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
|
||||
};
|
||||
|
||||
const auto handleLiteral =
|
||||
[&](const ::pddl::normalizedAST::Literal &literal)
|
||||
{
|
||||
literal.match(handleAtomicFormula, handleNot);
|
||||
};
|
||||
|
||||
const auto handleAnd =
|
||||
[&](const ::pddl::normalizedAST::AndPointer<::pddl::normalizedAST::Literal> &and_)
|
||||
{
|
||||
for (const auto &argument : and_->arguments)
|
||||
handleLiteral(argument);
|
||||
};
|
||||
|
||||
precondition.match(handleLiteral, handleAnd);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
109
include/plasp/pddl/translation/Predicate.h
Normal file
109
include/plasp/pddl/translation/Predicate.h
Normal file
@ -0,0 +1,109 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__PREDICATE_H
|
||||
#define __PLASP__PDDL__TRANSLATION__PREDICATE_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddl/NormalizedAST.h>
|
||||
#include <pddl/Parse.h>
|
||||
|
||||
#include <plasp/pddl/translation/Primitives.h>
|
||||
#include <plasp/pddl/translation/Variables.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Predicate
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void translatePredicate(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Predicate &predicate, VariableIDMap &variableIDs);
|
||||
void translatePredicateDeclaration(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::PredicateDeclaration &predicateDeclaration, VariableIDMap &variableIDs);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translatePredicate(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Predicate &predicate, VariableIDMap &variableIDs)
|
||||
{
|
||||
const auto &arguments = predicate.arguments;
|
||||
|
||||
if (arguments.empty())
|
||||
{
|
||||
outputStream << *predicate.declaration;
|
||||
return;
|
||||
}
|
||||
|
||||
outputStream << "(" << *predicate.declaration;
|
||||
|
||||
for (const auto &argument : arguments)
|
||||
{
|
||||
outputStream << ", ";
|
||||
|
||||
const auto handleConstant =
|
||||
[&](const ::pddl::normalizedAST::ConstantPointer &constant)
|
||||
{
|
||||
outputStream << colorlog::Keyword("constant") << "(" << *constant << ")";
|
||||
};
|
||||
|
||||
const auto handleVariable =
|
||||
[&](const ::pddl::normalizedAST::VariablePointer &variable)
|
||||
{
|
||||
translateVariable(outputStream, *variable, variableIDs);
|
||||
};
|
||||
|
||||
argument.match(handleConstant, handleVariable);
|
||||
}
|
||||
|
||||
outputStream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translatePredicateDeclaration(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::PredicateDeclaration &predicateDeclaration, VariableIDMap &variableIDs)
|
||||
{
|
||||
outputStream << colorlog::Keyword("variable") << "(";
|
||||
|
||||
if (predicateDeclaration.parameters.empty())
|
||||
{
|
||||
outputStream << predicateDeclaration << ")";
|
||||
return;
|
||||
}
|
||||
|
||||
outputStream << "(" << predicateDeclaration;
|
||||
translateVariablesForRuleHead(outputStream, predicateDeclaration.parameters, variableIDs);
|
||||
outputStream << "))";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void translatePredicateToVariable(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Predicate &predicate, VariableIDMap &variableIDs, bool isPositive = true)
|
||||
{
|
||||
outputStream << colorlog::Keyword("variable") << "(";
|
||||
|
||||
translatePredicate(outputStream, predicate, variableIDs);
|
||||
|
||||
outputStream
|
||||
<< "), "
|
||||
<< colorlog::Keyword("value") << "("
|
||||
<< colorlog::Keyword("variable") << "(";
|
||||
|
||||
translatePredicate(outputStream, predicate, variableIDs);
|
||||
|
||||
outputStream << "), ";
|
||||
|
||||
if (isPositive)
|
||||
outputStream << colorlog::Boolean("true");
|
||||
else
|
||||
outputStream << colorlog::Boolean("false");
|
||||
|
||||
outputStream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
100
include/plasp/pddl/translation/Primitives.h
Normal file
100
include/plasp/pddl/translation/Primitives.h
Normal file
@ -0,0 +1,100 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__PRIMITIVES_H
|
||||
#define __PLASP__PDDL__TRANSLATION__PRIMITIVES_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddl/NormalizedAST.h>
|
||||
|
||||
#include <plasp/TranslatorException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Primitives
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::ConstantDeclaration &constantDeclaration)
|
||||
{
|
||||
assert(!constantDeclaration.name.empty());
|
||||
|
||||
return (stream << colorlog::String(constantDeclaration.name.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::Constant &constant)
|
||||
{
|
||||
assert(constant.declaration != nullptr);
|
||||
|
||||
return (stream << *constant.declaration);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::PrimitiveTypeDeclaration &primitiveTypeDeclaration)
|
||||
{
|
||||
assert(!primitiveTypeDeclaration.name.empty());
|
||||
|
||||
return (stream << colorlog::String(primitiveTypeDeclaration.name.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::PrimitiveType &primitiveType)
|
||||
{
|
||||
assert(primitiveType.declaration != nullptr);
|
||||
|
||||
return (stream << *primitiveType.declaration);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: move to appropriate header
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::Action &action)
|
||||
{
|
||||
return (stream << colorlog::String(action.name.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: move to appropriate header
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::PredicateDeclaration &predicateDeclaration)
|
||||
{
|
||||
return (stream << colorlog::String(predicateDeclaration.name.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: move to appropriate header
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::Predicate &predicate)
|
||||
{
|
||||
return (stream << *predicate.declaration);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: move to appropriate header
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::DerivedPredicateDeclaration &derivedPredicateDeclaration)
|
||||
{
|
||||
return (stream << colorlog::String(derivedPredicateDeclaration.name.c_str()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO: move to appropriate header
|
||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::DerivedPredicate &derivedPredicate)
|
||||
{
|
||||
return (stream << *derivedPredicate.declaration);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
64
include/plasp/pddl/translation/Variable.h
Normal file
64
include/plasp/pddl/translation/Variable.h
Normal file
@ -0,0 +1,64 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__VARIABLE_H
|
||||
#define __PLASP__PDDL__TRANSLATION__VARIABLE_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddl/NormalizedAST.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Variable
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using VariableIDMap = std::map<const ::pddl::normalizedAST::VariableDeclaration *, size_t>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translateVariableDeclaration(colorlog::ColorStream &stream, ::pddl::normalizedAST::VariableDeclaration &variableDeclaration, VariableIDMap &variableIDs)
|
||||
{
|
||||
assert(!variableDeclaration.name.empty());
|
||||
|
||||
const auto variableID =
|
||||
[&]()
|
||||
{
|
||||
const auto matchingVariableID = variableIDs.find(&variableDeclaration);
|
||||
|
||||
if (matchingVariableID != variableIDs.cend())
|
||||
return matchingVariableID->second;
|
||||
|
||||
const auto variableID = variableIDs.size() + 1;
|
||||
|
||||
variableIDs.insert({&variableDeclaration, variableID});
|
||||
|
||||
return variableID;
|
||||
};
|
||||
|
||||
stream
|
||||
<< colorlog::Format({colorlog::Color::Green, colorlog::FontWeight::Bold})
|
||||
<< "X" << variableID()
|
||||
<< colorlog::ResetFormat();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void translateVariable(colorlog::ColorStream &stream, ::pddl::normalizedAST::Variable &variable, VariableIDMap &variableIDs)
|
||||
{
|
||||
assert(variable.declaration != nullptr);
|
||||
|
||||
translateVariableDeclaration(stream, *variable.declaration, variableIDs);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,32 +1,38 @@
|
||||
#ifndef __PLASP__PDDL__EXPRESSIONS__IMPLY_H
|
||||
#define __PLASP__PDDL__EXPRESSIONS__IMPLY_H
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__VARIABLE_STACK_H
|
||||
#define __PLASP__PDDL__TRANSLATION__VARIABLE_STACK_H
|
||||
|
||||
#include <plasp/pddl/expressions/Binary.h>
|
||||
#include <pddl/NormalizedAST.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
namespace expressions
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Imply
|
||||
// VariableStack
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Imply: public Binary<Imply>
|
||||
struct VariableStack
|
||||
{
|
||||
public:
|
||||
static const Expression::Type ExpressionType = Expression::Type::Imply;
|
||||
using Layer = ::pddl::normalizedAST::VariableDeclarations *;
|
||||
|
||||
static const std::string Identifier;
|
||||
void push(Layer layer)
|
||||
{
|
||||
layers.push_back(layer);
|
||||
}
|
||||
|
||||
void pop()
|
||||
{
|
||||
layers.pop_back();
|
||||
}
|
||||
|
||||
std::vector<Layer> layers;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
75
include/plasp/pddl/translation/Variables.h
Normal file
75
include/plasp/pddl/translation/Variables.h
Normal file
@ -0,0 +1,75 @@
|
||||
#ifndef __PLASP__PDDL__TRANSLATION__VARIABLES_H
|
||||
#define __PLASP__PDDL__TRANSLATION__VARIABLES_H
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddl/NormalizedAST.h>
|
||||
#include <pddl/Parse.h>
|
||||
|
||||
#include <plasp/TranslatorException.h>
|
||||
#include <plasp/pddl/translation/Variable.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Variables
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
void translateVariablesForRuleHead(colorlog::ColorStream &outputStream, const T &variables, VariableIDMap &variableIDs);
|
||||
template<class T>
|
||||
void translateVariablesForRuleBody(colorlog::ColorStream &outputStream, const T &variables, VariableIDMap &variableIDs);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
inline void translateVariablesForRuleHead(colorlog::ColorStream &outputStream, const T &variables, VariableIDMap &variableIDs)
|
||||
{
|
||||
for (const auto &variable : variables)
|
||||
{
|
||||
outputStream << ", ";
|
||||
translateVariableDeclaration(outputStream, *variable, variableIDs);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class T>
|
||||
void translateVariablesForRuleBody(colorlog::ColorStream &outputStream, const T &variables, VariableIDMap &variableIDs)
|
||||
{
|
||||
for (const auto &variable : variables)
|
||||
{
|
||||
if (&variable != &*variables.begin())
|
||||
outputStream << ", ";
|
||||
|
||||
if (variable->type)
|
||||
{
|
||||
if (!variable->type.value().template is<::pddl::normalizedAST::PrimitiveTypePointer>())
|
||||
throw TranslatorException("only primitive types supported currently");
|
||||
|
||||
const auto &type = variable->type.value().template get<::pddl::normalizedAST::PrimitiveTypePointer>();
|
||||
|
||||
outputStream << colorlog::Function("has") << "(";
|
||||
translateVariableDeclaration(outputStream, *variable, variableIDs);
|
||||
outputStream << ", " << colorlog::Keyword("type") << "(" << *type << "))";
|
||||
}
|
||||
else
|
||||
{
|
||||
outputStream << colorlog::Function("has") << "(";
|
||||
translateVariableDeclaration(outputStream, *variable, variableIDs);
|
||||
outputStream << ", " << colorlog::Keyword("type") << "(" << colorlog::String("object") << "))";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -4,9 +4,10 @@
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/Value.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -27,8 +28,8 @@ using AssignedVariables = std::vector<AssignedVariable>;
|
||||
class AssignedVariable
|
||||
{
|
||||
public:
|
||||
static AssignedVariable fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static AssignedVariable fromSAS(utils::Parser<> &parser, const Variable &variable);
|
||||
static AssignedVariable fromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &variables);
|
||||
static AssignedVariable fromSAS(tokenize::Tokenizer<> &tokenizer, const Variable &variable);
|
||||
|
||||
public:
|
||||
explicit AssignedVariable(const Variable &variable, const Value &value);
|
||||
|
@ -3,9 +3,10 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -29,7 +30,7 @@ class AxiomRule
|
||||
using Condition = AssignedVariable;
|
||||
using Conditions = AssignedVariables;
|
||||
|
||||
static AxiomRule fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static AxiomRule fromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &variables);
|
||||
|
||||
public:
|
||||
const Conditions &conditions() const;
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
#include <plasp/sas/Description.h>
|
||||
|
||||
namespace plasp
|
||||
@ -16,7 +18,7 @@ namespace sas
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
utils::LogStream &operator<<(utils::LogStream &ostream, const Description &description);
|
||||
colorlog::ColorStream &operator<<(colorlog::ColorStream &ostream, const Description &description);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
#ifndef __PLASP__SAS__DESCRIPTION_H
|
||||
#define __PLASP__SAS__DESCRIPTION_H
|
||||
|
||||
#include <experimental/filesystem>
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/AxiomRule.h>
|
||||
#include <plasp/sas/Goal.h>
|
||||
@ -13,7 +14,6 @@
|
||||
#include <plasp/sas/MutexGroup.h>
|
||||
#include <plasp/sas/Operator.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -29,9 +29,9 @@ namespace sas
|
||||
class Description
|
||||
{
|
||||
public:
|
||||
static Description fromParser(utils::Parser<> &&parser);
|
||||
static Description fromTokenizer(tokenize::Tokenizer<> &&tokenizer);
|
||||
static Description fromStream(std::istream &istream);
|
||||
static Description fromFile(const boost::filesystem::path &path);
|
||||
static Description fromFile(const std::experimental::filesystem::path &path);
|
||||
|
||||
public:
|
||||
bool usesActionCosts() const;
|
||||
@ -50,16 +50,16 @@ class Description
|
||||
private:
|
||||
Description();
|
||||
|
||||
void parseContent(utils::Parser<> &parser);
|
||||
void parseContent(tokenize::Tokenizer<> &tokenizer);
|
||||
|
||||
void parseVersionSection(utils::Parser<> &parser) const;
|
||||
void parseMetricSection(utils::Parser<> &parser);
|
||||
void parseVariablesSection(utils::Parser<> &parser);
|
||||
void parseMutexSection(utils::Parser<> &parser);
|
||||
void parseInitialStateSection(utils::Parser<> &parser);
|
||||
void parseGoalSection(utils::Parser<> &parser);
|
||||
void parseOperatorSection(utils::Parser<> &parser);
|
||||
void parseAxiomSection(utils::Parser<> &parser);
|
||||
void parseVersionSection(tokenize::Tokenizer<> &tokenizer) const;
|
||||
void parseMetricSection(tokenize::Tokenizer<> &tokenizer);
|
||||
void parseVariablesSection(tokenize::Tokenizer<> &tokenizer);
|
||||
void parseMutexSection(tokenize::Tokenizer<> &tokenizer);
|
||||
void parseInitialStateSection(tokenize::Tokenizer<> &tokenizer);
|
||||
void parseGoalSection(tokenize::Tokenizer<> &tokenizer);
|
||||
void parseOperatorSection(tokenize::Tokenizer<> &tokenizer);
|
||||
void parseAxiomSection(tokenize::Tokenizer<> &tokenizer);
|
||||
|
||||
bool m_usesActionCosts;
|
||||
|
||||
|
@ -3,9 +3,10 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -29,7 +30,7 @@ class Effect
|
||||
using Condition = AssignedVariable;
|
||||
using Conditions = AssignedVariables;
|
||||
|
||||
static Effect fromSAS(utils::Parser<> &parser, const Variables &variables, Conditions &preconditions);
|
||||
static Effect fromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &variables, Conditions &preconditions);
|
||||
|
||||
public:
|
||||
const Conditions &conditions() const;
|
||||
|
@ -1,8 +1,9 @@
|
||||
#ifndef __PLASP__SAS__GOAL_H
|
||||
#define __PLASP__SAS__GOAL_H
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -21,7 +22,7 @@ class Goal
|
||||
using Fact = AssignedVariable;
|
||||
using Facts = AssignedVariables;
|
||||
|
||||
static Goal fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static Goal fromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &variables);
|
||||
|
||||
public:
|
||||
const Facts &facts() const;
|
||||
|
@ -1,8 +1,9 @@
|
||||
#ifndef __PLASP__SAS__INITIAL_STATE_H
|
||||
#define __PLASP__SAS__INITIAL_STATE_H
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -21,7 +22,7 @@ class InitialState
|
||||
using Fact = AssignedVariable;
|
||||
using Facts = AssignedVariables;
|
||||
|
||||
static InitialState fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static InitialState fromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &variables);
|
||||
|
||||
public:
|
||||
const Facts &facts() const;
|
||||
|
@ -3,8 +3,9 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -28,7 +29,7 @@ class MutexGroup
|
||||
using Fact = AssignedVariable;
|
||||
using Facts = AssignedVariables;
|
||||
|
||||
static MutexGroup fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static MutexGroup fromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &variables);
|
||||
|
||||
public:
|
||||
const Facts &facts() const;
|
||||
|
@ -4,12 +4,15 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
#include <plasp/sas/AssignedVariable.h>
|
||||
#include <plasp/sas/Effect.h>
|
||||
#include <plasp/sas/Predicate.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/LogStream.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -33,10 +36,10 @@ class Operator
|
||||
using Condition = AssignedVariable;
|
||||
using Conditions = AssignedVariables;
|
||||
|
||||
static Operator fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static Operator fromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &variables);
|
||||
|
||||
public:
|
||||
void printPredicateAsASP(utils::LogStream &ostream) const;
|
||||
void printPredicateAsASP(colorlog::ColorStream &stream) const;
|
||||
|
||||
const Predicate &predicate() const;
|
||||
const Conditions &preconditions() const;
|
||||
|
@ -5,8 +5,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/utils/LogStream.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -22,13 +23,13 @@ namespace sas
|
||||
class Predicate
|
||||
{
|
||||
public:
|
||||
static Predicate fromSAS(utils::Parser<> &parser);
|
||||
static Predicate fromSAS(tokenize::Tokenizer<> &tokenizer);
|
||||
|
||||
using Arguments = std::vector<std::string>;
|
||||
|
||||
public:
|
||||
void printAsSAS(utils::LogStream &outputStream) const;
|
||||
void printAsASP(utils::LogStream &outputStream) const;
|
||||
void printAsSAS(colorlog::ColorStream &stream) const;
|
||||
void printAsASP(colorlog::ColorStream &stream) const;
|
||||
|
||||
const std::string &name() const;
|
||||
const Arguments &arguments() const;
|
||||
|
@ -1,11 +1,12 @@
|
||||
#ifndef __PLASP__SAS__TRANSLATOR_ASP_H
|
||||
#define __PLASP__SAS__TRANSLATOR_ASP_H
|
||||
|
||||
#include <plasp/sas/Description.h>
|
||||
#include <plasp/utils/LogStream.h>
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
#include <plasp/sas/Description.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace sas
|
||||
@ -20,7 +21,7 @@ namespace sas
|
||||
class TranslatorASP
|
||||
{
|
||||
public:
|
||||
explicit TranslatorASP(const Description &description, utils::LogStream &outputStream);
|
||||
explicit TranslatorASP(const Description &description, colorlog::ColorStream &outputStream);
|
||||
|
||||
void translate() const;
|
||||
|
||||
@ -34,7 +35,7 @@ class TranslatorASP
|
||||
void translateAxiomRules() const;
|
||||
|
||||
const Description &m_description;
|
||||
utils::LogStream &m_outputStream;
|
||||
colorlog::ColorStream &m_outputStream;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -5,8 +5,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <plasp/utils/LogStream.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -39,15 +40,14 @@ struct Value
|
||||
static const Value Any;
|
||||
static const Value None;
|
||||
|
||||
static Value fromSAS(utils::Parser<> &parser);
|
||||
static const Value &referenceFromSAS(utils::Parser<> &parser, const Variable &variable);
|
||||
static Value fromSAS(tokenize::Tokenizer<> &tokenizer);
|
||||
static const Value &referenceFromSAS(tokenize::Tokenizer<> &tokenizer, const Variable &variable);
|
||||
|
||||
public:
|
||||
Value negated() const;
|
||||
|
||||
void printAsSAS(utils::LogStream &outputStream) const;
|
||||
void printAsASP(utils::LogStream &outputStream) const;
|
||||
void printAsASPPredicate(utils::LogStream &outputStream) const;
|
||||
void printAsSAS(colorlog::ColorStream &stream) const;
|
||||
void printAsASPPredicate(colorlog::ColorStream &stream) const;
|
||||
|
||||
Sign sign() const;
|
||||
const std::string &name() const;
|
||||
|
@ -5,9 +5,11 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <colorlog/ColorStream.h>
|
||||
|
||||
#include <plasp/sas/Value.h>
|
||||
#include <plasp/utils/LogStream.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -28,11 +30,11 @@ using Variables = std::vector<Variable>;
|
||||
class Variable
|
||||
{
|
||||
public:
|
||||
static Variable fromSAS(utils::Parser<> &parser);
|
||||
static const Variable &referenceFromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static Variable fromSAS(tokenize::Tokenizer<> &tokenizer);
|
||||
static const Variable &referenceFromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &variables);
|
||||
|
||||
public:
|
||||
void printNameAsASPPredicate(utils::LogStream &outputStream) const;
|
||||
void printNameAsASPPredicate(colorlog::ColorStream &outputStream) const;
|
||||
|
||||
const std::string &name() const;
|
||||
int axiomLayer() const;
|
||||
|
@ -3,9 +3,10 @@
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
#include <tokenize/Tokenizer.h>
|
||||
|
||||
#include <plasp/sas/Value.h>
|
||||
#include <plasp/sas/Variable.h>
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -26,7 +27,7 @@ using VariableTransitions = std::vector<VariableTransition>;
|
||||
class VariableTransition
|
||||
{
|
||||
public:
|
||||
static VariableTransition fromSAS(utils::Parser<> &parser, const Variables &variables);
|
||||
static VariableTransition fromSAS(tokenize::Tokenizer<> &tokenizer, const Variables &variables);
|
||||
|
||||
public:
|
||||
const Variable &variable() const;
|
||||
|
@ -1,203 +0,0 @@
|
||||
#ifndef __PLASP__UTILS__FORMATTING_H
|
||||
#define __PLASP__UTILS__FORMATTING_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <plasp/utils/LogStream.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace utils
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Formatting
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class Color
|
||||
{
|
||||
Black = 0,
|
||||
Red = 1,
|
||||
Green = 2,
|
||||
Yellow = 3,
|
||||
Blue = 4,
|
||||
Magenta = 5,
|
||||
Cyan = 6,
|
||||
White = 7
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class FontWeight
|
||||
{
|
||||
Normal = 0,
|
||||
Bold = 1
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Format
|
||||
{
|
||||
Format(Color color, FontWeight fontWeight = FontWeight::Normal)
|
||||
: m_color{color},
|
||||
m_fontWeight{fontWeight}
|
||||
{
|
||||
}
|
||||
|
||||
Color m_color;
|
||||
FontWeight m_fontWeight;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Format &format)
|
||||
{
|
||||
if (!stream.supportsColor())
|
||||
return stream;
|
||||
|
||||
const auto fontWeightCode = static_cast<size_t>(format.m_fontWeight);
|
||||
const auto colorCode = 30 + static_cast<size_t>(format.m_color);
|
||||
|
||||
return (stream << "\033[" << fontWeightCode << ";" << colorCode << "m");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct ResetFormat
|
||||
{
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const ResetFormat &)
|
||||
{
|
||||
if (!stream.supportsColor())
|
||||
return stream;
|
||||
|
||||
return (stream << "\033[0m");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Token
|
||||
{
|
||||
Token(const std::string &name)
|
||||
: name(name)
|
||||
{
|
||||
}
|
||||
|
||||
const std::string &name;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Keyword: public Token
|
||||
{
|
||||
Keyword(const std::string &name)
|
||||
: Token(name)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Keyword &keyword)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::White, utils::FontWeight::Bold)
|
||||
<< keyword.name
|
||||
<< utils::ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Number: public Token
|
||||
{
|
||||
Number(const std::string &name)
|
||||
: Token(name)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Number &number)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::Yellow, utils::FontWeight::Bold)
|
||||
<< number.name
|
||||
<< utils::ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Variable: public Token
|
||||
{
|
||||
Variable(const std::string &name)
|
||||
: Token(name)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Variable &variable)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::Green, utils::FontWeight::Bold)
|
||||
<< variable.name
|
||||
<< utils::ResetFormat());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Heading1: public Token
|
||||
{
|
||||
Heading1(const std::string &name)
|
||||
: Token(name)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Heading1 &heading1)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::Blue, utils::FontWeight::Bold)
|
||||
<< "%---------------------------------------" << std::endl
|
||||
<< "% " << heading1.name << std::endl
|
||||
<< "%---------------------------------------"
|
||||
<< utils::ResetFormat()
|
||||
<< std::endl);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct Heading2: public Token
|
||||
{
|
||||
Heading2(const std::string &name)
|
||||
: Token(name)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline LogStream &operator<<(LogStream &stream, const Heading2 &heading2)
|
||||
{
|
||||
return (stream
|
||||
<< utils::Format(utils::Color::Blue, utils::FontWeight::Bold)
|
||||
<< "% " << heading2.name
|
||||
<< utils::ResetFormat());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user