|
| 1 | +# Copyright 2015, Vincent Leclere, Francois Pacaud and Henri Gerard |
| 2 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | +# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | +############################################################################# |
| 6 | +# Display SDDP simulations with matplotlib |
| 7 | +############################################################################# |
| 8 | + |
| 9 | +# WARNING: Matplotlib and PyCall must be installed! |
| 10 | +using PyPlot |
| 11 | + |
| 12 | +""" |
| 13 | +Display evolution of stocks. |
| 14 | +
|
| 15 | +Parameters: |
| 16 | +- model (SPModel) |
| 17 | +
|
| 18 | +- stocks (Array{Float64, 3}) |
| 19 | +
|
| 20 | +""" |
| 21 | +function display_stocks(model, stocks) |
| 22 | + |
| 23 | + ndims = size(stocks)[3] |
| 24 | + nsteps = model.stageNumber |
| 25 | + |
| 26 | + figure() |
| 27 | + for ind in 1:ndims |
| 28 | + subplot(ndims, 1, ind) |
| 29 | + plot(stocks[:, :, ind], lw=.5, color="k") |
| 30 | + xlim(0, nsteps) |
| 31 | + grid() |
| 32 | + ylabel(string("X", ind)) |
| 33 | + end |
| 34 | + xlabel("Time") |
| 35 | +end |
| 36 | + |
| 37 | + |
| 38 | +""" |
| 39 | +Display evolution of controls. |
| 40 | +
|
| 41 | +Parameters: |
| 42 | +- model (SPModel) |
| 43 | +
|
| 44 | +- controls (Array{Float64, 3}) |
| 45 | +
|
| 46 | +""" |
| 47 | +function display_controls(model, controls) |
| 48 | + |
| 49 | + ndims = size(controls)[3] |
| 50 | + nsteps = model.stageNumber |
| 51 | + |
| 52 | + figure() |
| 53 | + for ind in 1:ndims |
| 54 | + subplot(ndims, 1, ind) |
| 55 | + plot(controls[:, :, ind], lw=.5, color="k") |
| 56 | + xlim(0, nsteps) |
| 57 | + grid() |
| 58 | + ylabel(string("U", ind)) |
| 59 | + end |
| 60 | + xlabel("Time") |
| 61 | +end |
| 62 | + |
| 63 | + |
| 64 | +""" |
| 65 | +Display costs distribution along scenarios. |
| 66 | +
|
| 67 | +Parameters: |
| 68 | +- costs (Vector{Float64}) |
| 69 | +
|
| 70 | +""" |
| 71 | +function display_costs_distribution(costs) |
| 72 | + figure() |
| 73 | + boxplot(costs, boxprops=Dict(:linewidth=>3, :color=>"k")) |
| 74 | + ylabel("Costs") |
| 75 | + grid() |
| 76 | +end |
| 77 | + |
| 78 | + |
| 79 | +""" |
| 80 | +Display distributions of aleas along time. |
| 81 | +
|
| 82 | +Parameters: |
| 83 | +- aleas (Array{Float64, 3}) |
| 84 | +
|
| 85 | +""" |
| 86 | +function display_aleas(aleas) |
| 87 | + ndims = size(aleas)[3] |
| 88 | + nsteps = size(aleas)[1] |
| 89 | + |
| 90 | + figure() |
| 91 | + for ind in 1:ndims |
| 92 | + subplot(ndims, 1, ind) |
| 93 | + plot(1:nsteps, mean(aleas[:, :, ind], 2), lw=2, color="k") |
| 94 | + box = boxplot(aleas[:, :, ind]', widths=.25, boxprops=Dict(:color=>"k", :marker=>"+")) |
| 95 | + xlim(0, nsteps) |
| 96 | + grid() |
| 97 | + ylabel(string("\$W_", ind, "\$")) |
| 98 | + end |
| 99 | + xlabel("Time") |
| 100 | + |
| 101 | +end |
| 102 | + |
| 103 | + |
| 104 | +""" |
| 105 | +Display evolution of execution time along SDDP iterations. |
| 106 | +
|
| 107 | +Parameters: |
| 108 | +- exectime (Vector{Float64}) |
| 109 | +
|
| 110 | +""" |
| 111 | +function display_execution_time(exectime) |
| 112 | + nit = size(exectime)[1] |
| 113 | + |
| 114 | + figure() |
| 115 | + plot(exectime, lw=.5, color="k") |
| 116 | + grid() |
| 117 | + xlim(0, nit) |
| 118 | + xlabel("Iteration") |
| 119 | + ylabel("Execution time (s)") |
| 120 | +end |
| 121 | + |
| 122 | + |
| 123 | +""" |
| 124 | +Display evolution of upper and lower bounds along SDDP iterations. |
| 125 | +
|
| 126 | +Parameters: |
| 127 | +- model (SPModel) |
| 128 | +
|
| 129 | +""" |
| 130 | +function display_bounds(model) |
| 131 | + nit = size(model.upperbounds)[1] |
| 132 | + |
| 133 | + figure() |
| 134 | + plot(model.upperbounds, lw=2, color="r", label="Upper bound") |
| 135 | + plot(model.lowerbounds, lw=2, color="g", label="Lower bound") |
| 136 | + xlabel("Iteration") |
| 137 | + ylabel("Estimation of bounds") |
| 138 | + grid() |
| 139 | + legend() |
| 140 | +end |
| 141 | + |
| 142 | + |
| 143 | +""" |
| 144 | +Display results of SDDP simulation. |
| 145 | +
|
| 146 | +""" |
| 147 | +function display_all(model, costs, stocks, controls, aleas) |
| 148 | + display_aleas(aleas) |
| 149 | + display_controls(model, controls) |
| 150 | + display_stocks(model, stocks) |
| 151 | +end |
| 152 | + |
0 commit comments