From f7e089042dc6e76735d48a827ef3643b057de14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Fri, 17 Nov 2017 15:52:25 +0100 Subject: [PATCH] Updated documentation to new output format. --- KNOWN-ISSUES.md | 2 +- doc/output-format.md | 137 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 110 insertions(+), 29 deletions(-) diff --git a/KNOWN-ISSUES.md b/KNOWN-ISSUES.md index 5d8c343..3f1b0c3 100644 --- a/KNOWN-ISSUES.md +++ b/KNOWN-ISSUES.md @@ -16,5 +16,5 @@ ## Encodings -- the [simple example encoding](encodings/sequential-horizon.lp) does not support layers of SAS axiom rules +- the [simple example encoding](encodings/sequential-horizon.lp) does not SAS axiom rules - [multiple encodings](encodings/outdated) are outdated and need to be adapted to the output format introduced with `plasp` 3.1.0 diff --git a/doc/output-format.md b/doc/output-format.md index 9fd491e..191eb40 100644 --- a/doc/output-format.md +++ b/doc/output-format.md @@ -15,33 +15,63 @@ Actions are modeled exactly as PDDL actions and SAS operators. ## In a Nutshell -The following illustrates `plasp`’s output format for the problem of turning switches on and off. +Consider the following, simplistic PDDL problem of turning a switch on: + +```lisp +; simplistic example of turning a switch on +(define (domain switch) + (:requirements :typing) + (:types switch) + (:predicates + (on ?x - switch)) + (:action turn-on + :parameters + (?x - switch) + :precondition + (not (on ?x)) + :effect + (on ?x))) + +; example problem with one switch +(define (problem switch-problem) + (:domain switch) + (:objects a - switch) + (:init + (not (on a))) + (:goal + (on a))) +``` + +This is translated by `plasp translate` into the following output format (slightly restructured for clarity): ```prolog -% declares the type "type(switch)" -type(type(switch)). +% declares the type “type("switch")” +type(type("switch")). -% introduces a switch "constant(a)" -constant(constant(a)). -has(constant(a), type(switch)). +% introduces a switch “constant("a")” +constant(constant("a")). +has(constant("a"), type("switch")). -% declares a variable "variable(on(X))" for switches X -variable(variable(on(X))) :- has(X, type(switch)). +% declares a variable “variable(on(X))” for switches X +variable(variable(("on", X))) :- has(X, type("switch")). -% the variable may be true or false -contains(variable(on(X)), value(on(X)), true)) :- has(X, type(switch)). -contains(variable(on(X)), value(on(X)), false)) :- has(X, type(switch)). +% variables may have the values true and false +boolean(true). +boolean(false). +contains(X, value(X, B)) :- variable(X), boolean(B). -% declares the action "action(turnOn(X))", which requires switch X to be off and then turns it on -action(action(turnOn(X))) :- has(X, type(switch)). -precondition(action(turnOn(X)), variable(on(X)), value(on(X), false)) :- has(X, type(switch)). -postcondition(action(turnOn(X)), effect(0), variable(on(X)), value(on(X), true)) :- has(X, type(switch)). +% declares the action “action(turnOn(X))”, which requires switch X to be off and then turns it on +action(action(("turn-on", X))) :- has(X, type("switch")). +precondition(action(("turn-on", X)), variable(("on", X)), value(variable(("on", X)), false)) + :- action(action(("turn-on", X))). +postcondition(action(("turn-on", X)), effect(unconditional), variable(("on", X)), value(variable(("on", X)), true)) + :- action(action(("turn-on", X))). % initially, the switch is off -initialState(variable(on(constant(a))), value(on(constant(a)), false)). +initialState(variable(("on", constant("a"))), value(variable(("on", constant("a"))), false)). % in the end, the switch should be on -goal(variable(on(constant(a))), value(on(constant(a)), true)). +goal(variable(("on", constant("a"))), value(variable(("on", constant("a"))), true)). ``` ## Syntax and Semantics @@ -55,7 +85,7 @@ goal(variable(on(constant(a))), value(on(constant(a)), true)). requires(feature()). ``` -`plasp` recognizes and declares advanced features used by the input problem, such as conditional effects, [mutex groups](#mutex-groups) and [axiom rules](#axiom-rules) (currently only SAS). +`plasp` recognizes and declares advanced features used by the input problem, such as [conditional effects](#actions), [mutex groups](#mutex-groups) and [axiom rules](#axiom-rules) (currently only SAS). See the [full list of supported features](feature-requirements.md) for more information. The feature requirement predicates may be used in meta encodings to warn about unsupported features. @@ -67,10 +97,10 @@ The feature requirement predicates may be used in meta encodings to warn about u type(type()). % specifies that inherits -inherits(type(), type()). +inherits(, ). -% specifies to have type type() -has(, type()). +% specifies to have type +has(, ). ``` [Variables](#variables), [constants](#constants-objects), and [objects](#constants-objects) may be typed. Types are only available with PDDL and if typing is enabled. @@ -96,9 +126,27 @@ With SAS, variable names are numbers starting at 0, `variable()`. SAS variables are inherently multivalued, which results in two or more values of the form `value(, )` for each variable. With PDDL, Boolean variables are created from the PDDL predicates. -Variables are named after the PDDL predicates, `variable().` -Each variable contains exactly two values (one `true`, one `false`) of the form `value(, )`. -Note that with PDDL, variables and values are named identically. +Variables are named after the PDDL predicate signatures, `variable().` +Each variable contains exactly two values (one `true`, one `false`) of the form `value(, )`. +Note that with PDDL, values contain the corresponding variables as the first argument to make the format consistent with the multi-valued variables obtained with SAS input. + +### Derived Variables + +```prolog +% declares a +derivedVariable(derivedVariable()). + +% adds a to the domain of a +contains(, ). +``` + +Derived variables are introduced whenever the translator needs to use [derived predicates](#derived-predicates). +When the preconditions of a [derived predicate](#derived-predicates) are met, the corresponding derived variable (named after the derived predicate) is set as an effect. + +Derived variables are analogously defined to common variables and may also be referenced in preconditions, conditions of conditional effects, and goal descriptions, just as variables. + +In contrast to common variables, derived variables *are not subject to inertia rules.* +In other words, derived variables are computed for each time step separately, and reset when going to the next time step (their values don’t automatically carry over to the next time step). ### Actions @@ -106,20 +154,22 @@ Note that with PDDL, variables and values are named identically. % declares an action(action()). -% defines that as a precondition to , must have value +% defines that as a precondition to , and must have value precondition(, , ). +precondition(, , ). % defines that after applying , is assigned postcondition(, effect(), , ). % defines the condition of a conditional effect precondition(effect(), , ). +precondition(effect(), , ). % specifies the costs of applying costs(, ). ``` -Actions may require certain variables to have specific values in order to be executed. +Actions may require certain [variables](#variables) (or [derived variables](#derived-variables)) to have specific values in order to be executed. After applying an action, variables get new values according to the action's postconditions. Actions may have *conditional effects*, that is, certain postconditions are only applied if additional conditions are satisfied. @@ -132,6 +182,36 @@ Conditional effects are currently only supported with SAS input problems. Actions may also have *action costs* required to apply them. Action costs are currently supported for SAS only. +### Derived Predicates + +```prolog +% declares a of with conjunctive (type(and)) or disjunctive (type(or)) preconditions +derivedPredicate(derivedPredicate(), type()). + +% defines that as a precondition to , and must have value +precondition(, type(), , ). +precondition(, type(), , ). + +% defines that after applying , is assigned +postcondition(, type(), effect(), , ). + +% defines the condition of a conditional effect +precondition(effect(), , ). +precondition(effect(), , ). + +% specifies the costs of applying +costs(, ). +``` + +Derived predicates are introduced by the translator when there are nested expressions or disjunctions in action preconditions, conditions of conditional effects, or goal descriptions. +Derived predicates operate on [derived variables](#derived-variables) of the same name. + +Like actions, derived predicates must satisfy preconditions in order for their effect to be applicable. +The effect of all derived predicates is to set the corresponding [derived variables](#derived-variables) to `true` or `false`. + +In contrast to actions, however, derived predicates specify whether their preconditions are to be interpreted as a *conjunction* (`type(and)`) or as a *disjunction* (`type(or)`). +Encoding authors need to ensure that derived predicate preconditions are interpreted in the correct way. + ### Constants/Objects ```prolog @@ -161,11 +241,12 @@ Note that with PDDL, `plasp` sets all unspecified initial state variables to `fa ### Goal ```prolog -% specifies that shall obtain in the end +% specifies that and shall obtain a respective in the end goal(, ). +goal(, ). ``` -The goal specifies all variable assignments that have to be fulfilled after executing the plan. +The goal specifies all assignments of [variables](#variables) and [derived variables](#derived-variables) that have to be fulfilled after executing the action sequence. ### Mutex Groups