Compare commits

...

503 Commits

Author SHA1 Message Date
af325e3991
Version bump after release 3.1.1. 2017-11-25 17:52:52 +01:00
31542c6adc
Version bump for release 3.1.1. 2017-11-25 17:21:45 +01:00
2d0e4b09fa
Updated changelog with variable name replacement. 2017-11-25 17:18:50 +01:00
2288fa891e
Replacing user-defined variable names.
This replaces all user-defined variable names with continuously numbered
ones so that they don’t lead to syntax problems in ASP, while still
unique and distinguishable. For instance, this avoids problems when
variable names contain hyphens, which are allowed in PDDL identifiers
but not in ASP variables.
2017-11-25 00:37:09 +01:00
7c02b46f7c
Version bump after release 3.1.0. 2017-11-17 19:33:21 +01:00
1c44dfcda7
Version bump for release 3.1.0. 2017-11-17 18:43:02 +01:00
b93e41d5bc
Removed Arch PKGBUILD from repository.
The PKGBUILD for Arch Linux is already hosted at AUR, and there
shouldn’t be two sources for it.
2017-11-17 18:40:08 +01:00
0ff78f43e6
Added PDDL 3.1 feature support documentation. 2017-11-17 18:27:35 +01:00
0f039f0837
Excluding derived variables from inertia.
In the example encoding, derived variables were accidentally included in
the inertia rule, as this only checked the position of the parameter.
This commit fixes this by only allowing common variables (and not
derived ones) within the inertia rule.
2017-11-17 17:43:44 +01:00
9d04996b0a
Minor formatting.
This change doesn’t affect derived variables, because these aren’t
affected by the “caused” predicate (the “caused” predicate requires a
variable to be in the postcondition of an action, and these may never be
derived variables).
2017-11-17 17:34:16 +01:00
b2280c155a
Fixed handling of goal in example encoding.
The example encoding assumed that derived predicates weren’t necessary
in the final time step. This is, however, incorrect, as the goal may
have a precondition that requires derived predicates. In this case, the
derived variables must be evaluated for the final time step.
2017-11-17 17:32:05 +01:00
f7e089042d
Updated documentation to new output format. 2017-11-17 17:12:34 +01:00
ce4fe6a113
Fixed typo. 2017-11-17 15:39:21 +01:00
3e2adf6db4
Added “known issues” file. 2017-11-17 15:39:21 +01:00
8ff87985f5
Moved outdated encodings to separate directory.
These encodings need to be updated to match the new output format. Until
this is done, hide these files in a separate directory in order not to
confuse users.
2017-11-17 15:38:59 +01:00
9fde2b8e1b
Updated cxxopts to 2.0.0.
Starting from version 2.0.0, cxxopts returns a ParseResult object
instead of storing the results directly within the Options structure.
Additionally, Booleans are handled slightly differently.

These two changes required some minor adjustment of the command-line
argument parsing code.
2017-11-17 00:51:51 +01:00
c283adc42a
Minor formatting. 2017-11-17 00:47:35 +01:00
9281592c39
Rephrased change log for 3.1.0 for clarity. 2017-11-17 00:18:51 +01:00
6889e97f47
Updated readme for release 3.1.0.
This adds a section about the new commands, updates out-of-date
references, and highlights the translator as the currently most
interesting component.
2017-11-16 18:24:27 +01:00
23130134bb
Made translator descriptions more concise. 2017-11-16 18:11:38 +01:00
5af0c26650
Added tests for derived predicate numbering.
These tests ensure that derived predicates are numbered correctly,
whether they are introduced by the domain, the problem, or both.
2017-11-16 17:30:53 +01:00
39410ac98b
Added normalization tests for nested expressions.
These tests ensure that nested expressions in preconditions and effects
are correctly flattened via derived predicates.
2017-11-16 17:23:08 +01:00
5621820fe4
Added normalization tests for negations.
These tests ensure that multiple negations are eliminated, negated
quantifiers are replaced appropriately, negations introduced by
reduction are correctly handled, and negated disjunctions and
conjunctions are replaced according to De Morgan’s rules.
2017-11-15 18:53:43 +01:00
9e9040cac0
Added normalization tests for “forall” statements.
These tests ensure that universal quantifiers are correctly reduced to
negated existential quantifiers over the negated argument via derived
predicates in preconditions (nested and not) and goal descriptions.
2017-11-15 17:26:56 +01:00
0cf84dd5ca
Added normalization tests for implications.
These tests ensure that implications are correctly reduced to
disjunctions in preconditions (nested and not) and goal descriptions.
2017-11-15 16:34:48 +01:00
b063f5047e
Added basic normalization tests.
These tests make sure that simple PDDL descriptions are preserved by
normalization.
2017-11-15 16:01:26 +01:00
08a2eebe2c
Removed obsolete test file.
This file will soon be replaced by a dedicated test suite in the pddl
library and is obsolete thus.
2017-11-15 16:01:22 +01:00
010e7bf41e
Requiring goal to contain only one statement.
Previously, the parser read the first statement of the goal as its
precondition, but didn’t check that it was properly terminated with a
closing parenthesis. This allowed arbitrary text to be included within
the goal description without error, which was incorrect.

This commit fixes this issue and adds a corresponding unit test.
2017-11-15 15:52:10 +01:00
Patrick Lühne
a1a80332ca
Merge pull request #4 from mgebser/strips
Introduced flat representation of transition constraints, activated by
default with respect to the new constant _inertia.
2017-11-09 14:35:31 +01:00
f0e553df23
Minor formatting. 2017-11-08 17:11:36 +01:00
0d0a4337a2
Updated Catch to 2.0.1. 2017-11-04 20:54:39 +01:00
b21b4f47bf
Made form of variables within values consistent.
Previously, variables referenced within values were unpacked within
values. This was inconsistent, because all predicates are usually used
in their unpacked form in the rest of the output format. This commit
makes this consistent by using variables in their packed form within
values, making it more compact to handle them.
2017-11-03 01:49:24 +01:00
3a7b61de68
Fixed syntax error at end of initial state facts.
Due to a mistake in commit 6d07fcb, the closing parenthesis and period
at the end of initial state facts was omitted. This adds these back in
order to solve this syntax error.
2017-11-01 16:00:48 +01:00
mgebser
efee22a655 introduced flat representation of transition constraints, activated by default w.r.t. the new constant _inertia 2017-11-01 13:58:04 +01:00
4faa8813e4
Added removed Boost dependency to change log. 2017-10-28 17:33:26 +02:00
dd1b2f9636
Removed Boost dependency from building instructions. 2017-10-28 17:31:37 +02:00
a31d8638e7
Fixed typos in documentation. 2017-10-28 17:30:41 +02:00
6af0d4ec7a
Removed Boost dependency from Arch PKGBUILD. 2017-10-28 17:16:18 +02:00
021e6c439c
Removed Boost packages from Travis configuration.
As the Boost dependency isn’t required anymore, this commit removes the
Boost packages from the Travis configuration.
2017-10-28 16:50:45 +02:00
e87f86af95
Removed Boost dependency in assertions.
Instead of using BOOST_ASSERT, this commit changes all assertions to
plain C-style assertions in order to drop the dependency to Boost.
2017-10-28 16:49:15 +02:00
ca7ae883ee
Removed Boost dependency in unit tests.
Some of the unit tests depended on Boost’s null_sink to redirect the
unwanted test output to /dev/null. This commit adds a simple
NullOutputStream as a replacement and removes the obsolete Boost
includes.
2017-10-28 16:45:29 +02:00
72fc7493b2
Removed Boost dependency in language distinction.
As Boost isn’t used in the rest of this project anymore, this commit
removes the unnecessary dependency to boost::bimap just for language
detection, and replaces it with a simple std::map instead.
2017-10-28 15:44:37 +02:00
1631a70a0b
Ensuring that goal is variable-free.
Even though the parser shouldn’t be able to put variables into the goal
description, the AST theoretically allows for this case. This commit
adds a defensive check that goal descriptions are variable-free.
2017-10-27 17:10:35 +02:00
27f773e091
Added support for derived predicates in goals.
By accident, the support for derived predicates in goals was missing.
This commit adds this, in a very similar way to how normal predicates
are handled in the goal description.
2017-10-27 16:46:38 +02:00
6d07fcbd6c
Moved initial state translation to new header. 2017-10-27 16:38:01 +02:00
6415f871d7
Error for derived predicates in initial state.
Previously, derived predicates in the initial state weren’t handled at
all. That’s not an issue, because derived predicates shouldn’t occur in
the initial state. However, as a defensive measure, this commit adds an
error thrown in such cases.
2017-10-27 16:27:33 +02:00
feaef5a3fa
Translating derived predicates of problems.
While derived predicates stemming from the domain were already
translated, the ones from the problem were missing. This commit fixes
that, although it duplicates the definition of “contains.”
2017-10-27 16:21:54 +02:00
624ddc38aa
Fixed incorrect derived predicate IDs in problems.
The IDs of derived predicates within problems were accidentally starting
with 1 again, colliding with the IDs of derived predicates in the
domain. With this fix, the IDs are continuously incremented, even after
switching from domain to problem.
2017-10-25 19:01:11 +02:00
9803710ff3
Fixed typo. 2017-10-25 19:00:54 +02:00
4d8525f52d
Added comment for consistency. 2017-10-25 18:03:11 +02:00
d0b7f89925
Removed unwanted newlines at the end of output. 2017-10-25 17:01:19 +02:00
032fa14f61
Updated tagline to match plasp’s recently extended tool set. 2017-10-14 02:37:46 +02:00
8b487b0a82
Structured change log more nicely. 2017-10-14 02:31:04 +02:00
f6eed53550
Minor formatting. 2017-10-14 02:13:47 +02:00
cb61f7cc5e
Making command-line options in change log more specific. 2017-10-14 02:13:47 +02:00
5ec4dd2aaf
Added new commands to the change log. 2017-10-14 02:13:47 +02:00
b8bd42d361
Implemented “check-syntax” command. 2017-10-14 02:13:47 +02:00
89edafb586
Implemented “beautify” command. 2017-10-14 02:13:47 +02:00
0d5245b48b
Showing list of available commands in help message. 2017-10-14 02:13:47 +02:00
d20b30d34d
Implemented “normalize” command. 2017-10-14 02:13:47 +02:00
b99e7c198a
Refactored “translate” command. 2017-10-14 02:13:46 +02:00
c3b6d6939f
Added missing inline directive. 2017-10-14 02:13:46 +02:00
868c220e42
Minor formatting. 2017-10-14 02:13:46 +02:00
cde892c771
Added command for printing version information. 2017-10-14 02:13:46 +02:00
974c94fbb0
Unified version printing. 2017-10-14 02:13:46 +02:00
2be3f4256a
Refactored command base class for simplicity. 2017-10-14 02:13:46 +02:00
5427876e36
Added workaround for GCC 6 compiler error. 2017-10-14 02:13:46 +02:00
abdc4e31dc
Refactored printing help messages in commands. 2017-10-14 02:13:46 +02:00
db7ea6f2fe
Removed unwanted methods. 2017-10-14 02:13:46 +02:00
d8b2aa9720
Updated change log with new command interface. 2017-10-14 02:13:46 +02:00
63c4da8fad
Made option group parsing more uniform. 2017-10-14 02:13:46 +02:00
3fe2886925
Updated CMake in Travis configuration for C++17 support. 2017-10-14 02:13:46 +02:00
86486207b8
Added help and version options to the translate command. 2017-10-14 02:13:46 +02:00
569b170aba
Using cxxopts as a submodule. 2017-10-14 02:13:45 +02:00
f6c9e19a60
Outsourced parsing of common options in plasp app. 2017-10-14 02:13:45 +02:00
6b891fcb8e
Prepared app directory for future subcommands. 2017-10-14 02:13:45 +02:00
Patrick Lühne
8b6c4beed8 Merge pull request #3 from mgebser/strips
Support for parallel actions without checking mutual disablement
2017-10-12 19:27:26 +02:00
mgebser
5e0c8a695c new constant value '_parallel=0' to allow for parallel actions without checking mutual disablement 2017-10-05 20:24:59 +02:00
46cd4de854
Updated changelog with parser support for equalities. 2017-08-31 19:29:54 +02:00
871d3fcdb3
Renamed test suites for clarity. 2017-08-31 19:15:17 +02:00
4ad9355e47
Removed domains from blacklist that are now supported by parser. 2017-08-31 19:08:28 +02:00
1dee4655a7
Minor refactoring. 2017-08-31 19:04:10 +02:00
0a104d222c
Removed unneeded constant parsing functions. 2017-08-31 18:51:27 +02:00
80167fd21b
Removed unneeded variable parsing functions. 2017-08-31 18:48:48 +02:00
7de9980c10
Refactoring to reuse term parsing code. 2017-08-31 18:37:43 +02:00
89f3eb0306
Implemented term parser. 2017-08-31 18:34:34 +02:00
716b4801aa
Added AST representation for “equals” expressions. 2017-08-31 17:54:30 +02:00
9199b68080
Renamed “pddlparse” library to simply “pddl”. 2017-08-09 17:52:50 +02:00
Patrick Lühne
a24ce91acb Merge pull request #2 from mgebser/strips
improved strips encodings
2017-08-09 17:19:35 +02:00
mgebser
9ab1ea1c23 improved strips encodings 2017-08-09 12:12:39 +02:00
8b232e0155
Updated sequential horizon-bound meta encoding to match new output format. 2017-06-28 16:41:31 +02:00
aec16f4407
Added option to compile plasp statically. 2017-06-28 01:43:12 +02:00
b2ac47c2d3
Moved Boost dependency to plasp application only. 2017-06-28 01:42:29 +02:00
31cf6d287d
Internal version bump to 3.1.0-git because of the scope of the changes since 3.0.3. 2017-06-28 01:06:30 +02:00
b282225363
Moved util predicates to separate section. 2017-06-28 01:00:36 +02:00
95c03396d0
Fixed incorrect argument format in ASP output. 2017-06-28 00:51:42 +02:00
a5038535f4
Added missing argument to ASP predicate. 2017-06-28 00:35:28 +02:00
d82ae8544b
Implemented translation of conditional PDDL effects. 2017-06-28 00:33:00 +02:00
0caef2e81c
Extended error message. 2017-06-27 23:35:44 +02:00
cb333fd420
Updated Catch to 1.9.6. 2017-06-27 23:21:36 +02:00
f61cfa532d
Added support for unconditional “forall” effect statements. 2017-06-27 23:17:32 +02:00
39b885c47c
Handling effects in PDDL normalization step. 2017-06-27 22:32:49 +02:00
da85683f7c
Changed effects in normalized PDDL effects according to recent changes. 2017-06-27 18:17:02 +02:00
0beab67bd4
Made effect variant more concise. 2017-06-27 17:50:42 +02:00
4622f31fa4
Made conditional effect variant more concise. 2017-06-27 17:43:00 +02:00
0eff8e5dcf
Only enumerating existentially bound parameters for “and” expressions. 2017-06-27 16:52:50 +02:00
1516561a58
Allowing “not” expressions without introducing derived predicates. 2017-06-27 12:39:51 +02:00
5c93840f85
Allowing “exists” derived predicates to hold the precondition directly. 2017-06-27 12:34:15 +02:00
ea50cffac9
Separating top-level and nested preconditions correctly. 2017-06-27 12:29:43 +02:00
8a48a5043a
Minor refactoring for consistency. 2017-06-27 12:17:42 +02:00
cc90ef3ec6
Restructured file for clarity. 2017-06-27 11:56:51 +02:00
31e5ead21e
Minor refactoring. 2017-06-27 11:44:33 +02:00
d451d2d548
Handling negations introduced by “forall” elimination correctly. 2017-06-27 11:35:47 +02:00
729ecc9475
Added missing recursion step in PDDL reduction. 2017-06-27 11:34:53 +02:00
6c9ca0ccb8
Implemented translation of derived predicates. 2017-06-24 23:54:57 +02:00
6b1d079f69
Enabled test cases again by removing unsupported features from test files. 2017-06-24 21:49:13 +02:00
6e858ff52f
Enabled test case again by exchanging unsupported input file. 2017-06-24 21:49:06 +02:00
ca02b8ce62
Throwing exceptions for unsupported features instead of silently accepting them. 2017-06-24 20:27:01 +02:00
2b0b6570ea
Excluding unsupported domains and instances from acceptance tests. 2017-06-24 20:14:06 +02:00
909949ff22
Removed unwanted test case. 2017-06-24 20:11:12 +02:00
436933f73f
Added function to dermine stream location from arbitrary positions. 2017-06-24 19:01:09 +02:00
4d59732263
Minor refactoring. 2017-06-24 18:37:49 +02:00
12efe41551
Fixed issue due to undefined implementations. 2017-06-24 18:37:20 +02:00
362222c882
Finished implementing reduction. 2017-06-24 17:38:11 +02:00
fcb9aa0a76
Added missing forward declaration. 2017-06-24 17:35:52 +02:00
d9bae984b2
Implemented elimination of “forall” statements. 2017-06-24 17:30:08 +02:00
994801525a
Implemented negation normalization (NFF). 2017-06-24 17:19:35 +02:00
939c2c735c
Explicitly deleted default constructors of all variant types to avoid future errors. 2017-06-24 17:17:27 +02:00
287e1041bd
Added missing inline directive. 2017-06-24 16:51:45 +02:00
9845c5ae9e
Added missing parentheses in PDDL output. 2017-06-24 16:33:42 +02:00
7ae2734e9f
Started implementing reduction, added support for “imply” expressions. 2017-06-24 16:03:32 +02:00
d5dd8e849f
Avoiding to decompose “not” expressions if they form simple literals. 2017-06-24 16:02:48 +02:00
079e2ac539
Printing arguments of “not” expressions on the same line for clarity. 2017-06-24 16:00:50 +02:00
aeb8132fc7
Added missing inline directives. 2017-06-24 15:53:40 +02:00
dd51f2b4fd
Added missing const directive. 2017-06-24 15:53:16 +02:00
d7e0beabdf
Implemented normalization of preconditions. 2017-06-24 14:29:13 +02:00
9d1a8f4c0f
Started implementing PDDL normalization. 2017-06-23 04:18:07 +02:00
e4f4b5e066
Added initial normalized PDDL debug output functionality. 2017-06-23 03:54:51 +02:00
19f2c2ebf8
Added missing forward declaration. 2017-06-23 03:53:01 +02:00
2851f8d286
Corrected grammar of initial state facts. 2017-06-23 03:41:52 +02:00
9360ad3487
Added missing forward declaration. 2017-06-23 02:31:07 +02:00
c0b71290a4
Minor formatting in PDDL debug output. 2017-06-23 01:48:47 +02:00
3d9bf2582f
Fixed format of PDDL debug output. 2017-06-23 01:22:28 +02:00
cbc9c86edd
Removed unnecessary include directives. 2017-06-23 00:58:58 +02:00
480da6ff09
Built initial AST for normalized PDDL. 2017-06-23 00:51:09 +02:00
834209d506
Moved common output utilities to separate header. 2017-06-23 00:50:19 +02:00
ef606f3d9b
Merge branch 'develop' of github.com:potassco/plasp into feature-normalization 2017-06-22 23:45:15 +02:00
b5131fa00d
Added debug output functions for PDDL AST. 2017-06-22 23:19:49 +02:00
768afa9bf5
Added to-do. 2017-06-22 23:19:17 +02:00
59dc239c67
Removed unused class. 2017-06-22 23:18:43 +02:00
ec546758a8
Minor formatting. 2017-06-22 22:48:25 +02:00
e93085d88a
Moved color logging to separate library for reusing it in PDDL parser. 2017-06-22 20:58:31 +02:00
595891f040
Minor formatting. 2017-06-22 20:36:48 +02:00
b7b4d926b4
Removed unused declarations. 2017-06-22 00:03:35 +02:00
12e55da662
Allowing “at” as a predicate name even though it is an expression identifier. 2017-06-21 23:00:07 +02:00
08c55adfbd
Added test case covering missing variable names. 2017-06-21 16:55:56 +02:00
ec8007125f
Fixed segfault occurring with accidentally unnamed variables. 2017-06-21 16:48:43 +02:00
17985e3b5a
Added note suggesting using the compatibility mode if errors occur. 2017-06-21 03:07:09 +02:00
002f875c53
Lowered default message logging priority to info. 2017-06-21 03:05:37 +02:00
39c0e27cb2
Refactoring of tokenizer and stream classes for better efficiency and maintainability. 2017-06-21 02:56:27 +02:00
97c6e58355
Minor refactoring in stream reading. 2017-06-20 18:13:49 +02:00
7162fa76f6
Updated change log with new compatibility parsing mode. 2017-06-20 03:27:06 +02:00
f5a73f09f8
Added command-line option to enable the parser’s compatibility mode. 2017-06-20 03:23:19 +02:00
ee56a105b3
Resizing file content one time if stream is seekable and dynamically otherwise. 2017-06-20 03:14:51 +02:00
19f2ad19b0
Fixed incorrect language detection with legacy “in-package” directives. 2017-06-20 03:01:20 +02:00
178a55d29e
Added missing CMake option for testing PDDL parsing library to Travis configuration. 2017-06-20 02:11:15 +02:00
ff782a8642
Updated change log with internal switch to PDDL parsing library. 2017-06-20 01:59:33 +02:00
e345fd60fd
Reimplemented plasp with PDDL parsing library. 2017-06-20 01:53:55 +02:00
9c7532bd9d
Merge branch 'develop' of github.com:potassco/plasp into feature-plasp-with-pddlparse 2017-06-19 16:09:06 +02:00
9d906a195a
Fixed incorrectly labeled badges in readme file. 2017-06-19 16:07:44 +02:00
2d44ca7955
Updated PDDL instance repository. 2017-06-19 15:55:58 +02:00
799c9ce2fb
Replicated test cases for former issues in PDDL parsing library. 2017-06-19 01:15:20 +02:00
c35faab104
Replicated syntax error tests in PDDL parsing library. 2017-06-19 01:09:55 +02:00
ce812d449b
Added exceptions for inconsistent use of typing. 2017-06-19 01:09:55 +02:00
17b8306394
Minor refactoring, as there is only one typing section. 2017-06-19 01:09:55 +02:00
df2359712f
Removed unwanted debug output. 2017-06-19 01:09:55 +02:00
de648fbb1d
Fixed incorrect names of test cases. 2017-06-19 01:09:55 +02:00
d0d141ef99
Replicated test cases with missing or mismatched domains in PDDL parsing library. 2017-06-19 01:09:50 +02:00
40b43217fc
Replicated white space test case in new PDDL parsing library. 2017-06-19 00:35:31 +02:00
c6c36273b5
Dropped support for GCC 5 due to unsupported conversion with optional types. 2017-06-19 00:29:55 +02:00
586e93190c
Made plasp compatible to recent tokenizer changes. 2017-06-19 00:28:17 +02:00
9fe489de53
Added unit tests covering predicate signature matching. 2017-06-19 00:18:03 +02:00
60d8b9ba77
Fixed incorrect parsing order of type declarations. 2017-06-19 00:18:02 +02:00
1379c24362
Renamed test sections for clarity. 2017-06-19 00:18:02 +02:00
bbf2a7d02d
Allowing not declaring implicit “object” type without warning or error. 2017-06-19 00:18:02 +02:00
4c0583c91f
Refactored tokenizer to lazily evaluate file locations. 2017-06-19 00:18:02 +02:00
04dffdb09e
Fixed accidentally truncated ends of files after removing comments. 2017-06-19 00:18:02 +02:00
dd7fb31309
Made CMake configuration consistent. 2017-06-19 00:18:02 +02:00
268fa84c9e
Reimplemented tokenizer with plain streams. 2017-06-19 00:18:02 +02:00
b9b987490b
Fixed incorrect CMake option handling. 2017-06-19 00:18:02 +02:00
230844c3ae
Fixed whitespace issue in typing sections and added test cases. 2017-06-19 00:18:02 +02:00
6ce4eecb18
Implemented predicate signature checks. 2017-06-19 00:18:02 +02:00
e364d01cf4
Fixed issue in parsing typed objects in multiple iterations and added test case. 2017-06-19 00:18:02 +02:00
04ded5e8b8
Removed unnecessary include directive. 2017-06-19 00:18:02 +02:00
83a36003b1
Added test case covering complicated nested effects. 2017-06-19 00:18:01 +02:00
fc48b8f694
Added test case covering typed objects. 2017-06-19 00:18:01 +02:00
b0db73ab2f
Added to-do. 2017-06-19 00:18:01 +02:00
195cffbf88
Fixed incorrectly determined parent types and added unit test. 2017-06-19 00:18:01 +02:00
bfb382de52
Fixed incorrect constant types and added unit test. 2017-06-19 00:18:01 +02:00
101f33df6e
Removed unused test file. 2017-06-19 00:18:01 +02:00
615167e7cd
Implemented compatibility mode to support old instances. 2017-06-19 00:18:01 +02:00
dde277cc3e
Added to-do. 2017-06-19 00:18:01 +02:00
7ead2277e8
Prepared exceptions to have different types. 2017-06-19 00:18:01 +02:00
da2a3eefa4
Added extensive test covering Blocksworld instance. 2017-06-19 00:18:01 +02:00
3877012274
Minor extension of unit test covering Blocksworld domain. 2017-06-19 00:18:01 +02:00
e0aca18b38
Removed unnecessary directives in test case. 2017-06-19 00:18:01 +02:00
19c81effbe
Added extensive test for Blocksworld domain. 2017-06-19 00:18:00 +02:00
f83f9edbef
Reimplemented goal parser. 2017-06-19 00:17:53 +02:00
f90009b6d1
Reimplemented initial state parser. 2017-06-19 00:15:32 +02:00
fbcb790611
Minor refactoring. 2017-06-19 00:15:27 +02:00
8c98548dbc
Minor formatting. 2017-06-19 00:15:24 +02:00
20c687a787
Corrected exception types. 2017-06-19 00:15:14 +02:00
d376c1a993
Allowing atomic formulas and not just predicates in preconditions and effects. 2017-06-19 00:15:11 +02:00
10e658a922
Added back support for parsing effects and even conditional effects. 2017-06-19 00:15:07 +02:00
9c30e27875
Fixed incorrect parsing method for “when” expressions. 2017-06-19 00:15:04 +02:00
14c498c539
Handling unsupported preferences in preconditions. 2017-06-19 00:15:00 +02:00
f4c1d65365
Made warnings more concise and consistent. 2017-06-19 00:14:56 +02:00
34d9c7a1c2
Added warnings for currently under-construction sections. 2017-06-19 00:14:52 +02:00
0d3cb152f9
Finished precondition parsing. 2017-06-19 00:14:48 +02:00
63e15d37e8
Made precondition parsing more robust. 2017-06-19 00:14:45 +02:00
51249fd678
Refactored parsing variables, constants, and predicates. 2017-06-19 00:14:40 +02:00
0de5b9eb56
Added to-do. 2017-06-19 00:14:36 +02:00
8288345bcb
Added missing method implementation to tokenizer. 2017-06-19 00:14:33 +02:00
f349b5e351
Minor formatting. 2017-06-19 00:14:29 +02:00
de69003105
Sectioning unit tests for meaningful error messages. 2017-06-19 00:14:25 +02:00
c84cafda18
Fixed constant parsing if no problem is specified. 2017-06-19 00:14:18 +02:00
78b4636028
Continued working on reimplementing action parser. 2017-06-19 00:14:18 +02:00
9fbe0db567
Extended unit test on “either” types. 2017-06-19 00:14:05 +02:00
1876d1fe0b
Fixed parsing of types. 2017-06-19 00:14:01 +02:00
30a092b365
Corrected scope of acceptance tests. 2017-06-19 00:13:56 +02:00
464550cb5b
Renamed tests file. 2017-06-19 00:13:52 +02:00
a6babf3e90
Reimplemented major parts of parsing preconditions. 2017-06-19 00:13:48 +02:00
62b9da844a
Started reimplementing expression parsing. 2017-06-19 00:13:43 +02:00
fa9fd0935b
Made error message more precise. 2017-06-19 00:13:35 +02:00
1e77a6b043
Added “domain-axioms” as an ignored requirement to increase compatibility. 2017-06-19 00:13:29 +02:00
216decafc1
Allowing types to be undeclared for increased compatibility. 2017-06-19 00:13:24 +02:00
849faad134
Added compatibility check for unsupported “in-package” sections. 2017-06-19 00:13:18 +02:00
9642bab0c8
Enabled colored unit test results by default. 2017-06-19 00:13:13 +02:00
517698475c
Added test cases for all competition domains (not all of them supported yet). 2017-06-19 00:13:03 +02:00
0b8da69394
Added official PDDL competition instances for automated testing. 2017-06-19 00:13:03 +02:00
a7c4fdb242
Started reimplementing problem parser. 2017-06-19 00:12:51 +02:00
06b9632b70
Removed unused flags. 2017-05-18 15:55:20 +02:00
94dd209e5e
Linking constants to their declarations by reference instead of pointer. 2017-05-17 20:21:34 +02:00
5d65cc3100
Added missing include directive. 2017-05-17 20:21:20 +02:00
2042d6329d
Hiding implementation details in variant classes. 2017-05-17 20:09:07 +02:00
ff1d582605
Removed unwanted copy constructor. 2017-05-17 20:00:01 +02:00
b3fd49ef97
Removed duplicate entry from predicates. 2017-05-17 19:59:32 +02:00
8a103ea89d
Added class for PDDL parser exceptions. 2017-05-17 15:29:51 +02:00
29f8ee0778
Added parsing utils to skip PDDL sections. 2017-05-17 15:28:58 +02:00
5f240b632a
Added default constructors to AST structs. 2017-05-17 14:29:00 +02:00
d711fcd0f1
Removed unneeded class. 2017-05-12 14:31:26 +02:00
e312a91632
Renamed tokenizing module for clarity. 2017-05-12 14:17:57 +02:00
c10187f6ba
Minor refactoring to simplify parser classes. 2017-05-12 13:58:28 +02:00
d7db0d8ccd
Started implementing clean, separate PDDL syntax tree and parser. 2017-05-12 13:58:28 +02:00
d2f9e55e68
Merge branch 'master' of github.com:potassco/plasp into develop 2017-05-09 15:12:19 +02:00
ebcf263abd
Removed unnecessary boost::filesystem dependency. 2017-05-09 15:11:35 +02:00
27c6b69874
Moved basic parsing to a separate module. 2017-05-09 15:05:59 +02:00
386e5356af
Updated Catch. 2017-05-09 14:55:47 +02:00
88cb8f4516
Improved CMake structure. 2017-05-09 13:01:10 +02:00
9c9995380e
Resolved compiler warnings with clang. 2017-05-09 13:00:44 +02:00
mgebser
ff8dc0e85f just stylistic change 2017-01-18 15:45:12 +01:00
gebser
1b94053542 revised redundant rules 2017-01-18 10:12:52 +01:00
gebser
d1f1f9230c added predicate 2017-01-17 19:52:12 +01:00
mgebser
59e95c7097 some refactoring 2017-01-17 17:15:21 +01:00
mgebser
18f4a87dd7 slight modification 2017-01-17 13:31:34 +01:00
gebser
664762fdec about to revise encodings 2017-01-17 10:12:37 +01:00
mgebser
1458d93408 more parallel ''exists'' encoding variants 2017-01-16 17:15:19 +01:00
33e61beb4f
Fixed bug related to decomposing quantified expression. 2016-12-08 02:59:20 +01:00
0b31d8d56c
Fixed bugs related in decomposition of expressions. 2016-12-08 02:54:28 +01:00
cb2db2cadf
Removed unnecessary test file copies in CMake configuration. 2016-12-08 02:16:17 +01:00
f1d2c4e532
Removed invalid to-do. 2016-12-08 01:58:36 +01:00
a07d105906
Added missing include. 2016-12-08 01:44:36 +01:00
31182b6de9
Implemented translation of derived predicates in action preconditions. 2016-12-08 01:28:00 +01:00
586f53a788
Restructured functions related to translation of predicates. 2016-12-08 01:27:38 +01:00
1561aa5eb9
Put functions related to translation of predicates in separate file. 2016-12-08 01:18:00 +01:00
f4672a5b50
Added -Wextra flag to notice warnings more easily. 2016-12-08 01:17:09 +01:00
a5f1ebdc09
Removed unnecessary include directives. 2016-12-08 01:07:17 +01:00
8587aa23c4
Put functions related to translation of variables in separate file. 2016-12-08 01:05:39 +01:00
66cb09c8e4
Fixed incorrect auxiliary rule for derived predicates. 2016-12-08 00:54:13 +01:00
6355921e59
Implemented preconditions for derived predicates. 2016-12-08 00:52:09 +01:00
4172d320e4
Cleaned up output of translated derived predicates. 2016-12-07 23:26:46 +01:00
a8ba375e36
Implemented printing body of derived predicate definition rules. 2016-12-07 02:58:25 +01:00
2334686c59
Renamed arguments to parameters in predicate declarations. 2016-12-07 02:55:44 +01:00
ebab65e233
Refactoring to avoid dynamic casts. 2016-12-07 02:29:48 +01:00
692d3fe83a
Refactoring to avoid checking expression types via type enum. 2016-12-07 02:11:54 +01:00
3b110c0b8a
Started implementing translation for derived predicates. 2016-12-07 01:56:06 +01:00
443c126b88
Merge branch 'develop' of github.com:potassco/plasp into normalization 2016-12-05 02:23:43 +01:00
eb4798df4e
Updated catch. 2016-12-05 02:17:11 +01:00
c1340f6297
Merge branch 'develop' of github.com:potassco/plasp into normalization 2016-12-02 01:16:22 +01:00
9e1cdaaa51
Implemented new command-line options replacing --warning-level. 2016-12-01 17:18:58 +01:00
cfce6b1bbd
Removed unnecessary namespace directive. 2016-12-01 16:26:29 +01:00
c4e19dddae
Refactoring to use cleaner output implementation. 2016-11-29 06:03:05 +01:00
9b49b8ebe7
CMake project restructuring. 2016-11-29 02:55:26 +01:00
8b069d8149
Minor formatting. 2016-11-29 02:11:43 +01:00
f4efb4f3d4
Improved command-line interface. 2016-11-29 02:05:01 +01:00
180cc33ded
Merge branch 'develop' of github.com:potassco/plasp into develop 2016-11-29 01:32:25 +01:00
431b33a4da
Merge branch 'master' of github.com:potassco/plasp into develop 2016-11-22 02:17:55 +01:00
58e784408c
Fixed incorrect build status badge in readme. 2016-11-22 02:17:07 +01:00
91b2a23c78
Added a sequential, fixed-horizon meta encoding. 2016-11-20 23:52:55 +01:00
cbbe942dfd
Merge branch 'master' of github.com:potassco/plasp into develop 2016-11-16 23:56:44 +01:00
8bab1e19cb
Made readme file sections and documentation more consistent. 2016-11-16 23:53:21 +01:00
c80688b241
Changed format of readme file for STRIPS encodings to Markdown. 2016-11-16 23:46:00 +01:00
gebser
b1e98bd091 README file summarizing functionalities and example invocations 2016-11-15 22:48:24 +01:00
gebser
367f49253e finalizing redundant rules to restrict number of parallel plans 2016-11-15 21:16:01 +01:00
mgebser
6f1a64a705 some restriction of instantiation 2016-11-15 19:34:07 +01:00
mgebser
f12ac1c839 optional redundant rules to reduce the number of parallel plans 2016-11-15 18:57:52 +01:00
gebser
03c83702ad postprocessing encoding checked 2016-11-15 09:07:36 +01:00
mgebser
e2c38b5459 Merge branch 'master' of ssh://github.com/potassco/plasp 2016-11-14 18:36:49 +01:00
mgebser
7f62503237 first version of postprocessing program to check plans and represent them sequentially 2016-11-14 18:36:01 +01:00
e1e9efde25
Added contributor. 2016-11-14 17:11:05 +01:00
fb3f847f6a
Merge branch 'develop' of github.com:potassco/plasp into develop 2016-11-14 17:10:07 +01:00
mgebser
888f12d88d completed main parallel planning encodings for STRIPS instances 2016-11-14 16:56:51 +01:00
mgebser
b8357629a2 started to develop STRIPS encoding variants 2016-11-14 12:00:14 +01:00
1b56e9ed9b
Merge branch 'master' of github.com:potassco/plasp into develop 2016-11-12 18:36:10 +01:00
ba63a9fb05
Moved Catch to lib directory. 2016-11-12 18:24:09 +01:00
2585f726c5 Merge branch 'master' of github.com:potassco/plasp into develop 2016-11-04 16:15:42 +01:00
Patrick Lühne
dadb1801aa Minor formatting in readme file. 2016-11-04 16:12:05 +01:00
37732f35dd Merge branch 'develop' of github.com:potassco/plasp into develop 2016-11-04 16:11:26 +01:00
Patrick Lühne
2f6255a4e8 Added contributor. 2016-11-03 18:36:57 +01:00
5d8c143e60 Added Travis target for g++ 6. 2016-10-11 00:30:42 +02:00
0b94e315b4 Added compiler name to Travis configuration. 2016-10-10 20:56:09 +02:00
4a422795d9 Added language specification to Travis configuration. 2016-10-10 20:46:25 +02:00
1a27a21fa1 Added default packages and sources to Travis configuration. 2016-10-10 18:28:59 +02:00
bba069599f Merge branch 'develop' of github.com:potassco/plasp into develop 2016-10-10 18:24:05 +02:00
ba751f8c35 Added Travis target for g++ 6. 2016-10-10 18:22:56 +02:00
1f7ee57889 Updated building instructions after change to Catch testing framework. 2016-10-08 16:06:37 +02:00
d4faaf428c Switched from Google Test to Catch. 2016-10-08 16:03:14 +02:00
a163278fb5 Added license file to PKGBUILD for AUR. 2016-10-07 18:41:53 +02:00
1e2573d3e7 Added PKGBUILD for AUR. 2016-10-07 18:29:22 +02:00
5c5f0665e8 Minor formatting. 2016-10-07 16:40:01 +02:00
0ca51236bd Added unique ID to derived predicates for easier translation. 2016-09-09 17:08:31 +02:00
a62cc8b3b9 Started implementing derived predicates for decomposing complex PDDL conditions. 2016-09-09 16:42:16 +02:00
cc0b9726ed Added to-do. 2016-09-09 13:38:15 +02:00
bec63898af Updated change log with newly supported expression types. 2016-09-08 15:59:02 +02:00
9cccba42e0 Implemented parsing conditional effects. 2016-09-08 15:56:30 +02:00
4fc9b35c13 Implemented disjunctive normal form. 2016-09-08 03:42:32 +02:00
34496a7158 Finished implementing the prenex normal form with maximal groups of same-type quantifiers. 2016-09-08 02:40:51 +02:00
e0ed145716 Implemented prenex normalization. 2016-09-07 00:34:26 +02:00
2e52357dd2 Allowing universal quantifiers in effect expressions. 2016-09-06 22:36:48 +02:00
104f7165cd Fixed compiler error occurring in debug mode only. 2016-09-06 21:47:03 +02:00
edbc8770e3 Testing simplification of nested existential quantifiers. 2016-09-06 18:51:29 +02:00
31068bf89c Implemented simplification of nested quantified expressions. 2016-09-06 18:50:23 +02:00
ad6b3d60eb Implemented De Morgan normalization for quantified expressions. 2016-09-06 17:43:47 +02:00
bd2ef96216 Added forward declarations for quantified expressions. 2016-09-06 17:41:04 +02:00
faa920e1ad Correctly parsing quantified expressions thanks to variable stack. 2016-09-06 17:36:51 +02:00
eb28ed3938 Implemented variable stack for parsing nested variable lists (as within quantified expressions). 2016-09-06 17:34:07 +02:00
f4f0e07bc1 Started supporting quantified expressions. 2016-09-06 16:57:31 +02:00
ca6664feb2 Refactored parsing variable lists to reuse it with quantified expressions. 2016-09-06 16:28:38 +02:00
6f3769f364 Removed unnecessary includes. 2016-09-05 17:05:48 +02:00
0c5936ad38 Noted to-do. 2016-09-05 00:39:12 +02:00
263b611a7b Implemented simplification of directly nested n-ary expressions of the same type. 2016-09-05 00:37:43 +02:00
79d449d0df Renaming to not confuse expression simplification and reduction. 2016-09-05 00:06:09 +02:00
dd621fcd5c Minor clean-up. 2016-09-04 23:54:15 +02:00
c2af84a800 Removed redundant normalization statement. 2016-09-04 23:52:06 +02:00
3fa7b93d44 Fixed wrong recursive call. 2016-09-04 23:34:20 +02:00
4d72c20d9b Added separate simplification step to normalize in a single recursion. 2016-09-04 23:30:08 +02:00
97ad4268d7 Added second double negation elimination step after normalizing the argument of a “not” expression. 2016-09-04 22:45:37 +02:00
ed2d64c1c9 Added debug printing function to facilitate testing expression normalization. 2016-09-04 22:26:17 +02:00
c9ecd0c020 Implemented De Morgan’s rules for normalization purposes. 2016-09-04 20:49:22 +02:00
6aaf7c039d Refactored normalization because of recent changes to the pointer usage. 2016-09-04 19:29:05 +02:00
7aa20a5820 Refactored expressions thanks to intrusive pointers. 2016-09-04 18:48:46 +02:00
9afabacde3 Switched to intrusive pointers for much easier maintenance. 2016-09-04 18:26:02 +02:00
f10f4ac29c Added back reference expressions to make the expression tree structure simpler. 2016-09-04 14:49:34 +02:00
da88a8816c Fixed issue with multiple negations. 2016-09-03 00:25:58 +02:00
63de1891af Fixed missing normalization step of arguments to imply statements and extended test to cover the issue. 2016-09-02 19:25:25 +02:00
23e851ccef Normalizing problems’ goal descriptions. 2016-09-02 18:49:30 +02:00
5f406e6b18 Added support for imply expressions to change log. 2016-09-02 18:46:24 +02:00
9aad139aae Added test covering the removal of implications. 2016-09-02 18:45:00 +02:00
4fb2c331f3 Added dummy expression to check that with removed double negations, expressions are still correctly normalized. 2016-09-02 18:32:13 +02:00
1a96c3ec72 Added test covering removal of double negations. 2016-09-02 18:27:00 +02:00
b084a1f727 Implemented removal of double negations. 2016-09-02 18:07:37 +02:00
56ce55677f Started implementing PDDL normalization. 2016-09-02 17:58:00 +02:00
c528626fe9 Preparing more general form of PDDL normalization. 2016-09-02 16:39:42 +02:00
8361f3767b Version bump after release 3.0.3. 2016-09-02 15:46:58 +02:00
b72a17c190 Version bump for release 3.0.3. 2016-09-02 15:46:14 +02:00
6842bff04b Removed temporary directory. 2016-09-02 15:45:44 +02:00
6bec233e23 Moved IPC 2000 Elevator example instances to instance directory. 2016-09-02 15:44:33 +02:00
873ccef4ff Moved IPC 2008 OpenStacks example instances to instance directory. 2016-09-02 15:44:12 +02:00
4706d2915f Clarified how to plasp handle updates before executing the test suite. 2016-08-30 18:52:59 +02:00
1d59ad20c1 Merge branch 'develop' of github.com:potassco/plasp into develop 2016-08-30 18:48:40 +02:00
b4f7e4f102 Added test case covering unexpected whitespaces in SAS file. 2016-08-30 18:48:24 +02:00
e664fe8470 Updated readme file with new location of the meta encoding. 2016-08-30 14:28:29 +02:00
28b9d22a4c Hiding example instances from Linguist. 2016-08-30 13:05:03 +02:00
be376a9ffb Hiding mutex group section in output if there are none. 2016-08-30 13:02:00 +02:00
76f8df13fc Fixed parsing issue with unexpected whitespaces in SAS files. 2016-08-30 13:01:22 +02:00
9447912fbf Added a few SAS example instances for testing. 2016-08-29 18:26:59 +02:00
87717606b2 Moved PDDL example instances to subdirectory. 2016-08-29 17:49:57 +02:00
Torsten Schaub
348bc32cef generated some sas files from Rene's PDDL samples
- should be deleted later -
2016-08-28 21:00:05 +02:00
Torsten Schaub
fcdb0b65c2 fixed bug: frame axiom only on true fluents
renamed modified by changed (more frequent naming)
2016-08-28 20:53:25 +02:00
Torsten Schaub
0fb79d1268 just re-formatting 2016-08-26 18:21:33 +02:00
Torsten Schaub
69757e50ac fixed bug in conditional effects
- still one test screwing up -
2016-08-26 18:00:33 +02:00
06feeab244 Merge branch 'master' of github.com:potassco/plasp into develop 2016-08-26 15:51:07 +02:00
568945c7a8 Fixed incorrect output format of conditional effects with SAS. 2016-08-26 15:50:39 +02:00
dd33e47dd9 Fixed minor issues in output format documentation. 2016-08-26 15:42:39 +02:00
Torsten Schaub
7dfe760285 PRELIMINARY version of an encoding for sequential SAS planning
featuring: axioms and conditional effects
(extending Patrick's basic multi-valued encoding)
2016-08-23 18:31:33 +02:00
Torsten Schaub
d7b8cec50d simple fixed horizon-based encoding for sequential PDDL planning 2016-08-23 11:51:03 +02:00
Torsten Schaub
92f3018b89 first throw at PDDL specifc encoding for sequential planning using Boolean fluents only 2016-08-22 22:35:35 +02:00
3806fba9c2 Version bump after release 3.0.2. 2016-08-18 15:56:29 +02:00
b44c04d3c0 Version bump for release 3.0.2. 2016-08-18 15:55:51 +02:00
220b9959a3 Added IPC 2004 Satellite example instances. 2016-08-18 15:51:58 +02:00
f8ec341015 Added IPC 2006 TPP example instances. 2016-08-18 15:43:14 +02:00
3ceeb3ae40 Added IPC 2002 Driver Log example instances. 2016-08-18 15:29:27 +02:00
56f0091f1e Added IPC 2002 Depots example instances. 2016-08-18 15:25:10 +02:00
ec886e345b Added IPC 2000 Elevator example instances. 2016-08-18 15:06:53 +02:00
786eabb748 Added IPC 2000 Blocks World example instances. 2016-08-18 15:00:31 +02:00
fa18dc7979 Restructured example instances for consistency. 2016-08-18 14:53:26 +02:00
136f9ed00a Added IPC 1998 Gripper example instances. 2016-08-18 14:40:06 +02:00
e312740629 Fixed syntax error in output. 2016-08-18 14:39:40 +02:00
31d0a1fb38 Turned exception about unspecified requirements into a warning, now also for problems. 2016-08-18 14:30:47 +02:00
ca30f8a815 Turned exception about unspecified requirements into a warning. 2016-08-18 14:29:17 +02:00
21c337e0fa Removed now obsolete ASP variable handling for PDDL. 2016-08-18 00:25:47 +02:00
8251652445 Implemented parameter name normalization for PDDL to avoid escaping the names. 2016-08-18 00:24:10 +02:00
5e28dd046b Further simplified the output of the PDDL variable value facts. 2016-08-18 00:00:50 +02:00
363070b579 Replaced the two rules for the values of a PDDL variable with a single one. 2016-08-17 23:31:31 +02:00
63ed1299ec Updated documentation to recent change of PDDL translator output. 2016-08-17 19:05:01 +02:00
7bd483cd7e Added rule to PDDL translator output to make all unspecified initial state variables false by default. 2016-08-17 19:02:51 +02:00
91019f52aa Fixed issue with unsupported expression negations. 2016-08-16 18:58:30 +02:00
69a26cb22f Fixed undetected issue with unsupported negations. 2016-08-16 18:43:37 +02:00
cdb06fa5bf Improved output format and highlighting. 2016-08-16 18:35:55 +02:00
9c76ce7174 Documented type inheritance. 2016-08-16 18:07:18 +02:00
676dc44619 Updated meta encoding to new feature requirement format. 2016-08-15 18:24:51 +02:00
b8a3019e5b Made unconditional effects a keyword. 2016-08-15 16:59:28 +02:00
e0a15849df Updated documentation to changes of axiom rule output format. 2016-08-15 16:48:17 +02:00
ef57f27c6a Changed output format of axiom rules for consistency. 2016-08-15 16:33:33 +02:00
169c5ae8e9 Fixed typo. 2016-08-15 15:26:34 +02:00
760143a4a2 Documented CMake option for building tests. 2016-08-15 02:23:05 +02:00
b100bcd446 Disabled tests by default. 2016-08-15 02:23:05 +02:00
04ddbaabae Version bump after release 3.0.2 RC 1. 2016-08-14 17:40:51 +02:00
4a2882711d Version bump for release 3.0.2 RC 1. 2016-08-14 17:36:59 +02:00
08113c961a Continuously incrementing effect IDs, with a special identifier for unconditional effects. 2016-08-14 17:21:41 +02:00
e2da46e20a Updated change log with documentation of output format. 2016-08-14 16:37:31 +02:00
0cf44da917 Minor formatting. 2016-08-14 16:35:38 +02:00
d03638919a Added more detail to the command-line interface documentation. 2016-08-14 16:34:39 +02:00
f5d342a442 Minor formatting. 2016-08-14 16:33:11 +02:00
06cab2f098 Put command-line interface documentation in a separate documentation file. 2016-08-14 16:31:23 +02:00
9d67ae800d Put building instructions in a separate documentation file. 2016-08-14 16:27:43 +02:00
d2a1030320 Added link to output format to the readme file. 2016-08-14 16:23:28 +02:00
5c17d23606 Added list of supported feature requirements. 2016-08-14 16:15:43 +02:00
bc1759aedf Minor formatting. 2016-08-14 16:09:36 +02:00
b9aef10db3 Documented axiom rules. 2016-08-14 16:07:45 +02:00
bdb6ac9fba Changed output format of axiom rules. 2016-08-14 16:02:28 +02:00
4d5f935e82 Minor formatting. 2016-08-14 16:01:39 +02:00
d604e44dff Documented mutex groups. 2016-08-14 16:00:31 +02:00
2c37da4cb4 Clarification about variables’ value uniqueness. 2016-08-14 16:00:09 +02:00
741078c4fd Minor formatting. 2016-08-14 15:50:49 +02:00
e101cf2aab Documented action costs. 2016-08-14 15:49:34 +02:00
3dfae74468 Documented goal. 2016-08-14 15:47:49 +02:00
2363f42bc9 Minor clarification in the documentation concerning action sequences. 2016-08-14 15:46:12 +02:00
491454ca3c Extended introduction to the documentation. 2016-08-14 15:44:14 +02:00
562b2296e5 Documented initial state. 2016-08-14 15:39:25 +02:00
3535afb1e1 Minor clarification concerning constants and objects. 2016-08-14 15:31:23 +02:00
7a63e4abb9 Documented constants and objects. 2016-08-14 15:29:27 +02:00
2281cd1cd4 Documented actions. 2016-08-14 15:14:27 +02:00
4037b339e4 Changed keyword for conditions of conditional effects. 2016-08-14 15:14:13 +02:00
00c3140f3b Restructured output format documentation once more and documented variables. 2016-08-14 14:58:04 +02:00
0fb282d153 Changed output format of feature requirements. 2016-08-14 14:55:46 +02:00
7a73f99581 Updated change log with recent fixes in SAS output formatting. 2016-08-13 19:14:04 +02:00
bdd68f04e1 Minor cleanup in documentation. 2016-08-13 19:02:05 +02:00
a5a300b150 Documented constants and objects. 2016-08-13 18:59:11 +02:00
197cec923e Added introductory example to output format documentation. 2016-08-13 18:47:01 +02:00
c391a1f566 Removed unwanted newline in SAS output. 2016-08-13 18:44:18 +02:00
1727113a8b Documented types. 2016-08-13 18:07:17 +02:00
18ac959970 Restructured documentation of feature requirements and added an example. 2016-08-13 17:52:27 +02:00
d00c5bb753 Minor rephrasing in documentation. 2016-08-13 17:42:02 +02:00
ffcf07b935 Documented feature requirements. 2016-08-13 17:39:39 +02:00
042531abc3 Started documenting the unified output format. 2016-08-13 13:35:30 +02:00
4fc7355fba Removed unwanted newline. 2016-08-13 13:21:00 +02:00
c12be088c6 Updated change log with unified output format. 2016-08-13 11:12:38 +02:00
9c3cfe8f7b Dropped »meta« prefix of encoding file because there will only be meta encodings. 2016-08-13 11:10:29 +02:00
d4c168af30 Unified SAS and PDDL meta encodings. 2016-08-13 11:09:35 +02:00
f2d3aee662 Updated PDDL meta encoding to recent changes of output format. 2016-08-13 11:09:35 +02:00
340db244f6 Fixed bug in output format. 2016-08-13 04:04:28 +02:00
8969364f73 Fixed syntax error in output format. 2016-08-13 03:27:37 +02:00
b67168134b Made initial state definition consistent with unified output format. 2016-08-13 03:22:25 +02:00
97d33da686 Added effect ID as a placeholder (for conditional effects) for consistency with unified output format. 2016-08-13 03:17:48 +02:00
1f35bda3d2 Wrapped translated PDDL action definitions for usability in meta encodings. 2016-08-13 03:11:38 +02:00
6960e8a8c7 Wrapped translated PDDL constant definitions for usability in meta encodings. 2016-08-13 03:09:14 +02:00
b30cecd297 Turning translated PDDL predicates into unified variable format in rest of output format. 2016-08-13 03:08:05 +02:00
99fc6988a3 Renamed heading to »variables«. 2016-08-13 02:50:07 +02:00
cf022f9959 Started turning translated PDDL predicates into unified variable format. 2016-08-13 02:48:30 +02:00
0a1044743e Renamed meta predicate for simplicity. 2016-08-13 02:33:28 +02:00
94b204615b Wrapped translated PDDL type definitions for usability in meta encodings. 2016-08-13 02:32:27 +02:00
230c6dfc15 Made order of sections of translated SAS more uniform with PDDL. 2016-08-13 02:29:48 +02:00
8be67e7065 Updated SAS meta encoding to recent changes of output format. 2016-08-13 01:49:00 +02:00
378b2ae673 Wrapped translated SAS axiom rule definitions for usability in meta encodings. 2016-08-13 01:44:45 +02:00
36e517bd80 Wrapped translated SAS mutex group definitions for usability in meta encodings. 2016-08-13 01:42:18 +02:00
569b3d0c97 Wrapped translated SAS action definitions for usability in meta encodings. 2016-08-13 01:40:31 +02:00
daf68d24ab Added highlighting of variable names. 2016-08-13 01:39:49 +02:00
8a82f52100 Wrapped translated SAS variable definitions for usability in meta encodings. 2016-08-13 01:36:08 +02:00
d0864b9efe Extended parser tests. 2016-08-08 12:40:02 +02:00
18bd606262 Extended parser tests. 2016-08-07 16:46:48 +02:00
252f50108b Removed unnecessary file. 2016-08-07 16:22:26 +02:00
015c34fc2b Minor refactoring. 2016-08-03 00:33:20 +02:00
d7b47797df Made Stream members protected again. 2016-08-03 00:28:22 +02:00
544d4e0635 Major refactoring of underlying Parser class. 2016-08-02 20:33:49 +02:00
73c9d6c1f3 Checking that Parser initially is case-sensitive. 2016-06-22 09:14:01 +01:00
d9578b6f1c Testing Parser position with seek and advance. 2016-06-22 09:07:19 +01:00
b5e325cbee Testing Parser’s reset method. 2016-06-22 09:02:46 +01:00
234938349c Fixed incorrect seek positions. 2016-06-22 08:59:18 +01:00
9ed7277ec9 Fixed minor formatting issue with axiom rules. 2016-06-22 08:45:48 +01:00
dc87c09442 Merge branch 'master' of github.com:potassco/plasp into develop 2016-06-15 00:57:01 +02:00
00688765fd Fixed typos in readme file. 2016-06-15 00:56:17 +02:00
3702b72feb Version bump after release 3.0.1. 2016-06-15 00:18:09 +02:00
343 changed files with 34912 additions and 8502 deletions

1
.gitattributes vendored
View File

@ -4,3 +4,4 @@
.travis.yml export-ignore
tests/data/* linguist-documentation
instances/* linguist-documentation

16
.gitmodules vendored
View File

@ -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

View File

@ -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

View File

@ -1,8 +1,67 @@
# Change Log
# Changelog
## (unreleased)
## 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 plasps 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
* 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
@ -13,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

View File

@ -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
View 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

109
README.md
View File

@ -1,96 +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` 3 translates planning problem instances to ASP facts.
`plasp` 3 supports the input languages [PDDL](https://helios.hud.ac.uk/scommv/IPC-14/software.html) (only basic features currently) and the [SAS](http://www.fast-downward.org/TranslatorOutputFormat) (full support of the current version 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 instance.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>...]
```
`[files]` may be omitted, in which case the input is read from `std::cin`.
The `[options]` are listed below:
Aside from translating PDDL to ASP facts, `plasp` provides the following commands:
| **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`). |
| command | description |
|---|---|
| `translate` | Translate PDDL and SAS to ASP facts |
| `normalize` | Normalize PDDL to plasps custom PDDL format |
| `check-syntax` | Check the syntax of PDDL specifications |
| `beautify` | Cleanly format PDDL specifications |
| `help` | Display help message |
| `version` | Display version information |
`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` automatically detects the language (PDDL or SAS) of the input descriptions.
## Building
`plasp` requires a C++14 compiler (preferrably GCC ≥ 6.1 or clang ≥ 3.8), the `boost` libraries (≥ 1.55), and CMake for building.
`plasp` is built with CMake and a C++ compiler.
See [building](doc/building.md) for more details.
```bash
$ git clone https://github.com/potassco/plasp.git
$ cd plasp
$ mkdir -p build/release
$ cd build/release
$ cmake ../.. -DCMAKE_BUILD_TYPE=Release
$ make
```
## PDDL Feature Support
The built `plasp` binary is then located at `plasp/build/release/bin/plasp`.
### 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
```
`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
View File

@ -0,0 +1 @@
add_subdirectory(src)

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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 plasps custom PDDL format";
public:
int run(int argc, char **argv);
};
////////////////////////////////////////////////////////////////////////////////////////////////////
#endif

View 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

View 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
View 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)

View 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 + "");
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View 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;
}

View File

@ -0,0 +1,14 @@
#include <plasp-app/commands/CommandVersion.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Command Version
//
////////////////////////////////////////////////////////////////////////////////////////////////////
int CommandVersion::run(int, char **)
{
printVersion();
return EXIT_SUCCESS;
}

View 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;
}

View File

@ -1 +0,0 @@
add_subdirectory(plasp-app)

View File

@ -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)

View File

@ -1,177 +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.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 parser;
parser.setCaseSensitive(false);
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.readFile(inputFile);
});
}
else
parser.readStream("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;
}

47
doc/building.md Normal file
View 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.

View File

@ -0,0 +1,22 @@
# Feature Requirements
Feature requirements are part of `plasp`s [output format](output-format.md).
Currently, `plasp` detects feature requirements only for SAS problems.
`plasp` supports the following feature requirements:
SAS feature | description
------------|------------
`actionCosts` | actions have associated costs (see [action costs](output-format.md#action-costs))
`axiomRules` | immediate actions are used, which are executed as soon as the preconditions are satisfied (see [axiom rules](output-format.md#axiom-rules))
`conditionalEffects` | some effects of an action may have additional conditions (see [actions](output-format.md#actions))
## Example
The following specifies that the input problem has the two requirements `actionCosts` and `conditionalEffects`.
```prolog
% requirements
requiresFeature(actionCosts).
requiresFeature(conditionalEffects).
```

290
doc/output-format.md Normal file
View File

@ -0,0 +1,290 @@
# Output Format
`plasp` 3 translates SAS and PDDL files into a uniform ASP fact format.
## Overview
Essentially, `plasp`s output format consists of [state variables](#variables) that are modified by [actions](#actions) if their preconditions are fulfilled.
Variables reference [entities](#constants-objects) that are affected by the actions.
As with PDDL, the objective is to achieve a specific [goal](#goal) starting from an [initial state](#initial-state) by executing a sequence of actions.
`plasp`s variables correspond to the multivalued variables in SAS.
PDDL predicates are turned into Boolean variables to make the output format consistent.
Actions are modeled exactly as PDDL actions and SAS operators.
## In a Nutshell
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")).
% 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")).
% 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(("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(variable(("on", constant("a"))), false)).
% in the end, the switch should be on
goal(variable(("on", constant("a"))), value(variable(("on", constant("a"))), true)).
```
## Syntax and Semantics
`plasp` structures the translated ASP facts into multiple sections, which are explained in the following.
### Feature Requirements
```prolog
% declares a required feature
requires(feature(<name>)).
```
`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.
### Types
```prolog
% declares a <type>
type(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
% declares a <variable>
variable(variable(<name>)).
% adds a <value> to the domain of a <variable>
contains(<variable>, <value>).
```
`plasp`s variables represent the current state of the planning problem.
Variables are linked to the problem's [objects](#constants-objects) and [constants](#constants-objects).
`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>, <SAS value>)` for each variable.
With PDDL, Boolean variables are created from the PDDL predicates.
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 dont automatically carry over to the next time step).
### Actions
```prolog
% declares an <action>
action(action(<name>)).
% 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](#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.
For this reason, each conditional effect is uniquely identified with a predicate `effect(<number>)` as the second argument of the `postcondition` facts.
The conditions of conditional effects are given by additional `precondition` facts that take the respective `effect(<number>)` predicates as the first argument.
Unconditional effects are identified with `effect(unconditional)`.
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 have type type(<name>)
has(<constant>, <type>).
```
Constants and objects are the entities that are affected by [actions](#actions), for instance, the blocks in a Blocks World problem.
Constants are global for a domain, while objects are problem-specific.
`plasp` does not distinguish between the two (modeling both as constants), as both are identically used static identifiers.
### Initial State
```prolog
% initializes <variable> with a specific <value>
initialState(<variable>, <value>).
```
The initial state contains all [variable](#variables) assignments that hold before executing any [actions](#actions).
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> and <derived variable> shall obtain a respective <value> in the end
goal(<variable>, <value>).
goal(<derived variable>, <value>).
```
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
```prolog
% declares a <mutex group>
mutexGroup(mutexGroup(<number>)).
% adds the assignment of <variable> to <value> to a <mutex group>
contains(<mutex group>, <variable>, <value>).
```
SAS contains information about mutually exclusive [variable](#variables) assignments.
That is, *at most one* variable assignment of each mutex group must be satisfied at all times.
Mutex group facts are only present with SAS input programs and not PDDL.
Mutex groups contain essential information in order to find plans correctly.
That is, if mutex groups are present in `plasp`s output, they have to be accounted for appropriately.
### Axiom Rules
```prolog
% declares an <axiom rule>
axiomRule(axiomRule(<number>)).
% defines that as a precondition to <axiom rule>, <variable> must have value <value>
precondition(<axiom rule>, <variable>, <value>).
% defines that after applying <axiom rule>, <variable> is assigned <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.
That is, if axiom rules are present in `plasp`s output, they have to be accounted for appropriately.

View File

@ -0,0 +1,27 @@
# PDDL Feature Support
This document describes the PDDL features are currently supported by `plasp`s very own translator.
This doesnt cover PDDL feature support through SAS conversion with [Fast Downward](http://www.fast-downward.org/) (please refer to [Fast Downwards 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 |

View 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.

View 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.

View File

@ -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.

View File

@ -0,0 +1,40 @@
#include <incmode>.
% Check feature requirements
:- requires(feature(actionCosts)).
:- requires(feature(axiomRules)).
:- requires(feature(conditionalEffects)).
#program base.
% Establish initial state
holds(Variable, Value, 0) :- initialState(Variable, Value).
#program step(t).
% 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, _, Variable, Value).
modified(Variable, t) :- caused(Variable, Value, t).
holds(Variable, Value, t) :- caused(Variable, Value, t).
holds(Variable, Value, t) :- holds(Variable, Value, t - 1), not modified(Variable, t).
% Check that variables have unique values
:- variable(Variable), not 1 {holds(Variable, Value, t) : contains(Variable, Value)} 1.
% Check mutexes
:- mutexGroup(MutexGroup), not {holds(Variable, Value, t) : contains(MutexGroup, Variable, Value)} 1.
#program check(t).
% Verify that goal is met
:- query(t), goal(Variable, Value), not holds(Variable, Value, t).
#show query/1.
#show occurs/2.

View File

@ -1,31 +0,0 @@
#include <incmode>.
#program base.
% Establish initial state
holds(Predicate, 0) :- initialState(Predicate).
#program step(t).
% Perform actions
1 {occurs(action(Action), t) : action(Action)} 1.
% Check preconditions
:- occurs(Action, t), precondition(Action, Predicate, true), not holds(Predicate, t - 1).
:- occurs(Action, t), precondition(Action, Predicate, false), holds(Predicate, t - 1).
% Apply effects
caused(Predicate, true, t) :- occurs(Action, t), postcondition(Action, Predicate, true).
caused(Predicate, false, t) :- occurs(Action, t), postcondition(Action, Predicate, false).
holds(Predicate, t) :- caused(Predicate, true, t).
holds(Predicate, t) :- holds(Predicate, t - 1), not caused(Predicate, false, t).
#program check(t).
% Verify that goal is met
:- query(t), goal(Predicate, true), not holds(Predicate, t).
:- query(t), goal(Predicate, false), holds(Predicate, t).
#show query/1.
#show occurs/2.

View File

@ -1,40 +0,0 @@
#include <incmode>.
% Check feature requirements
:- requiresFeature(actionCosts).
:- requiresFeature(axiomRules).
:- requiresFeature(conditionalEffects).
#program base.
% Establish initial state
holds(Var, Val, 0) :- initialState(Var, Val).
#program step(t).
% Perform actions
1 {occurs(action(A), t) : action(A)} 1.
% Check preconditions
:- occurs(A, t), precondition(A, Var, Val), not holds(Var, Val, t - 1).
% Apply effects
caused(Var, Val, t) :- occurs(A, t), postcondition(A, _, Var, Val).
modified(Var, t) :- caused(Var, Val, t).
holds(Var, Val, t) :- caused(Var, Val, t).
holds(Var, Val, t) :- holds(Var, Val, t - 1), not modified(Var, t).
% Check that variables have unique values
:- variable(X), Var = variable(X), not 1 {holds(Var, Val, t) : contains(Var, Val)} 1.
% Check mutexes
:- mutexGroup(X), M = mutexGroup(X), not {holds(Var, Val, t) : contains(M, Var, Val)} 1.
#program check(t).
% Verify that goal is met
:- query(t), goal(Var, Val), not holds(Var, Val, t).
#show query/1.
#show occurs/2.

View 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.

View 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)
```

View File

@ -0,0 +1,3 @@
% Include built-in "iclingo" script for incremental grounding and solving
#include <incmode>.

View 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).

View 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.

View 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.

View 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.

View File

@ -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:

View File

@ -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,33 +14,34 @@ namespace plasp
//
////////////////////////////////////////////////////////////////////////////////////////////////////
Language::Type detectLanguage(utils::Parser &parser)
inline Language::Type detectLanguage(tokenize::Tokenizer<tokenize::CaseInsensitiveTokenizerPolicy> &tokenizer)
{
parser.setCaseSensitive(false);
parser.skipWhiteSpace();
tokenizer.skipWhiteSpace();
// SAS begins with "begin_version"
if (parser.probe<std::string>("begin"))
if (tokenizer.testAndSkip<std::string>("begin"))
{
parser.seek(std::ios::beg);
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.probe<std::string>("(") && parser.probe<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;
}

View File

@ -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

View File

@ -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 &parameters() 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

View File

@ -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

View File

@ -1,68 +0,0 @@
#ifndef __PLASP__PDDL__CONTEXT_H
#define __PLASP__PDDL__CONTEXT_H
#include <memory>
#include <unordered_map>
#include <vector>
#include <plasp/utils/Logger.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Context
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Context
{
public:
Context() = default;
explicit Context(utils::Parser &&parser)
: parser{std::move(parser)}
{
}
explicit Context(utils::Logger &&logger)
: logger{std::move(logger)}
{
}
explicit Context(utils::Parser &&parser, utils::Logger &&logger)
: parser{std::move(parser)},
logger{std::move(logger)}
{
}
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;
}
utils::Parser parser;
utils::Logger logger;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -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::Parser::Position m_domainPosition;
std::unique_ptr<Domain> m_domain;
utils::Parser::Position m_problemPosition;
std::unique_ptr<Problem> m_problem;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -1,92 +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/expressions/Constant.h>
#include <plasp/pddl/expressions/PredicateDeclaration.h>
#include <plasp/pddl/expressions/PrimitiveType.h>
#include <plasp/pddl/Requirement.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::Parser::Position m_requirementsPosition;
Requirements m_requirements;
utils::Parser::Position m_typesPosition;
expressions::PrimitiveTypes m_types;
utils::Parser::Position m_constantsPosition;
expressions::Constants m_constants;
utils::Parser::Position m_predicatesPosition;
expressions::PredicateDeclarations m_predicates;
std::vector<utils::Parser::Position> m_actionPositions;
std::vector<std::unique_ptr<Action>> m_actions;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -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

View File

@ -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 &parameters);
ExpressionContext(Domain &domain, Problem *problem, expressions::Variables &parameters);
bool hasRequirement(Requirement::Type requirementType) const;
void checkRequirement(Requirement::Type requirementType) const;
Domain &domain;
Problem *problem;
expressions::Variables &parameters;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -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

View File

@ -1,84 +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/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::Parser::Position m_domainPosition;
utils::Parser::Position m_requirementsPosition;
Requirements m_requirements;
utils::Parser::Position m_objectsPosition;
expressions::Constants m_objects;
utils::Parser::Position m_initialStatePosition;
std::unique_ptr<InitialState> m_initialState;
utils::Parser::Position m_goalPosition;
ExpressionPointer m_goal;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -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

View File

@ -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;
};
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,106 +0,0 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__AT_H
#define __PLASP__PDDL__EXPRESSIONS__AT_H
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/Identifier.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.probe<std::string>("(")
|| !parser.probeIdentifier("at", isIdentifier))
{
parser.seek(position);
return nullptr;
}
size_t timePoint;
const auto timePointPosition = parser.position();
if (parser.probeIdentifier("start", isIdentifier))
timePoint = TimePointStart;
else if (parser.probeIdentifier("end", isIdentifier))
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

View File

@ -1,112 +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/Identifier.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.probe<std::string>("(")
|| !parser.probeIdentifier(Derived::Identifier, isIdentifier))
{
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

View File

@ -1,65 +0,0 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__CONSTANT_H
#define __PLASP__PDDL__EXPRESSIONS__CONSTANT_H
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/Identifier.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

View File

@ -1,118 +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/Identifier.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.probe<std::string>("(")
|| !parser.probeIdentifier(Derived::Identifier, isIdentifier))
{
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(context.parser, "" + 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

View File

@ -1,78 +0,0 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__NOT_H
#define __PLASP__PDDL__EXPRESSIONS__NOT_H
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/Identifier.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.probe<std::string>("(")
|| !parser.probeIdentifier("not", isIdentifier))
{
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

View File

@ -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

View File

@ -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

View File

@ -1,56 +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/pddl/Identifier.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

View File

@ -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

View File

@ -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 &parameters);
private:
Variable();
bool m_isDirty;
std::string m_name;
const Expression *m_type;
// Stores "either" expression if necessary
ExpressionPointer m_eitherExpression;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View 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_)
{
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

View 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

View 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_)
{
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

View 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_)
{
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

View 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_)
{
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
};
fact.match(handleAtomicFormula, handleNot);
outputStream << ").";
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View 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_)
{
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

View 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_)
{
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

View 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

View 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

View 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

View File

@ -1,32 +1,38 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__EITHER_H
#define __PLASP__PDDL__EXPRESSIONS__EITHER_H
#ifndef __PLASP__PDDL__TRANSLATION__VARIABLE_STACK_H
#define __PLASP__PDDL__TRANSLATION__VARIABLE_STACK_H
#include <plasp/pddl/expressions/NAry.h>
#include <pddl/NormalizedAST.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Either
// VariableStack
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Either: public NAry<Either>
struct VariableStack
{
public:
static const Expression::Type ExpressionType = Expression::Type::Either;
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;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}

View 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

View File

@ -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);

View File

@ -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;

View File

@ -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);
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -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;
@ -45,19 +45,21 @@ class Description
bool usesAxiomRules() const;
bool usesConditionalEffects() const;
bool hasRequirements() const;
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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
};
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -1,57 +0,0 @@
#ifndef __PLASP__UTILS__IO_H
#define __PLASP__UTILS__IO_H
#include <boost/algorithm/string/replace.hpp>
namespace plasp
{
namespace utils
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// IO
//
////////////////////////////////////////////////////////////////////////////////////////////////////
inline std::string escapeASP(const std::string &string)
{
auto escaped = string;
boost::replace_all(escaped, "_", "__");
boost::replace_all(escaped, "-", "_h");
boost::replace_all(escaped, "@", "_a");
return escaped;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
inline std::string unescapeASP(const std::string &string)
{
auto unescaped = string;
boost::replace_all(unescaped, "_a", "@");
boost::replace_all(unescaped, "_h", "-");
boost::replace_all(unescaped, "__", "_");
return unescaped;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
inline std::string escapeASPVariable(const std::string &string)
{
auto escaped = escapeASP(string);
escaped.front() = std::toupper(escaped.front());
return escaped;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More