From 02c35b215fdb8f4fb5ce95f89e14462b0db2f75b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 17 Sep 2026 11:40:39 +0200 Subject: [PATCH] Replace ProductOfSets by RuntimeProductOfSets --- Project.toml | 2 +- src/MatrixOptInterface.jl | 1 - src/conic_form.jl | 6 ++-- src/product_of_sets.jl | 75 --------------------------------------- 4 files changed, 5 insertions(+), 79 deletions(-) delete mode 100644 src/product_of_sets.jl diff --git a/Project.toml b/Project.toml index 8895067..7101706 100644 --- a/Project.toml +++ b/Project.toml @@ -10,7 +10,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] FillArrays = "1.15.0" -MathOptInterface = "1.49" +MathOptInterface = "1.52" julia = "1.10" [extras] diff --git a/src/MatrixOptInterface.jl b/src/MatrixOptInterface.jl index 80c5a73..145daf2 100644 --- a/src/MatrixOptInterface.jl +++ b/src/MatrixOptInterface.jl @@ -65,7 +65,6 @@ end @enum VariableType CONTINUOUS INTEGER BINARY -include("product_of_sets.jl") include("conic_form.jl") include("matrix_input.jl") #include("change_form.jl") diff --git a/src/conic_form.jl b/src/conic_form.jl index 03fe18f..a43361d 100644 --- a/src/conic_form.jl +++ b/src/conic_form.jl @@ -26,10 +26,12 @@ function empty_geometric_conic_form( Tv, MOI.Utilities.MutableSparseMatrixCSC{Tv,Ti,I}, Vector{Tv}, - ProductOfSets{Tv}, + MOI.Utilities.RuntimeProductOfSets{Tv}, }(), ) - set_set_types(model.constraints.sets, cones) + for S in cones + MOI.Utilities.add_set_type(model.constraints.sets, S) + end return model end diff --git a/src/product_of_sets.jl b/src/product_of_sets.jl deleted file mode 100644 index 1a6a1df..0000000 --- a/src/product_of_sets.jl +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright (c) 2019: Joaquim Dias Garcia, and contributors -# -# Use of this source code is governed by an MIT-style license that can be found -# in the LICENSE.md file or at https://opensource.org/licenses/MIT. -# Copied from DiffOpt - -""" - ProductOfSets{T} <: MOI.Utilities.OrderedProductOfSets{T} - -The `MOI.Utilities.@product_of_sets` macro requires to know the list of sets -at compile time. In DiffOpt however, the list depends on what the user is going -to use as set as DiffOpt supports any set as long as it implements the -required function of MathOptSetDistances. -For this type, the list of sets can be given a run-time. -""" -mutable struct ProductOfSets{T} <: MOI.Utilities.OrderedProductOfSets{T} - """ - During the copy, this counts the number of rows corresponding to - each set. At the end of copy, `final_touch` is called, which - converts this list into a cumulative ordering. - """ - num_rows::Vector{Int} - - """ - A dictionary which maps the `set_index` and `offset` of a set to the - dimension, i.e., `dimension[(set_index,offset)] → dim`. - """ - dimension::Dict{Tuple{Int,Int},Int} - - """ - A sanity bit to check that we don't call functions out-of-order. - """ - final_touch::Bool - - set_types::Vector{Type} - set_types_dict::Dict{Type,Int} - - function ProductOfSets{T}() where {T} - return new( - Int[], - Dict{Tuple{Int,Int},Int}(), - false, - Type[], - Dict{Type,Int}(), - ) - end -end - -function MOI.Utilities.set_index(set::ProductOfSets, S::Type{<:MOI.AbstractSet}) - return get(set.set_types_dict, S, nothing) -end - -MOI.Utilities.set_types(set::ProductOfSets) = set.set_types - -function set_set_types(set::ProductOfSets, set_types) - resize!(set.num_rows, length(set_types)) - fill!(set.num_rows, 0) - resize!(set.set_types, length(set_types)) - copy!(set.set_types, set_types) - empty!(set.set_types_dict) - for i in eachindex(set_types) - set.set_types_dict[set_types[i]] = i - end - return -end - -function add_set_types(set::ProductOfSets, S::Type) - if !haskey(set.set_types_dict, S) - push!(set.num_rows, 0) - push!(set.set_types, S) - set.set_types_dict[S] = length(set.set_types) - return true - end - return false -end