Skip to content

Commit

Permalink
add timing
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorb1 committed Jan 11, 2025
1 parent c21ae96 commit fc11c4c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/osemosys_step/snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,36 @@ rule solve_lp:
output:
sol_file = "steps/{option}/model.sol"
params:
ilp = "steps/{option}/model.ilp"
ilp = "steps/{option}/model.ilp",
log:
log = "logs/solves/{option}/model.log"
log = "logs/solves/{option}/model.log",
solve_time = "logs/solves/{option}/solve_time.log"
shell:
"""
start_time=$(date +%s%3N)

if [ {config[solver]} = gurobi ]
then
gurobi_cl Method=2 ResultFile={output.sol_file} ResultFile={params.ilp} {input.lp_file}
end_time=$(date +%s%3N)
elif [ {config[solver]} = cbc ]
then
cbc {input.lp_file} solve -solu {output.sol_file}
end_time=$(date +%s%3N)
elif [ {config[solver]} = cplex ]
then
cplex -c "read {input.lp_file}" "optimize" "write {output.sol_file}"
end_time=$(date +%s%3N)
elif [ {config[solver]} = glpk ]
then
cp ../model/osemosys.txt ../steps/{wildcards.option}/osemosys.txt &&
cd ../steps/{wildcards.option} &&
mkdir results &&
glpsol -m osemosys.txt -d data_pp.txt -w model.sol
end_time=$(date +%s%3N)
fi > {log.log}

solve_time=$(awk "BEGIN {{print ($end_time - $start_time) / 1000}}")

printf "Solve Time: %.3f seconds" "$solve_time" > {log.solve_time}
"""

0 comments on commit fc11c4c

Please sign in to comment.