#! /bin/bash ############################################################################# # Propositional Ferry 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. # ############################################################################# # 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 #port #car [#seed]" echo " #port : number of ports (>= 2)" echo " #car : number of cars (>= 1)" echo " #seed : optional seed for random number generation" echo "Description:" echo " > the propositional ferry can have only one car on board." echo " > the cars at different ports are to be carried to other ports." 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 " port car" echo " )" echo " (:predicates" echo " (ferry-empty)" echo " (ferry-at-port ?p - port)" echo " (car-at-port ?c - car ?p - port)" echo " (car-on-ferry ?c - car)" echo " )" echo " (:action embark" echo " :parameters (?c - car ?p - port)" echo " :precondition" echo " (and" echo " (car-at-port ?c ?p)" echo " (ferry-at-port ?p)" echo " (ferry-empty)" echo " )" echo " :effect" echo " (and" echo " (not (car-at-port ?c ?p))" echo " (not (ferry-empty))" echo " (car-on-ferry ?c)" echo " )" echo " )" echo " (:action debark" echo " :parameters (?c - car ?p - port)" echo " :precondition" echo " (and" echo " (car-on-ferry ?c)" echo " (ferry-at-port ?p)" echo " )" echo " :effect" echo " (and" echo " (not (car-on-ferry ?c))" echo " (car-at-port ?c ?p)" echo " (ferry-empty)" echo " )" echo " )" echo " (:action sail" echo " :parameters (?fp ?tp - port)" echo " :precondition" echo " (and" echo " (ferry-at-port ?fp)" if [[ -z $EQUALITY || $EQUALITY == "ey" ]] then echo " (not (= ?fp ?tp))" fi echo " )" echo " :effect" echo " (and" echo " (not (ferry-at-port ?fp))" echo " (ferry-at-port ?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-$PORT-$CAR)" echo " (:domain $DOMAIN)" echo " (:objects" for (( i = 0; i < PORT; i++ )) do echo " p$i" # port done echo " - port" for (( i = 0; i < CAR; i++ )) do echo " c$i" # car done echo " - car" echo " )" declare -i INITCARATPORT declare -i GOALCARATPORT for(( i = 0; i < CAR; i++)) do INITCARATPORT[$i]=$((RANDOM % PORT)) GOALCARATPORT[$i]=$((RANDOM % PORT)) while ((INITCARATPORT[$i] == GOALCARATPORT[$i])) do GOALCARATPORT[$i]=$((RANDOM % PORT)) done done echo " (:init" echo " (ferry-empty)" echo " (ferry-at-port p$((RANDOM % PORT)))" for((k = 0; k < CAR; k++)) do echo " (car-at-port c$k p${INITCARATPORT[$k]})" done echo " )" echo " (:goal" echo " (and" for((k = 0; k < CAR; k++)) do echo " (car-at-port c$k p${GOALCARATPORT[$k]})" done echo " )" echo " )" echo ")" echo return 0 } # main body if [[ $OPTION == "-p" ]] then declare -i PORT=$2 # number of ports declare -i CAR=$3 # number of cars declare -i SEED=$4 # optional seed for random number generation if (( ($COUNT == 3 || $COUNT == 4) && $PORT >= 2 && $CAR >= 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 $?