Skip to content

Commit e192c11

Browse files
committed
Allow creating model from parts
1 parent 80d5a32 commit e192c11

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/Utilities/matrix_of_constraints.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,24 @@ mutable struct MatrixOfConstraints{T,AT,BT,ST} <: MOI.ModelLike
9292
caches::Vector{Any}
9393
are_indices_mapped::Vector{BitSet}
9494
final_touch::Bool
95-
function MatrixOfConstraints{T,AT,BT,ST}() where {T,AT,BT,ST}
96-
model = new{T,AT,BT,ST}(AT(), BT(), ST(), Any[], BitSet[], false)
95+
function MatrixOfConstraints{T}(coefficients, constants, sets) where {T}
96+
model = new{T,typeof(coefficients),typeof(constants),typeof(sets)}(
97+
coefficients,
98+
constants,
99+
sets,
100+
Any[],
101+
BitSet[],
102+
false,
103+
)
97104
MOI.empty!(model)
98105
return model
99106
end
100107
end
101108

109+
function MatrixOfConstraints{T,AT,BT,ST}() where {T,AT,BT,ST}
110+
return MatrixOfConstraints{T}(AT(), BT(), ST())
111+
end
112+
102113
###
103114
### Interface for the .coefficients field
104115
###

src/Utilities/model.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ mutable struct GenericModel{T,O,V,C} <: AbstractModelLike{T}
3232
# A useful dictionary for extensions to store things. These are
3333
# _not_ copied between models.
3434
ext::Dict{Symbol,Any}
35-
function GenericModel{T,O,V,C}() where {T,O,V,C}
36-
return new{T,O,V,C}(
35+
function GenericModel{T}(objective, variables, constraints) where {T}
36+
return new{T,typeof(objective),typeof(variables),typeof(constraints)}(
3737
"",
38-
O(),
39-
V(),
40-
C(),
38+
objective,
39+
variables,
40+
constraints,
4141
Dict{MOI.VariableIndex,String}(),
4242
nothing,
4343
Dict{MOI.ConstraintIndex,String}(),
@@ -47,6 +47,10 @@ mutable struct GenericModel{T,O,V,C} <: AbstractModelLike{T}
4747
end
4848
end
4949

50+
function GenericModel{T,O,V,C}() where {T,O,V,C}
51+
return GenericModel{T}(O(), V(), C())
52+
end
53+
5054
abstract type AbstractOptimizer{T} <: MOI.AbstractOptimizer end
5155

5256
"""

0 commit comments

Comments
 (0)