I am trying to develop a algorithm using PDDL. Below here I am trying to define the domain and the problem files
Domain File:
(define (domain sp)
(:requirements :typing)
(:types location agent item - object
robot human - agent
room - location
fruit cup table - item)
(:predicates
(at ?o - object ?l - location)
(detected ?p - human ?l - room)
(greeted ?r - robot ?p - human)
)
(:action detect
:parameters (?p - human ?i - item ?r - robot ?l - location)
:precondition (at ?r ?l)
:effect (and (at ?p ?l) (at ?r ?l))
)
(:action greet
:parameters (?r - robot ?p - human ?l - location)
:precondition (and (at ?r ?l) (detected ?p ?l))
:effect (greeted ?r ?p)
)
)
Problem File:
(define (problem test12)
(:domain sp)
(:objects person0 - Human
pepper0 - Robot
apple - Fruit
cup0 - Cup
table0 - Table
room0 - Room)
(:init
(at pepper0 room0)
)
(:goal (and
(detected person0 room0)
(greeted pepper0 person0)
)
)
)
What I am trying to achieve is
Robot is in the room
When human enters the room, robot needs to detect human
Greet human
The it has to detect other objects in the room (like cup, fruit, etc.)
When I run this code I am going to the following error.
solution-impossbible
ff: parsing domain file
domain 'SP' defined
... done.
ff: parsing problem file
problem 'TEST12' defined
... done.
ff: goal can be simplified to FALSE. No plan will solve it
I followed the syntax correctly but it throws this error. I am not sure how to go about it. Can anyone show me a direction and if possible some debugging resources for PDDL?
the output per-se is not an error. It simply indicates that there is no plan to your problem. The issue is that (detected ?p ?l) is never added by any action and is not in your initial state, so you will never be able to achieve it. You probably want to add it as an effect of the detect action (instead of (at ?r ?l)?).
Related
During development I find that there's a lot of resources that get "left behind" on my local xtdb server.
What's the best way to clear this data locally without restarting my repl?
While posing the question I thought of the answer:
;; Given some `xtdb-node`
(let [res (xt/q (xt/db xtdb-node)
'{:find [id]
:where [[id :xt/id _]]})
ids (map first res)]
(->> ids
(mapv (fn [id] [::xt/delete id]))
(xt/submit-tx xtdb-node)))
Just search for all documents with the :xt/id key as that is a requirement of xtdb.
I have read the documentation, and I am struggling with the following case (probably I am thinking in neo4j and hyperedges and that's why I can think clearly here):
Assume that I want to model the following entities: :person (with some attributes like :name, id, etc), :school (again some attributes) the relation ship of between the school and the person could be like :student or :teacher. And this could evolve through time (a :person could not be related to the school, later is a :student and much later maybe as a :teacher)
When the :person is a :student it will have an student-id, and as a :teacher it will have another id lets say teacher-id.
So, should I have:
:person/name 'John'
:school/id 'SCHOOL-1'
:student/name 'John'
:student/school 'SCHOOL-1'
? How I should include information as the student-id, What if there is more schools?
But now, it seems to me that the relationship between this entities is an hyperedge (that's why I mentioned neo4j). And I don't know what is the best way of modelling this is datomic.
Thanks in advance
I have a good example of using Datomic to keep track of James Bond and various villians available here. Everything is written in the form of unit tests using the Tupelo Datomic library so it is easy to verify the base project and any changes you have:
~/io.tupelo.demo/datomic > lct
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
lein test _bootstrap
-------------------------------
Clojure 1.10.1 Java 13
-------------------------------
lein test tst.tupelo.datomic.bond
Ran 2 tests containing 35 assertions.
0 failures, 0 errors.
The above will work with Datomic Free edition, so you don't even need a paid license to get started.
In the Bond example, the characters may have multiple weapons, which are modeled as a set:
; Create some antagonists and load them into the db. We can specify some of the
; attribute-value pairs at the time of creation, and add others later. Note that
; whenever we are adding multiple values for an attribute in a single step (e.g.
; :weapon/type), we must wrap all of the values in a set. Note that the set
; implies there can never be duplicate weapons for any one person. As before,
; we immediately commit the new entities into the DB.
(td/transact *conn*
(td/new-entity { :person/name "James Bond" :location "London" :weapon/type #{ :weapon/gun :weapon/wit } } )
(td/new-entity { :person/name "M" :location "London" :weapon/type #{ :weapon/gun :weapon/guile } } )
(td/new-entity { :person/name "Dr No" :location "Caribbean" :weapon/type :weapon/gun } ))
In my schema I have the attribute :base/type that is supposed to exist for every entity created. To check that this is indeed true, I'm trying to find entities where it is missing:
[:find [?entities ...]
:in $ :where
[(missing? $ ?entities :base/type)]]
Unfortunately this gives me back:
Execution error (Exceptions$IllegalArgumentExceptionInfo) at datomic.error/arg (error.clj:57).
:db.error/insufficient-binding [?entities] not bound in expression clause: [(missing? $ ?entities :base/type)]
How should this query be constructed?
This is because your query is too general. You need at least one positive clause in where statement if you use query API. You can access raw index to get the result, though. If you have enough RAM, you can:
(def snapshot (d/db connection)) ; your db snapshot
(def all-datoms (d/datoms snapshot :eavt))
(def base-type-id (:db/id (d/entity snapshot :base/type))
(def entities (group-by #(.e %) all-datoms))
(def entities-without-base-type (map
(comp #(into {} %) (partial d/entity snapshot) first)
(filter (fn [[k l]]
(empty? (filter #(= base-type-id (.a %))
l)))
entities)))
(def only-relevant-entities (filter #(not (or (:db/ident %) (:db/txInstant %))) entities-without-base-type))
only-relevant-entities
The last filter is to get rid of attribute definitions and transactions (they are stored as datoms in the db as well!).
If you have too many entities you can chunk datoms using the async atoms API.
Using ::singer/songs as an example attribute, this is how to do the query:
[:find [?entities ...]
:in $ :where
[?entities ::singer/songs ?s]
[(missing? $ ?entities :base/type)]]
Unfortunately (in my answer) many such queries would be required until the whole database has been covered. So another query with ::song/composers, etc...
I need to know which are the most common datatypes in DBpedia. So I am asking a query to Virtuoso like this:
SELECT datatype(?d) (COUNT(?d) as ?dCount)
WHERE
{
?s ?p ?d
}
GROUP BY ?d
ORDER BY DESC(?dCount)
I am not sure if the query is correct and, above all, the transaction timed out. How can I get my answer or reduce my research space to "something relevant"? Or, for example, get anyway my result when the query times out?
The query is not correct.
You must group by the datatype, not the literal value:
SELECT (datatype(?d) as ?dt) (COUNT(?d) as ?dCount)
WHERE
{
?s ?p ?d
FILTER(isLiteral(?d))
}
GROUP BY datatype(?d)
ORDER BY DESC(?dCount)
The query might still timeout.
You could restrict it to data properties of DBpedia, i.e.
SELECT (datatype(?d) as ?dt) (COUNT(*) as ?dCount)
WHERE
{
?p a owl:DatatypeProperty .
?s ?p ?d
}
GROUP BY datatype(?d)
ORDER BY DESC(?dCount)
but you would miss the triples with properties of http://dbpedia.org/property/ namespace.
Alternatives:
load the data into a local more powerful server
simply use the DBpedia ontology although this probably doesn't contain all datatypes used in the instance data
I'm sorry if this is painfully obvious, but how do I represent logical disjunction in Datomic? For instance, if I'm looking for an entity whose name is "1" or whose age is less than 5, how would I go about that?
Thanks!
As of 0.9.5130, you can write disjunctive queries directly:
(q '[:find ?e
:where
(or-join [?e]
[?e :name "1"]
(and [?e :age ?age]
[(< ?age 5)]))]
db)
For a quick overview of the new functionality, check out the blog post where they announced it.
You can accomplish this by using rules. An example from the docs shows a rule form that expresses logical OR:
[[(social-media ?c)
[?c :community/type :community.type/twitter]]
[(social-media ?c)
[?c :community/type :community.type/facebook-page]]]
In this case, the rule defines two logical paths to meet the definition "social-media." So, either community/type twitter or community/type facebook-page meet the criteria for "social media." This example is fleshed out in more detail towards the end of the "querying with rules" section of the tutorial.
(let [rules '[[[region ?c ?r]
[?c :community/neighborhood ?n]
[?n :neighborhood/district ?d]
[?d :district/region ?re]
[?re :db/ident ?r]]
[[social-media ?c]
[?c :community/type :community.type/twitter]]
[[social-media ?c]
[?c :community/type :community.type/facebook-page]]
[[northern ?c]
(region ?c :region/ne)]
[[northern ?c]
(region ?c :region/n)]
[[northern ?c]
(region ?c :region/nw)]
[[southern ?c]
(region ?c :region/sw)]
[[southern ?c]
(region ?c :region/s)]
[[southern ?c]
(region ?c :region/se)]]]
(pprint (q '[:find [?n ...]
:in $ %
:where
[?c :community/name ?n]
(southern ?c)
(social-media ?c)]
(db conn)
rules)))
This example combines multiple logical pathways to inclusion in southern - :region/sw, region:se, and region:s, as well as multiple pathways into social media.