#!/bin/bash
# This bash script downloads and compiles all the code that is required to build my mgjpomdp package. This script
# assumes that cplex is installed. The paths to cplex should be set in the mgjpomdp/build.xml file. The execution of the
# main program requires -Djava.library.path=/opt/ibm/ILOG/CPLEX_Studio1261/cplex/bin/x86-64_linux/ and
# /opt/ibm/ILOG/CPLEX_Studio1261/cplex/lib/cplex.jar as well.
#
# Marek Grzes
echo "about to build all dependencies"
echo "note that all jar files will be copied to $HOME/lib"
# this should be ../mgjpomdp-IPI-branch
CURRDIR=$(pwd)
mkdir -p $HOME/lib
cd $HOME/lib/
wget https://www.cs.kent.ac.uk/people/staff/mg483/code/IPI/trove-3.0.3.jar
wget https://www.cs.kent.ac.uk/people/staff/mg483/code/IPI/trove-3.0.3-src.jar
wget https://www.cs.kent.ac.uk/people/staff/mg483/code/IPI/junit-4.11.jar
cd $CURRDIR
echo "build mgjcommon"
hg clone https://mgrzes@bitbucket.org/mgrzes/mgjcommon
cd mgjcommon/
ant dist dist-src
echo "at this point you should see mgjcommon.jar and mgjcommon-src.jar in $HOME/lib"
cd $CURRDIR
echo "build matrix toolkits for java"
hg clone https://bitbucket.org/mgrzes/mtj-mdp
cd mtj-mdp/
ant package
echo "at this point you should see Matrix_Toolkits_for_Java.jar and Matrix_Toolkits_for_Java-src.jar in $HOME/lib"
cd $HOME/lib
wget https://www.cs.kent.ac.uk/people/staff/mg483/code/IPI/antlrworks-1.4.3.jar
wget https://www.cs.kent.ac.uk/people/staff/mg483/code/IPI/glpk-java.jar
wget https://www.cs.kent.ac.uk/people/staff/mg483/code/IPI/jmatharray.jar
cd $CURRDIR
echo "build the POMDP parser; note that this package has to be compiled after mtj-mdp"
echo "this package is required by mglibpomdp"
#sudo apt-get install libglpk-java
git clone https://github.com/mgrzes/libpomdp.git
cd libpomdp
ln -s $HOME/lib external
ant
cd $CURRDIR
echo "build mgjpomdp"
cd mgjpomdp-IPI-branch
ant dist-one-jar
echo "check if the final program can be executed"
java -cp dist/mgjpomdp-ALL.jar mgjpomdp.apps.IPI --help
echo "run the planner on the tiger problem; the logs will be saved in /tmp"
java -Djava.library.path=/opt/ibm/ILOG/CPLEX_Studio1261/cplex/bin/x86-64_linux/ \
-cp dist/mgjpomdp-ALL.jar:/opt/ibm/ILOG/CPLEX_Studio1261/cplex/lib/cplex.jar mgjpomdp.apps.IPI --show-fsc \
--init-num-nodes=1 --node-rewiring DETocf --max-num-nodes 5