Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- num_items=$1 # number of items to generate for the knapsack
- weight_low=100 # low end of item weigths range
- weight_high=1000000 # high end of item weights range
- value_low=1 # low end of item values range
- value_high=1000 # high end of item values range
- echo "\ngenerating item weights (=how heavy they are)..."
- w_out=/tmp/weights-${num_items}.csv
- echo "weight" > ${w_out}
- shuf -i ${weight_low}-${weight_high} -n ${num_items} -r >> ${w_out}
- echo "\ngenerating item values (=how valuable they are)..."
- v_out=/tmp/values-${num_items}.csv
- echo "value" > ${v_out}
- shuf -i ${value_low}-${value_high} -n ${num_items} -r >> ${v_out}
- out=items-${num_items}.csv
- echo "\nsaving items into \"${out}\"..."
- paste -d, ${w_out} ${v_out}> ${out}
- echo "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement