run-experiments.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # Number to run in parallel
  3. parallel="$1"
  4. # Number of runs in each configuration
  5. n="$2"
  6. # First and last configuration of experiment 1
  7. e1b="$3"
  8. e1e="$4"
  9. # First and last configuration of experiment 2
  10. e2b="$5"
  11. e2e="$6"
  12. # Build docker container
  13. docker build -t troll-patrol .
  14. # Parameters should be:
  15. # $1: experiment number (1 or 2)
  16. # $2: censor secrecy (Overt or Flooding)
  17. # $3: harshness (0-4)
  18. # $4: probability of users submitting reports (0.0-1.0)
  19. run_docker() {
  20. # Get a UUID so each simulation run stores its output in a different file
  21. uuid=$(cat /proc/sys/kernel/random/uuid)
  22. ./scripts/gen-configs.sh $1 $2 $3 $4 $uuid
  23. ./scripts/run-container.sh $1 $uuid
  24. # If harshness = 2, probability of users submitting reports=0.25,
  25. # experiment number = 1, then copy the results to experiment 2
  26. # directory.
  27. if [[ "$3" == 2 && "$4" == 0.25 && "$1" == 1 ]]; then
  28. mkdir -p results/2
  29. cp results/1/${uuid}-* results/2/
  30. fi
  31. }
  32. # Make list of all configurations to use
  33. configs=()
  34. # Experiment 1
  35. for i in $(seq $e1b $e1e); do
  36. line=$(sed -n "${i}p" configs/experiment-1)
  37. for j in $(seq $n); do
  38. configs+=( "1 $line" )
  39. done
  40. done
  41. # Experiment 2
  42. for i in $(seq $e2b $e2e); do
  43. line=$(sed -n "${i}p" configs/experiment-2)
  44. for j in $(seq $n); do
  45. configs+=( "2 $line" )
  46. done
  47. done
  48. # Go through configs in batches of $n
  49. index=0
  50. while [[ $index -lt ${#configs[@]} ]]; do
  51. # Note: Elements contain multiple tokens. Don't put this in quotes.
  52. run_docker ${configs[$index]} &
  53. index=$((index + 1))
  54. if [[ $(($index % parallel)) == 0 ]]; then
  55. # Finish this batch before starting the next one
  56. wait
  57. fi
  58. done
  59. # Finish the final batch
  60. wait