Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/pddl/PddlDomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class PddlDomain {
this.actions = actions
}

addPredicate (predicate) { // predicate = ['light-on', 'l']
addPredicate (predicate, parameters = []) { // predicate = ['light-on', 'l']
if ( this.predicates.find( (e) => e[0]==predicate[0]) )
return false
this.predicates.push(predicate)
predicate.toPddlString = function () {
return '('+predicate[0]+' ' + predicate.slice(1).map( v => '?'+v ).join(' ') + ')'
return '('+predicate[0]+' ' + predicate.slice(1).map( v => (parameters.includes(v) ? "?" + v : v)).join(' ') + ')'
}
return predicate
}
Expand All @@ -29,14 +29,14 @@ class PddlDomain {
let not = p[0].split(' ')[0]=='not'
let predicate = (not ? p[0].split(' ')[1] : p[0])
let args = p.slice(1)
this.addPredicate([predicate, ...args])
this.addPredicate([predicate, ...args], parameters)
}

for ( let p of effect ) {
let not = p[0].split(' ')[0]=='not'
let predicate = (not ? p[0].split(' ')[1] : p[0])
let args = p.slice(1)
this.addPredicate([predicate, ...args])
this.addPredicate([predicate, ...args], parameters)
}

this.actions.push(actionClass)
Expand All @@ -45,22 +45,22 @@ class PddlDomain {
(:action ${actionClass.name}
:parameters (${parameters.map( p => '?'+p ).join(' ')})
:precondition (and
${PddlDomain.mapTokens(precondition)}
${PddlDomain.mapTokens(precondition, parameters)}
)
:effect (and
${PddlDomain.mapTokens(effect)}
${PddlDomain.mapTokens(effect, parameters)}
)
)`
}

}
}

static mapTokens(tokens) {
static mapTokens(tokens, parameters = []) {
return tokens.map( p => {
let not = p[0].split(' ')[0]=='not'
let predicate = (not ? p[0].split(' ')[1] : p[0])
let args = p.slice(1).map( v => '?'+v ).join(' ')
let args = p.slice(1).map( v => (parameters.includes(v) ? "?" + v : v)).join(' ')
if (not)
return `${padding}(not (${predicate} ${args}))`
return `${padding}(${predicate} ${args})`
Expand Down Expand Up @@ -88,7 +88,7 @@ class PddlDomain {
return `\
;; domain file: domain-${this.name}.pddl
(define (domain ${this.name})
(:requirements :strips)
(:requirements :strips :negative-preconditions)
(:predicates
${this.predicates.map( p => p.toPddlString()).join('\n' + padding.repeat(2))}
)
Expand Down
6 changes: 4 additions & 2 deletions src/pddl/actions/pddlActionIntention.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ class pddlActionIntention extends Intention {
let possibly_negated_predicate = literal[0]
let vars = literal.slice(1)
let grounded = possibly_negated_predicate
for (let v of vars)
grounded = grounded + ' ' + parametersMap[v]
for (let v of vars) {
grounded += " ";
grounded += parametersMap[v] ? parametersMap[v] : v;
}
return grounded
})
}
Expand Down