Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/src/submodules/FileFormats/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ julia> print(read("file.mof.json", String))
"name": "MathOptFormat Model",
"version": {
"major": 1,
"minor": 4
"minor": 5
},
"variables": [
{
Expand Down Expand Up @@ -230,7 +230,7 @@ julia> good_model = JSON.parse("""
{
"version": {
"major": 1,
"minor": 4
"minor": 5
},
"variables": [{"name": "x"}],
"objective": {"sense": "feasibility"},
Expand All @@ -249,7 +249,7 @@ julia> bad_model = JSON.parse("""
{
"version": {
"major": 1,
"minor": 4
"minor": 5
},
"variables": [{"NaMe": "x"}],
"objective": {"sense": "feasibility"},
Expand Down
7 changes: 4 additions & 3 deletions src/FileFormats/MOF/MOF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import OrderedCollections
import JSON
import MathOptInterface as MOI

const SCHEMA_PATH = joinpath(@__DIR__, "mof.1.4.schema.json")
const VERSION = v"1.4"
const SCHEMA_PATH = joinpath(@__DIR__, "mof.1.5.schema.json")
const VERSION = v"1.5"
const SUPPORTED_VERSIONS =
(v"1.4", v"1.3", v"1.2", v"1.1", v"1.0", v"0.6", v"0.5", v"0.4")
(v"1.5", v"1.4", v"1.3", v"1.2", v"1.1", v"1.0", v"0.6", v"0.5", v"0.4")

const OrderedObject = OrderedCollections.OrderedDict{String,Any}
const UnorderedObject = Dict{String,Any}
Expand Down Expand Up @@ -92,6 +92,7 @@ MOI.Utilities.@model(

# Indicator is handled by UniversalFallback.
# Reified is handled by UniversalFallback.
# Scaled is handled bby UniversalFallback.

const Model = MOI.Utilities.UniversalFallback{InnerModel{Float64}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/schema#",
"$id": "https://jump.dev/MathOptFormat/schemas/mof.1.4.schema.json",
"$id": "https://jump.dev/MathOptFormat/schemas/mof.1.5.schema.json",
"title": "The schema for MathOptFormat",
"type": "object",
"required": ["version", "variables", "objective", "constraints"],
Expand All @@ -11,7 +11,7 @@
"required": ["minor", "major"],
"properties": {
"minor": {
"enum": [0, 1, 2, 3, 4]
"enum": [0, 1, 2, 3, 4, 5]
},
"major": {
"const": 1
Expand Down Expand Up @@ -765,8 +765,7 @@
}
}
}, {
"description": "The (vectorized) cone of symmetric positive semidefinite matrices, with `side_dimension` rows and columns, such that the off-diagonal entries are scaled by √2. The entries of the upper-right triangular part of the matrix are given column by column (or equivalently, the entries of the lower-left triangular part are given row by row).",
"examples": ["{\"type\": \"ScaledPositiveSemidefiniteConeTriangle\", \"side_dimension\": 2}"],
"description": "DEPRECATED: use the Scaled set combinned with PositiveSemidefiniteConeTriangle instead.",
"required": ["side_dimension"],
"properties": {
"type": {
Expand Down Expand Up @@ -1151,6 +1150,18 @@
"type": "number"
}
}
}, {
"description": "The set in the `set` field, scaled such that the inner product of two elements in the set is the same as the dot product of the two vector functions. This is most useful for solvers which require PSD matrices in _scaled_ form.",
"examples": ["{\"type\": \"Scaled\", \"set\": {\"type\": \"PositiveSemidefiniteConeTriangle\", \"side_dimension\": 2}}"],
"required": ["set"],
"properties": {
"type": {
"const": "Scaled"
},
"set": {
"$ref": "#/definitions/vector_sets"
}
}
}]
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/FileFormats/MOF/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ end
LogDetConeSquare,
PositiveSemidefiniteConeTriangle,
ScaledPositiveSemidefiniteConeTriangle, # Required for v1.4
Scaled, # Required for v1.5
PositiveSemidefiniteConeSquare,
HermitianPositiveSemidefiniteConeTriangle,
ExponentialCone,
Expand Down Expand Up @@ -543,6 +544,10 @@ function set_to_moi(
return MOI.Scaled(MOI.PositiveSemidefiniteConeTriangle(d))
end

function set_to_moi(::Val{:Scaled}, object::Object)
return MOI.Scaled(set_to_moi(object["set"]))
end

function set_to_moi(::Val{:PositiveSemidefiniteConeSquare}, object::Object)
return MOI.PositiveSemidefiniteConeSquare(object["side_dimension"])
end
Expand Down
6 changes: 3 additions & 3 deletions src/FileFormats/MOF/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ function moi_to_object(
end

function moi_to_object(
set::MOI.Scaled{MOI.PositiveSemidefiniteConeTriangle},
set::MOI.Scaled,
name_map::Dict{MOI.VariableIndex,String},
)
return OrderedObject(
"type" => "ScaledPositiveSemidefiniteConeTriangle",
"side_dimension" => set.set.side_dimension,
"type" => "Scaled",
"set" => moi_to_object(set.set, name_map),
)
end
22 changes: 22 additions & 0 deletions test/FileFormats/MOF/MOF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,18 @@ c1: [x1, x2, x3] in ScaledPositiveSemidefiniteConeTriangle(2)
)
end

function test_Scaled_PositiveSemidefiniteConeTriangle()
return _test_model_equality(
"""
variables: x1, x2, x3
minobjective: x1
c1: [x1, x2, x3] in Scaled(PositiveSemidefiniteConeTriangle(2))
""",
["x1", "x2", "x3"],
["c1"],
)
end

function test_PositiveSemidefiniteConeSquare()
return _test_model_equality(
"""
Expand Down Expand Up @@ -1364,6 +1376,16 @@ function test_integer_coefficients()
return
end

function test_ScaledPositiveSemidefiniteConeTriangle()
object = Dict(
"type" => "ScaledPositiveSemidefiniteConeTriangle",
"side_dimension" => 2,
)
@test MOF.set_to_moi(object) ==
MOI.Scaled(MOI.PositiveSemidefiniteConeTriangle(2))
return
end

end

TestMOF.runtests()
2 changes: 1 addition & 1 deletion test/FileFormats/MOF/nlp.mof.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "MathOptFormat Model",
"version": {
"major": 1,
"minor": 4
"minor": 5
},
"variables": [
{
Expand Down