385 Commits

Author SHA1 Message Date
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
9af383d2f6 Version bump for release 3.0.1. 2016-06-14 19:26:41 +02:00
d3039d55e5 Fixed typo in PDDL translation output. 2016-06-14 19:21:27 +02:00
6b5c8df03a Fixed issues with color output. 2016-06-14 19:14:26 +02:00
8084fe5574 Merge branch 'develop' of github.com:potassco/plasp 2016-06-14 18:54:43 +02:00
3d661cd1f4 Fixed unescaped ASP identifier. 2016-06-14 18:53:50 +02:00
853d7471c2 Added error message when using command-line options incorrectly. 2016-06-14 18:47:02 +02:00
0a205680fe Made default color policy autodetection again. 2016-06-14 18:46:47 +02:00
52fee6a4c1 Made the language command-line option lowercase for consistency. 2016-06-14 18:42:29 +02:00
fcdd3bba2b Added command-line options to readme file. 2016-06-14 18:40:40 +02:00
b491efa9f4 Minor rephrasing. 2016-06-14 18:30:06 +02:00
401cf79cf6 Fixed incorrect usage information in help message. 2016-06-14 18:28:45 +02:00
44a20ca7e3 Updated usage information in the readme file. 2016-06-14 18:25:24 +02:00
5bda1c2245 Reordered change log items. 2016-06-14 18:08:32 +02:00
eb3d91f085 Added command-line option to autodetect, enable, or disable color output. 2016-06-14 18:02:59 +02:00
aff396d919 Colorizing numbers in translated SAS output. 2016-06-14 17:41:41 +02:00
f7cd24b67a Colorized output for SAS translator. 2016-06-14 17:35:32 +02:00
1e21457efb Refactored color output of headings. 2016-06-14 17:11:45 +02:00
583ec78eef Removed deleted methods. 2016-06-14 17:06:07 +02:00
9969281b11 Refactored color output of variables and keywords. 2016-06-14 17:05:41 +02:00
6fec1cc409 Made all error and warning messages lowercase consistently. 2016-06-14 16:53:48 +02:00
2984da773d Fixed errors with gcc. 2016-06-14 16:47:11 +02:00
1b83708a6d Colorized PDDL translator output. 2016-06-14 16:38:41 +02:00
0de2489440 Using LogStreams in the PDDL translator. 2016-06-14 16:14:39 +02:00
fd5416c94e Removed template from LogStream. 2016-06-14 16:09:47 +02:00
48137ec24d Fixed an issue with gcc 5. 2016-06-14 15:59:16 +02:00
febef4bed4 Made output and error streams members of the logger. 2016-06-14 15:56:35 +02:00
b599670572 Added LogStream class for uniform color output handling. 2016-06-14 15:53:53 +02:00
57e9de6b05 Renamed method to »logWarning.« 2016-06-14 15:12:45 +02:00
9679706a08 Removed ParserWarning class. 2016-06-14 15:09:39 +02:00
777c9839a1 Removed error message prefixes. 2016-06-14 15:06:43 +02:00
a6c9434590 Fixed missing error message prefix. 2016-06-14 15:00:56 +02:00
fd77b65226 Merge branch 'master' of github.com:potassco/plasp into colored-output 2016-06-14 14:59:23 +02:00
a23063fd4f Minor formatting. 2016-06-14 14:22:41 +02:00
a7cf696357 Minor formatting. 2016-06-14 14:18:38 +02:00
94d448d438 Minor formatting. 2016-06-14 14:05:38 +02:00
c62f3f88f1 Handling untyped variables as variables of type »object« in PDDL translator for simplicity. 2016-06-14 13:53:09 +02:00
39a32a6e0a Handling untyped variables correctly in the PDDL translator. 2016-06-14 13:21:41 +02:00
342a346fce Started implementing colored output. 2016-06-14 12:47:39 +02:00
e0dd9833a3 Made unsupported expressions a separate type for disambiguation to fix issues with unsupported features. 2016-06-14 01:31:22 +02:00
591d3fcafd Correctly terminate plasp with failure exit code when unhandled exceptions are caught. 2016-06-14 00:32:26 +02:00
22f294493e Removed bloated translation feature support checks and replaced them with inline ones. 2016-06-13 19:20:00 +02:00
5d3496fa41 Fixed missing assignment of member variable in At expression parser. 2016-06-13 19:19:17 +02:00
4b500e4bf6 Implemented At expressions. 2016-06-13 19:02:15 +02:00
da85e5dd9b Checking whether variables have types before accessing them in the PDDL translator. 2016-06-13 16:37:35 +02:00
2b55d156ae Fixed performance issue caused by skipping over unsupported sections multiple times. 2016-06-13 16:17:55 +02:00
f24491cd5a Updated help message with PDDL support. 2016-06-13 15:01:23 +02:00
268bee3c5f Updated change log with new command-line option --warning-level. 2016-06-13 14:46:30 +02:00
5c3ea28e48 Added command-line option for treating warnings as errors or completely ignoring them. 2016-06-13 14:45:31 +02:00
fdbcb261df Avoiding empty arguments in n-ary expressions. 2016-06-13 14:04:12 +02:00
2c3481d027 Initializing PDDL problem description only if available. 2016-06-13 13:37:18 +02:00
1c2ad0ceec Updated change log with addition of basic PDDL translation. 2016-06-13 03:59:48 +02:00
7899d3e262 Added simple encoding for translated PDDL instances. 2016-06-13 03:48:04 +02:00
6b88cb7926 Renamed SAS → ASP encoding for clarity. 2016-06-13 03:32:58 +02:00
421125fee6 Escaping PDDL identifiers for use with ASP. 2016-06-13 03:31:41 +02:00
8563011939 Minor formatting. 2016-06-13 03:22:48 +02:00
e07672ffe6 Added transitive deduction of object types to PDDL translation. 2016-06-13 03:22:19 +02:00
23f6f9b26b Added translation of a PDDL problem’s goal. 2016-06-13 03:19:24 +02:00
e9c464b319 Added translation of a PDDL problem’s initial state. 2016-06-13 02:59:43 +02:00
d3dc9101dd Added translation of objects in PDDL problems. 2016-06-13 02:48:16 +02:00
e018cdbc91 Added translation of effects of PDDL actions. 2016-06-13 02:41:23 +02:00
e2b8fd2880 Added translation for preconditions of PDDL actions. 2016-06-13 02:38:56 +02:00
680206b40b Removed Reference expressions. 2016-06-13 01:38:56 +02:00
1c8af793c2 Made PDDL action preconditions and effects optional. 2016-06-12 23:51:45 +02:00
46351b2fe7 Ensuring that input contains only predicates, negations, and conjunctions for the time being. 2016-06-12 23:38:44 +02:00
30cfa1b45e Fixes lambda issue with gcc. 2016-06-12 22:58:17 +02:00
0756d63769 Put translation of PDDL variable lists into separate method. 2016-06-12 22:55:35 +02:00
87ca54a253 Translating names of PDDL actions. 2016-06-12 22:47:39 +02:00
9c2f49e4a0 Put PDDL translation sections into separate methods. 2016-06-12 22:39:04 +02:00
49002ac52d Made output stream a member of the SAS translator for convenience. 2016-06-12 22:35:31 +02:00
b70e62ff3b Made output stream a member of the PDDL translator for convenience. 2016-06-12 22:31:31 +02:00
046f803538 Implemented translation of PDDL predicates (with primitive types only). 2016-06-12 22:25:12 +02:00
639b7646c9 Making sure that PDDL predicates contain only primitive types for the time being. 2016-06-12 22:19:55 +02:00
89bb54a3ec Hiding translated PDDL sections if empty. 2016-06-12 22:19:24 +02:00
979d9509c1 Added function for escaping ASP variables. 2016-06-12 22:12:43 +02:00
e9d48bcb7d Removing visitor pattern and replacing it with CRTP. 2016-06-12 22:12:09 +02:00
318bd8297c Disambiguation of parser and translation errors in plasp binary. 2016-06-12 22:09:47 +02:00
0513b3aa0c Implemented translation of PDDL domain constants. 2016-06-10 17:52:19 +02:00
458dbd723c Restructured translated PDDL type output. 2016-06-10 17:48:17 +02:00
8f0f4bfa65 Implemented translation of PDDL domain types. 2016-06-10 17:40:32 +02:00
da71d4947b Added method for checking whether PDDL description contains problem. 2016-06-10 17:26:36 +02:00
6a83147ac0 Moved TranslatorException class to utils directory. 2016-06-10 17:21:56 +02:00
f6cfc55e21 Put exception handling back into plasp binary for convenient use. 2016-06-10 17:12:23 +02:00
34a413cf05 Clarified error message. 2016-06-10 17:12:08 +02:00
854ade5fa9 Ensuring input to contain only one SAS description. 2016-06-10 17:09:06 +02:00
be09230410 Added test for PDDL comment parsing. 2016-06-10 16:50:08 +02:00
20b40d3e1c Allowing primitive type »objects« for compatibility. 2016-06-10 16:46:02 +02:00
9f0e784a4a Implemented recognition of comments in PDDL. 2016-06-10 16:40:43 +02:00
168fcc874e Added PDDL-related changes to change log. 2016-06-10 01:30:30 +02:00
d446c192cf Made plasp’s help message more precise. 2016-06-10 01:28:13 +02:00
eb5a120286 Fixed wrong comparison for language detection. 2016-06-10 01:25:51 +02:00
2e1a011dcf Implemented automatic language detection for plasp application. 2016-06-10 01:23:41 +02:00
8ef874eb22 Simplified plasp application by initializing parser externally. 2016-06-10 00:59:44 +02:00
c6dc84f27f Removed now unnecessary check for number of files with SAS parser. 2016-06-10 00:51:31 +02:00
8bb25e9b90 Implemented construction of SAS and PDDL Descriptions from Parser object. 2016-06-10 00:46:40 +02:00
c6bdfe3f38 Renamed issue checking test. 2016-06-09 23:35:57 +02:00
d1063b345d Renamed error detection tests. 2016-06-09 23:31:12 +02:00
dea879199a Removed debug output. 2016-06-09 23:26:00 +02:00
9a034cb556 Testing goal for Storage problem. 2016-06-09 23:21:05 +02:00
5cd22d284b Testing goal for Blocks World problem. 2016-06-09 23:19:20 +02:00
f8fc1865a2 Added to-do. 2016-06-09 22:55:16 +02:00
85444f235b Parsing goal section of PDDL problem specifications. 2016-06-09 22:54:39 +02:00
15061f75a9 Added test covering last issue. 2016-06-09 18:48:16 +02:00
d138e869fc Fixed further white space issue with empty n-ary predicates. 2016-06-09 18:46:06 +02:00
23170e170a Added test covering last two issues. 2016-06-09 18:32:55 +02:00
156dfd88c2 Fixed issue with parsing unsupported sections. 2016-06-09 18:30:34 +02:00
730a9b7e63 Fixed whitespace issues when parsing constants. 2016-06-09 18:26:04 +02:00
3041b6a278 Testing initial state for Storage problem. 2016-06-09 18:16:51 +02:00
2da5be548a Testing initial state for Blocks World problem. 2016-06-09 18:13:19 +02:00
6f1b38cdb7 Fixed parsing issue with predicates in problem description. 2016-06-09 18:04:24 +02:00
a8e4ef7234 Added missing implementation of facts accessor of InitialState. 2016-06-09 18:03:43 +02:00
c7405e054f Minor formatting. 2016-06-09 18:03:32 +02:00
9506dcb31e Refactored parsing of expressions, all classes parse from opening to closing parenthesis now. 2016-06-09 17:51:10 +02:00
04aac10f1d Allowing empty and expressions for compatibility and added a warning if used. 2016-06-09 15:56:14 +02:00
bbb6379907 Added goal-utilities requirement with a warning if used for compatibility. 2016-06-09 15:52:57 +02:00
26d7e216a6 Fixed issue with invalid suffixes on section names. 2016-06-09 15:33:09 +02:00
d629f50661 Added many PDDL syntax error tests. 2016-06-09 15:19:01 +02:00
2245422d0f Made parser exception message more meaningful. 2016-06-09 15:18:36 +02:00
87889f5efe Implemented two-pass parsing for PDDL problems. 2016-06-09 14:39:03 +02:00
fb15a131ac Enabling tests by default. 2016-06-09 01:25:50 +02:00
8428c20bd4 Parsing domains in two passes and continued working on parsing the initial state. 2016-06-09 01:25:18 +02:00
ff7a6b8c8f Removed unnecessary include. 2016-06-08 16:52:44 +02:00
d92a3e9239 Started testing PDDL problem parsing for a Storage problem. 2016-06-08 13:57:01 +02:00
d23ec14e9d Started testing PDDL problem parsing for a Blocks World problem. 2016-06-08 13:52:36 +02:00
ad23c89266 Refactored PDDL tests. 2016-06-08 13:41:17 +02:00
1c8958ad9d Check that variables are not declared multiple times. 2016-06-08 13:35:10 +02:00
c99b7018c6 Checking that type declarations are not missing. 2016-06-08 13:34:41 +02:00
f2089f48b8 Fixed typo. 2016-06-08 12:56:50 +02:00
75e51c856e Implemented early checking for typing requirement in Variables and Constants. 2016-06-08 12:51:39 +02:00
e60af33f75 Added functions for checking PDDL requirements. 2016-06-08 12:22:31 +02:00
993d14d409 Implemented type requirement checking for problem objects. 2016-06-08 01:51:45 +02:00
bf0e636d57 Fixed PDDL problem header parsing. 2016-06-08 01:51:21 +02:00
374ac3b07f Removed unneeded temporary object. 2016-06-08 01:44:06 +02:00
183b0c954e Fixed debug output. 2016-06-08 01:41:21 +02:00
42559fd601 Minor refactoring removing unnecessary temporary variable. 2016-06-08 01:31:14 +02:00
069ad4ca99 To-dos and formatting. 2016-06-08 01:19:49 +02:00
8db4b5a53e Implemented constant type checking. 2016-06-08 01:14:39 +02:00
32883910bb Fixed typo. 2016-06-08 01:12:29 +02:00
9b3f78559e Implemented primitive type declaration check. 2016-06-08 01:08:22 +02:00
7bd2782fc8 Implemented variable type requirement checking. 2016-06-08 01:05:36 +02:00
75fbb5fb48 Checking type requirement. 2016-06-08 00:48:33 +02:00
af2f9290c6 Removed obsolete functionality. 2016-06-08 00:36:48 +02:00
31fb8ba79b Started parsing in a two-pass approach. 2016-06-08 00:34:59 +02:00
ee9626e4d2 Made the section skipping function a proper function. 2016-06-08 00:14:43 +02:00
9360f4295a Extracted function for skipping entire sections. 2016-06-08 00:13:53 +02:00
abfa3b3ca1 Added -Wextra compiler flag. 2016-06-08 00:13:07 +02:00
a1b93624d6 Fixed accepting std::cin input when omitting input file arguments. 2016-06-08 00:06:54 +02:00
69ff84eecc Added efficient probing functions to Parser. 2016-06-08 00:02:40 +02:00
78889e18c6 Fixed accidentally removed std::cin support. 2016-06-07 23:31:09 +02:00
fa178d5ee1 Fixed SAS file input bug. 2016-06-07 20:59:02 +02:00
eea3272c56 Made Parser seekable for easier maintenance. 2016-06-07 18:41:01 +02:00
27e76fc035 Added check that typing requirement is not added by PDDL problem. 2016-06-07 16:34:15 +02:00
188165bc4d Added fix for gcc. 2016-06-07 16:14:35 +02:00
e6ddad5960 Checking that all variables in predicates have types if and only if typing is enabled. 2016-06-07 16:11:12 +02:00
4228ca01dc Implemented multi-file input. 2016-06-07 15:54:01 +02:00
64190ba55a Added more tests for PDDL actions. 2016-06-07 14:07:17 +02:00
c489c7fd5a Added tests for PDDL actions. 2016-06-07 14:00:29 +02:00
acc063822e Minor formatting in PDDL parser tests. 2016-06-07 13:40:01 +02:00
b612122180 Refactoring to make parsing expressions consistent across PDDL domains and problems. 2016-06-07 13:26:19 +02:00
d5fa00a4a4 Started parsing initial state and object sections. 2016-06-06 15:18:06 +02:00
e607ca4e8e Refactored PDDL parser to make all input case-insensitive. 2016-06-04 18:28:43 +02:00
d64c68f754 Improved error message. 2016-06-04 18:21:42 +02:00
e5bf7d754f Refactored expression parsing. 2016-06-04 18:12:41 +02:00
0e739755b7 Making References transparent by forwarding visitors to their referee. 2016-06-04 18:08:34 +02:00
f8eab1cbb6 Removed unnecessary includes. 2016-06-04 18:07:57 +02:00
0f2c81f894 Added to-dos. 2016-06-04 17:55:17 +02:00
e481732fae Started implementation of PDDL problem parser. 2016-06-04 17:53:42 +02:00
ee597c805e Added to-do. 2016-06-04 17:52:37 +02:00
e561c55f73 Made Action section parsing case-insensitive. 2016-06-04 17:51:21 +02:00
2870bc6434 Made section identifier parsing case-insensitive. 2016-06-04 17:47:41 +02:00
7e60631840 Refactored Requirement parsing. 2016-06-04 17:47:01 +02:00
f2a1528ea9 Fixed determination of default requirement (STRIPS). 2016-06-04 17:28:52 +02:00
21af7e9983 Removed unnecessary include. 2016-06-04 17:22:57 +02:00
4ae37603f4 Added support for Imply expression. 2016-06-04 17:20:25 +02:00
30b4a1f614 Made include guards consistent. 2016-06-04 17:10:50 +02:00
2797b58646 Added missing ParserWarning file. 2016-06-04 16:45:14 +02:00
837612bb8d Made type warnings non-fatal by default. 2016-06-04 16:42:41 +02:00
813fecbf15 Removed now unnecessary Parser function arguments. 2016-06-04 16:24:10 +02:00
a776fc9e06 Put Parser into Context. 2016-06-04 16:10:11 +02:00
08eb14e400 Made section parsing function names consistent. 2016-06-04 15:07:18 +02:00
60c072a2b3 Clean-up. 2016-06-04 15:06:04 +02:00
feedb95295 Turned exception about undeclared types into a consistency warning. 2016-06-04 15:04:18 +02:00
c93661f44e Finished refactoring of expressions. 2016-06-04 14:46:05 +02:00
daa063c338 Big refactoring (build still broken). 2016-06-03 17:12:39 +02:00
5abf1f8a84 Removed obsolete Variable class. 2016-06-03 13:37:23 +02:00
133aa051eb Shortened Expression class names. 2016-06-03 13:33:05 +02:00
d334b4150b Started refactoring Variables as expressions. 2016-06-03 13:21:02 +02:00
36e28994ee Updated change log. 2016-06-03 00:19:05 +02:00
01908c52f8 Merge branch 'master' of github.com:potassco/plasp into develop 2016-06-03 00:15:40 +02:00
f9463d629a Added Travis badge for develop branch to readme file. 2016-06-03 00:14:51 +02:00
50315f5fae Relaxing white space requirements. 2016-06-02 23:41:40 +02:00
8817a3f226 Fixed whitespace parsing issue. 2016-06-02 22:47:25 +02:00
fcde9c9b6b Finished basic support for action parsing. 2016-06-02 22:31:02 +02:00
fb5a5a71a5 Removed unnecessary include. 2016-06-02 21:56:40 +02:00
8134c6af80 Started parsing action effects. 2016-06-02 21:53:10 +02:00
7271a5e52b Implemented predicate expressions. 2016-06-02 18:31:47 +02:00
7baf15d9f0 Implemented And expressions. 2016-06-02 17:35:01 +02:00
d070b5be9e Added expression visitor base class. 2016-06-02 16:29:17 +02:00
63d74e3524 Replaced tabs with spaces in test file to get more accurate parser positions in errors. 2016-06-02 16:28:26 +02:00
a07019801c Refactored expressions to inherit from base class. 2016-06-02 16:28:08 +02:00
97ab22461c Started implementing parsing of action preconditions. 2016-06-02 16:06:11 +02:00
138db460a9 Merge branch 'master' of github.com:potassco/plasp into pddl-parser 2016-06-01 22:54:49 +02:00
a9c0431ded Changed Travis configuration to use 3 threads for building. 2016-06-01 22:49:59 +02:00
7e4a05e1db Assuming parent types to be declared properly. 2016-06-01 18:09:40 +02:00
0a4541a401 Put parsing of typed variables into Variables class. 2016-06-01 17:20:34 +02:00
79773ba634 Removed unnecessary include. 2016-06-01 17:06:23 +02:00
b249e1cbf8 Put generic Type parsing in separate function. 2016-06-01 17:02:35 +02:00
25cf7c8ae8 Implemented parsing of PDDL constants. 2016-06-01 16:47:34 +02:00
3c97ced486 Implemented predicate parsing and refactored context storage. 2016-06-01 14:11:13 +02:00
44482ae438 Renamed TypePrimitive to PrimitiveType and made Type hash map contain PrimitiveTypes only. 2016-06-01 01:54:43 +02:00
f597b3ab80 Moved include to the right location. 2016-06-01 01:32:49 +02:00
b8223b42bd Removed unnecessary include. 2016-06-01 01:31:14 +02:00
ced1fd0038 Started refactoring Types with variants. 2016-06-01 01:29:46 +02:00
2654a6ff23 Started implementing predicate parsing. 2016-05-31 16:43:25 +02:00
5f763e90fc Refactored Requirement to be a proper class. 2016-05-31 14:11:21 +02:00
cf1c66a085 Refactored interface for parsing Types. 2016-05-31 14:01:18 +02:00
1395b62e60 Added checks that used types are correctly declared previously. 2016-05-31 13:50:30 +02:00
85da5024ea Refactored type parsing. 2016-05-31 01:06:57 +02:00
a989f5f86e Started implementing PDDL type parsing. 2016-05-30 20:43:36 +02:00
1c4c035acc Added missing test file for PDDL parser tests. 2016-05-30 15:47:57 +02:00
d26ff2df77 Implemented computation of derived requirements. 2016-05-30 15:44:13 +02:00
5c37026ec7 Parsing PDDL requirements. 2016-05-30 15:06:04 +02:00
8aa419b5c2 Implemented requirement parsing. 2016-05-30 14:34:17 +02:00
c191b418f2 Added PDDL requirements enum. 2016-05-30 13:36:47 +02:00
0eb2714c9e Removed incorrect parentheses check. 2016-05-30 13:22:17 +02:00
0b33ac0e7d Minor formatting. 2016-05-30 13:06:10 +02:00
f55e366b17 Removed unnecessary statement. 2016-05-30 13:03:18 +02:00
b89b1708c3 Additional line-skipping tests for Parser. 2016-05-30 13:00:55 +02:00
f9c5a830e1 Additional assertions in Parser test cases. 2016-05-30 12:58:10 +02:00
348bd98de8 Extended Parser tests with whitespace handling check. 2016-05-30 12:56:30 +02:00
4d984d32c3 Refactoring of Parser class with std::istreambuf_iterator. 2016-05-30 12:54:56 +02:00
8d879344f2 Merge branch 'pddl-parser' of github.com:potassco/plasp into pddl-parser 2016-05-30 12:54:41 +02:00
40547691a0 Started implementing PDDL domain parser. 2016-05-30 12:51:00 +02:00
8f705b0737 Added test for Parser’s cursor position. 2016-05-30 12:32:13 +02:00
67c9e2148d Started implementing PDDL domain parser. 2016-05-29 16:55:43 +02:00
42fda5925d Simplified Parser interface. 2016-05-29 15:08:10 +02:00
2c564f47d3 Refactored predicate argument parsing. 2016-05-28 14:21:05 +02:00
b4bc347006 Removed unnecessary include. 2016-05-28 14:18:51 +02:00
f81fd1a1b4 Introduced alias for parser’s underlying character type. 2016-05-27 19:25:59 +02:00
a1b334a302 Made Parser constructor explicit. 2016-05-27 19:08:31 +02:00
ff420fbe57 Minor formatting. 2016-05-27 18:39:43 +02:00
07eb23b312 Refactored basic parsing. 2016-05-27 03:58:59 +02:00
6017cfe3d5 Removed version numbers from contributors to earlier versions. 2016-05-26 13:01:46 +02:00
8eb0a4847f Refactoring of TranslatorASP class. 2016-05-26 12:59:18 +02:00
47f269782e Reduced the number of boost dependencies with Travis. 2016-05-26 00:23:30 +02:00
d9a40af3f0 Using unsigned constants in tests to avoid warnings with Google Test. 2016-05-26 00:17:55 +02:00
2281967176 Added info about running the tests to the readme file. 2016-05-26 00:11:32 +02:00
6b38b55c58 Merge branch 'master' of github.com:potassco/plasp 2016-05-25 23:50:38 +02:00
12ffbb4d80 Ignoring configuration files for exporting the repository. 2016-05-25 23:49:58 +02:00
045239b620 Fixed wrong operator in debug output. 2016-05-25 23:22:25 +02:00
dda81e9011 Merge branch 'master' of github.com:potassco/plasp 2016-05-25 23:02:17 +02:00
98a15bbf8e Removed gtest package from Travis configuration to properly use the git submodule instead. 2016-05-25 23:01:42 +02:00
7a8b562173 Fixed URLs in readme file. 2016-05-25 18:11:00 +02:00
0cbb3453bd Added version badge to readme file. 2016-05-25 18:04:49 +02:00
062a04233f Changed license to Markdown format. 2016-05-25 12:44:28 +02:00
75c841e3c5 Added change log. 2016-05-25 12:42:31 +02:00
441b8b0154 Added support for input from std::cin. 2016-05-25 12:36:45 +02:00
204 changed files with 29828 additions and 546 deletions

6
.gitattributes vendored
View File

@@ -1 +1,7 @@
.gitignore export-ignore
.gitattributes export-ignore
.gitmodules export-ignore
.travis.yml export-ignore
tests/data/* linguist-documentation tests/data/* linguist-documentation
instances/* linguist-documentation

View File

@@ -11,11 +11,15 @@ matrix:
- boost-latest - boost-latest
packages: packages:
- g++-5 - g++-5
- libboost1.55-all-dev - libboost-program-options1.55-dev
- libgtest-dev - libboost-iostreams1.55-dev
- libboost-system1.55-dev
- libboost-filesystem1.55-dev
env: COMPILER=g++-5 env: COMPILER=g++-5
script: script:
- git submodule init
- git submodule update
- mkdir build - mkdir build
- cd build - cd build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$COMPILER - cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$COMPILER
- make && make run-tests - make -j3 && make -j3 run-tests

46
CHANGELOG.md Normal file
View File

@@ -0,0 +1,46 @@
# Change Log
## 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:
* basic support for parsing PDDL 3.1 domains and problems
* limited support for translating PDDL 3.1 domains and problems to ASP facts
* automatic language detection for PDDL and SAS
* supports input from `std::cin`
* supports colorized output
* new command-line option `--language` to explicitly specify input language
* 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:
* fixes bug in translation of SAS axiom rules
## 3.0.0 (2016-05-24)
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

@@ -3,7 +3,7 @@ project(plasp CXX)
find_package(Boost 1.55.0 COMPONENTS program_options iostreams system filesystem REQUIRED) find_package(Boost 1.55.0 COMPONENTS program_options iostreams system filesystem REQUIRED)
set(CMAKE_CXX_FLAGS "-Wall -Wpedantic") set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic")
set(CMAKE_CXX_FLAGS_DEBUG "-g") set(CMAKE_CXX_FLAGS_DEBUG "-g")
add_definitions(-std=c++14) add_definitions(-std=c++14)

View File

@@ -1,6 +1,6 @@
The MIT License (MIT) # The MIT License (MIT)
Copyright (c) 2016 Patrick Lühne Copyright © 2016 Patrick Lühne
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,50 +1,70 @@
# plasp—Translate PDDL to ASP # plasp—Translate PDDL to ASP
[![Build Status](https://travis-ci.org/potassco/plasp.svg?branch=master)](https://travis-ci.org/potassco/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/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)
`plasp` 3 is in early development and not intended for productive use yet. `plasp` 3 is in early development and not intended for productive use yet.
As of now, `plasp` 3 experimentally supports the full [SAS Format](http://www.fast-downward.org/TranslatorOutputFormat) (as of version 3) used by [Fast Downward](http://www.fast-downward.org/). `plasp` translates planning problem instances to ASP facts.
`plasp` 3 supports the input languages [PDDL 3.1](https://helios.hud.ac.uk/scommv/IPC-14/software.html) (only basic features currently) and [SAS](http://www.fast-downward.org/TranslatorOutputFormat) (full support of SAS 3), which is used by [Fast Downward](http://www.fast-downward.org/).
Please get in touch with [Patrick Lühne](https://www.luehne.de) if you have any suggestions. Please get in touch with [Patrick Lühne](https://www.luehne.de) if you have any suggestions.
## Usage ## Usage
To translate an SAS file into ASP facts, call: ### Translating PDDL to ASP Facts
PDDL instances are translated to ASP facts as follows:
```bash ```bash
$ plasp file.sas $ plasp domain.pddl problem.pddl
``` ```
For instance, a PDDL instance can be solved as follows. Alternatively, PDDL instances may first be translated to SAS, the output format of [Fast Downward](http://www.fast-downward.org/).
First, use [Fast Downward](http://www.fast-downward.org/) to translate the files from PDDL to SAS:
```bash ```bash
$ ./fast-downward.py --translate --build=release64 domain.pddl instance.pddl $ ./fast-downward.py --translate --build=release64 domain.pddl problem.pddl
``` ```
This creates the file `output.sas`. This creates a file called `output.sas`, which may now be translated by `plasp`.
The translated SAS instance can now be solved incrementally with `clingo` and the meta encoding `meta-sequential-incremental.lp`:
```bash ```bash
$ plasp output.sas > instance.lp $ plasp output.sas
$ clingo encodings/meta-sequential-incremental.lp instance.lp
``` ```
### Solving the Translated Instance
The translated instance can finally be solved incrementally with `clingo` and a meta encoding, for instance, [`sequential-incremental.lp`](encodings/sequential-incremental.lp):
```bash
$ plasp domain.pddl problem.pddl > instance.lp
$ clingo encodings/sequential-incremental.lp instance.lp
```
## Command-Line Interface
```bash
$ plasp [files] [options]
```
`plasp` automatically detects the language of the input program.
See [command-line interface](doc/command-line-interface.md) for more details.
## Output Format
`plasp` 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`s output, this [simple example encoding](encodings/sequential-incremental.lp) gets you started.
## Building ## Building
`plasp` requires a C++14 compiler (preferrably GCC ≥ 6.1), the `boost` libraries (≥ 1.55), and CMake for building. `plasp` requires `boost` and is built via CMake and a C++ compiler.
```bash See [building instructions](doc/building-instructions.md) for more details.
$ 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`.
## Contributors ## Contributors
@@ -52,5 +72,5 @@ The built `plasp` binary is then located at `plasp/build/release/bin/plasp`.
### Earlier Versions ### Earlier Versions
* René Knaebel (`plasp` 2) * René Knaebel
* Murat Knecht (`plasp`) * Murat Knecht

View File

@@ -1,9 +1,16 @@
#include <algorithm>
#include <iostream> #include <iostream>
#include <string>
#include <boost/program_options.hpp> #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/Description.h>
#include <plasp/sas/TranslatorASP.h> #include <plasp/sas/TranslatorASP.h>
#include <plasp/utils/LogStream.h>
#include <plasp/utils/TranslatorException.h>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@@ -13,7 +20,10 @@ int main(int argc, char **argv)
description.add_options() description.add_options()
("help,h", "Display this help message.") ("help,h", "Display this help message.")
("version,v", "Display version information.") ("version,v", "Display version information.")
("input,i", po::value<std::string>(), "Specify the SAS input file."); ("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; po::positional_options_description positionalOptionsDescription;
positionalOptionsDescription.add("input", -1); positionalOptionsDescription.add("input", -1);
@@ -23,12 +33,14 @@ int main(int argc, char **argv)
const auto printHelp = const auto printHelp =
[&]() [&]()
{ {
std::cout << "Usage: plasp file [options]" << std::endl; std::cout << "Usage: plasp [files] [options]" << std::endl;
std::cout << "Translate PDDL instances to ASP facts." << std::endl << std::endl; std::cout << "Translate PDDL instances to ASP facts." << std::endl << std::endl;
std::cout << description; std::cout << description;
}; };
plasp::utils::Logger logger;
try try
{ {
po::store(po::command_line_parser(argc, argv) po::store(po::command_line_parser(argc, argv)
@@ -40,7 +52,8 @@ int main(int argc, char **argv)
} }
catch (const po::error &e) catch (const po::error &e)
{ {
std::cerr << "Error: " << e.what() << std::endl << std::endl; logger.logError(e.what());
std::cout << std::endl;
printHelp(); printHelp();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@@ -53,27 +66,108 @@ int main(int argc, char **argv)
if (variablesMap.count("version")) if (variablesMap.count("version"))
{ {
std::cout << "plasp version 3.0.0" << std::endl; std::cout << "plasp version 3.0.3" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
if (!variablesMap.count("input")) 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
{ {
std::cerr << "Error: No input file specified" << std::endl << std::endl; 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(); printHelp();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
try try
{ {
const auto sasDescription = plasp::sas::Description::fromFile(variablesMap["input"].as<std::string>()); plasp::utils::Parser<plasp::utils::CaseInsensitiveParserPolicy> parser;
const auto sasTranslator = plasp::sas::TranslatorASP(sasDescription);
sasTranslator.translate(std::cout); if (variablesMap.count("input"))
{
const auto &inputFiles = variablesMap["input"].as<std::vector<std::string>>();
std::for_each(inputFiles.cbegin(), inputFiles.cend(),
[&](const auto &inputFile)
{
parser.read(inputFile);
});
}
else
parser.read("std::cin", std::cin);
const auto detectLanguage =
[&]()
{
if (variablesMap.count("language") == 0)
return plasp::detectLanguage(parser);
const auto languageName = variablesMap["language"].as<std::string>();
return plasp::Language::fromString(languageName);
};
const auto language = detectLanguage();
if (language == plasp::Language::Type::Unknown)
{
logger.logError("unknown input language");
std::cout << std::endl;
printHelp();
return EXIT_FAILURE;
}
if (language == plasp::Language::Type::PDDL)
{
auto pddlLogger = logger;
auto context = plasp::pddl::Context(std::move(parser), std::move(pddlLogger));
auto description = plasp::pddl::Description::fromContext(std::move(context));
const auto translator = plasp::pddl::TranslatorASP(description, description.context().logger.outputStream());
translator.translate();
}
else if (language == plasp::Language::Type::SAS)
{
const auto description = plasp::sas::Description::fromParser(std::move(parser));
const auto translator = plasp::sas::TranslatorASP(description, logger.outputStream());
translator.translate();
}
}
catch (const plasp::utils::ParserException &e)
{
logger.logError(e.coordinate(), e.message());
return EXIT_FAILURE;
}
catch (const plasp::utils::TranslatorException &e)
{
logger.logError(e.what());
return EXIT_FAILURE;
} }
catch (const std::exception &e) catch (const std::exception &e)
{ {
std::cerr << "Error: " << e.what() << std::endl << std::endl; logger.logError(e.what());
printHelp();
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@@ -0,0 +1,44 @@
# Building Instructions
`plasp` requires a C++14 compiler (preferrably GCC ≥ 6.1 or clang ≥ 3.8), the `boost` libraries (≥ 1.55), and CMake for building.
```bash
$ git clone https://github.com/potassco/plasp.git
$ cd plasp
$ mkdir -p build/release
$ cd build/release
$ cmake ../.. -DCMAKE_BUILD_TYPE=Release
$ make
```
The built `plasp` binary is then located at `plasp/build/release/bin/plasp`.
To update `plasp` to the most recent version, perform the following steps:
```bash
$ cd plasp
$ git pull
$ cd build/release
$ cmake .
$ make
```
## Running the Tests
`plasp` provides unit tests written using the [Google Test](https://github.com/google/googletest) framework.
Before building and running the tests, make sure you have fetched the Google Test git submodule:
```bash
$ git submodule init
$ git submodule update
```
Afterward, enable the flag `BUILD_TESTS` in your CMake configuration.
Finally, build and run the tests as follows:
```bash
$ 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,18 @@
# Command-Line Interface
```bash
$ plasp [files] [options]
```
`plasp` automatically detects the language of the input files.
Multiple files may be provided in an arbitrary order.
`[files]` may also be omitted, in which case the input is read from `std::cin`.
`plasp` supports the following options:
| **option** | **explanation** |
|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|
| `-l` [ `--language` ] | Specify the input language (`sas` or `pddl`). Omit for automatic detection. |
| `--warning-level` arg (=`normal`) | Specify whether to output warnings normally (`normal`), to treat them as critical errors (`error`), or to ignore them (`ignore`). |
| `--color` arg (=`auto`) | Specify whether to colorize the output (`always`, `never`, or `auto`). |

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

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

@@ -0,0 +1,209 @@
# 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
The following illustrates `plasp`s output format for the problem of turning switches on and off.
```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)).
% the variable may be true or false
contains(variable(on(X)), value(on(X)), true)) :- has(X, type(switch)).
contains(variable(on(X)), value(on(X)), false)) :- has(X, type(switch)).
% declares the action "action(turnOn(X))", which requires switch X to be off and then turns it on
action(action(turnOn(X))) :- has(X, type(switch)).
precondition(action(turnOn(X)), variable(on(X)), value(on(X), false)) :- has(X, type(switch)).
postcondition(action(turnOn(X)), effect(0), variable(on(X)), value(on(X), true)) :- has(X, type(switch)).
% initially, the switch is off
initialState(variable(on(constant(a))), value(on(constant(a)), false)).
% in the end, the switch should be on
goal(variable(on(constant(a))), value(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, [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(<type 1>), type(<type 2>)).
% specifies <constant> to have type type(<name>)
has(<constant>, type(<name>)).
```
[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 predicates, `variable(<PDDL predicate>).`
Each variable contains exactly two values (one `true`, one `false`) of the form `value(<PDDL predicate>, <bool>)`.
Note that with PDDL, variables and values are named identically.
### Actions
```prolog
% declares an <action>
action(action(<name>)).
% defines that as a precondition to <action>, <variable> must have value <value>
precondition(<action>, <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>).
% specifies the costs of applying <action>
costs(<action>, <number>).
```
Actions may require certain 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.
### 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> shall obtain <value> in the end
goal(<variable>, <value>).
```
The goal specifies all variable assignments that have to be fulfilled after executing the plan.
### 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

@@ -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,28 @@
#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,31 @@
#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.

36
include/plasp/Language.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef __PLASP__LANGUAGE_H
#define __PLASP__LANGUAGE_H
#include <plasp/utils/Parser.h>
namespace plasp
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Language
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Language
{
public:
enum class Type
{
Unknown,
PDDL,
SAS
};
static std::string toString(Type language);
static Language::Type fromString(const std::string &languageName);
public:
Language() = delete;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
#endif

View File

@@ -0,0 +1,49 @@
#ifndef __PLASP__LANGUAGE_DETECTION_H
#define __PLASP__LANGUAGE_DETECTION_H
#include <plasp/Language.h>
#include <plasp/utils/Parser.h>
namespace plasp
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// LanguageDetection
//
////////////////////////////////////////////////////////////////////////////////////////////////////
Language::Type detectLanguage(utils::Parser<utils::CaseInsensitiveParserPolicy> &parser)
{
parser.skipWhiteSpace();
// SAS begins with "begin_version"
if (parser.testAndSkip<std::string>("begin"))
{
parser.seek(0);
return Language::Type::SAS;
}
// Skip potential PDDL comments
while (parser.currentCharacter() == ';')
{
parser.skipLine();
parser.skipWhiteSpace();
}
// PDDL contains sections starting with "(define"
if (parser.testAndSkip<std::string>("(") && parser.testAndSkip<std::string>("define"))
{
parser.seek(std::ios::beg);
return Language::Type::PDDL;
}
parser.seek(std::ios::beg);
return Language::Type::Unknown;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
#endif

View File

@@ -0,0 +1,50 @@
#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;
void normalizeParameterNames();
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

@@ -0,0 +1,57 @@
#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

@@ -0,0 +1,70 @@
#ifndef __PLASP__PDDL__CONTEXT_H
#define __PLASP__PDDL__CONTEXT_H
#include <memory>
#include <unordered_map>
#include <vector>
#include <plasp/pddl/Parser.h>
#include <plasp/utils/Logger.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Context
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Context
{
public:
Context() = default;
~Context() = default;
explicit Context(Parser &&otherParser)
: parser{std::move(otherParser)}
{
}
explicit Context(utils::Logger &&otherLogger)
: logger{std::move(otherLogger)}
{
}
explicit Context(Parser &&otherParser, utils::Logger &&otherLogger)
: parser{std::move(otherParser)},
logger{std::move(otherLogger)}
{
}
Context(const Context &other) = delete;
Context &operator=(const Context &other) = delete;
Context(Context &&other)
: parser(std::move(other.parser)),
logger(std::move(other.logger))
{
}
Context &operator=(Context &&other)
{
parser = std::move(other.parser);
logger = std::move(other.logger);
return *this;
}
Parser parser;
utils::Logger logger;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,61 @@
#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;
void normalizeParameterNames();
private:
Description();
void parse();
void findSections();
void checkConsistency();
Context m_context;
utils::Stream::Position m_domainPosition;
std::unique_ptr<Domain> m_domain;
utils::Stream::Position m_problemPosition;
std::unique_ptr<Problem> m_problem;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,95 @@
#ifndef __PLASP__PDDL__DOMAIN_H
#define __PLASP__PDDL__DOMAIN_H
#include <plasp/pddl/Action.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/Parser.h>
#include <plasp/pddl/Requirement.h>
#include <plasp/pddl/expressions/Constant.h>
#include <plasp/pddl/expressions/PredicateDeclaration.h>
#include <plasp/pddl/expressions/PrimitiveType.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Domain
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Domain
{
public:
Domain(Context &context);
public:
void findSections();
void parse();
void setName(std::string name);
const std::string &name() const;
const Requirements &requirements() const;
bool hasRequirement(Requirement::Type requirementType) const;
void checkRequirement(Requirement::Type requirementType);
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();
void normalizeParameterNames();
private:
void parseSection();
void parseRequirementSection();
void computeDerivedRequirements();
void parseTypeSection();
void parseConstantSection();
void parsePredicateSection();
void parseActionSection();
Context &m_context;
std::string m_name;
utils::Stream::Position m_requirementsPosition;
Requirements m_requirements;
utils::Stream::Position m_typesPosition;
expressions::PrimitiveTypes m_types;
utils::Stream::Position m_constantsPosition;
expressions::Constants m_constants;
utils::Stream::Position m_predicatesPosition;
expressions::PredicateDeclarations m_predicates;
std::vector<utils::Stream::Position> m_actionPositions;
std::vector<std::unique_ptr<Action>> m_actions;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,130 @@
#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

@@ -0,0 +1,38 @@
#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

45
include/plasp/pddl/IO.h Normal file
View File

@@ -0,0 +1,45 @@
#ifndef __PLASP__PDDL__IO_H
#define __PLASP__PDDL__IO_H
#include <iostream>
#include <plasp/pddl/Parser.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// IO
//
////////////////////////////////////////////////////////////////////////////////////////////////////
inline void skipSection(Parser &parser)
{
size_t openParentheses = 1;
while (true)
{
const auto character = parser.currentCharacter();
parser.advance();
if (character == '(')
openParentheses++;
else if (character == ')')
{
openParentheses--;
if (openParentheses == 0)
return;
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,35 @@
#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

@@ -0,0 +1,54 @@
#ifndef __PLASP__PDDL__PARSER_H
#define __PLASP__PDDL__PARSER_H
#include <plasp/utils/Parser.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Parser
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class PDDLParserPolicy
{
public:
static char transformCharacter(char c) noexcept
{
return std::tolower(c);
}
static bool isWhiteSpaceCharacter(char c)
{
return std::iswspace(c);
}
static bool isBlankCharacter(char c)
{
return std::isblank(c);
}
static bool isIdentifierCharacter(char c)
{
return c != '?'
&& c != '('
&& c != ')'
&& c != ';'
&& std::isgraph(c);
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
using Parser = utils::Parser<PDDLParserPolicy>;
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,85 @@
#ifndef __PLASP__PDDL__PROBLEM_H
#define __PLASP__PDDL__PROBLEM_H
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/InitialState.h>
#include <plasp/pddl/Parser.h>
#include <plasp/pddl/Requirement.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Problem
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Problem
{
public:
Problem(Context &context, Domain &domain);
void findSections();
void parse();
Domain &domain();
const Domain &domain() const;
const std::string &name() const;
const Requirements &requirements() const;
bool hasRequirement(Requirement::Type requirementType) const;
void checkRequirement(Requirement::Type requirementType);
expressions::Constants &objects();
const expressions::Constants &objects() const;
InitialState &initialState();
const InitialState &initialState() const;
const Expression &goal() const;
void checkConsistency();
private:
void parseRequirementSection();
void computeDerivedRequirements();
void parseDomainSection();
void parseObjectSection();
void parseInitialStateSection();
void parseGoalSection();
Context &m_context;
Domain &m_domain;
std::string m_name;
utils::Stream::Position m_domainPosition;
utils::Stream::Position m_requirementsPosition;
Requirements m_requirements;
utils::Stream::Position m_objectsPosition;
expressions::Constants m_objects;
utils::Stream::Position m_initialStatePosition;
std::unique_ptr<InitialState> m_initialState;
utils::Stream::Position m_goalPosition;
ExpressionPointer m_goal;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,72 @@
#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

@@ -0,0 +1,51 @@
#ifndef __PLASP__PDDL__TRANSLATOR_ASP_H
#define __PLASP__PDDL__TRANSLATOR_ASP_H
#include <plasp/pddl/Description.h>
#include <iosfwd>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// TranslatorASP
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class TranslatorASP
{
public:
explicit TranslatorASP(Description &description, utils::LogStream &outputStream);
void translate() const;
private:
void translateDomain() const;
void translateTypes() const;
void translatePredicates() const;
void translateActions() const;
void translateProblem() const;
void translateInitialState() const;
void translateGoal() 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;
Description &m_description;
utils::LogStream &m_outputStream;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,33 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__AND_H
#define __PLASP__PDDL__EXPRESSIONS__AND_H
#include <plasp/pddl/expressions/NAry.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// And
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class And: public NAry<And>
{
public:
static const Expression::Type ExpressionType = Expression::Type::And;
static const std::string Identifier;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@@ -0,0 +1,105 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__AT_H
#define __PLASP__PDDL__EXPRESSIONS__AT_H
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Expression.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// At
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class At: public ExpressionCRTP<At>
{
public:
static const Expression::Type ExpressionType = Expression::Type::At;
template<typename ExpressionParser>
static AtPointer parse(Context &context, ExpressionContext &expressionContext,
ExpressionParser parseExpression);
static const size_t TimePointStart = std::numeric_limits<size_t>::max();
static const size_t TimePointEnd = std::numeric_limits<size_t>::max() - 1;
public:
At();
size_t timePoint() const;
const Expression *argument() const;
private:
void setArgument(const Expression *argument);
void setArgument(ExpressionPointer &&argument);
size_t m_timePoint;
const Expression *m_argument;
ExpressionPointer m_argumentStorage;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename ExpressionParser>
AtPointer At::parse(Context &context, ExpressionContext &expressionContext,
ExpressionParser parseExpression)
{
auto &parser = context.parser;
const auto position = parser.position();
if (!parser.testAndSkip<std::string>("(")
|| !parser.testIdentifierAndSkip("at"))
{
parser.seek(position);
return nullptr;
}
size_t timePoint;
const auto timePointPosition = parser.position();
if (parser.testIdentifierAndSkip("start"))
timePoint = TimePointStart;
else if (parser.testIdentifierAndSkip("end"))
timePoint = TimePointEnd;
else if (parser.probeNumber())
{
parser.seek(timePointPosition);
timePoint = parser.parse<size_t>();
}
else
{
parser.seek(position);
return nullptr;
}
auto expression = std::make_unique<At>(At());
expression->m_timePoint = timePoint;
context.parser.skipWhiteSpace();
// Parse argument
expression->setArgument(parseExpression(context, expressionContext));
parser.expect<std::string>(")");
return expression;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@@ -0,0 +1,111 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__BINARY_H
#define __PLASP__PDDL__EXPRESSIONS__BINARY_H
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/expressions/Variable.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Binary
//
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived>
class Binary: public ExpressionCRTP<Derived>
{
public:
template<typename ExpressionParser>
static std::unique_ptr<Derived> parse(Context &context,
ExpressionContext &expressionContext, ExpressionParser parseExpression);
public:
const std::array<const Expression *, 2> &arguments() const;
private:
template<size_t i>
void setArgument(const Expression *argument);
template<size_t i>
void setArgument(ExpressionPointer &&argument);
std::array<const Expression *, 2> m_arguments;
std::array<ExpressionPointer, 2> m_argumentStorage;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived>
template<typename ExpressionParser>
std::unique_ptr<Derived> Binary<Derived>::parse(Context &context,
ExpressionContext &expressionContext, ExpressionParser parseExpression)
{
auto &parser = context.parser;
const auto position = parser.position();
if (!parser.testAndSkip<std::string>("(")
|| !parser.testIdentifierAndSkip(Derived::Identifier))
{
parser.seek(position);
return nullptr;
}
auto expression = std::make_unique<Derived>();
// Assume that expression identifier (imply, exists, etc.) is already parsed
// Parse arguments of the expression
expression->Binary<Derived>::setArgument<0>(parseExpression(context, expressionContext));
expression->Binary<Derived>::setArgument<1>(parseExpression(context, expressionContext));
parser.expect<std::string>(")");
return expression;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived>
template<size_t i>
void Binary<Derived>::setArgument(const Expression *expression)
{
static_assert(i <= 2, "Index out of range");
m_argumentStorage[i] = nullptr;
m_arguments[i] = expression;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived>
template<size_t i>
void Binary<Derived>::setArgument(ExpressionPointer &&expression)
{
static_assert(i <= 2, "Index out of range");
m_argumentStorage[i] = std::move(expression);
m_arguments[i] = m_argumentStorage[i].get();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived>
const std::array<const Expression *, 2> &Binary<Derived>::arguments() const
{
return m_arguments;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@@ -0,0 +1,64 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__CONSTANT_H
#define __PLASP__PDDL__EXPRESSIONS__CONSTANT_H
#include <plasp/pddl/Expression.h>
#include <plasp/utils/Parser.h>
#include <plasp/utils/ParserException.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Constant
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Constant: public ExpressionCRTP<Constant>
{
public:
static const Expression::Type ExpressionType = Expression::Type::Constant;
static void parseTypedDeclaration(Context &context, Domain &domain);
static void parseTypedDeclarations(Context &context, Domain &domain);
static void parseTypedDeclaration(Context &context, Problem &problem);
static void parseTypedDeclarations(Context &context, Problem &problem);
static Constant *parseAndFind(Context &context, const Domain &domain);
static Constant *parseAndFind(Context &context, const Problem &problem);
public:
const std::string &name() const;
const PrimitiveType *type() const;
private:
static ConstantPointer parseDeclaration(Context &context);
static void parseTypedDeclaration(Context &context, Domain &domain, Constants &constants);
static Constant *parseAndFind(const std::string &constantName, const Constants &constants);
Constant();
void setDirty(bool isDirty = true);
bool isDirty() const;
void setType(const PrimitiveType *parentType);
bool m_isDirty;
std::string m_name;
const PrimitiveType *m_type;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@@ -0,0 +1,33 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__EITHER_H
#define __PLASP__PDDL__EXPRESSIONS__EITHER_H
#include <plasp/pddl/expressions/NAry.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Either
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Either: public NAry<Either>
{
public:
static const Expression::Type ExpressionType = Expression::Type::Either;
static const std::string Identifier;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@@ -0,0 +1,33 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__IMPLY_H
#define __PLASP__PDDL__EXPRESSIONS__IMPLY_H
#include <plasp/pddl/expressions/Binary.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Imply
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Imply: public Binary<Imply>
{
public:
static const Expression::Type ExpressionType = Expression::Type::Imply;
static const std::string Identifier;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@@ -0,0 +1,117 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__N_ARY_H
#define __PLASP__PDDL__EXPRESSIONS__N_ARY_H
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/expressions/Variable.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// NAry
//
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived>
class NAry: public ExpressionCRTP<Derived>
{
public:
template<typename ExpressionParser>
static std::unique_ptr<Derived> parse(Context &context,
ExpressionContext &expressionContext, ExpressionParser parseExpression);
public:
const std::vector<const Expression *> &arguments() const;
private:
void addArgument(const Expression *argument);
void addArgument(ExpressionPointer &&argument);
std::vector<const Expression *> m_arguments;
Expressions m_argumentStorage;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived>
template<typename ExpressionParser>
std::unique_ptr<Derived> NAry<Derived>::parse(Context &context,
ExpressionContext &expressionContext, ExpressionParser parseExpression)
{
auto &parser = context.parser;
const auto position = parser.position();
if (!parser.testAndSkip<std::string>("(")
|| !parser.testIdentifierAndSkip(Derived::Identifier))
{
parser.seek(position);
return nullptr;
}
auto expression = std::make_unique<Derived>();
parser.skipWhiteSpace();
// Assume that expression identifier (and, or, etc.) is already parsed
// Parse arguments of the expression
while (parser.currentCharacter() != ')')
{
expression->addArgument(parseExpression(context, expressionContext));
parser.skipWhiteSpace();
}
if (expression->m_arguments.empty())
context.logger.logWarning(parser.coordinate(), "" + Derived::Identifier + "” expressions should not be empty");
parser.expect<std::string>(")");
return expression;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived>
void NAry<Derived>::addArgument(const Expression *argument)
{
if (!argument)
return;
m_arguments.emplace_back(argument);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived>
void NAry<Derived>::addArgument(ExpressionPointer &&argument)
{
if (!argument)
return;
m_argumentStorage.emplace_back(std::move(argument));
m_arguments.emplace_back(m_argumentStorage.back().get());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class Derived>
const std::vector<const Expression *> &NAry<Derived>::arguments() const
{
return m_arguments;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@@ -0,0 +1,77 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__NOT_H
#define __PLASP__PDDL__EXPRESSIONS__NOT_H
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Expression.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Not
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Not: public ExpressionCRTP<Not>
{
public:
static const Expression::Type ExpressionType = Expression::Type::Not;
template<typename ExpressionParser>
static NotPointer parse(Context &context, ExpressionContext &expressionContext,
ExpressionParser parseExpression);
public:
Not();
const Expression *argument() const;
private:
void setArgument(const Expression *argument);
void setArgument(ExpressionPointer &&argument);
const Expression *m_argument;
ExpressionPointer m_argumentStorage;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
template<typename ExpressionParser>
NotPointer Not::parse(Context &context, ExpressionContext &expressionContext,
ExpressionParser parseExpression)
{
auto &parser = context.parser;
const auto position = parser.position();
if (!parser.testAndSkip<std::string>("(")
|| !parser.testIdentifierAndSkip("not"))
{
parser.seek(position);
return nullptr;
}
auto expression = std::make_unique<Not>(Not());
context.parser.skipWhiteSpace();
// Parse argument
expression->setArgument(parseExpression(context, expressionContext));
parser.expect<std::string>(")");
return expression;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@@ -0,0 +1,33 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__OR_H
#define __PLASP__PDDL__EXPRESSIONS__OR_H
#include <plasp/pddl/expressions/NAry.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Or
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Or: public NAry<Or>
{
public:
static const Expression::Type ExpressionType = Expression::Type::Or;
static const std::string Identifier;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@@ -0,0 +1,50 @@
#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

@@ -0,0 +1,51 @@
#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;
void normalizeParameterNames();
private:
PredicateDeclaration();
void setDeclared();
bool m_isDeclared;
std::string m_name;
Variables m_parameters;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@@ -0,0 +1,55 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__PRIMITIVE_TYPE_H
#define __PLASP__PDDL__EXPRESSIONS__PRIMITIVE_TYPE_H
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/Expression.h>
#include <plasp/utils/ParserException.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// PrimitiveType
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class PrimitiveType: public ExpressionCRTP<PrimitiveType>
{
public:
static const Expression::Type ExpressionType = Expression::Type::PrimitiveType;
static void parseDeclaration(Context &context, Domain &domain);
static void parseTypedDeclaration(Context &context, Domain &domain);
static PrimitiveType *parseAndFind(Context &context, Domain &domain);
public:
PrimitiveType();
PrimitiveType(std::string name);
const std::string &name() const;
const std::vector<const PrimitiveType *> &parentTypes() const;
private:
void setDirty(bool isDirty = true);
bool isDirty() const;
bool m_isDirty;
std::string m_name;
std::vector<const PrimitiveType *> m_parentTypes;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@@ -0,0 +1,28 @@
#ifndef __PLASP__PDDL__EXPRESSIONS__TYPE_H
#define __PLASP__PDDL__EXPRESSIONS__TYPE_H
#include <plasp/pddl/Expression.h>
namespace plasp
{
namespace pddl
{
namespace expressions
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Type
//
////////////////////////////////////////////////////////////////////////////////////////////////////
const Expression *parseExistingPrimitiveType(Context &context,
ExpressionContext &expressionContext);
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
#endif

View File

@@ -0,0 +1,40 @@
#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

@@ -0,0 +1,63 @@
#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:
void setName(std::string name);
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

@@ -6,6 +6,7 @@
#include <plasp/sas/Value.h> #include <plasp/sas/Value.h>
#include <plasp/sas/Variable.h> #include <plasp/sas/Variable.h>
#include <plasp/utils/Parser.h>
namespace plasp namespace plasp
{ {
@@ -26,8 +27,8 @@ using AssignedVariables = std::vector<AssignedVariable>;
class AssignedVariable class AssignedVariable
{ {
public: public:
static AssignedVariable fromSAS(std::istream &istream, const Variables &variables); static AssignedVariable fromSAS(utils::Parser<> &parser, const Variables &variables);
static AssignedVariable fromSAS(std::istream &istream, const Variable &variable); static AssignedVariable fromSAS(utils::Parser<> &parser, const Variable &variable);
public: public:
explicit AssignedVariable(const Variable &variable, const Value &value); explicit AssignedVariable(const Variable &variable, const Value &value);

View File

@@ -5,6 +5,7 @@
#include <plasp/sas/AssignedVariable.h> #include <plasp/sas/AssignedVariable.h>
#include <plasp/sas/Variable.h> #include <plasp/sas/Variable.h>
#include <plasp/utils/Parser.h>
namespace plasp namespace plasp
{ {
@@ -28,7 +29,7 @@ class AxiomRule
using Condition = AssignedVariable; using Condition = AssignedVariable;
using Conditions = AssignedVariables; using Conditions = AssignedVariables;
static AxiomRule fromSAS(std::istream &istream, const Variables &variables); static AxiomRule fromSAS(utils::Parser<> &parser, const Variables &variables);
public: public:
const Conditions &conditions() const; const Conditions &conditions() const;

View File

@@ -16,7 +16,7 @@ namespace sas
// //
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
std::ostream &operator >>(std::ostream &ostream, const Description &description); utils::LogStream &operator<<(utils::LogStream &ostream, const Description &description);
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -13,6 +13,7 @@
#include <plasp/sas/MutexGroup.h> #include <plasp/sas/MutexGroup.h>
#include <plasp/sas/Operator.h> #include <plasp/sas/Operator.h>
#include <plasp/sas/Variable.h> #include <plasp/sas/Variable.h>
#include <plasp/utils/Parser.h>
namespace plasp namespace plasp
{ {
@@ -28,6 +29,7 @@ namespace sas
class Description class Description
{ {
public: public:
static Description fromParser(utils::Parser<> &&parser);
static Description fromStream(std::istream &istream); static Description fromStream(std::istream &istream);
static Description fromFile(const boost::filesystem::path &path); static Description fromFile(const boost::filesystem::path &path);
@@ -43,17 +45,21 @@ class Description
bool usesAxiomRules() const; bool usesAxiomRules() const;
bool usesConditionalEffects() const; bool usesConditionalEffects() const;
bool hasRequirements() const;
private: private:
Description(); Description();
void parseVersionSection(std::istream &istream) const; void parseContent(utils::Parser<> &parser);
void parseMetricSection(std::istream &istream);
void parseVariablesSection(std::istream &istream); void parseVersionSection(utils::Parser<> &parser) const;
void parseMutexSection(std::istream &istream); void parseMetricSection(utils::Parser<> &parser);
void parseInitialStateSection(std::istream &istream); void parseVariablesSection(utils::Parser<> &parser);
void parseGoalSection(std::istream &istream); void parseMutexSection(utils::Parser<> &parser);
void parseOperatorSection(std::istream &istream); void parseInitialStateSection(utils::Parser<> &parser);
void parseAxiomSection(std::istream &istream); void parseGoalSection(utils::Parser<> &parser);
void parseOperatorSection(utils::Parser<> &parser);
void parseAxiomSection(utils::Parser<> &parser);
bool m_usesActionCosts; bool m_usesActionCosts;

View File

@@ -5,6 +5,7 @@
#include <plasp/sas/AssignedVariable.h> #include <plasp/sas/AssignedVariable.h>
#include <plasp/sas/Variable.h> #include <plasp/sas/Variable.h>
#include <plasp/utils/Parser.h>
namespace plasp namespace plasp
{ {
@@ -28,7 +29,7 @@ class Effect
using Condition = AssignedVariable; using Condition = AssignedVariable;
using Conditions = AssignedVariables; using Conditions = AssignedVariables;
static Effect fromSAS(std::istream &istream, const Variables &variables, Conditions &preconditions); static Effect fromSAS(utils::Parser<> &parser, const Variables &variables, Conditions &preconditions);
public: public:
const Conditions &conditions() const; const Conditions &conditions() const;

View File

@@ -2,6 +2,7 @@
#define __PLASP__SAS__GOAL_H #define __PLASP__SAS__GOAL_H
#include <plasp/sas/AssignedVariable.h> #include <plasp/sas/AssignedVariable.h>
#include <plasp/utils/Parser.h>
namespace plasp namespace plasp
{ {
@@ -20,7 +21,7 @@ class Goal
using Fact = AssignedVariable; using Fact = AssignedVariable;
using Facts = AssignedVariables; using Facts = AssignedVariables;
static Goal fromSAS(std::istream &istream, const Variables &variables); static Goal fromSAS(utils::Parser<> &parser, const Variables &variables);
public: public:
const Facts &facts() const; const Facts &facts() const;

View File

@@ -2,6 +2,7 @@
#define __PLASP__SAS__INITIAL_STATE_H #define __PLASP__SAS__INITIAL_STATE_H
#include <plasp/sas/AssignedVariable.h> #include <plasp/sas/AssignedVariable.h>
#include <plasp/utils/Parser.h>
namespace plasp namespace plasp
{ {
@@ -20,7 +21,7 @@ class InitialState
using Fact = AssignedVariable; using Fact = AssignedVariable;
using Facts = AssignedVariables; using Facts = AssignedVariables;
static InitialState fromSAS(std::istream &istream, const Variables &variables); static InitialState fromSAS(utils::Parser<> &parser, const Variables &variables);
public: public:
const Facts &facts() const; const Facts &facts() const;

View File

@@ -4,6 +4,7 @@
#include <vector> #include <vector>
#include <plasp/sas/AssignedVariable.h> #include <plasp/sas/AssignedVariable.h>
#include <plasp/utils/Parser.h>
namespace plasp namespace plasp
{ {
@@ -27,7 +28,7 @@ class MutexGroup
using Fact = AssignedVariable; using Fact = AssignedVariable;
using Facts = AssignedVariables; using Facts = AssignedVariables;
static MutexGroup fromSAS(std::istream &istream, const Variables &variables); static MutexGroup fromSAS(utils::Parser<> &parser, const Variables &variables);
public: public:
const Facts &facts() const; const Facts &facts() const;

View File

@@ -8,6 +8,8 @@
#include <plasp/sas/Effect.h> #include <plasp/sas/Effect.h>
#include <plasp/sas/Predicate.h> #include <plasp/sas/Predicate.h>
#include <plasp/sas/Variable.h> #include <plasp/sas/Variable.h>
#include <plasp/utils/LogStream.h>
#include <plasp/utils/Parser.h>
namespace plasp namespace plasp
{ {
@@ -31,10 +33,10 @@ class Operator
using Condition = AssignedVariable; using Condition = AssignedVariable;
using Conditions = AssignedVariables; using Conditions = AssignedVariables;
static Operator fromSAS(std::istream &istream, const Variables &variables); static Operator fromSAS(utils::Parser<> &parser, const Variables &variables);
public: public:
void printPredicateAsASP(std::ostream &ostream) const; void printPredicateAsASP(utils::LogStream &ostream) const;
const Predicate &predicate() const; const Predicate &predicate() const;
const Conditions &preconditions() const; const Conditions &preconditions() const;

View File

@@ -5,6 +5,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <plasp/utils/LogStream.h>
#include <plasp/utils/Parser.h>
namespace plasp namespace plasp
{ {
namespace sas namespace sas
@@ -19,13 +22,13 @@ namespace sas
class Predicate class Predicate
{ {
public: public:
static Predicate fromSAS(std::istream &istream); static Predicate fromSAS(utils::Parser<> &parser);
using Arguments = std::vector<std::string>; using Arguments = std::vector<std::string>;
public: public:
void printAsSAS(std::ostream &ostream) const; void printAsSAS(utils::LogStream &outputStream) const;
void printAsASP(std::ostream &ostream) const; void printAsASP(utils::LogStream &outputStream) const;
const std::string &name() const; const std::string &name() const;
const Arguments &arguments() const; const Arguments &arguments() const;

View File

@@ -2,6 +2,7 @@
#define __PLASP__SAS__TRANSLATOR_ASP_H #define __PLASP__SAS__TRANSLATOR_ASP_H
#include <plasp/sas/Description.h> #include <plasp/sas/Description.h>
#include <plasp/utils/LogStream.h>
#include <iosfwd> #include <iosfwd>
@@ -19,12 +20,21 @@ namespace sas
class TranslatorASP class TranslatorASP
{ {
public: public:
explicit TranslatorASP(const Description &description); explicit TranslatorASP(const Description &description, utils::LogStream &outputStream);
void translate(std::ostream &ostream) const; void translate() const;
private: private:
void translateRequirements() const;
void translateInitialState() const;
void translateGoal() const;
void translateVariables() const;
void translateActions() const;
void translateMutexes() const;
void translateAxiomRules() const;
const Description &m_description; const Description &m_description;
utils::LogStream &m_outputStream;
}; };
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -5,6 +5,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <plasp/utils/LogStream.h>
#include <plasp/utils/Parser.h>
namespace plasp namespace plasp
{ {
namespace sas namespace sas
@@ -36,15 +39,14 @@ struct Value
static const Value Any; static const Value Any;
static const Value None; static const Value None;
static Value fromSAS(std::istream &istream); static Value fromSAS(utils::Parser<> &parser);
static const Value &referenceFromSAS(std::istream &istream, const Variable &variable); static const Value &referenceFromSAS(utils::Parser<> &parser, const Variable &variable);
public: public:
Value negated() const; Value negated() const;
void printAsSAS(std::ostream &ostream) const; void printAsSAS(utils::LogStream &outputStream) const;
void printAsASP(std::ostream &ostream) const; void printAsASPPredicate(utils::LogStream &outputStream) const;
void printAsASPPredicate(std::ostream &ostream) const;
Sign sign() const; Sign sign() const;
const std::string &name() const; const std::string &name() const;

View File

@@ -6,6 +6,8 @@
#include <vector> #include <vector>
#include <plasp/sas/Value.h> #include <plasp/sas/Value.h>
#include <plasp/utils/LogStream.h>
#include <plasp/utils/Parser.h>
namespace plasp namespace plasp
{ {
@@ -26,11 +28,11 @@ using Variables = std::vector<Variable>;
class Variable class Variable
{ {
public: public:
static Variable fromSAS(std::istream &istream); static Variable fromSAS(utils::Parser<> &parser);
static const Variable &referenceFromSAS(std::istream &istream, const Variables &variables); static const Variable &referenceFromSAS(utils::Parser<> &parser, const Variables &variables);
public: public:
void printNameAsASPPredicate(std::ostream &ostream) const; void printNameAsASPPredicate(utils::LogStream &outputStream) const;
const std::string &name() const; const std::string &name() const;
int axiomLayer() const; int axiomLayer() const;

View File

@@ -5,6 +5,7 @@
#include <plasp/sas/Value.h> #include <plasp/sas/Value.h>
#include <plasp/sas/Variable.h> #include <plasp/sas/Variable.h>
#include <plasp/utils/Parser.h>
namespace plasp namespace plasp
{ {
@@ -25,7 +26,7 @@ using VariableTransitions = std::vector<VariableTransition>;
class VariableTransition class VariableTransition
{ {
public: public:
static VariableTransition fromSAS(std::istream &istream, const Variables &variables); static VariableTransition fromSAS(utils::Parser<> &parser, const Variables &variables);
public: public:
const Variable &variable() const; const Variable &variable() const;

View File

@@ -0,0 +1,282 @@
#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 RuleName: public Token
{
RuleName(const std::string &name)
: Token(name)
{
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
inline LogStream &operator<<(LogStream &stream, const RuleName &keyword)
{
return (stream
<< utils::Format(utils::Color::White, utils::FontWeight::Bold)
<< keyword.name
<< utils::ResetFormat());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
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::Blue, utils::FontWeight::Normal)
<< 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::Normal)
<< 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 String: public Token
{
String(const std::string &name)
: Token(name)
{
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
inline LogStream &operator<<(LogStream &stream, const String &string)
{
return (stream
<< utils::Format(utils::Color::Green, utils::FontWeight::Normal)
<< "\"" << string.name << "\""
<< utils::ResetFormat());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
struct Boolean: public Token
{
Boolean(const std::string &name)
: Token(name)
{
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
inline LogStream &operator<<(LogStream &stream, const Boolean &string)
{
return (stream
<< utils::Format(utils::Color::Red, utils::FontWeight::Normal)
<< string.name
<< utils::ResetFormat());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
struct Reserved: public Token
{
Reserved(const std::string &name)
: Token(name)
{
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
inline LogStream &operator<<(LogStream &stream, const Reserved &string)
{
return (stream
<< utils::Format(utils::Color::White, utils::FontWeight::Normal)
<< string.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

@@ -0,0 +1,335 @@
#ifndef __PLASP__UTILS__LOG_STREAM_H
#define __PLASP__UTILS__LOG_STREAM_H
#include <iostream>
#include <unistd.h>
namespace plasp
{
namespace utils
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// LogStream
//
////////////////////////////////////////////////////////////////////////////////////////////////////
enum class StandardStream
{
Out,
Err
};
////////////////////////////////////////////////////////////////////////////////////////////////////
class LogStream
{
public:
enum class ColorPolicy
{
Never,
Auto,
Always
};
private:
using CharacterType = std::ostream::char_type;
using TraitsType = std::ostream::traits_type;
public:
LogStream(StandardStream standardStream)
: m_standardStream{standardStream},
m_colorPolicy{ColorPolicy::Auto}
{
}
LogStream(const LogStream &other)
: m_standardStream{other.m_standardStream},
m_colorPolicy{other.m_colorPolicy}
{
}
LogStream &operator=(const LogStream &other)
{
m_standardStream = other.m_standardStream;
m_colorPolicy = other.m_colorPolicy;
return *this;
}
LogStream(LogStream &&other)
: m_standardStream{other.m_standardStream},
m_colorPolicy{other.m_colorPolicy}
{
other.m_colorPolicy = ColorPolicy::Auto;
}
LogStream &operator=(LogStream &&other)
{
m_standardStream = other.m_standardStream;
m_colorPolicy = other.m_colorPolicy;
other.m_colorPolicy = ColorPolicy::Auto;
return *this;
}
void setColorPolicy(ColorPolicy colorPolicy)
{
m_colorPolicy = colorPolicy;
}
bool supportsColor() const
{
if (m_colorPolicy == ColorPolicy::Never)
return false;
if (m_colorPolicy == ColorPolicy::Always)
return true;
// Autodetect by checking whether output goes to a terminal
const auto fileDescriptor =
(m_standardStream == utils::StandardStream::Out)
? STDOUT_FILENO
: STDERR_FILENO;
return isatty(fileDescriptor);
}
std::ostream &ostream()
{
return (m_standardStream == utils::StandardStream::Out)
? std::cout
: std::cerr;
}
inline LogStream &operator<<(short value);
inline LogStream &operator<<(unsigned short value);
inline LogStream &operator<<(int value);
inline LogStream &operator<<(unsigned int value);
inline LogStream &operator<<(long value);
inline LogStream &operator<<(unsigned long value);
inline LogStream &operator<<(long long value);
inline LogStream &operator<<(unsigned long long value);
inline LogStream &operator<<(float value);
inline LogStream &operator<<(double value);
inline LogStream &operator<<(long double value);
inline LogStream &operator<<(bool value);
inline LogStream &operator<<(const void *value);
inline LogStream &operator<<(const char *value);
inline LogStream &operator<<(const signed char *value);
inline LogStream &operator<<(const unsigned char *value);
inline LogStream &operator<<(std::basic_streambuf<CharacterType, TraitsType> *sb);
inline LogStream &operator<<(std::ios_base &(*func)(std::ios_base &));
inline LogStream &operator<<(std::basic_ios<CharacterType, TraitsType> &(*func)(std::basic_ios<CharacterType, TraitsType> &));
inline LogStream &operator<<(std::basic_ostream<CharacterType, TraitsType> &(*func)(std::basic_ostream<CharacterType, TraitsType> &));
inline LogStream &operator<<(char value);
inline LogStream &operator<<(signed char value);
inline LogStream &operator<<(unsigned char value);
private:
StandardStream m_standardStream;
ColorPolicy m_colorPolicy;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(short value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(unsigned short value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(int value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(unsigned int value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(long value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(unsigned long value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(long long value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(unsigned long long value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(float value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(double value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(long double value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(bool value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(const void *value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(const char *value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(const signed char *value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(const unsigned char *value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(std::basic_streambuf<CharacterType, TraitsType>* sb)
{
ostream() << sb;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(std::ios_base &(*func)(std::ios_base &))
{
ostream() << func;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(std::basic_ios<CharacterType, TraitsType> &(*func)(std::basic_ios<CharacterType, TraitsType> &))
{
ostream() << func;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(std::basic_ostream<CharacterType, TraitsType> &(*func)(std::basic_ostream<CharacterType, TraitsType> &))
{
ostream() << func;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class CharacterType, class Traits, class Allocator>
inline LogStream &operator<<(LogStream &stream, const std::basic_string<CharacterType, Traits, Allocator> &string)
{
stream.ostream() << string;
return stream;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(char value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(signed char value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
LogStream &LogStream::operator<<(unsigned char value)
{
ostream() << value;
return *this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,62 @@
#ifndef __PLASP__UTILS__LOGGER_H
#define __PLASP__UTILS__LOGGER_H
#include <string>
#include <plasp/utils/LogStream.h>
#include <plasp/utils/ParserException.h>
#include <plasp/utils/StreamCoordinate.h>
namespace plasp
{
namespace utils
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Logger
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Logger
{
public:
enum class WarningLevel
{
Normal,
Error,
Ignore
};
public:
Logger();
Logger(const Logger &other);
Logger &operator=(const Logger &other);
Logger(Logger &&other);
Logger &operator=(Logger &&other);
LogStream &outputStream();
LogStream &errorStream();
void setWarningLevel(WarningLevel warningLevel);
void setColorPolicy(LogStream::ColorPolicy colorPolicy);
void logError(const std::string &message);
void logError(const StreamCoordinate &coordinate, const std::string &message);
void logWarning(const StreamCoordinate &parserCoordinate, const std::string &message);
private:
LogStream m_outputStream;
LogStream m_errorStream;
WarningLevel m_warningLevel;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,571 @@
#ifndef __PLASP__UTILS__PARSER_H
#define __PLASP__UTILS__PARSER_H
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>
#include <boost/filesystem.hpp>
#include <plasp/utils/ParserException.h>
#include <plasp/utils/ParserPolicy.h>
#include <plasp/utils/Stream.h>
#include <plasp/utils/StreamCoordinate.h>
namespace plasp
{
namespace utils
{
template<typename Type>
struct Tag
{
};
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Parser
//
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy = CaseSensitiveParserPolicy>
class Parser: public Stream, public ParserPolicy
{
template<class OtherParserPolicy>
friend class Parser;
public:
explicit Parser();
explicit Parser(std::string streamName, std::istream &istream);
template<class OtherParser>
Parser(OtherParser &&otherParser)
{
m_stream = std::move(otherParser.m_stream);
m_delimiters = std::move(otherParser.m_delimiters);
}
void removeComments(const std::string &startSequence, const std::string &endSequence, bool removeEnd);
char currentCharacter() const;
template<typename Type>
Type parse();
template<typename Type>
bool testAndReturn(const Type &expectedValue);
template<typename Type>
bool testAndSkip(const Type &expectedValue);
template<typename Type>
void expect(const Type &expectedValue);
std::string parseIdentifier();
bool testIdentifierAndReturn(const std::string &identifier);
bool testIdentifierAndSkip(const std::string &identifier);
// TODO: remove
bool probeNumber();
std::string parseLine();
void skipWhiteSpace();
void skipBlankSpace();
void skipLine();
private:
std::string parseImpl(Tag<std::string>);
char parseImpl(Tag<char>);
uint64_t parseImpl(Tag<uint64_t>);
int64_t parseImpl(Tag<int64_t>);
uint32_t parseImpl(Tag<uint32_t>);
int32_t parseImpl(Tag<int32_t>);
bool parseImpl(Tag<bool>);
bool testImpl(const std::string &expectedValue);
bool testImpl(char expectedValue);
bool testImpl(uint64_t expectedValue);
bool testImpl(int64_t expectedValue);
bool testImpl(uint32_t expectedValue);
bool testImpl(int32_t expectedValue);
bool testImpl(bool expectedValue);
uint64_t parseIntegerBody();
};
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
Parser<ParserPolicy>::Parser()
: Stream()
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
Parser<ParserPolicy>::Parser(std::string streamName, std::istream &istream)
: Stream(streamName, istream)
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
void Parser<ParserPolicy>::skipWhiteSpace()
{
check();
while (!atEnd() && ParserPolicy::isWhiteSpaceCharacter(currentCharacter()))
advance();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
void Parser<ParserPolicy>::skipBlankSpace()
{
check();
while (!atEnd() && ParserPolicy::isBlankCharacter(currentCharacter()))
advance();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
void Parser<ParserPolicy>::skipLine()
{
check();
while (currentCharacter() != '\n')
advance();
advance();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
template<typename Type>
Type Parser<ParserPolicy>::parse()
{
return parseImpl(Tag<Type>());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
template<typename Type>
bool Parser<ParserPolicy>::testAndReturn(const Type &expectedValue)
{
const auto previousPosition = position();
const auto result = testImpl(expectedValue);
seek(previousPosition);
return result;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
template<typename Type>
bool Parser<ParserPolicy>::testAndSkip(const Type &expectedValue)
{
const auto previousPosition = position();
const auto result = testImpl(expectedValue);
if (result == false)
seek(previousPosition);
return result;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
template<typename Type>
void Parser<ParserPolicy>::expect(const Type &expectedValue)
{
if (testAndSkip(expectedValue))
return;
std::stringstream message;
message << "unexpected value, expected “" << expectedValue << "";
throw ParserException(coordinate(), message.str());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
std::string Parser<ParserPolicy>::parseIdentifier()
{
skipWhiteSpace();
std::string value;
while (true)
{
const auto character = currentCharacter();
if (!ParserPolicy::isIdentifierCharacter(character))
return value;
value.push_back(character);
advance();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
bool Parser<ParserPolicy>::testIdentifierAndSkip(const std::string &expectedValue)
{
return testAndSkip(expectedValue) && !ParserPolicy::isIdentifierCharacter(currentCharacter());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
bool Parser<ParserPolicy>::probeNumber()
{
const auto previousPosition = position();
skipWhiteSpace();
while (!ParserPolicy::isWhiteSpaceCharacter(currentCharacter()))
if (!std::isdigit(currentCharacter()))
{
seek(previousPosition);
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
std::string Parser<ParserPolicy>::parseLine()
{
std::string value;
while (true)
{
const auto character = currentCharacter();
advance();
if (character == '\n')
break;
else if (character == '\r')
continue;
value.push_back(character);
}
return value;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
void Parser<ParserPolicy>::removeComments(const std::string &startSequence, const std::string &endSequence, bool removeEnd)
{
const auto inPosition = m_stream.tellg();
const auto outPosition = m_stream.tellp();
m_stream.seekg(0);
const auto removeRange =
[&](const auto &start, const auto &end)
{
BOOST_ASSERT(start != -1);
m_stream.clear();
m_stream.seekp(start);
m_stream.seekg(start);
auto position = start;
while (end == -1 || position < end)
{
m_stream.ignore(1);
if (atEnd())
return;
m_stream.put(' ');
position += static_cast<std::streamoff>(1);
}
};
while (!atEnd())
{
Position startPosition = m_stream.tellg();
while (!atEnd())
{
startPosition = m_stream.tellg();
if (testAndSkip(startSequence))
break;
advance();
}
Position endPosition = m_stream.tellg();
while (!atEnd())
{
endPosition = m_stream.tellg();
if (testAndSkip(endSequence))
break;
advance();
}
if (removeEnd)
endPosition = m_stream.tellg();
removeRange(startPosition, endPosition);
}
m_stream.clear();
m_stream.seekg(inPosition);
m_stream.seekp(outPosition);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
char Parser<ParserPolicy>::currentCharacter() const
{
return ParserPolicy::transformCharacter(Stream::currentCharacter());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
std::string Parser<ParserPolicy>::parseImpl(Tag<std::string>)
{
skipWhiteSpace();
const auto startPosition = position();
while (!ParserPolicy::isWhiteSpaceCharacter(currentCharacter()))
advance();
const auto endPosition = position();
const auto length = static_cast<size_t>(endPosition - startPosition);
std::string value;
value.reserve(length);
seek(startPosition);
for (size_t i = 0; i < length; i++)
{
value.push_back(currentCharacter());
advance();
}
return value;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
char Parser<ParserPolicy>::parseImpl(Tag<char>)
{
const auto value = currentCharacter();
advance();
return value;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
uint64_t Parser<ParserPolicy>::parseIntegerBody()
{
check();
if (!std::isdigit(currentCharacter()))
throw ParserException(coordinate(), "could not parse integer value");
uint64_t value = 0;
while (!atEnd())
{
const auto character = currentCharacter();
if (!std::isdigit(character))
break;
value *= 10;
value += character - '0';
advance();
}
return value;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
int64_t Parser<ParserPolicy>::parseImpl(Tag<int64_t>)
{
skipWhiteSpace();
bool positive = testAndSkip<char>('+') || !testAndSkip<char>('-');
const auto value = parseIntegerBody();
return (positive ? value : -value);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
uint64_t Parser<ParserPolicy>::parseImpl(Tag<uint64_t>)
{
skipWhiteSpace();
if (currentCharacter() == '-')
throw ParserException(coordinate(), "expected unsigned integer, got signed one");
return parseIntegerBody();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
int32_t Parser<ParserPolicy>::parseImpl(Tag<int32_t>)
{
return static_cast<int32_t>(parseImpl(Tag<int64_t>()));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
uint32_t Parser<ParserPolicy>::parseImpl(Tag<uint32_t>)
{
return static_cast<uint32_t>(parseImpl(Tag<uint64_t>()));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
bool Parser<ParserPolicy>::parseImpl(Tag<bool>)
{
skipWhiteSpace();
if (testAndSkip<char>('0'))
return false;
if (testAndSkip<char>('1'))
return true;
throw ParserException(coordinate(), "could not parse Boolean value");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
bool Parser<ParserPolicy>::testImpl(const std::string &expectedValue)
{
if (!ParserPolicy::isWhiteSpaceCharacter(expectedValue.front()))
skipWhiteSpace();
const auto match = std::find_if(expectedValue.cbegin(), expectedValue.cend(),
[&](const auto &expectedCharacter)
{
const auto character = static_cast<char>(this->currentCharacter());
if (character != expectedCharacter)
return true;
this->advance();
return false;
});
return (match == expectedValue.cend());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
bool Parser<ParserPolicy>::testImpl(char expectedValue)
{
const auto result = (currentCharacter() == expectedValue);
advance();
return result;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
bool Parser<ParserPolicy>::testImpl(int64_t expectedValue)
{
const auto value = parseImpl(Tag<int64_t>());
return (value == expectedValue);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
bool Parser<ParserPolicy>::testImpl(uint64_t expectedValue)
{
const auto value = parseImpl(Tag<uint64_t>());
return (value == expectedValue);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
bool Parser<ParserPolicy>::testImpl(int32_t expectedValue)
{
return testImpl(static_cast<int64_t>(expectedValue));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
bool Parser<ParserPolicy>::testImpl(uint32_t expectedValue)
{
return testImpl(static_cast<uint64_t>(expectedValue));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class ParserPolicy>
bool Parser<ParserPolicy>::testImpl(bool expectedValue)
{
const auto value = parseImpl(Tag<bool>());
return (value == expectedValue);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -4,6 +4,8 @@
#include <exception> #include <exception>
#include <string> #include <string>
#include <plasp/utils/StreamCoordinate.h>
namespace plasp namespace plasp
{ {
namespace utils namespace utils
@@ -18,17 +20,21 @@ namespace utils
class ParserException: public std::exception class ParserException: public std::exception
{ {
public: public:
explicit ParserException() explicit ParserException(const StreamCoordinate &coordinate)
: ParserException(coordinate, "unspecified parser error")
{ {
} }
explicit ParserException(const char *message) explicit ParserException(const StreamCoordinate &coordinate, const char *message)
: m_message(message) : ParserException(coordinate, static_cast<std::string>(message))
{ {
} }
explicit ParserException(const std::string &message) explicit ParserException(const StreamCoordinate &coordinate, const std::string &message)
: m_message(message) : m_coordinate{coordinate},
m_message{message},
m_plainMessage{m_coordinate.sectionName + ":" + std::to_string(m_coordinate.row)
+ ":" + std::to_string(m_coordinate.column) + " " + m_message}
{ {
} }
@@ -38,14 +44,23 @@ class ParserException: public std::exception
const char *what() const throw() const char *what() const throw()
{ {
if (m_message.empty()) return m_plainMessage.c_str();
return "Unspecified error while parsing SAS description file"; }
return m_message.c_str(); const StreamCoordinate &coordinate() const
{
return m_coordinate;
}
const std::string &message() const
{
return m_message;
} }
private: private:
StreamCoordinate m_coordinate;
std::string m_message; std::string m_message;
std::string m_plainMessage;
}; };
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,72 @@
#ifndef __PLASP__UTILS__PARSER_POLICY_H
#define __PLASP__UTILS__PARSER_POLICY_H
#include <iostream>
namespace plasp
{
namespace utils
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// ParserPolicy
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class CaseSensitiveParserPolicy
{
public:
static constexpr char transformCharacter(char c) noexcept
{
return c;
}
static bool isWhiteSpaceCharacter(char c)
{
return std::iswspace(c);
}
static bool isBlankCharacter(char c)
{
return std::isblank(c);
}
static bool isIdentifierCharacter(char c)
{
return std::isgraph(c);
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
class CaseInsensitiveParserPolicy
{
public:
static char transformCharacter(char c) noexcept
{
return std::tolower(c);
}
static bool isWhiteSpaceCharacter(char c)
{
return std::iswspace(c);
}
static bool isBlankCharacter(char c)
{
return std::isblank(c);
}
static bool isIdentifierCharacter(char c)
{
return std::isgraph(c);
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -1,91 +0,0 @@
#ifndef __PLASP__UTILS__PARSING_H
#define __PLASP__UTILS__PARSING_H
#include <algorithm>
#include <exception>
#include <iosfwd>
#include <sstream>
#include <string>
#include <typeinfo>
#include <boost/algorithm/string/replace.hpp>
#include <plasp/utils/ParserException.h>
namespace plasp
{
namespace utils
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Parsing
//
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class T>
T parse(std::istream &istream)
{
T value;
try
{
istream >> value;
}
catch (const std::exception &e)
{
throw ParserException(std::string("Could not parse value of type ") + typeid(T).name() + " (" + e.what() + ")");
}
return value;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
template<class T>
void parseExpected(std::istream &istream, const T &expectedValue)
{
const auto value = parse<T>(istream);
if (value == expectedValue)
return;
std::stringstream errorStream;
errorStream << "Invalid format, expected " << expectedValue << ", got " + value;
throw utils::ParserException(errorStream.str());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
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;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,84 @@
#ifndef __PLASP__UTILS__STREAM_H
#define __PLASP__UTILS__STREAM_H
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>
#include <boost/filesystem.hpp>
#include <plasp/utils/ParserException.h>
#include <plasp/utils/StreamCoordinate.h>
namespace plasp
{
namespace utils
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Stream
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Stream
{
public:
using Position = std::stringstream::pos_type;
struct Delimiter
{
Position position;
std::string sectionName;
};
public:
explicit Stream();
explicit Stream(std::string streamName, std::istream &istream);
Stream(const Stream &other) = delete;
Stream &operator=(const Stream &other) = delete;
Stream(Stream &&other)
: m_stream{std::move(other.m_stream)},
m_delimiters{std::move(other.m_delimiters)}
{
}
Stream &operator=(Stream &&other)
{
m_stream = std::move(other.m_stream);
m_delimiters = std::move(other.m_delimiters);
return *this;
}
~Stream() = default;
void read(std::string streamName, std::istream &istream);
void read(const boost::filesystem::path &path);
void reset();
void seek(Position position);
Position position() const;
StreamCoordinate coordinate() const;
char currentCharacter() const;
void advance();
bool atEnd() const;
void check() const;
protected:
mutable std::stringstream m_stream;
std::vector<Delimiter> m_delimiters;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -0,0 +1,29 @@
#ifndef __PLASP__UTILS__STREAM_COORDINATE_H
#define __PLASP__UTILS__STREAM_COORDINATE_H
#include <string>
namespace plasp
{
namespace utils
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// StreamCoordinate
//
////////////////////////////////////////////////////////////////////////////////////////////////////
struct StreamCoordinate
{
std::string sectionName;
size_t row;
size_t column;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@@ -1,12 +1,12 @@
#ifndef __PLASP__SAS__TRANSLATOR_EXCEPTION_H #ifndef __PLASP__UTILS__TRANSLATOR_EXCEPTION_H
#define __PLASP__SAS__TRANSLATOR_EXCEPTION_H #define __PLASP__UTILS__TRANSLATOR_EXCEPTION_H
#include <exception> #include <exception>
#include <string> #include <string>
namespace plasp namespace plasp
{ {
namespace sas namespace utils
{ {
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -39,7 +39,7 @@ class TranslatorException: public std::exception
const char *what() const throw() const char *what() const throw()
{ {
if (m_message.empty()) if (m_message.empty())
return "Unspecified error while translating SAS description"; return "Unspecified error while translating description";
return m_message.c_str(); return m_message.c_str();
} }

View File

@@ -0,0 +1,34 @@
(define (domain gripper-strips)
(:predicates (room ?r)
(ball ?b)
(gripper ?g)
(at-robby ?r)
(at ?b ?r)
(free ?g)
(carry ?o ?g))
(:action move
:parameters (?from ?to)
:precondition (and (room ?from) (room ?to) (at-robby ?from))
:effect (and (at-robby ?to)
(not (at-robby ?from))))
(:action pick
:parameters (?obj ?room ?gripper)
:precondition (and (ball ?obj) (room ?room) (gripper ?gripper)
(at ?obj ?room) (at-robby ?room) (free ?gripper))
:effect (and (carry ?obj ?gripper)
(not (at ?obj ?room))
(not (free ?gripper))))
(:action drop
:parameters (?obj ?room ?gripper)
:precondition (and (ball ?obj) (room ?room) (gripper ?gripper)
(carry ?obj ?gripper) (at-robby ?room))
:effect (and (at ?obj ?room)
(free ?gripper)
(not (carry ?obj ?gripper)))))

View File

@@ -0,0 +1,22 @@
(define (problem strips-gripper-x-1)
(:domain gripper-strips)
(:objects rooma roomb ball4 ball3 ball2 ball1 left right)
(:init (room rooma)
(room roomb)
(ball ball4)
(ball ball3)
(ball ball2)
(ball ball1)
(at-robby rooma)
(free left)
(free right)
(at ball4 rooma)
(at ball3 rooma)
(at ball2 rooma)
(at ball1 rooma)
(gripper left)
(gripper right))
(:goal (and (at ball4 roomb)
(at ball3 roomb)
(at ball2 roomb)
(at ball1 roomb))))

View File

@@ -0,0 +1,28 @@
(define (problem strips-gripper-x-2)
(:domain gripper-strips)
(:objects rooma roomb ball6 ball5 ball4 ball3 ball2 ball1 left right)
(:init (room rooma)
(room roomb)
(ball ball6)
(ball ball5)
(ball ball4)
(ball ball3)
(ball ball2)
(ball ball1)
(at-robby rooma)
(free left)
(free right)
(at ball6 rooma)
(at ball5 rooma)
(at ball4 rooma)
(at ball3 rooma)
(at ball2 rooma)
(at ball1 rooma)
(gripper left)
(gripper right))
(:goal (and (at ball6 roomb)
(at ball5 roomb)
(at ball4 roomb)
(at ball3 roomb)
(at ball2 roomb)
(at ball1 roomb))))

View File

@@ -0,0 +1,4 @@
instance | minimal horizon | #solutions with minimal horizon
============================================================
problem-01.pddl | 11 | 384
problem-02.pddl | 17 | 46080

View File

@@ -0,0 +1,49 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 4 Op-blocks world
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (domain BLOCKS)
(:requirements :strips :typing)
(:types block)
(:predicates (on ?x - block ?y - block)
(ontable ?x - block)
(clear ?x - block)
(handempty)
(holding ?x - block)
)
(:action pick-up
:parameters (?x - block)
:precondition (and (clear ?x) (ontable ?x) (handempty))
:effect
(and (not (ontable ?x))
(not (clear ?x))
(not (handempty))
(holding ?x)))
(:action put-down
:parameters (?x - block)
:precondition (holding ?x)
:effect
(and (not (holding ?x))
(clear ?x)
(handempty)
(ontable ?x)))
(:action stack
:parameters (?x - block ?y - block)
:precondition (and (holding ?x) (clear ?y))
:effect
(and (not (holding ?x))
(not (clear ?y))
(clear ?x)
(handempty)
(on ?x ?y)))
(:action unstack
:parameters (?x - block ?y - block)
:precondition (and (on ?x ?y) (clear ?x) (handempty))
:effect
(and (holding ?x)
(clear ?y)
(not (clear ?x))
(not (handempty))
(not (on ?x ?y)))))

View File

@@ -0,0 +1,7 @@
(define (problem BLOCKS-4-0)
(:domain BLOCKS)
(:objects D B A C - block)
(:INIT (CLEAR C) (CLEAR A) (CLEAR B) (CLEAR D) (ONTABLE C) (ONTABLE A)
(ONTABLE B) (ONTABLE D) (HANDEMPTY))
(:goal (AND (ON D C) (ON C B) (ON B A)))
)

View File

@@ -0,0 +1,7 @@
(define (problem BLOCKS-5-1)
(:domain BLOCKS)
(:objects A D C E B - block)
(:INIT (CLEAR B) (CLEAR E) (CLEAR C) (ONTABLE D) (ONTABLE E) (ONTABLE C)
(ON B A) (ON A D) (HANDEMPTY))
(:goal (AND (ON D C) (ON C B) (ON B A) (ON A E)))
)

View File

@@ -0,0 +1,7 @@
(define (problem BLOCKS-8-1)
(:domain BLOCKS)
(:objects B A G C F D H E - block)
(:INIT (CLEAR E) (CLEAR H) (CLEAR D) (CLEAR F) (ONTABLE C) (ONTABLE G)
(ONTABLE D) (ONTABLE F) (ON E C) (ON H A) (ON A B) (ON B G) (HANDEMPTY))
(:goal (AND (ON C D) (ON D B) (ON B G) (ON G F) (ON F H) (ON H A) (ON A E)))
)

View File

@@ -0,0 +1,8 @@
(define (problem BLOCKS-9-2)
(:domain BLOCKS)
(:objects B I C E D A G F H - block)
(:INIT (CLEAR H) (CLEAR F) (ONTABLE G) (ONTABLE F) (ON H A) (ON A D) (ON D E)
(ON E C) (ON C I) (ON I B) (ON B G) (HANDEMPTY))
(:goal (AND (ON F G) (ON G H) (ON H D) (ON D I) (ON I E) (ON E B) (ON B C)
(ON C A)))
)

View File

@@ -0,0 +1,6 @@
instance | minimal horizon | #solutions with minimal horizon
============================================================
problem-04-00.pddl | 6 | 1
problem-05-01.pddl | 10 | 2
problem-08-01.pddl | 20 | 60
problem-09-02.pddl | 20 | 37

View File

@@ -0,0 +1,66 @@
(define (domain miconic)
(:requirements :strips)
(:types passenger - object
floor - object
)
(:predicates
(origin ?person - passenger ?floor - floor)
;; entry of ?person is ?floor
;; inertia
(destin ?person - passenger ?floor - floor)
;; exit of ?person is ?floor
;; inertia
(above ?floor1 - floor ?floor2 - floor)
;; ?floor2 is located above of ?floor1
(boarded ?person - passenger)
;; true if ?person has boarded the lift
(not-boarded ?person - passenger)
;; true if ?person has not boarded the lift
(served ?person - passenger)
;; true if ?person has alighted as her destination
(not-served ?person - passenger)
;; true if ?person is not at their destination
(lift-at ?floor - floor)
;; current position of the lift is at ?floor
)
;;stop and allow boarding
(:action board
:parameters (?f - floor ?p - passenger)
:precondition (and (lift-at ?f) (origin ?p ?f))
:effect (boarded ?p))
(:action depart
:parameters (?f - floor ?p - passenger)
:precondition (and (lift-at ?f) (destin ?p ?f)
(boarded ?p))
:effect (and (not (boarded ?p))
(served ?p)))
;;drive up
(:action up
:parameters (?f1 - floor ?f2 - floor)
:precondition (and (lift-at ?f1) (above ?f1 ?f2))
:effect (and (lift-at ?f2) (not (lift-at ?f1))))
;;drive down
(:action down
:parameters (?f1 - floor ?f2 - floor)
:precondition (and (lift-at ?f1) (above ?f2 ?f1))
:effect (and (lift-at ?f2) (not (lift-at ?f1))))
)

View File

@@ -0,0 +1,58 @@
(define (problem mixed-f6-p3-u0-v0-g0-a0-n0-A0-B0-N0-F0-r0)
(:domain miconic)
(:objects p0 p1 p2 - passenger
f0 f1 f2 f3 f4 f5 - floor)
(:init
(above f0 f1)
(above f0 f2)
(above f0 f3)
(above f0 f4)
(above f0 f5)
(above f1 f2)
(above f1 f3)
(above f1 f4)
(above f1 f5)
(above f2 f3)
(above f2 f4)
(above f2 f5)
(above f3 f4)
(above f3 f5)
(above f4 f5)
(origin p0 f1)
(destin p0 f4)
(origin p1 f3)
(destin p1 f1)
(origin p2 f5)
(destin p2 f1)
(lift-at f0)
)
(:goal (and
(served p0)
(served p1)
(served p2)
))
)

View File

@@ -0,0 +1,58 @@
(define (problem mixed-f6-p3-u0-v0-g0-a0-n0-A0-B0-N0-F0-r1)
(:domain miconic)
(:objects p0 p1 p2 - passenger
f0 f1 f2 f3 f4 f5 - floor)
(:init
(above f0 f1)
(above f0 f2)
(above f0 f3)
(above f0 f4)
(above f0 f5)
(above f1 f2)
(above f1 f3)
(above f1 f4)
(above f1 f5)
(above f2 f3)
(above f2 f4)
(above f2 f5)
(above f3 f4)
(above f3 f5)
(above f4 f5)
(origin p0 f2)
(destin p0 f5)
(origin p1 f5)
(destin p1 f2)
(origin p2 f4)
(destin p2 f1)
(lift-at f0)
)
(:goal (and
(served p0)
(served p1)
(served p2)
))
)

View File

@@ -0,0 +1,77 @@
(define (problem mixed-f8-p4-u0-v0-g0-a0-n0-A0-B0-N0-F0-r0)
(:domain miconic)
(:objects p0 p1 p2 p3 - passenger
f0 f1 f2 f3 f4 f5 f6 f7 - floor)
(:init
(above f0 f1)
(above f0 f2)
(above f0 f3)
(above f0 f4)
(above f0 f5)
(above f0 f6)
(above f0 f7)
(above f1 f2)
(above f1 f3)
(above f1 f4)
(above f1 f5)
(above f1 f6)
(above f1 f7)
(above f2 f3)
(above f2 f4)
(above f2 f5)
(above f2 f6)
(above f2 f7)
(above f3 f4)
(above f3 f5)
(above f3 f6)
(above f3 f7)
(above f4 f5)
(above f4 f6)
(above f4 f7)
(above f5 f6)
(above f5 f7)
(above f6 f7)
(origin p0 f7)
(destin p0 f6)
(origin p1 f1)
(destin p1 f3)
(origin p2 f1)
(destin p2 f7)
(origin p3 f2)
(destin p3 f4)
(lift-at f0)
)
(:goal (and
(served p0)
(served p1)
(served p2)
(served p3)
))
)

View File

@@ -0,0 +1,77 @@
(define (problem mixed-f8-p4-u0-v0-g0-a0-n0-A0-B0-N0-F0-r1)
(:domain miconic)
(:objects p0 p1 p2 p3 - passenger
f0 f1 f2 f3 f4 f5 f6 f7 - floor)
(:init
(above f0 f1)
(above f0 f2)
(above f0 f3)
(above f0 f4)
(above f0 f5)
(above f0 f6)
(above f0 f7)
(above f1 f2)
(above f1 f3)
(above f1 f4)
(above f1 f5)
(above f1 f6)
(above f1 f7)
(above f2 f3)
(above f2 f4)
(above f2 f5)
(above f2 f6)
(above f2 f7)
(above f3 f4)
(above f3 f5)
(above f3 f6)
(above f3 f7)
(above f4 f5)
(above f4 f6)
(above f4 f7)
(above f5 f6)
(above f5 f7)
(above f6 f7)
(origin p0 f0)
(destin p0 f5)
(origin p1 f7)
(destin p1 f4)
(origin p2 f0)
(destin p2 f7)
(origin p3 f1)
(destin p3 f6)
(lift-at f0)
)
(:goal (and
(served p0)
(served p1)
(served p2)
(served p3)
))
)

View File

@@ -0,0 +1,6 @@
instance | minimal horizon | #solutions with minimal horizon
============================================================
problem-03-00.pddl | 10 | 12
problem-03-01.pddl | 11 | 40
problem-04-00.pddl | 14 | 180
problem-04-01.pddl | 13 | 120

View File

@@ -0,0 +1,42 @@
(define (domain Depot)
(:requirements :typing)
(:types place locatable - object
depot distributor - place
truck hoist surface - locatable
pallet crate - surface)
(:predicates (at ?x - locatable ?y - place)
(on ?x - crate ?y - surface)
(in ?x - crate ?y - truck)
(lifting ?x - hoist ?y - crate)
(available ?x - hoist)
(clear ?x - surface))
(:action Drive
:parameters (?x - truck ?y - place ?z - place)
:precondition (and (at ?x ?y))
:effect (and (not (at ?x ?y)) (at ?x ?z)))
(:action Lift
:parameters (?x - hoist ?y - crate ?z - surface ?p - place)
:precondition (and (at ?x ?p) (available ?x) (at ?y ?p) (on ?y ?z) (clear ?y))
:effect (and (not (at ?y ?p)) (lifting ?x ?y) (not (clear ?y)) (not (available ?x))
(clear ?z) (not (on ?y ?z))))
(:action Drop
:parameters (?x - hoist ?y - crate ?z - surface ?p - place)
:precondition (and (at ?x ?p) (at ?z ?p) (clear ?z) (lifting ?x ?y))
:effect (and (available ?x) (not (lifting ?x ?y)) (at ?y ?p) (not (clear ?z)) (clear ?y)
(on ?y ?z)))
(:action Load
:parameters (?x - hoist ?y - crate ?z - truck ?p - place)
:precondition (and (at ?x ?p) (at ?z ?p) (lifting ?x ?y))
:effect (and (not (lifting ?x ?y)) (in ?y ?z) (available ?x)))
(:action Unload
:parameters (?x - hoist ?y - crate ?z - truck ?p - place)
:precondition (and (at ?x ?p) (at ?z ?p) (available ?x) (in ?y ?z))
:effect (and (not (in ?y ?z)) (not (available ?x)) (lifting ?x ?y)))
)

View File

@@ -0,0 +1,34 @@
(define (problem depotprob1818) (:domain Depot)
(:objects
depot0 - Depot
distributor0 distributor1 - Distributor
truck0 truck1 - Truck
pallet0 pallet1 pallet2 - Pallet
crate0 crate1 - Crate
hoist0 hoist1 hoist2 - Hoist)
(:init
(at pallet0 depot0)
(clear crate1)
(at pallet1 distributor0)
(clear crate0)
(at pallet2 distributor1)
(clear pallet2)
(at truck0 distributor1)
(at truck1 depot0)
(at hoist0 depot0)
(available hoist0)
(at hoist1 distributor0)
(available hoist1)
(at hoist2 distributor1)
(available hoist2)
(at crate0 distributor0)
(on crate0 pallet1)
(at crate1 depot0)
(on crate1 pallet0)
)
(:goal (and
(on crate0 pallet2)
(on crate1 pallet1)
)
))

View File

@@ -0,0 +1,40 @@
(define (problem depotprob7512) (:domain Depot)
(:objects
depot0 - Depot
distributor0 distributor1 - Distributor
truck0 truck1 - Truck
pallet0 pallet1 pallet2 - Pallet
crate0 crate1 crate2 crate3 - Crate
hoist0 hoist1 hoist2 - Hoist)
(:init
(at pallet0 depot0)
(clear crate0)
(at pallet1 distributor0)
(clear crate3)
(at pallet2 distributor1)
(clear crate2)
(at truck0 depot0)
(at truck1 depot0)
(at hoist0 depot0)
(available hoist0)
(at hoist1 distributor0)
(available hoist1)
(at hoist2 distributor1)
(available hoist2)
(at crate0 depot0)
(on crate0 pallet0)
(at crate1 distributor1)
(on crate1 pallet2)
(at crate2 distributor1)
(on crate2 crate1)
(at crate3 distributor0)
(on crate3 pallet1)
)
(:goal (and
(on crate0 pallet2)
(on crate1 crate3)
(on crate2 pallet0)
(on crate3 pallet1)
)
))

View File

@@ -0,0 +1,4 @@
instance | minimal horizon | #solutions with minimal horizon
============================================================
problem-01.pddl | 10 | 16
problem-02.pddl | 15 | 448

View File

@@ -0,0 +1,79 @@
(define (domain driverlog)
(:requirements :typing)
(:types location locatable - object
driver truck obj - locatable
)
(:predicates
(at ?obj - locatable ?loc - location)
(in ?obj1 - obj ?obj - truck)
(driving ?d - driver ?v - truck)
(link ?x ?y - location) (path ?x ?y - location)
(empty ?v - truck)
)
(:action LOAD-TRUCK
:parameters
(?obj - obj
?truck - truck
?loc - location)
:precondition
(and (at ?truck ?loc) (at ?obj ?loc))
:effect
(and (not (at ?obj ?loc)) (in ?obj ?truck)))
(:action UNLOAD-TRUCK
:parameters
(?obj - obj
?truck - truck
?loc - location)
:precondition
(and (at ?truck ?loc) (in ?obj ?truck))
:effect
(and (not (in ?obj ?truck)) (at ?obj ?loc)))
(:action BOARD-TRUCK
:parameters
(?driver - driver
?truck - truck
?loc - location)
:precondition
(and (at ?truck ?loc) (at ?driver ?loc) (empty ?truck))
:effect
(and (not (at ?driver ?loc)) (driving ?driver ?truck) (not (empty ?truck))))
(:action DISEMBARK-TRUCK
:parameters
(?driver - driver
?truck - truck
?loc - location)
:precondition
(and (at ?truck ?loc) (driving ?driver ?truck))
:effect
(and (not (driving ?driver ?truck)) (at ?driver ?loc) (empty ?truck)))
(:action DRIVE-TRUCK
:parameters
(?truck - truck
?loc-from - location
?loc-to - location
?driver - driver)
:precondition
(and (at ?truck ?loc-from)
(driving ?driver ?truck) (link ?loc-from ?loc-to))
:effect
(and (not (at ?truck ?loc-from)) (at ?truck ?loc-to)))
(:action WALK
:parameters
(?driver - driver
?loc-from - location
?loc-to - location)
:precondition
(and (at ?driver ?loc-from) (path ?loc-from ?loc-to))
:effect
(and (not (at ?driver ?loc-from)) (at ?driver ?loc-to)))
)

View File

@@ -0,0 +1,48 @@
(define (problem DLOG-2-2-2)
(:domain driverlog)
(:objects
driver1 - driver
driver2 - driver
truck1 - truck
truck2 - truck
package1 - obj
package2 - obj
s0 - location
s1 - location
s2 - location
p1-0 - location
p1-2 - location
)
(:init
(at driver1 s2)
(at driver2 s2)
(at truck1 s0)
(empty truck1)
(at truck2 s0)
(empty truck2)
(at package1 s0)
(at package2 s0)
(path s1 p1-0)
(path p1-0 s1)
(path s0 p1-0)
(path p1-0 s0)
(path s1 p1-2)
(path p1-2 s1)
(path s2 p1-2)
(path p1-2 s2)
(link s0 s1)
(link s1 s0)
(link s0 s2)
(link s2 s0)
(link s2 s1)
(link s1 s2)
)
(:goal (and
(at driver1 s1)
(at truck1 s1)
(at package1 s0)
(at package2 s0)
))
)

View File

@@ -0,0 +1,59 @@
(define (problem DLOG-2-2-4)
(:domain driverlog)
(:objects
driver1 - driver
driver2 - driver
truck1 - truck
truck2 - truck
package1 - obj
package2 - obj
package3 - obj
package4 - obj
s0 - location
s1 - location
s2 - location
p0-1 - location
p2-0 - location
p2-1 - location
)
(:init
(at driver1 s1)
(at driver2 s0)
(at truck1 s1)
(empty truck1)
(at truck2 s2)
(empty truck2)
(at package1 s0)
(at package2 s0)
(at package3 s1)
(at package4 s1)
(path s0 p0-1)
(path p0-1 s0)
(path s1 p0-1)
(path p0-1 s1)
(path s2 p2-0)
(path p2-0 s2)
(path s0 p2-0)
(path p2-0 s0)
(path s2 p2-1)
(path p2-1 s2)
(path s1 p2-1)
(path p2-1 s1)
(link s1 s0)
(link s0 s1)
(link s1 s2)
(link s2 s1)
(link s2 s0)
(link s0 s2)
)
(:goal (and
(at driver2 s2)
(at truck1 s1)
(at truck2 s2)
(at package1 s1)
(at package2 s1)
(at package3 s2)
))
)

View File

@@ -0,0 +1,4 @@
instance | minimal horizon | #solutions with minimal horizon
============================================================
problem-01.pddl | 7 | 1
problem-03.pddl | 12 | 1056

View File

@@ -0,0 +1,75 @@
(define (domain satellite)
(:requirements :strips :equality :typing)
(:types satellite direction instrument mode)
(:predicates
(on_board ?i - instrument ?s - satellite)
(supports ?i - instrument ?m - mode)
(pointing ?s - satellite ?d - direction)
(power_avail ?s - satellite)
(power_on ?i - instrument)
(calibrated ?i - instrument)
(have_image ?d - direction ?m - mode)
(calibration_target ?i - instrument ?d - direction))
(:action turn_to
:parameters (?s - satellite ?d_new - direction ?d_prev - direction)
:precondition (and (pointing ?s ?d_prev)
)
:effect (and (pointing ?s ?d_new)
(not (pointing ?s ?d_prev))
)
)
(:action switch_on
:parameters (?i - instrument ?s - satellite)
:precondition (and (on_board ?i ?s)
(power_avail ?s)
)
:effect (and (power_on ?i)
(not (calibrated ?i))
(not (power_avail ?s))
)
)
(:action switch_off
:parameters (?i - instrument ?s - satellite)
:precondition (and (on_board ?i ?s)
(power_on ?i)
)
:effect (and (not (power_on ?i))
(power_avail ?s)
)
)
(:action calibrate
:parameters (?s - satellite ?i - instrument ?d - direction)
:precondition (and (on_board ?i ?s)
(calibration_target ?i ?d)
(pointing ?s ?d)
(power_on ?i)
)
:effect (calibrated ?i)
)
(:action take_image
:parameters (?s - satellite ?d - direction ?i - instrument ?m - mode)
:precondition (and (calibrated ?i)
(on_board ?i ?s)
(supports ?i ?m)
(power_on ?i)
(pointing ?s ?d)
(power_on ?i)
)
:effect (have_image ?d ?m)
)
)

View File

@@ -0,0 +1,30 @@
(define (problem strips-sat-x-1)
(:domain satellite)
(:objects
satellite0 - satellite
instrument0 - instrument
image1 - mode
spectrograph2 - mode
thermograph0 - mode
Star0 - direction
GroundStation1 - direction
GroundStation2 - direction
Phenomenon3 - direction
Phenomenon4 - direction
Star5 - direction
Phenomenon6 - direction
)
(:init
(supports instrument0 thermograph0)
(calibration_target instrument0 GroundStation2)
(on_board instrument0 satellite0)
(power_avail satellite0)
(pointing satellite0 Phenomenon6)
)
(:goal (and
(have_image Phenomenon4 thermograph0)
(have_image Star5 thermograph0)
(have_image Phenomenon6 thermograph0)
))
)

View File

@@ -0,0 +1,40 @@
(define (problem strips-sat-x-1)
(:domain satellite)
(:objects
satellite0 - satellite
instrument0 - instrument
instrument1 - instrument
infrared0 - mode
infrared1 - mode
image2 - mode
GroundStation1 - direction
Star0 - direction
GroundStation2 - direction
Planet3 - direction
Planet4 - direction
Phenomenon5 - direction
Phenomenon6 - direction
Star7 - direction
)
(:init
(supports instrument0 infrared1)
(supports instrument0 infrared0)
(calibration_target instrument0 Star0)
(supports instrument1 image2)
(supports instrument1 infrared1)
(supports instrument1 infrared0)
(calibration_target instrument1 GroundStation2)
(on_board instrument0 satellite0)
(on_board instrument1 satellite0)
(power_avail satellite0)
(pointing satellite0 Planet4)
)
(:goal (and
(have_image Planet3 infrared0)
(have_image Planet4 infrared0)
(have_image Phenomenon5 image2)
(have_image Phenomenon6 infrared0)
(have_image Star7 infrared0)
))
)

View File

@@ -0,0 +1,52 @@
(define (problem strips-sat-x-1)
(:domain satellite)
(:objects
satellite0 - satellite
instrument0 - instrument
instrument1 - instrument
instrument2 - instrument
satellite1 - satellite
instrument3 - instrument
image1 - mode
infrared0 - mode
spectrograph2 - mode
Star1 - direction
Star2 - direction
Star0 - direction
Star3 - direction
Star4 - direction
Phenomenon5 - direction
Phenomenon6 - direction
Phenomenon7 - direction
)
(:init
(supports instrument0 spectrograph2)
(supports instrument0 infrared0)
(calibration_target instrument0 Star1)
(supports instrument1 image1)
(calibration_target instrument1 Star2)
(supports instrument2 infrared0)
(supports instrument2 image1)
(calibration_target instrument2 Star0)
(on_board instrument0 satellite0)
(on_board instrument1 satellite0)
(on_board instrument2 satellite0)
(power_avail satellite0)
(pointing satellite0 Star4)
(supports instrument3 spectrograph2)
(supports instrument3 infrared0)
(supports instrument3 image1)
(calibration_target instrument3 Star0)
(on_board instrument3 satellite1)
(power_avail satellite1)
(pointing satellite1 Star0)
)
(:goal (and
(pointing satellite0 Phenomenon5)
(have_image Star3 infrared0)
(have_image Star4 spectrograph2)
(have_image Phenomenon5 spectrograph2)
(have_image Phenomenon7 spectrograph2)
))
)

View File

@@ -0,0 +1,5 @@
instance | minimal horizon | #solutions with minimal horizon
============================================================
problem-01.pddl | 9 | 12
problem-02.pddl | 13 | 240
problem-03.pddl | 11 | 276

View File

@@ -0,0 +1,65 @@
; IPC5 Domain: TPP Propositional
; Authors: Alfonso Gerevini and Alessandro Saetti
(define (domain TPP-Propositional)
(:requirements :strips :typing)
(:types place locatable level - object
depot market - place
truck goods - locatable)
(:predicates (loaded ?g - goods ?t - truck ?l - level)
(ready-to-load ?g - goods ?m - market ?l - level)
(stored ?g - goods ?l - level)
(on-sale ?g - goods ?m - market ?l - level)
(next ?l1 ?l2 - level)
(at ?t - truck ?p - place)
(connected ?p1 ?p2 - place))
(:action drive
:parameters (?t - truck ?from ?to - place)
:precondition (and (at ?t ?from) (connected ?from ?to))
:effect (and (not (at ?t ?from)) (at ?t ?to)))
; ### LOAD ###
; ?l1 is the level of ?g ready to be loaded at ?m before loading
; ?l2 is the level of ?g ready to be loaded at ?m after loading
; ?l3 is the level of ?g in ?t before loading
; ?l4 is the level of ?g in ?t after loading
(:action load
:parameters (?g - goods ?t - truck ?m - market ?l1 ?l2 ?l3 ?l4 - level)
:precondition (and (at ?t ?m) (loaded ?g ?t ?l3)
(ready-to-load ?g ?m ?l2) (next ?l2 ?l1) (next ?l4 ?l3))
:effect (and (loaded ?g ?t ?l4) (not (loaded ?g ?t ?l3))
(ready-to-load ?g ?m ?l1) (not (ready-to-load ?g ?m ?l2))))
; ### UNLOAD ###
; ?l1 is the level of ?g in ?t before unloading
; ?l2 is the level of ?g in ?t after unloading
; ?l3 is the level of ?g in ?d before unloading
; ?l4 is the level of ?g in ?d after unloading
(:action unload
:parameters (?g - goods ?t - truck ?d - depot ?l1 ?l2 ?l3 ?l4 - level)
:precondition (and (at ?t ?d) (loaded ?g ?t ?l2)
(stored ?g ?l3) (next ?l2 ?l1) (next ?l4 ?l3))
:effect (and (loaded ?g ?t ?l1) (not (loaded ?g ?t ?l2))
(stored ?g ?l4) (not (stored ?g ?l3))))
; ### BUY ###
; ?l1 is the level of ?g on sale at ?m before buying
; ?l2 is the level of ?g on sale at ?m after buying
; ?l3 is the level of ?g ready to be loaded at ?m before buying
; ?l4 is the level of ?g ready to be loaded at ?m after buying
(:action buy
:parameters (?t - truck ?g - goods ?m - market ?l1 ?l2 ?l3 ?l4 - level)
:precondition (and (at ?t ?m) (on-sale ?g ?m ?l2) (ready-to-load ?g ?m ?l3)
(next ?l2 ?l1) (next ?l4 ?l3))
:effect (and (on-sale ?g ?m ?l1) (not (on-sale ?g ?m ?l2))
(ready-to-load ?g ?m ?l4) (not (ready-to-load ?g ?m ?l3))))
)

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