#!/bin/bash
#Run from problem directory, no input arguments are relevant for us, the instance is piped on stdin

ASPINSTANCE=tmp.aspinstance`date +%s`
INSTANCE=tmp.instance`date +%s`
SOLUTION=tmp.solution`date +%s`

touch $ASPINSTANCE
touch $INSTANCE
touch $SOLUTION

DIRNAME=`dirname $0`

CORRECT=1
if [[ $CORRECT -eq 1 ]]
then 
	cat /dev/stdin | shifter -ss -nS -q >$ASPINSTANCE
	"$DIRNAME/lp2idp" $ASPINSTANCE "$INSTANCE" `cat "$DIRNAME/trans"`
	RESULT=$?
	if [[ RESULT -ne 0 ]]
	then
		CORRECT=0
	fi
fi

if [[ $CORRECT -eq 1 ]]
then 
	"$DIRNAME/gidl" "$DIRNAME/fastest.idp" "$INSTANCE" -W --maxapp=6 --verbose | "$DIRNAME/minisatid" --verbosity=1 --outputformat=asp
	RESULT=$?
	if [[ RESULT -ne 10 && RESULT -ne 20 ]]
	then
		CORRECT=0
	fi
fi

if [[ $CORRECT -eq 0 ]]
then
	echo "UNKNOWN"
fi

rm "$ASPINSTANCE" 2>/dev/null
rm "$INSTANCE" 2>/dev/null
rm "$SOLUTION" 2>/dev/null
