#!/bin/bash

# uruchamia generalizowanie grafow oraz liczy
# po kazdym zgeneralizwanym grafie (konfiguracji) podobienstwo miedzy
# tymi zgeneralizowanymi grafami

njobs=11
# exp_done_dir=done_experiments
exp_done_dir=/mnt/dane_eksperymenty/entailment/grafon-experiments/gen-graphs/13.01.2016/complex/
reldir=/mnt/dane_eksperymenty/entailment/new-2015-09/not-sampled-separated/with-other-rels-fixed/

# NCOUNTS=(1 2 3 4 5 6 7 8 9 10 15 20)
# TCOUNTS=(1 2 3 4 5 6 7 8 9 10 15 20)
NCOUNTS=(1)
TCOUNTS=(1)
# NCOUNTS=(20 15 10 9 8 7 6 5 4 3 2 1)
# TCOUNTS=(20 15 10 9 8 7 6 5 4 3 2 1)

run_parallel_summarizer()
{
  MN=${1}
  MT=${2}
  tmpfile=tmp-gener-entailment.job
  rm -f ${tmpfile}
  for relfile in `ls ${reldir}/*.rel.xml --sort=size`
  do
    bname=`basename $relfile|sed 's/.rel.xml//'`
    echo "python gsummarizer.py \
      -f /mnt/dane_eksperymenty/entailment/new-2015-09/not-sampled-separated/output.xml \
      -r $relfile \
      -c ~/repos/grafon/cfg/grafon.ini \
      -mn ${MN} \
      -mt ${MT} \
      --rel-name  ${bname}" >> ${tmpfile}
  done;

  if [ -e ${tmpfile} ]
  then
    parallel -j$njobs -a ${tmpfile}
    # parallel --tag --line-buffer -j$njobs -a ${tmpfile}
    rm -f ${tmpfile}
  fi
}


run_parallel_summarizer_whole()
{
  for mn in ${NCOUNTS[@]}; do
    for mt in ${TCOUNTS[@]}; do
      echo "[*] min num of nodes=$mn min num of tokens=$mt..."
      run_parallel_summarizer $mn $mt
    done
  done
}


run_parallel_sim_between()
{
  tmpfile=tmp-betweensim-entailment.job

  if [ ! -d ${exp_done_dir} ]
  then
    mkdir ${exp_done_dir}
  fi

  rm -f ${tmpfile}
  for dirname in `ls -d */ | grep grafon_graphs`
  do
    echo "python betweengsim.py \
      -d ${dirname} \
      -c ~/repos/grafon/cfg/grafon.ini && mv ${dirname} ${exp_done_dir}" >> ${tmpfile}
  done;

  if [ -e ${tmpfile} ]
  then
    parallel -j$njobs -a ${tmpfile}
    rm -f ${tmpfile}
  fi
}

run_parallel_res_summarizer()
{
  tmpfile=tmp-ressummarizer-entailment.job

  if [ ! -d ${exp_done_dir} ]
  then
    mkdir ${exp_done_dir}
  fi

  for dirname in `ls ${exp_done_dir}/ | grep grafon_graph`
  do
    outcsv="${exp_done_dir}/${dirname}.csv"
    resdir="${exp_done_dir}/${dirname}"
    echo "python res-summarizer.py -d ${resdir} -o ${outcsv}" >> ${tmpfile}
  done

  if [ -e ${tmpfile} ]
  then
    parallel -j$njobs -a ${tmpfile}
    rm -f ${tmpfile}
  fi
}


run_parallel_summarizer_whole
# run_parallel_sim_between
# run_parallel_res_summarizer

