Skip to content

Commit

Permalink
Merge pull request #168 from shop-planner/fixes-for-plan-repair
Browse files Browse the repository at this point in the history
Fixes for plan repair
  • Loading branch information
rpgoldman authored Aug 18, 2024
2 parents f5e60c5 + bd1612e commit 1b35cdb
Show file tree
Hide file tree
Showing 8 changed files with 615 additions and 161 deletions.
151 changes: 85 additions & 66 deletions shop3/examples/rovers/strips/domain.lisp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(defpackage :shop3-rovers
(:use common-lisp shop3)
(:nicknames #:shop2-rovers)
(:nicknames #:shop2-rovers #:shop-rovers)
(:intern
#:communicated_image_data
#:communicated_rock_data
Expand All @@ -9,8 +9,17 @@
;; rewrite for goals
#:communicate_image_data
#:communicate_rock_data
#:communicate_soil_data))
(in-package :shop3-rovers)
#:communicate_soil_data
)
(:export #:roverprob01 #:roverprob02 #:roverprob03
#:roverprob04 #:roverprob05 #:roverprob06
#:roverprob07 #:roverprob08 #:roverprob09
#:roverprob10 #:roverprob11 #:roverprob12
#:roverprob13 #:roverprob14 #:roverprob15
#:roverprob16 #:roverprob17 #:roverprob19
#:roverprob20
#:rovers-problems))
(in-package :shop-rovers)

(defclass pure-pddl-domain (pure-logic-domain-mixin pddl-domain)
())
Expand All @@ -29,7 +38,7 @@
store_of
on_board)
(:types rover waypoint store camera mode lander objective)
(:predicates (at ?x - rover ?y - waypoint)
(:predicates (at ?x - rover ?y - waypoint)
(at_lander ?x - lander ?y - waypoint)
(can_traverse ?r - rover ?x - waypoint ?y - waypoint)
(equipped_for_soil_analysis ?r - rover)
Expand All @@ -39,7 +48,7 @@
(have_rock_analysis ?r - rover ?w - waypoint)
(have_soil_analysis ?r - rover ?w - waypoint)
(full ?s - store)
(calibrated ?c - camera ?r - rover)
(calibrated ?c - camera ?r - rover)
(supports ?c - camera ?m - mode)
(available ?r - rover)
(visible ?w - waypoint ?p - waypoint)
Expand All @@ -55,16 +64,16 @@
(on_board ?i - camera ?r - rover)
(channel_free ?l - lander)
)

(:action navigate
:parameters (?x - rover ?y - waypoint ?z - waypoint)
:precondition (and (can_traverse ?x ?y ?z) (available ?x) (at ?x ?y)
:parameters (?x - rover ?y - waypoint ?z - waypoint)
:precondition (and (can_traverse ?x ?y ?z) (available ?x) (at ?x ?y)
(visible ?y ?z)
)
:effect (and (not (at ?x ?y)) (at ?x ?z)
)
)

(:action sample_soil
:parameters (?x - rover ?s - store ?p - waypoint)
:precondition (and (at ?x ?p) (at_soil_sample ?p)
Expand All @@ -73,30 +82,30 @@
:effect (and (not (empty ?s)) (full ?s) (have_soil_analysis ?x ?p) (not (at_soil_sample ?p))
)
)

(:action sample_rock
:parameters (?x - rover ?s - store ?p - waypoint)
:precondition (and (at ?x ?p) (at_rock_sample ?p) (equipped_for_rock_analysis ?x) (store_of ?s ?x)(empty ?s)
)
:effect (and (not (empty ?s)) (full ?s) (have_rock_analysis ?x ?p) (not (at_rock_sample ?p))
)
)

(:action drop
:parameters (?x - rover ?y - store)
:precondition (and (store_of ?y ?x) (full ?y)
)
:effect (and (not (full ?y)) (empty ?y)
)
)

(:action calibrate
:parameters (?r - rover ?i - camera ?t - objective ?w - waypoint)
:precondition (and (equipped_for_imaging ?r) (calibration_target ?i ?t) (at ?r ?w) (visible_from ?t ?w)(on_board ?i ?r)
)
:effect (calibrated ?i ?r)
:effect (calibrated ?i ?r)
)

(:action take_image
:parameters (?r - rover ?p - waypoint ?o - objective ?i - camera ?m - mode)
:precondition (and (calibrated ?i ?r)
Expand All @@ -109,7 +118,7 @@
:effect (and (have_image ?r ?o ?m)(not (calibrated ?i ?r))
)
)

(:action communicate_soil_data
:parameters (?r - rover ?l - lander
;; the location from which ?r took the soil data
Expand All @@ -120,7 +129,7 @@
?y - waypoint)
:precondition (and (at ?r ?x)
(at_lander ?l ?y)
(have_soil_analysis ?r ?p)
(have_soil_analysis ?r ?p)
(visible ?x ?y)
(available ?r)
(channel_free ?l)
Expand All @@ -132,16 +141,18 @@
(available ?r)
)
)

(:action communicate_rock_data
:parameters (?r - rover ?l - lander ?p - waypoint ?x - waypoint ?y - waypoint)
:precondition (and (at ?r ?x)(at_lander ?l ?y)(have_rock_analysis ?r ?p)
(visible ?x ?y)(available ?r)(channel_free ?l)
)
:effect (and (not (available ?r))(not (channel_free ?l))(channel_free ?l)(communicated_rock_data ?p)(available ?r)
)
)

:effect (and (not (available ?r))
(not (channel_free ?l))
(channel_free ?l)
(communicated_rock_data ?p)
(available ?r)))

(:action communicate_image_data
:parameters (?r - rover ?l - lander ?o - objective ?m - mode
;; rover position
Expand All @@ -167,21 +178,21 @@
communicate-one-soil-data
(communicate_soil_data ?goal-loc)
(:ordered
(communicated_soil_data ?goal-loc ?_rover)
(communicated_soil_data ?goal-loc)
(achieve-goals)))

(:pddl-method (achieve-goals)
communicate-one-rock-data
(communicate_rock_data ?goal-loc)
(:ordered
(communicated_rock_data ?goal-loc ?_rover)
(communicated_rock_data ?goal-loc)
(achieve-goals)))

(:method (achieve-goals)
communicate-one-image-data
(communicate_image_data ?obj ?mode)
(:ordered
(communicated_image_data ?obj ?mode ?_rover)
(communicated_image_data ?obj ?mode)
(achieve-goals)))

(:pddl-method (achieve-goals)
Expand All @@ -197,12 +208,12 @@
already-empty
((empty ?s))
())

(:method (empty-store ?s ?rover)
drop-to-empty
((not (empty ?s)))
((!drop ?rover ?s)))

(:method (navigate ?rover ?to)
already-there
((at ?rover ?to))
Expand All @@ -228,37 +239,58 @@
((!navigate ?rover ?from ?first)
(move ?rover ?first ?rest)))

(:method (communicated_soil_data ?goal-loc ?rover)
(:method (communicated_soil_data ?goal-loc)
achieve-communicated-soil-data
((store_of ?s ?rover))
((rover ?rover)
(store_of ?s ?rover))
((navigate ?rover ?goal-loc)
(:immediate empty-store ?s ?rover)
(:immediate empty-store ?s ?rover)
(:immediate !sample_soil ?rover ?s ?goal-loc)
;; FIXME: shouldn't there be a protection of the store until the communication is done?
(:immediate communicate soil ?goal-loc ?_rover-loc ?rover)
(:immediate communicate soil ?goal-loc ?rover)
(:immediate !!retract ((COMMUNICATE_SOIL_DATA ?goal-loc)))))

(:method (communicated_rock_data ?goal-loc ?rover)
(:method (communicated_rock_data ?goal-loc)
achieve-communicated-rock-data
((store_of ?s ?rover))
((navigate ?rover ?goal-loc)
(:immediate empty-store ?s ?rover)
((rover ?rover)
(store_of ?s ?rover))
((navigate ?rover ?goal-loc)
(:immediate empty-store ?s ?rover)
(:immediate !sample_rock ?rover ?s ?goal-loc)
(:immediate communicate ROCK ?goal-loc ?_rover-loc ?rover)
(:immediate communicate ROCK ?goal-loc ?rover)
(:immediate !!retract ((COMMUNICATE_ROCK_DATA ?goal-loc)))))

(:method (communicated_image_data ?obj ?mode ?rover)
(:method (communicated_image_data ?obj ?mode)
achieve-communicated-image-data
((on_board ?camera ?rover)
(supports ?camera ?mode)
(at_lander ?_lander ?lander-loc))
(supports ?camera ?mode))
((calibrate-camera ?rover ?camera)
(get-line-of-sight ?rover ?obj ?photo-loc)
(!take_image ?rover ?photo-loc ?obj ?camera ?mode)
;; navigate to a transmission location and transmit
(communicate-image ?photo-loc ?lander-loc ?rover ?obj ?mode)
;; move to a photo location, take the image, then move to
;; a position that has line of sight to a lander and communicate
;; the image.
(get-image ?rover ?obj ?camera ?mode)
(:immediate !!retract ((COMMUNICATE_IMAGE_DATA ?obj ?mode)))))

(:method (get-image ?rover ?obj ?camera ?mode)
have-line-of-sight-for-photo
((at ?rover ?photo-loc)
(visible_from ?obj ?photo-loc)
(at_lander ?_lander ?lander-loc))
((!take_image ?rover ?photo-loc ?obj ?camera ?mode)
;; navigate to a transmission location and transmit
(communicate-image ?photo-loc ?lander-loc ?rover ?obj ?mode)))

(:method (get-image ?rover ?obj ?camera ?mode)
need-line-of-sight
((at ?rover ?rover-loc)
(not (visible_from ?obj ?rover-loc))
(visible_from ?obj ?photo-loc)
(at_lander ?_lander ?lander-loc))
(:ordered (navigate ?rover ?photo-loc)
(!take_image ?rover ?photo-loc ?obj ?camera ?mode)
;; navigate to a transmission location and transmit
(communicate-image ?photo-loc ?lander-loc ?rover ?obj ?mode)))

(:method (calibrate-camera ?rover ?camera)
camera-already-calibrated
((calibrated ?camera ?rover))
Expand All @@ -272,24 +304,11 @@
(:ordered (navigate ?rover ?calibration-loc)
(!calibrate ?rover ?camera ?calibration-obj ?calibration-loc)))

(:method (get-line-of-sight ?rover ?obj ?photo-loc)
have-line-of-sight-for-photo
((at ?rover ?photo-loc)
(visible_from ?obj ?photo-loc))
())

(:method (get-line-of-sight ?rover ?obj ?photo-loc)
need-line-of-sight
((at ?rover ?rover-loc)
(not (visible_from ?obj ?rover-loc))
(visible_from ?obj ?photo-loc))
(:ordered (navigate ?rover ?photo-loc)))


;; HELPERS
;; the following shows a need for some higher-order method constructs

(:method (communicate soil ?analysis-loc ?rover-loc ?rover)
(:method (communicate soil ?analysis-loc ?rover)
have-line-of-sight-for-soil
((at ?rover ?rover-loc)
(at_lander ?l ?lander-loc)
Expand All @@ -298,7 +317,7 @@
?lander-loc)))


(:method (communicate soil ?analysis-loc ?rover-loc ?rover)
(:method (communicate soil ?analysis-loc ?rover)
go-to-line-of-sight-for-soil
;; Otherwise, go somewhere where the lander is visible
((at ?rover ?rover-loc)
Expand All @@ -310,15 +329,15 @@
(!communicate_soil_data ?rover ?l ?analysis-loc ?new-loc
?lander-loc)))

(:method (communicate rock ?analysis-loc ?rover-loc ?rover)
(:method (communicate rock ?analysis-loc ?rover)
have-line-of-sight-for-rock
((at ?rover ?rover-loc)
(at_lander ?l ?lander-loc)
(visible ?rover-loc ?lander-loc))
((!communicate_rock_data ?rover ?l ?analysis-loc ?rover-loc
?lander-loc)))

(:method (communicate rock ?analysis-loc ?rover-loc ?rover)
(:method (communicate rock ?analysis-loc ?rover)
go-to-line-of-sight-for-rock
;; Otherwise, go somewhere where the lander is visible
((at ?rover ?rover-loc)
Expand All @@ -330,15 +349,15 @@
(!communicate_rock_data ?rover ?l ?analysis-loc ?new-loc
?lander-loc)))

(:method (communicate image ?analysis-loc ?rover-loc ?rover)
(:method (communicate image ?analysis-loc ?rover)
have-line-of-sight-for-image
((at ?rover ?rover-loc)
(at_lander ?l ?lander-loc)
(visible ?rover-loc ?lander-loc))
((!communicate_image_data ?rover ?l ?analysis-loc ?rover-loc
?lander-loc)))

(:method (communicate image ?analysis-loc ?rover-loc ?rover)
(:method (communicate image ?analysis-loc ?rover)
go-to-line-of-sight-for-image
;; Otherwise, go somewhere where the lander is visible
((at ?rover ?rover-loc)
Expand Down Expand Up @@ -372,7 +391,7 @@
(visible ?new-loc ?lander-loc)
(different ?loc ?new-loc))

((navigate ?rover ?new-loc)
((navigate ?rover ?new-loc)
(!communicate_image_data ?rover ?l ?obj ?mode ?new-loc
?lander-loc)))

Expand All @@ -382,17 +401,17 @@
;; State axioms
(:- (same ?x ?x) nil)
(:- (different ?x ?y) ((not (same ?x ?y))))


;; This is a simple implementation that looks for an existence of a
;; path, not necessarily a shortest or best path.
(:- (path ?_rover ?from ?from nil ?_visited)
nil)

(:- (path ?rover ?from ?to (?to . nil) ?_visited)
((not (same ?from ?to))
(can_traverse ?rover ?from ?to)))

(:- (path ?rover ?from ?to (?to1 . ?path1) ?visited)
((not (same ?from ?to))
(not (can_traverse ?rover ?from ?to))
Expand Down
Loading

0 comments on commit 1b35cdb

Please sign in to comment.