Skip to content

Commit

Permalink
add print functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mcosovic committed Sep 12, 2023
1 parent c8b203a commit c0630cb
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions src/utility/routine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,51 @@ function checkStatus(status)
end
end

######### Print Constraints ##########
######### Print Data ##########
import Base.print

function print(io::IO, obj::JuMP.Vector{ConstraintRef})
function print(io::IO, label::Dict{String, Int64}, data::Union{Array{Float64,1}, Array{Int64,1}, Array{Int8,1}})
names = collect(keys(sort(label; byvalue = true)))
for (k, i) in enumerate(data)
println(io::IO, names[k], ": ", i)
end
end

function print(io::IO, label::Dict{String, Int64}, data::BranchParameter)
fields = fieldnames(typeof(data))
numberFields = length(fields)
numberData = length(getfield(data, fields[1]))
names = collect(keys(sort(label; byvalue = true)))
for i = 1:numberData
print(io::IO, names[i], ": ")
for j = 1:numberFields
a = getfield(data, fields[j])
print(io::IO, a[i], " ")
end
println(io::IO)
end
end

function print(io::IO, label::Dict{String, Int64}, obj::JuMP.Vector{ConstraintRef})
names = collect(keys(sort(label; byvalue = true)))
for i in eachindex(obj)
try
println(obj[i])
println(names[i], ": ", obj[i])
catch
println("Undefined")
end
end
end

function print(io::IO, label::Dict{String, Int64}, obj::JuMP.Vector{Vector{ConstraintRef}})
names = collect(keys(sort(label; byvalue = true)))
for (k, con) in enumerate(obj)
try
for i in eachindex(con)
println(names[k], ": ", con[i])
end
catch
println("Undefined")
end
end
end

0 comments on commit c0630cb

Please sign in to comment.