#! /bin/bash ############################################################################# # Propositional Gripper Domain # ############################################################################# # Copyright (C) 2006 by Muhammad Abdul Hakim Newton mahnewton@gmail.com # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation; either version 2 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the # # Free Software Foundation, Inc., # # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################# # grippers and places are constant for the domain; not problem objects # global variables declare PROGRAM=$0 # program name declare -i COUNT=$# # parameter count declare DOMAIN=$(basename $0 | sed -r s/\.[[:alnum:]_-]+$//) # domain and file names are same declare OPTION=$1 # generate the domain (-d) or a problem (-p) or usage () # global functions declare -f explain declare -f domain declare -f problem # explain usage and game rules function explain { echo echo "Usage for domain:" echo " $PROGRAM -d [ey|en]" echo " ey : use object equality (default)" echo " en : do not use object equality" echo "Usage for problem:" echo " $PROGRAM -p #ball [#seed]" echo " #ball : number of balls (>= 1)" echo " #seed : optional seed for random number generation" echo "Description:" echo " > Balls from outside are to be taken inside a room and vice versa." echo " > The robot has two grippers to carry two balls while moving." echo return 2 } # generate the domain function domain { echo echo "(define" echo " (domain $DOMAIN)" echo " (:requirements" if [[ -z $EQUALITY || $EQUALITY == "ey" ]] then echo " :strips :typing :equality" else echo " :strips :typing" fi echo " )" echo " (:types" echo " ball gripper place" echo " )" echo " (:constants" echo " left right - gripper" echo " in out - place" echo " )" echo " (:predicates" echo " (gripper-empty ?g - gripper)" echo " (robot-at-place ?p - place)" echo " (ball-at-place ?b - ball ?p - place)" echo " (ball-at-gripper ?b - ball ?g - gripper)" echo " )" echo " (:action pick" echo " :parameters (?b - ball ?g - gripper ?p - place)" echo " :precondition" echo " (and" echo " (ball-at-place ?b ?p)" echo " (robot-at-place ?p)" echo " (gripper-empty ?g)" echo " )" echo " :effect" echo " (and" echo " (not (ball-at-place ?b ?p))" echo " (not (gripper-empty ?g))" echo " (ball-at-gripper ?b ?g)" echo " )" echo " )" echo " (:action drop" echo " :parameters (?b - ball ?g - gripper ?p - place)" echo " :precondition" echo " (and" echo " (ball-at-gripper ?b ?g)" echo " (robot-at-place ?p)" echo " )" echo " :effect" echo " (and" echo " (not (ball-at-gripper ?b ?g))" echo " (ball-at-place ?b ?p)" echo " (gripper-empty ?g)" echo " )" echo " )" echo " (:action move" echo " :parameters (?fp ?tp - place)" echo " :precondition" echo " (and" echo " (robot-at-place ?fp)" if [[ -z $EQUALITY || $EQUALITY == "ey" ]] then echo " (not (= ?fp ?tp))" fi echo " )" echo " :effect" echo " (and" echo " (not (robot-at-place ?fp))" echo " (robot-at-place ?tp)" echo " )" echo " )" echo ")" echo return 0 } function problem { if (( SEED != 0 )) # if a seed is given, use it then RANDOM=$SEED fi echo echo "(define" echo " (problem $DOMAIN-$BALL)" echo " (:domain $DOMAIN)" echo " (:objects" for (( i = 0; i < BALL; i++ )) do echo " b$i" # ball done echo " - ball" echo " )" declare -a BALLPLACE for((k = 0; k < BALL; k++)) do BALLPLACE[$k]=$RANDOM # initially odd for in and even for out, in goal the opposite done echo " (:init" echo " (robot-at-place out)" echo " (gripper-empty left)" echo " (gripper-empty right)" for((k = 0; k < BALL; k++)) do if (( BALLPLACE[k] % 2 == 0 )) then echo " (ball-at-place b$k out)" else echo " (ball-at-place b$k in)" fi done echo " )" echo " (:goal" echo " (and" for((k = 0; k < BALL; k++)) do if (( BALLPLACE[k] % 2 == 0 )) then echo " (ball-at-place b$k in)" else echo " (ball-at-place b$k out)" fi done echo " )" echo " )" echo ")" echo return 0 } # main body if [[ $OPTION == "-p" ]] then declare -i BALL=$2 # number of balls declare -i SEED=$3 # optional seed for random number generation if (( ($COUNT == 2 || $COUNT == 3) && $BALL >= 1)) then problem else echo echo " Error in parameter count or parameter values." echo explain fi elif [[ $OPTION == "-d" ]] then declare EQUALITY=$2 # optional equality (ey) no-equality (en) if [[ $COUNT -eq 1 || $COUNT -eq 2 && $EQUALITY == e[yn] ]] then domain else echo echo " Error in parameter count or parameter values." echo explain fi else explain fi exit $?