Skip to content

Commit 744b262

Browse files
committed
Update
1 parent e46b123 commit 744b262

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

test/FileFormats/MPS/MPS.jl

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,109 @@ function test_issue_2538()
12771277
return
12781278
end
12791279

1280+
function test_qmatrix_objective()
1281+
file = """
1282+
NAME
1283+
ROWS
1284+
N OBJ
1285+
COLUMNS
1286+
x OBJ 1
1287+
y OBJ 1
1288+
RHS
1289+
RANGES
1290+
BOUNDS
1291+
FR bounds x
1292+
FR bounds y
1293+
QMATRIX
1294+
x x 10
1295+
x y 2.0
1296+
y x 2.0
1297+
y y 2.0
1298+
ENDATA
1299+
"""
1300+
io = IOBuffer()
1301+
print(io, file)
1302+
seekstart(io)
1303+
model = MPS.Model()
1304+
read!(io, model)
1305+
x, y = MOI.get.(model, MOI.VariableIndex, ["x", "y"])
1306+
F = MOI.ScalarQuadraticFunction{Float64}
1307+
@test isapprox(
1308+
MOI.get(model, MOI.ObjectiveFunction{F}()),
1309+
1.0 * x + 1.0 * y + 5.0 * x * x + 2.0 * x * y + 1.0 * y * y,
1310+
)
1311+
return
1312+
end
1313+
1314+
function test_qsection_objective()
1315+
file = """
1316+
NAME
1317+
ROWS
1318+
N OBJ
1319+
COLUMNS
1320+
x OBJ 1
1321+
y OBJ 1
1322+
RHS
1323+
RANGES
1324+
BOUNDS
1325+
FR bounds x
1326+
FR bounds y
1327+
QSECTION OBJ
1328+
x x 10
1329+
x y 2.0
1330+
y y 2.0
1331+
ENDATA
1332+
"""
1333+
io = IOBuffer()
1334+
print(io, file)
1335+
seekstart(io)
1336+
model = MPS.Model()
1337+
read!(io, model)
1338+
x, y = MOI.get.(model, MOI.VariableIndex, ["x", "y"])
1339+
F = MOI.ScalarQuadraticFunction{Float64}
1340+
@test isapprox(
1341+
MOI.get(model, MOI.ObjectiveFunction{F}()),
1342+
1.0 * x + 1.0 * y + 5.0 * x * x + 2.0 * x * y + 1.0 * y * y,
1343+
)
1344+
return
1345+
end
1346+
1347+
function test_qsection_row()
1348+
file = """
1349+
NAME
1350+
ROWS
1351+
N OBJ
1352+
L c1
1353+
COLUMNS
1354+
x c1 1
1355+
y c1 1
1356+
RHS
1357+
rhs c1 1
1358+
RANGES
1359+
BOUNDS
1360+
FR bounds x
1361+
FR bounds y
1362+
QSECTION c1
1363+
x x 10
1364+
x y 2.0
1365+
y y 2.0
1366+
ENDATA
1367+
"""
1368+
io = IOBuffer()
1369+
print(io, file)
1370+
seekstart(io)
1371+
model = MPS.Model()
1372+
read!(io, model)
1373+
x, y = MOI.get.(model, MOI.VariableIndex, ["x", "y"])
1374+
c1 = MOI.get(model, MOI.ConstraintIndex, "c1")
1375+
@test isapprox(
1376+
MOI.get(model, MOI.ConstraintFunction(), c1),
1377+
1.0 * x + 1.0 * y + 10.0 * x * x + 4.0 * x * y + 2.0 * y * y,
1378+
)
1379+
return
1380+
end
1381+
1382+
12801383
function test_qcmatrix_read_gurobi()
12811384
file = """
12821385
NAME

0 commit comments

Comments
 (0)