Skip to content

Commit 3e3e998

Browse files
authored
[FileFormats.NL] fix reading defined variables that are not expressions (#2980)
1 parent b5778d0 commit 3e3e998

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/FileFormats/NL/read.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mutable struct _CacheModel
1717
objective::Expr
1818
sense::MOI.OptimizationSense
1919
complements_map::Dict{Int,Int}
20-
defined_variables::Dict{Int,Expr}
20+
defined_variables::Dict{Int,Union{Float64,MOI.VariableIndex,Expr}}
2121

2222
function _CacheModel()
2323
return new(
@@ -33,7 +33,7 @@ mutable struct _CacheModel
3333
:(),
3434
MOI.FEASIBILITY_SENSE,
3535
Dict{Int,Int}(),
36-
Dict{Int,Expr}(),
36+
Dict{Int,Union{Float64,MOI.VariableIndex,Expr}}(),
3737
)
3838
end
3939
end

test/FileFormats/NL/test_read.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,27 @@ function test_parse_V()
551551
return
552552
end
553553

554+
function test_parse_V_constant()
555+
model = NL._CacheModel()
556+
io = IOBuffer("V2 0 0\nn0\n")
557+
seekstart(io)
558+
NL._parse_section(io, model)
559+
@test length(model.defined_variables) == 1
560+
@test model.defined_variables[2] === 0.0
561+
return
562+
end
563+
564+
function test_parse_V_variable()
565+
model = NL._CacheModel()
566+
NL._resize_variables(model, 2)
567+
io = IOBuffer("V1 0 0\nv0\n")
568+
seekstart(io)
569+
NL._parse_section(io, model)
570+
@test length(model.defined_variables) == 1
571+
@test model.defined_variables[1] === MOI.VariableIndex(1)
572+
return
573+
end
574+
554575
function test_parse_L()
555576
model = NL._CacheModel()
556577
io = IOBuffer()

0 commit comments

Comments
 (0)