-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from blegat/refact-stopcrit
Refact Stopping Criterion
- Loading branch information
Showing
5 changed files
with
154 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
export AbstractSDDPStats | ||
|
||
abstract AbstractSDDPStats | ||
|
||
type SDDPStats <: AbstractSDDPStats | ||
# number of calls to solver | ||
nsolved::Int | ||
# total time passed inside solver | ||
solvertime::Float64 | ||
# number of cuts merged | ||
nmerged::Int | ||
# time required to merge | ||
mergetime::Float64 | ||
# number of feasibility cuts | ||
nfcuts::Int | ||
fcutstime::Float64 | ||
# number of optimality cuts | ||
nocuts::Int | ||
ocutstime::Float64 | ||
nsetx::Int | ||
setxtime::Float64 | ||
|
||
# number of iterations | ||
niterations::Int | ||
# n forwards passes of last computation of upper-bound: | ||
npaths::Int | ||
# current lower bound | ||
lowerbound::Float64 | ||
# current lower bound | ||
upperbound::Float64 | ||
# upper-bound std: | ||
σ_UB::Float64 | ||
# total time | ||
time::Float64 | ||
end | ||
|
||
SDDPStats() = SDDPStats(0,.0,0,.0,0,.0,0,.0,0,.0, 0, 0, 0, 0, 0, 0) | ||
|
||
import Base: +, show | ||
|
||
# Add two `SDDPStats` objects and return a new `SDDPStats` | ||
# The second SDDPStats is supposed to be more up to date that the first one | ||
# WARNING: the addition is currently non commutative ! | ||
function +(a::SDDPStats, b::SDDPStats) | ||
SDDPStats(a.nsolved + b.nsolved, a.solvertime + b.solvertime, | ||
a.nmerged + b.nmerged, a.mergetime + b.mergetime, | ||
a.nfcuts + b.nfcuts , a.fcutstime + b.fcutstime, | ||
a.nocuts + b.nocuts , a.ocutstime + b.ocutstime, | ||
a.nsetx + b.nsetx , a.setxtime + b.setxtime, | ||
a.niterations + b.niterations , b.npaths, | ||
b.lowerbound, b.upperbound, | ||
b.σ_UB, a.time + b.time) | ||
end | ||
|
||
macro mytime(x) | ||
quote | ||
y = @timed $(esc(x)) | ||
# y[1] is returned value | ||
# y[2] is time in seconds | ||
y[2] | ||
end | ||
end | ||
|
||
|
||
function showtime(t::Float64) | ||
if !isfinite(t) | ||
" min s ms μs" | ||
else | ||
s = Int(floor(t)) | ||
t = (t - s) * 1000 | ||
min = div(s, 60) | ||
s = mod(s, 60) | ||
ms = Int(floor(t)) | ||
t = (t - ms) * 1000 | ||
μs = Int(floor(t)) | ||
@sprintf "%3dmin %3ds %3dms %3dμs" min s ms μs | ||
end | ||
end | ||
|
||
function Base.show(io::IO, stat::SDDPStats) | ||
println(" | Total time [s] | Number | Average time [s]") | ||
@printf " Solving problem | %s | %8d | %s\n" showtime(stat.solvertime) stat.nsolved showtime(stat.solvertime / stat.nsolved) | ||
@printf " Merging paths | %s | %8d | %s\n" showtime(stat.mergetime ) stat.nmerged showtime(stat.mergetime / stat.nmerged) | ||
@printf "Adding feasibility cuts | %s | %8d | %s\n" showtime(stat.fcutstime ) stat.nfcuts showtime(stat.fcutstime / stat.nfcuts ) | ||
@printf "Adding optimality cuts | %s | %8d | %s\n" showtime(stat.ocutstime ) stat.nocuts showtime(stat.ocutstime / stat.nocuts ) | ||
@printf "Setting parent solution | %s | %8d | %s\n" showtime(stat.setxtime ) stat.nsetx showtime(stat.setxtime / stat.nsetx ) | ||
@printf " | %s |" showtime(stat.solvertime+stat.fcutstime+stat.ocutstime+stat.setxtime) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters