|
4 | 4 | #
|
5 | 5 | # D. Orban, 2015, 2016.
|
6 | 6 |
|
| 7 | +using CSV, Tables |
| 8 | + |
7 | 9 | """Compute performance ratios used to produce a performance profile.
|
8 | 10 |
|
9 | 11 | There is normally no need to call this function directly.
|
@@ -152,3 +154,57 @@ function performance_profile(
|
152 | 154 | kwargs...,
|
153 | 155 | )
|
154 | 156 | end
|
| 157 | + |
| 158 | +""" |
| 159 | +export_performance_profile(T, filename; solver_names = [], header, kwargs...) |
| 160 | +
|
| 161 | +Export a performance profile plot data as .csv file. Profiles data are padded with `NaN` to ensure .csv consistency. |
| 162 | +
|
| 163 | +## Arguments |
| 164 | +
|
| 165 | +* `T :: Matrix{Float64}`: each column of `T` defines the performance data for a solver (smaller is better). |
| 166 | + Failures on a given problem are represented by a negative value, an infinite value, or `NaN`. |
| 167 | +* `filename :: String` : path to the export file. |
| 168 | +
|
| 169 | +## Keyword Arguments |
| 170 | +
|
| 171 | +* `solver_names :: Vector{S}` : names of the solvers |
| 172 | +* `header::Vector{String}`: Contains .csv file column names. Note that `header` value does not change columns order in .csv exported files (see Output). |
| 173 | +
|
| 174 | +Other keyword arguments are passed `performance_profile_data`. |
| 175 | +
|
| 176 | +Output: |
| 177 | +File containing profile data in .csv format. Columns are solver1_x, solver1_y, solver2_x, ... |
| 178 | +""" |
| 179 | +function export_performance_profile( |
| 180 | + T::Matrix{Float64}, |
| 181 | + filename::String; |
| 182 | + solver_names::Vector{S} = String[], |
| 183 | + header::Vector{S} = String[], |
| 184 | + kwargs... |
| 185 | +) where {S <: AbstractString} |
| 186 | + nsolvers = size(T)[2] |
| 187 | + |
| 188 | + x_data, y_data, max_ratio = performance_profile_data(T;kwargs...) |
| 189 | + max_elem = maximum(length.(x_data)) |
| 190 | + for i in eachindex(x_data) |
| 191 | + append!(x_data[i],[NaN for i=1:max_elem-length(x_data[i])]) |
| 192 | + append!(y_data[i],[NaN for i=1:max_elem-length(y_data[i])]) |
| 193 | + end |
| 194 | + x_mat = hcat(x_data...) |
| 195 | + y_mat = hcat(y_data...) |
| 196 | + |
| 197 | + isempty(solver_names) && (solver_names = ["solver_$i" for i = 1:nsolvers]) |
| 198 | + |
| 199 | + if !isempty(header) |
| 200 | + header_l = size(T)[2]*2 |
| 201 | + length(header) == header_l || error("Header should contain $(header_l) elements") |
| 202 | + header = vcat([[sname*"_x",sname*"_y"] for sname in solver_names]...) |
| 203 | + end |
| 204 | + data = Matrix{Float64}(undef,max_elem,nsolvers*2) |
| 205 | + for i =0:nsolvers-1 |
| 206 | + data[:,2*i+1] .= x_mat[:,i+1] |
| 207 | + data[:,2*i+2] .= y_mat[:,i+1] |
| 208 | + end |
| 209 | + CSV.write(filename,Tables.table(data),header=header) |
| 210 | +end |
0 commit comments