Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #!/bin/sh
  2. num_items=$1 # number of items to generate for the knapsack
  3. weight_low=100 # low end of item weigths range
  4. weight_high=1000000 # high end of item weights range
  5. value_low=1 # low end of item values range
  6. value_high=1000 # high end of item values range
  7.  
  8. echo "\ngenerating item weights (=how heavy they are)..."
  9. w_out=/tmp/weights-${num_items}.csv
  10. echo "weight" > ${w_out}
  11. shuf -i ${weight_low}-${weight_high} -n ${num_items} -r >> ${w_out}
  12.  
  13. echo "\ngenerating item values (=how valuable they are)..."
  14. v_out=/tmp/values-${num_items}.csv
  15. echo "value" > ${v_out}
  16. shuf -i ${value_low}-${value_high} -n ${num_items} -r >> ${v_out}
  17.  
  18. out=items-${num_items}.csv
  19. echo "\nsaving items into \"${out}\"..."
  20. paste -d, ${w_out} ${v_out}> ${out}
  21.  
  22. echo "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement