PDDL doesn't compile - pddl

Trying to figure out this PDDL problem of getting robots to clean tiles but I'm stuck with what I'm doing wrong as far as I understand, I have the movements actions and clean actions only for up and down yet it still doesnt compile. It just gives me an error that says could not parse domain file.
This is the domain:
(define (domain floor-tile)
(:requirements :typing)
;; We have two types: robots and the tiles, both are objects
(:types robot tile - object)
;; define all the predicates as they are used in the probem files
(:predicates
;; described what tile a robot is at
(robot-at ?r - robot ?x - tile)
;; indicates that tile ?x is above tile ?y
(up ?x - tile ?y - tile)
;; indicates that tile ?x is below tile ?y
(down ?x - tile ?y - tile)
;; indicates that tile ?x is right of tile ?y
(right ?x - tile ?y - tile)
;; indicates that tile ?x is left of tile ?y
(left ?x - tile ?y - tile)
;; indicates that a tile is clear (robot can move there)
(clear ?x - tile)
;; indicates that a tile is cleaned
(cleaned ?x - tile)
)
(:action clean-up
:parameters (?r - robot ?x - tile ?y - tile )
:precondition (and (up ?y ?x) (robot-at ?r ?x) (clear ?y))
:effect (and (not (clear ?y)) (cleaned ?y)
)
(:action clean-down
:parameters (?r - robot?x - tile ?y - tile)
:precondition (and (down ?y ?x) (robot-at ?r ?x) (clear ?y))
:effect (and (not (clear ?y)) (cleaned ?y)
)
(:action up
:parameters (?r - robot?x - tile ?y - tile)
:precondition (and (up ?y ?x) (robot-at ?r ?x) (clear ?y))
:effect (and (robot-at ?r ?y) (not(robot-at ?r ?x)))
)
(:action down
:parameters (?r - robot?x - tile ?y - tile)
:precondition (and (down ?y ?x) (robot-at ?r ?x)(clear ?y))
:effect (and (robot-at ?r ?y)
(not(robot-at ?r ?x)))
)
(:action right
:parameters (?r - robot?x - tile ?y - tile)
:precondition (and (right ?y ?x) (robot-at ?r ?x) (clear ?y))
:effect (and (robot-at ?r ?y)
(not(robot-at ?r ?x)))
)
(:action left
:parameters (?r - robot?x - tile ?y - tile)
:precondition (and (left ?y ?x) (robot-at ?r ?x) (clear ?y))
:effect (and (robot-at ?r ?y )
(not(robot-at ?r ?x)))
)
)
Here is the problem:
(define (problem prob001)
(:domain floor-tile)
(:objects tile_0-1 tile_0-2
tile_1-1 tile_1-2
tile_2-1 tile_2-2 - tile
robot1 - robot
)
(:init
(robot-at robot1 tile_1-1)
(clear tile_0-1)
(clear tile_0-2)
(clear tile_1-2)
(clear tile_2-1)
(clear tile_2-2)
(up tile_1-1 tile_0-1)
(up tile_1-2 tile_0-2)
(up tile_2-1 tile_1-1)
(up tile_2-2 tile_1-2)
(down tile_0-1 tile_1-1)
(down tile_0-2 tile_1-2)
(down tile_1-1 tile_2-1)
(down tile_1-2 tile_2-2)
(right tile_0-2 tile_0-1)
(right tile_1-2 tile_1-1)
(right tile_2-2 tile_2-1)
(left tile_0-1 tile_0-2)
(left tile_1-1 tile_1-2)
(left tile_2-1 tile_2-2)
)
(:goal (and
(cleaned tile_0-1)
(cleaned tile_0-2)
(cleaned tile_1-1)
(cleaned tile_2-2)
))
)

Brackets are missing on the :effect of both clean-up and clean-down. After adding those brackets, the online editor's solver indicates that the goal trivially can't be reached, but at least it parses.

Related

PDDL Predicate name must be a string

I am trying to solve a planning assignment with pddl and i wrote the following domain
(define (domain Monster)
(:requirements :strips)
(:predicates (player ?p) (location ?x) (monster ?m) (treasure ?tr) (trap ?tp) (weapon ?w) (flyer ?f) ;entities
(playerat ?player ?location) (monsterat ?monster ?location) (trapat ?trap ?location) (treasureat ?trasure ?location) (weaponat ?weapon ?location) (flyerat ?flyer ?location); relations
(gameOver ?p) (holdsw ?p) (holdsf ?p) (holdst ?p) (go ?A ?B) (close ?A ?B)
)
(:action Move ;Move from location A to location B
:parameters (?P ?A ?B ?M) ; P->Player A->Location_1 B->Location_2
:precondition (and(player ?P) (location ?A) (location ?B) (monster ?M) (playerat ?P ?A) (go ?A ?B) (not(monsterat ?M ?B)) )
:effect (and(playerat ?P ?B) (not(playerat ?P ?A)) )
)
(:action PickWeapon ; picking up weapon
:parameters (?P ?L ?W) ;P->player L->location W->Weapon
:precondition (and(player ?P) (location ?L) (weapon ?W) (playerat ?P ?L) (weaponat ?W ?L) )
:effect (and(holdsw ?P) (not(weaponat ?W ?L)))
)
(:action PickFlyer ;picking up flyer
:parameters (?P ?L ?F) ;P->player L->location F->flyer
:precondition (and(player ?P) (location ?L) (flyer ?F) (playerat ?P ?L) (flyerat ?F ?L) )
:effect (and(holdsf ?P) (not(flyerat ?F ?L)) )
)
(:action PickTreasure ;picking up treasure
:parameters (?P ?L ?T) ;P->player L->location T->treasure
:precondition (and(player ?P) (location ?L) (treasure ?T) (playerat ?P ?L) (treasureat ?T ?L) )
:effect (and(holdst ?P) (not(treasureat ?T ?L)) )
)
(:action PlayerKilled ;player killed
:parameters (?P ?L ?M) ;P->player L->location M->monster
:precondition (and(player ?P) (location ?L) (monster ?M) (playerat ?P ?L) (monsterat ?M ?L) (not(holdsw ?P)) (not(holdsf ?P)) )
:effect (and(gameOver ?P) (not(playerat ?P ?L)) ); Game Over
)
(:action PlayerTraped ;Player traped
:parameters (?P ?L ?TR) ;P->player L->location TR->trap
:precondition (and(player ?P) (location ?L) (trap ?TR) (playerat ?P ?L) (trapat ?TR ?L) (not(holdsf ?P)) )
:effect (and(gameOver ?P) (not(playerat ?P ?L)) )
)
(:action Kill ;Killing Monster
:parameters (?P ?A ?M ?B) ;P->player L->location M->monster
:precondition (and(player ?P) (location ?B) (location ?A) (monster ?M) (playerat ?P ?A) (monsterat ?M ?B) (holdsw ?P) (close ?A ?B) (go ?A ?B) )
:effect (and(playerat ?P ?B) (not(monsterat ?M ?B)) (not(holdsw ?P)) )
)
(:action FlyOverMonster
:parameters (?P ?F ?L ?A ?M) ;P->player L->location F->flyer M->monster
:precondition (and(player ?P) (location ?L) (location ?A) (monster ?M) (playerat ?P ?A) (monsterat ?M ?L) (holdsf ?P) (close ?A ?L) (go ?A ?L) )
:effect (and(playerat ?P ?L) (not(holdsf ?P)) )
)
(:action FlyOverTrap
:parameters (?P ?F ?L ?A ?TR) ;P->player L->location F->flyer TR->trap
:precondition (and(player ?P) (location ?L) (location ?A) (trap ?TR) (playerat ?P ?A) (trapat ?TR ?L) (holdsf ?P) (close ?A ?L) (go ?A ?L) )
:effect (and(playerat ?P ?L) (not(holdsf ?P)) )
)
)
problem
i defined the problem to be planned as follows
(define (problem Monster2)
(:domain Monster)
(:objects a b c d e f g h i pl mo tp fl tr wp
)
(:init
(location a) (location b) (location c) (location d) (location e) (location f) (location g) (location h) (location i)
(player pl) (monster mo) (trap tp) (flyer fl) (treasure tr) (weapon wp)
(go a b) (go b a) (go b c) (go c b) (go c d) (go d c) (go a e) (go e b) (go e f) (go f d) (go e g) (go e h) (go h e) (go h i) (go i h)
(close b c) (close c d) (close e f)
(playerat pl a) (monsterat mo c) (treasureat tr d) (trapat tp f) (weaponat wp h) (flyerat fl i)
)
(:goal (and
(holdst pl)
(playerat pl a)
)
)
)
Trying to solve the problem i Changed my code but now I am facing another problem. The agent after killing the monster does not go to the next room but he returns back and then jambs to d room collects the treasure and stay at d. The strange thing is that the planer says that the agent is now at room c and in next state it says he is at room b.
Planner result
Planer Kill Monster agent at room c
Planner result
Planner Move next supposed to be room d and it says room b state which is wrong
Actually there are several mistakes in the PDDL file. I tested it with FF.
In the domain file you missed some AND and few parenthesis in different action definitions, e.g.
(:action Kill
:parameters (?P ?L ?M ?A) ;P->player L->location M->monster
:precondition (and(player ?P) (location ?L) (location ?A) (monster ?M) (atp ?P ?A) (atm ?M ?L) (holdsw ?P ?W) (close ?A ?L) )
:effect (and (not(atm ?M ?L)) (not(holdsw ?P ?W)) (atp ?P ?L))
)
Then you forgot to declare some predicates used in domain definition, e.g. at1...at6, located
Then in actions FlyOverMonster and FlyOverTrap you forgot to declare variable ?A, variable ?W in actions Kill and PlayerKilled.
In action PlayerKilled you have a predicate hold that doesn't appear anywhere else.
I don't continue, but I hope that the corrections are clear. Then, the planner should point out the kind of error it encounters.
Check your predicates name, I am not sure numbers are supported in their names, and in their parameter names.
In your problem, I can see occurrences of at1, at2, etc... These predicates are named strangely, and I am suspicious it is meant to work.
Moreover, they are not declared in your domain.

SPARQL Query: How to get all individual and data property assertions?

Same as you know if we retrieve the object property or data property and subclass can do that by joining them in one variable :
Query 1
SELECT ?x ?y
WHERE { ?x rdfs:subClassOf ?y.
?x rdf:type owl:ObjectProperty.
}
the x var it's same object property and subclass of other class
im need to join (all individual "NamedIndividual")
with object property or subclass .
the problem that is ( ?x rdf:type owl:NamedIndividual . )
couldn't use "?x" in any other location same as :
?x rdfs:subClassOf ?y.
Query 2
SELECT ?x ?y
WHERE { ?x rdfs:subClassOf ?y.
?x rdf:type owl:NamedIndividual .
}
Query 3
SELECT ?x ?y
WHERE { ?x rdf:type owl:ObjectProperty.
?x rdf:type owl:NamedIndividual .
}
So: Query 2 and Query 3 cannot be implemented.
how I can solve this problem?

Alternatives to the OPTIONAL fallback SPARQL pattern?

I need to retrieve a single image for each resource in a target set, testing multiple non-exclusive predicates with a priority order.
I'm currently using a standard OPTIONAL fallback pattern along the lines of
select ?r ?i where {
?r a dbo:Automobile .
optional { ?r <http://dbpedia.org/ontology/thumbnail> ?i }
optional { ?r <http://xmlns.com/foaf/0.1/depiction> ?i }
optional { ?r <http://xmlns.com/foaf/0.1/logo> ?i }
optional { ?r <http://schema.org/image> ?i }
}
but this approach is turning out to be troublesome on some backends: is anyone aware of any simple/efficient alternative?
What's the problem with the optionals? The repeated use of ?i?
A different approach is to get each alternative and pick the first one set.
select ?r ?i where {
?r a dbo:Automobile .
optional { ?r <http://dbpedia.org/ontology/thumbnail> ?i1 }
optional { ?r <http://xmlns.com/foaf/0.1/depiction> ?i2 }
optional { ?r <http://xmlns.com/foaf/0.1/logo> ?i3 }
optional { ?r <http://schema.org/image> ?i4 }
BIND(COALESCE(?i1,?i2,?i3,?i4) AS ?i)
}
I think you just need to filter you predicates. Something like this might help:
prefix schema:<http://schema.org/>
prefix foaf:<http://xmlns.com/foaf/0.1/>
prefix dbpedia-owl:<http://dbpedia.org/ontology/>
select distinct ?r ?i
where {
?r a dbpedia-owl:Automobile .
?r ?p ?i.
values ?p { foaf:logo foaf:depiction dbpedia-owl:thumbnail schema:image}
}
Golfing here from Artemis original, the problem is the ordering of the predicates. So rather than simple values we could use the following:
values (?p ?pref) {
(dbpedia-owl:thumbnail 1)
(foaf:depiction 2)
(foaf:logo 3)
(schema:image 4)
}
Now we can choose by order:
prefix schema:<http://schema.org/>
prefix foaf:<http://xmlns.com/foaf/0.1/>
prefix dbpedia-owl:<http://dbpedia.org/ontology/>
select distinct ?r ?i
where {
?r a dbpedia-owl:Automobile .
?r ?p ?i.
values (?p ?pref) {
(dbpedia-owl:thumbnail 1)
(foaf:depiction 2)
(foaf:logo 3)
(schema:image 4)
}
}
order by ?r ?pref
That gives us almost what is required. All we then need is to group by ?r and pick the row with the largest ?pref.
Unfortunately that's not simple in SPARQL.

semantic web request result difference

PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT * WHERE {
?x foaf:primaryTopic ?n .
?x rdf:type ?z .
FILTER (regex(?x, '^http://en.wikipedia.org/wiki/Barack_Obama$')).
}
LIMIT 10
when i call this request from http://dbpedia.org/snorql, it works. but when i try below
SELECT * WHERE {
?x foaf:primaryTopic ?n .
?x rdf:type ?z .
?x owl:activeYearsStartDate ?v .
FILTER (regex(?x, '^http://en.wikipedia.org/wiki/Barack_Obama$')).
}
it doesn't work. but why?
I expect that you meant
?x dbpedia-owl:activeYearsStartDate ?v .
rather than
?x owl:activeYearsStartDate ?v .
Also, using regex here is more expensive than it needs to be. You could check whether the string value of a URI is something in particular with
filter( str(?x) = "…" )
but even that is a lot more work than you need. If you want ?x to be <http://en.wikipedia.org/wiki/Barack_Obama>, just use it instead of ?x, or bind ?x to it with values:
SELECT * WHERE {
<http://en.wikipedia.org/wiki/Barack_Obama> foaf:primaryTopic ?n .
<http://en.wikipedia.org/wiki/Barack_Obama> rdf:type ?z .
<http://en.wikipedia.org/wiki/Barack_Obama> owl:activeYearsStartDate ?v .
}
SELECT * WHERE {
values ?x { <http://en.wikipedia.org/wiki/Barack_Obama> }
?x foaf:primaryTopic ?n .
?x rdf:type ?z .
?x owl:activeYearsStartDate ?v .
}
That still looks suspicious, though. Are you sure you didn't want <http://dbpedia.org/resource/Barack_Obama>? And the use of foaf:primaryTopic stuff really makes me think that you want something more like:
select * {
?x foaf:isPrimaryTopicOf <http://en.wikipedia.org/wiki/Barack_Obama> ;
a ?type ;
dbpedia-owl:activeYearsStartDate ?v
}
limit 10
SPARQL results

SPARQL: How to get an insance of an ontology, if depth of the class hierarchy is unknown?

I have a question about SPARQL. I have an ontology of animals:
Animals (is a superclass with object property <hasColor>)
------ Mammals (subclass of Animals)
------------- Dog (subclass of Mammals)
---------------- dog1 (a instance with property <hasColor>="white")
---------------- dog2 (a instance with property <hasColor>="red" )
------ Bird (subclass of Animals)
Is it possible to find with SPARQL "all Animals, that are 'white' " or "all instances of Animals"? And backwards: How can I know, if a instance (dog1) belongs to Animals?
NOTE: The depth and breadth of the class hierarchy is unknown in advance.
Also the query below will not work
SELECT ?x WHERE {?x rdfs:subClassOf :Animals . ?x :hasСolor "white"}
And the next query (find all Animals, that are 'white') works only if the depth of class hierarchy is known.
(So if the hierarchy is known, can I make the specified steps (from top of hierarchy to bottom) to reach the goal: in this case 2 steps.
SELECT ?z WHERE {
?x rdfs:subClassOf :Animals .
?y rdfs:subClassOf ?x .
?z rdf:type ?y .
?z :hasColor "white"
}
The same is true for the next example - "find all instances of Animals"
SELECT ?z WHERE {
?x rdfs:subClassOf :Animals .
?y rdfs:subClassOf ?x .
?z rdf:type ?y .
}
What to do, if the hierarchie is unknown?
The query will be processed with SDB (is a component of Jena).
I want something like :
select ?x where {?x rdfs:subClassOf :Animals . ?x :hasСolor "white"})
UPD. Solution for "find all Animals (instances), that are 'white'" might look like this:
SELECT ?y WHERE { ?x rdfs:subClassOf* :Animals . ?y rdf:type ?x . ?y
:hasColor "white"}
You can use transitivity in your SPARQL query (using *) :
SELECT ?y WHERE { ?x rdfs:subClassOf* :Animals .
?y rdf:type ?x .
?y :hasColor "white" }