Skip to content

Commit

Permalink
fix variable ownership issue when copying model
Browse files Browse the repository at this point in the history
  • Loading branch information
gsoleilhac committed Feb 3, 2018
1 parent 225dc0f commit 348b797
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/vOptGeneric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ mutable struct vOptData
objSenses::Vector{Symbol} #Objective Senses
Y_N::Vector{Vector{Float64}} #Objective values for each point
X_E::Vector{Vector{Float64}} #Variable values for each point
isacopy::Bool
end

Base.copy(vd::vOptData) = vOptData(deepcopy(vd.objs), deepcopy(vd.objSenses), [], [])
Base.copy(vd::vOptData) = vOptData(deepcopy(vd.objs), deepcopy(vd.objSenses), [], [], true)

function getvOptData(m::Model)
!haskey(m.ext, :vOpt) && error("This model wasn't created with vOptGeneric")
Expand All @@ -43,11 +44,17 @@ function vModel(;solver=JuMP.UnsetSolver())
m.ext[:vOpt] = vOptData(Vector{QuadExpr}(), #objs
Vector{Symbol}(), #objSenses
Vector{Vector{Float64}}(), #Y_N
Vector{Vector{Float64}}()) #X_E
Vector{Vector{Float64}}(), #X_E
false) #isacopy
return m
end

function solvehook(m::Model; suppress_warnings=false, method=nothing, step = 0.5)::Symbol
vd = getvOptData(m)
if vd.isacopy
vd.objs .= copy.(vd.objs, m)
end

if method == :epsilon
return solve_eps(m, step)
elseif method == :dicho || method == :dichotomy
Expand Down

0 comments on commit 348b797

Please sign in to comment.