#!/bin/sh
CURDIR=`pwd`
EXEDIR=`dirname $0`
EXENAME=`basename $0`

pushd $EXEDIR/.. >/dev/null
BASEDIR=`pwd`
popd >/dev/null

if [ -z "$1" -o -z "$2" ]
   then echo "Usage:  solve-cases Algorithm prefix [k] [start_num]"
   echo "where algorithm is the java class file with main,"
   echo "prefix is prepened to the case number (e.g. z for z-100),"
   echo "if k is specified the problem is kconsistent,"
   echo "and start_num (if specified) is the case to start with."
   exit
fi


if [ "$EXEDIR" == "." ]
    then EXEDIR=./
else EXEDIR=$EXEDIR/
fi

if [ "$3" == "k" ]
   then KVAL=k-
   KDIR=/strongK
else 
   if [ "$3" == "tr" ]
      then KVAL=tr-
      KDIR=/totalRand
   else KDIR=/notK
      KVAL=
   fi
fi

i=1
if [ "$4" ]
    then i=$4
fi
if [ "$5" ]
    then end=$5
else 
    end=1000
fi
while [ $i -le $end ]
    do echo "Solving $2 $3 case # $i using $1";
    /usr/bin/time -f "%U %S" -a -o $BASEDIR/output/results/$2-$KVAL$i-$1.time $EXEDIR$1 -q $BASEDIR/output/results$KDIR/$2-$i-$1.soln $BASEDIR/input$KDIR/$2-$i >>$BASEDIR/output/results/$2-$KVAL$i-$1.time
    cmp $BASEDIR/output/results$KDIR/$2-$i-$1.soln $BASEDIR/output/solutions$KDIR/$2-$i
    if [ $? -ne 0 ]
        then echo "Solutions do not match for $2$3-$i-$1.soln" >>$BASEDIR/output/results$KDIR/$2-mismatches.$1
    fi

    RESULTS=`cat $BASEDIR/output/results/$2-$KVAL$i-$1.time`

    if [ "$2" == "z" ]
        then TYPE=Zebra
    else TYPE=Sherlock
    fi
    if [ "$3" == "k" ]
        then STRONGK=StrongK
    else if [ "$3" == "tr" ]
        then STRONGK=totalRand
    else STRONGK=NotK
    fi
    fi

    echo -n "\"$TYPE\",\"$STRONGK\",\"$1\",\"$i\"" >>$BASEDIR/output/results/$TYPE$STRONGK-$1.csv

    for outpart in $RESULTS
       do echo -n ",\"$outpart\"" >>$BASEDIR/output/results/$TYPE$STRONGK-$1.csv 
    done
    echo "" >>$BASEDIR/output/results/$TYPE$STRONGK-$1.csv

    rm -f $BASEDIR/output/results/$2-$KVAL$i-$1.time
    i=`echo $i + 1 | bc`
done
# Copyright 2002-2003 University of Guelph, All Rights Reserved
# Copyright 2002-2003 University of Guelph, All Rights Reserved
