#!/bin/sh

PROGRAM=./mslave
if test ! "x$1" = x; then
  PROGRAM=$1
fi
GENERIC_DEPLOYMENT_FILE=deployment_generic.xml
if test ! "x$2" = x; then
  GENERIC_DEPLOYMENT_FILE=$2
fi
echo "Using $PROGRAM and $GENERIC_DEPLOYMENT_FILE";

FLAG="first"

#FASTEST_FIRST = 1

rm -f toto*.dat
rm -f gnuplot-command
touch toto.dat

echo "set terminal postscript eps color" >> gnuplot-command
echo "set xlabel \"Number of Tasks\"" >> gnuplot-command
echo "set ylabel \"Makespan\"" >> gnuplot-command
echo "set key left top" >> gnuplot-command


for request in `seq 8 8` ; do
   for heuristic in `seq 1 6` ; do

       case $heuristic in
	   1 ) 
	       TITLE="FASTEST_FIRST" ;;
	   * )
	       TITLE="UNKNOWN" ;;
       esac

      for nb_task in `seq 20 20 120` ; do
         cat $GENERIC_DEPLOYMENT_FILE | sed "s/max_request/$request/" | \
            sed "s/heuristic/$heuristic/" | sed "s/nb_task/$nb_task/" >  deployment.xml ;
         echo "max_request=$request  heuristic=$heuristic nb_task=$nb_task";
         time=`$PROGRAM platform.xml deployment.xml 2>/dev/null  | sed 's/.* //g'`;
         echo "-> $time";
         echo "$nb_task $time" >> toto-$request-$heuristic.dat;
      done;

      if [ "$FLAG" = "first" ] ; then
	  echo "plot \"toto-$request-$heuristic.dat\" with linespoints title \"$TITLE\"\\" >> gnuplot-command;
	  FLAG=last
      else
	  echo ", \"toto-$request-$heuristic.dat\" with linespoints title \"$TITLE\" \\" >> gnuplot-command;
      fi

   done
done
echo "" >> gnuplot-command
gnuplot < gnuplot-command > toto.eps
evince toto.eps