-
Notifications
You must be signed in to change notification settings - Fork 92
Description
Reported on Discourse: https://discourse.julialang.org/t/mathoptformat-jl-error-when-reading-mps-file-objective-functions-with-constant-terms/55683
CPLEX supports objective constants in MPS: https://www.ibm.com/support/knowledgecenter/SSSA5P_20.1.0/ilog.odms.cplex.help/CPLEX/FileFormats/topics/MPS_records.html
You can also declare an objective offset for a model in the RHS section of a file in MPS format. To do so, use the negative value of the offset, and declare it as the RHS of the objective function. For example, the following line declares an objective offset of 3.1415 (as in the example in the LP file format):
rhs obj -3.1415
Notice particularly the reversal of the sign from 3.1415 to -3.1415.
The writing code should be modified here:
MathOptInterface.jl/src/FileFormats/MPS/MPS.jl
Lines 347 to 371 in 4aebdf3
function _write_rhs(io, model, S, sense_char) | |
for index in MOI.get( | |
model, | |
MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{Float64},S}(), | |
) | |
row_name = MOI.get(model, MOI.ConstraintName(), index) | |
set = MOI.get(model, MOI.ConstraintSet(), index) | |
println( | |
io, | |
Card( | |
f2 = "rhs", | |
f3 = row_name, | |
f4 = sprint(print_shortest, value(set)), | |
), | |
) | |
end | |
end | |
function write_rhs(io::IO, model::Model) | |
println(io, "RHS") | |
for (set_type, sense_char) in SET_TYPES | |
_write_rhs(io, model, set_type, sense_char) | |
end | |
return | |
end |
The reading code should be modified here:
MathOptInterface.jl/src/FileFormats/MPS/MPS.jl
Lines 1012 to 1021 in 4aebdf3
function parse_single_rhs( | |
data, | |
row_name::String, | |
value::Float64, | |
items::Vector{String}, | |
) | |
row = get(data.name_to_row, row_name, nothing) | |
if row === nothing | |
error("ROW name $(row_name) not recognised. Is it in the ROWS field?") | |
end |