Repository navigation
Expand file tree
/
Copy pathdatatypes.jl
More file actions
707 lines (593 loc) · 23.1 KB
/
Copy pathdatatypes.jl
File metadata and controls
707 lines (593 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
################################################################################
# LOGICAL VARIABLES
################################################################################
"""
LogicalVariableIndex
A type for storing the index of a [`LogicalVariable`](@ref).
**Fields**
- `value::Int64`: The index value.
"""
struct LogicalVariableIndex
value::Int64
end
"""
LogicalVariableRef{M <: JuMP.AbstractModel}
A type for looking up logical variables.
"""
struct LogicalVariableRef{M <:JuMP.AbstractModel} <: JuMP.AbstractVariableRef
model::M
index::LogicalVariableIndex
end
"""
LogicalVariable <: JuMP.AbstractVariable
A variable type the logical variables associated with disjuncts in a [`Disjunction`](@ref).
**Fields**
- `fix_value::Union{Nothing, Bool}`: A fixed boolean value if there is one.
- `start_value::Union{Nothing, Bool}`: An initial guess if there is one.
- `logical_complement::Union{Nothing, LogicalVariableRef}`: The logical complement of
this variable if there is one.
"""
struct LogicalVariable <: JuMP.AbstractVariable
fix_value::Union{Nothing, Bool}
start_value::Union{Nothing, Bool}
logical_complement::Union{Nothing, LogicalVariableRef}
end
# Wrapper variable type for including arbitrary tags that will be used for
# creating reformulation variables later on
struct _TaggedLogicalVariable{T} <: JuMP.AbstractVariable
variable::LogicalVariable
tag_data::T
end
"""
Logical{T}
Tag for creating logical variables using `@variable`. Most often this will
be used to enable the syntax:
```julia
@variable(model, var_expr, Logical, [kwargs...])
```
which creates a [`LogicalVariable`](@ref) that will ultimately be
reformulated into a binary variable of the form:
```julia
@variable(model, var_expr, Bin, [kwargs...])
```
To include a tag that is used to create the reformulated variables, the syntax
becomes:
```julia
@variable(model, var_expr, Logical(MyTag()), [kwargs...])
```
which creates a [`LogicalVariable`](@ref) that is associated with `MyTag()` such
that the reformulation binary variables are of the form:
```julia
@variable(model, var_expr, Bin, MyTag(), [kwargs...])
```
"""
struct Logical{T}
tag_data::T
end
"""
LogicalVariableData
A type for storing [`LogicalVariable`](@ref)s and any meta-data they
possess.
**Fields**
- `variable::LogicalVariable`: The logical variable object.
- `name::String`: The name of the variable.
"""
mutable struct LogicalVariableData
variable::LogicalVariable
name::String
end
################################################################################
# LOGICAL SELECTOR (CARDINALITY) SETS
################################################################################
# TODO check required methods for AbstractVectorSet:
# All AbstractVectorSets of type S must implement:
# • dimension, unless the dimension is
# stored in the set.dimension field
# • Utilities.set_dot, unless the dot
# product between two vectors in the set
# is equivalent to LinearAlgebra.dot.
"""
AbstractCardinalitySet <: MOI.AbstractVectorSet
An abstract type for cardinality sets [`_MOIAtLeast`](@ref), [`_MOIExactly`](@ref),
and [`_MOIAtMost`](@ref).
"""
abstract type AbstractCardinalitySet <:_MOI.AbstractVectorSet end
"""
_MOIAtLeast <: AbstractCardinalitySet
MOI level set for AtLeast constraints, see [`AtLeast`](@ref) for recommended syntax.
"""
struct _MOIAtLeast <: AbstractCardinalitySet
dimension::Int
end
"""
_MOIAtMost <: AbstractCardinalitySet
MOI level set for AtMost constraints, see [`AtMost`](@ref) for recommended syntax.
"""
struct _MOIAtMost <: AbstractCardinalitySet
dimension::Int
end
"""
_MOIExactly <: AbstractCardinalitySet
MOI level set for Exactly constraints, see [`Exactly`](@ref) for recommended syntax.
"""
struct _MOIExactly <: AbstractCardinalitySet
dimension::Int
end
# Create our own JuMP level sets to infer the dimension using the expression
"""
AtLeast{T<:Union{Int,LogicalVariableRef}} <: JuMP.AbstractVectorSet
Convenient alias for using [`_MOIAtLeast`](@ref).
"""
struct AtLeast{T<:Union{Int, LogicalVariableRef}} <: JuMP.AbstractVectorSet
value::T
end
"""
AtMost{T<:Union{Int,LogicalVariableRef}} <: JuMP.AbstractVectorSet
Convenient alias for using [`_MOIAtMost`](@ref).
"""
struct AtMost{T<:Union{Int, LogicalVariableRef}} <: JuMP.AbstractVectorSet
value::T
end
"""
Exactly <: JuMP.AbstractVectorSet
Convenient alias for using [`_MOIExactly`](@ref).
"""
struct Exactly{T<:Union{Int, LogicalVariableRef}} <: JuMP.AbstractVectorSet
value::T
end
# Extend JuMP.moi_set as needed
JuMP.moi_set(::AtLeast, dim::Int) = _MOIAtLeast(dim)
JuMP.moi_set(::AtMost, dim::Int) = _MOIAtMost(dim)
JuMP.moi_set(::Exactly, dim::Int) = _MOIExactly(dim)
################################################################################
# LOGICAL CONSTRAINTS
################################################################################
const _LogicalExpr{M} = JuMP.GenericNonlinearExpr{LogicalVariableRef{M}}
"""
ConstraintData{C <: JuMP.AbstractConstraint}
A type for storing constraint objects in [`GDPData`](@ref) and any meta-data
they possess.
**Fields**
- `constraint::C`: The constraint.
- `name::String`: The name of the proposition.
"""
mutable struct ConstraintData{C <: JuMP.AbstractConstraint}
constraint::C
name::String
end
"""
LogicalConstraintIndex
A type for storing the index of a logical constraint.
**Fields**
- `value::Int64`: The index value.
"""
struct LogicalConstraintIndex
value::Int64
end
"""
LogicalConstraintRef{M <: JuMP.AbstractModel}
A type for looking up logical constraints.
"""
struct LogicalConstraintRef{M <: JuMP.AbstractModel}
model::M
index::LogicalConstraintIndex
end
################################################################################
# DISJUNCT CONSTRAINTS
################################################################################
"""
Disjunct
Used as a tag for constraints that will be used in disjunctions. This is done via
the following syntax:
```julia-repl
julia> @constraint(model, [constr_expr], Disjunct)
julia> @constraint(model, [constr_expr], Disjunct(lvref))
```
where `lvref` is a [`LogicalVariableRef`](@ref) that will ultimately be associated
with the disjunct the constraint is added to. If no `lvref` is given, then one is
generated when the disjunction is created.
"""
struct Disjunct{M <: JuMP.AbstractModel}
indicator::LogicalVariableRef{M}
end
# Create internal type for temporarily packaging constraints for disjuncts
struct _DisjunctConstraint{C <: AbstractConstraint, L <: LogicalVariableRef}
constr::C
lvref::L
end
"""
DisjunctConstraintIndex
A type for storing the index of a [`Disjunct`](@ref).
**Fields**
- `value::Int64`: The index value.
"""
struct DisjunctConstraintIndex
value::Int64
end
"""
DisjunctConstraintRef{M <: JuMP.AbstractModel}
A type for looking up disjunctive constraints.
"""
struct DisjunctConstraintRef{M <: JuMP.AbstractModel}
model::M
index::DisjunctConstraintIndex
end
################################################################################
# DISJUNCTIONS
################################################################################
"""
Disjunction{M <: JuMP.AbstractModel} <: JuMP.AbstractConstraint
A type for a disjunctive constraint that is comprised of a collection of
disjuncts of indicated by a unique [`LogicalVariableIndex`](@ref).
**Fields**
- `indicators::Vector{LogicalVariableref}`: The references to the logical variables
(indicators) that uniquely identify each disjunct in the disjunction.
- `nested::Bool`: Is this disjunction nested within another disjunction?
"""
struct Disjunction{M <: JuMP.AbstractModel} <: JuMP.AbstractConstraint
indicators::Vector{LogicalVariableRef{M}}
nested::Bool
end
"""
DisjunctionIndex
A type for storing the index of a [`Disjunction`](@ref).
**Fields**
- `value::Int64`: The index value.
"""
struct DisjunctionIndex
value::Int64
end
"""
DisjunctionRef{M <: JuMP.AbstractModel}
A type for looking up disjunctive constraints.
"""
struct DisjunctionRef{M <: JuMP.AbstractModel}
model::M
index::DisjunctionIndex
end
################################################################################
# CLEVER DICTS
################################################################################
## Extend the CleverDicts key access methods
# index_to_key
function _MOIUC.index_to_key(::Type{LogicalVariableIndex}, index::Int64)
return LogicalVariableIndex(index)
end
function _MOIUC.index_to_key(::Type{DisjunctConstraintIndex}, index::Int64)
return DisjunctConstraintIndex(index)
end
function _MOIUC.index_to_key(::Type{DisjunctionIndex}, index::Int64)
return DisjunctionIndex(index)
end
function _MOIUC.index_to_key(::Type{LogicalConstraintIndex}, index::Int64)
return LogicalConstraintIndex(index)
end
# key_to_index
function _MOIUC.key_to_index(key::LogicalVariableIndex)
return key.value
end
function _MOIUC.key_to_index(key::DisjunctConstraintIndex)
return key.value
end
function _MOIUC.key_to_index(key::DisjunctionIndex)
return key.value
end
function _MOIUC.key_to_index(key::LogicalConstraintIndex)
return key.value
end
################################################################################
# SOLUTION METHODS
################################################################################
"""
AbstractSolutionMethod
An abstract type for solution methods used to solve `GDPModel`s.
"""
abstract type AbstractSolutionMethod end
"""
AbstractReformulationMethod <: AbstractSolutionMethod
An abstract type for reformulation approaches used to solve `GDPModel`s.
"""
abstract type AbstractReformulationMethod <: AbstractSolutionMethod end
"""
BigM{T} <: AbstractReformulationMethod
A type for using the big-M reformulation approach for disjunctive constraints.
**Fields**
- `value::T`: Big-M value (default = `1e9`).
- `tight::Bool`: Attempt to tighten the Big-M value (default = `true`)?
"""
struct BigM{T} <: AbstractReformulationMethod
value::T
tighten::Bool
function BigM(val::T = 1e9, tight = true) where {T}
new{T}(val, tight)
end
end
"""
MBM{O, T, L <: LogicalVariableRef} <: AbstractReformulationMethod
A type for using the multiple big-M reformulation approach for disjunctive constraints.
**Fields**
- `optimizer::O`: Optimizer to use when solving mini-models (required).
- `default_M::T`: Default big-M value to use if no big-M is specified for a logical variable (1e9).
"""
mutable struct MBM{O, T} <: AbstractReformulationMethod
optimizer::O
default_M::T
# Constructor with optimizer (required) and optional default_M
function MBM(optimizer::O, default_M::T = 1e9) where {O, T}
new{O, T}(optimizer, default_M)
end
end
mutable struct _MBM{O, T, M <: JuMP.AbstractModel} <: AbstractReformulationMethod
optimizer::O
M::Dict{LogicalVariableRef{M}, Any}
default_M::T
subproblem_indicators::Vector{LogicalVariableRef{M}}
# Cached submodels: indicator => GDPSubmodel.
# Typed Any so extensions can store different types.
model_cache::Dict{LogicalVariableRef{M}, Any}
function _MBM(method::MBM{O, T}, model::M) where {O, T, M <: JuMP.AbstractModel}
new{O, T, M}(
method.optimizer,
Dict{LogicalVariableRef{M}, Any}(),
method.default_M,
Vector{LogicalVariableRef{M}}(),
Dict{LogicalVariableRef{M}, Any}()
)
end
end
"""
Hull{T} <: AbstractReformulationMethod
A type for using the convex hull reformulation approach for disjunctive
constraints.
**Fields**
- `value::T`: epsilon value for nonlinear hull reformulations (default = `1e-6`).
- `quadratic::Symbol`: reformulation used for quadratic disjunct
constraints (default = `:epsilon`). Options are:
- `:epsilon`: ε-approximated perspective (Furman, Sawaya & Grossmann
2020).
- `:exact`: exact hull (Gusev & Bernal Neira 2025); routes each
constraint to CEHR when its quadratic part is convex and to GEHR
otherwise (equality constraints always use GEHR since they are
nonconvex).
- `:gehr`: always use the General Exact Hull Reformulation.
- `:cehr`: always use the Conic Exact Hull Reformulation (errors on
nonconvex quadratic constraints).
- `:cehr_conic`: CEHR with the cone written out explicitly as a
rotated second-order cone via a spectral factorization of the
quadratic part, for solvers that consume cones natively (errors on
nonconvex quadratic constraints).
"""
struct Hull{T} <: AbstractReformulationMethod
value::T
quadratic::Symbol
function Hull(ϵ::T = 1e-6; quadratic::Symbol = :epsilon) where {T}
if !(quadratic in (:epsilon, :exact, :gehr, :cehr, :cehr_conic))
error("Invalid `quadratic` option `:$(quadratic)`. Choose " *
"from `:epsilon`, `:exact`, `:gehr`, `:cehr`, or " *
"`:cehr_conic`.")
end
new{T}(ϵ, quadratic)
end
end
# temp struct to store variable disaggregations (reset for each disjunction)
mutable struct _Hull{V <: JuMP.AbstractVariableRef, T} <: AbstractReformulationMethod
value::T
quadratic::Symbol
disjunction_variables::Dict{V, Vector{V}}
disjunct_variables::Dict{Tuple{V, Union{V, JuMP.GenericAffExpr{T, V}}}, V}
function _Hull(method::Hull{T}, vrefs::Set{V}) where {T, V <: JuMP.AbstractVariableRef}
new{V, T}(
method.value,
method.quadratic,
Dict{V, Vector{V}}(vref => V[] for vref in vrefs),
Dict{Tuple{V, Union{V, JuMP.GenericAffExpr{T, V}}}, V}()
)
end
end
"""
CuttingPlanes{O,T} <: AbstractReformulationMethod
A type for using the cutting planes approach for disjunctive constraints.
**Fields**
- `optimizer::O`: Optimizer to use when solving mini-models (required).
- `max_iter::Int`: Number of iterations (default = `3`).
- `seperation_tolerance::T`: Tolerance for the separation problem (default = `1e-6`).
- `final_reform_method::AbstractReformulationMethod`: Final reformulation
method to use after cutting planes (default = `BigM()`).
- `M_value::T`: Big-M value to use in the final reformulation (default = `1e9`).
"""
struct CuttingPlanes{O, T} <: AbstractReformulationMethod
optimizer::O;
max_iter::Int
seperation_tolerance::T
final_reform_method::AbstractReformulationMethod
M_value::T
function CuttingPlanes(
optimizer::O;
max_iter::Int = 3,
seperation_tolerance::T = 1e-6,
final_reform_method = BigM(),
M_value::T = 1e9
) where {O, T}
new{O, T}(optimizer, max_iter, seperation_tolerance, final_reform_method, M_value)
end
end
################################################################################
# GDP SUBMODEL
################################################################################
"""
GDPSubmodel{M, V, W}
A unified submodel wrapper used by MBM and cutting plane
reformulations. It encapsulates a flat JuMP optimization
submodel built from a single disjunct's feasible region,
along with mappings back to the original model's variables.
## Fields
- `model::M`: The JuMP submodel representing a disjunct's
feasible region (constraints and variable bounds).
- `decision_vars::Vector{V}`: Ordered decision variables in
the submodel, matching the original model's ordering.
- `fwd_map::Dict{V, Vector{W}}`: Forward map from original
model variables to their submodel counterparts.
"""
struct GDPSubmodel{M <: JuMP.AbstractModel,
V <: JuMP.AbstractVariableRef,
W <: JuMP.AbstractVariableRef}
model::M
decision_vars::Vector{V}
fwd_map::Dict{V, Vector{W}}
end
"""
PSplit <: AbstractReformulationMethod
A type for using the P-split reformulation approach for disjunctive constraints.
This method partitions variables into groups and handles each group separately.
# Constructors
- `PSplit(partition::Vector{Vector{V}})`: Create a PSplit with the given
partition of variables
- `PSplit(n_parts::Int, model::JuMP.AbstractModel)`: Automatically partition
model variables into `n_parts` groups
# Fields
- `partition::Vector{Vector{V}}`: The partition of variables, where each inner
vector represents a group of variables that will be handled together
"""
struct PSplit{V <: JuMP.AbstractVariableRef} <: AbstractReformulationMethod
partition::Vector{Vector{V}}
function PSplit(partition::Vector{Vector{V}}) where
{V <: JuMP.AbstractVariableRef}
new{V}(partition)
end
function PSplit(n_parts::Int, model::JuMP.AbstractModel)
n_parts > 0 || error("Number of partitions must be
positive, got $n_parts")
variables = collect_all_vars(model)
n_vars = length(variables)
n_parts = min(n_parts, n_vars)
n_parts > 0 || error("No variables found in the model")
base_size = n_vars ÷ n_parts
remaining = n_vars % n_parts
partition = Vector{Vector{eltype(variables)}}()
start_idx = 1
for i in 1:n_parts
part_size = i <= remaining ? base_size + 1 : base_size
end_idx = start_idx + part_size - 1
push!(partition, variables[start_idx:end_idx])
start_idx = end_idx + 1
end
return PSplit(partition)
end
end
# temp struct to store variable disaggregations (reset for each disjunction)
mutable struct _PSplit{V <: JuMP.AbstractVariableRef, M <: JuMP.AbstractModel, T} <: AbstractReformulationMethod
partition::Vector{Vector{V}}
sum_constraints::Dict{LogicalVariableRef{M}, Vector{<:AbstractConstraint}}
hull::_Hull{V, T}
function _PSplit(method::PSplit{V}, model::M) where
{V <: JuMP.AbstractVariableRef, M <: JuMP.AbstractModel}
T = JuMP.value_type(M)
new{V, M, T}(
method.partition,
Dict{LogicalVariableRef{M}, Vector{<:AbstractConstraint}}(),
_Hull(Hull(), Set{V}())
)
end
end
"""
Indicator <: AbstractReformulationMethod
A type for using indicator constraint approach for linear disjunctive constraints.
"""
struct Indicator <: AbstractReformulationMethod end
################################################################################
# GDP Data
################################################################################
"""
GDPData{M <: JuMP.AbstractModel, V <: JuMP.AbstractVariableRef, CrefType, ValueType}
The core type for storing information in a [`GDPModel`](@ref).
"""
mutable struct GDPData{M <: JuMP.AbstractModel, V <: JuMP.AbstractVariableRef, C, T}
# Objects
logical_variables::_MOIUC.CleverDict{LogicalVariableIndex, LogicalVariableData}
logical_constraints::_MOIUC.CleverDict{LogicalConstraintIndex, ConstraintData}
disjunct_constraints::_MOIUC.CleverDict{DisjunctConstraintIndex, ConstraintData}
disjunctions::_MOIUC.CleverDict{DisjunctionIndex, ConstraintData{Disjunction{M}}}
# Exactly one constraint mappings
exactly1_constraints::Dict{DisjunctionRef{M}, LogicalConstraintRef{M}}
# Indicator variable mappings
indicator_to_binary::Dict{LogicalVariableRef{M}, Union{V, JuMP.GenericAffExpr{T, V}}}
indicator_to_constraints::Dict{LogicalVariableRef{M}, Vector{Union{DisjunctConstraintRef{M}, DisjunctionRef{M}}}}
constraint_to_indicator::Dict{Union{DisjunctConstraintRef{M}, DisjunctionRef{M}}, LogicalVariableRef{M}} # needed for deletion
# Helpful metadata for most reformulations (not just one of them)
variable_bounds::Dict{V, Tuple{T, T}}
# Reformulation variables and constraints
reformulation_variables::Vector{V}
reformulation_constraints::Vector{C}
# Solution data
solution_method::Union{Nothing, AbstractSolutionMethod}
ready_to_optimize::Bool
# Default constructor
function GDPData{M, V, C}() where {M <: JuMP.AbstractModel, V <: JuMP.AbstractVariableRef, C}
T = JuMP.value_type(M)
new{M, V, C, T}(_MOIUC.CleverDict{LogicalVariableIndex, LogicalVariableData}(),
_MOIUC.CleverDict{LogicalConstraintIndex, ConstraintData}(),
_MOIUC.CleverDict{DisjunctConstraintIndex, ConstraintData}(),
_MOIUC.CleverDict{DisjunctionIndex, ConstraintData{Disjunction{M}}}(),
Dict{DisjunctionRef{M}, LogicalConstraintRef{M}}(),
Dict{LogicalVariableRef{M}, Union{V, JuMP.GenericAffExpr{T, V}}}(),
Dict{LogicalVariableRef{M}, Vector{Union{DisjunctConstraintRef{M}, DisjunctionRef{M}}}}(),
Dict{Union{DisjunctConstraintRef{M}, DisjunctionRef{M}}, LogicalVariableRef{M}}(),
Dict{V, Tuple{T, T}}(),
Vector{V}(),
Vector{C}(),
nothing,
false,
)
end
end
################################################################################
# VARIABLE INFO
################################################################################
"""
VariableProperties{L, U, F, S, SET, T}
A type for storing variable properties and attributes that can be applied to JuMP variables.
This is used to capture and transfer variable information between models during reformulation.
**Fields**
- `info::JuMP.VariableInfo{L, U, F, S}`: JuMP's VariableInfo struct containing bounds, fixed values, start values, and binary/integer constraints.
- `name::String`: The variable name.
- `set::SET`: The constraint set the variable belongs to (if any), obtained via `JuMP.moi_set`.
- `variable_type::T`: The variable type information, critical for extensions.
**Type Parameters**
- `L, U, F, S`: Type parameters from JuMP.VariableInfo for lower bound, upper bound, fixed value, and start value types.
- `SET`: Type of the constraint set the variable belongs to.
- `T`: Type of the variable type information.
**Constructor**
`VariableProperties(vref::JuMP.GenericVariableRef{T})` creates a VariableProperties instance
from a JuMP variable reference, automatically extracting all relevant properties.
"""
mutable struct VariableProperties{L, U, F, S, SET, T}
info::JuMP.VariableInfo{L, U, F, S}
name::String
set::SET
variable_type::T
end
function VariableProperties(vref::JuMP.GenericVariableRef{T}) where T
info = get_variable_info(vref)
name = JuMP.name(vref)
set = JuMP.is_variable_in_set(vref) ? JuMP.moi_set(JuMP.constraint_object(JuMP.VariableInSetRef(vref))) : nothing
return VariableProperties(info, name, set, nothing)
end
function VariableProperties(vref::JuMP.AbstractVariableRef)
info = get_variable_info(vref)
name = JuMP.name(vref)
return VariableProperties(info, name, nothing, nothing)
end
"""
VariableProperties(expr)::VariableProperties
Creates a `VariableProperties` object with blank variable info (no bounds, not fixed,
not binary/integer) from an expression. The `expr` argument is provided for
extensions to infer additional properties.
## Arguments
- `expr`: Expression for extensions to extract metadata from
## Returns
A `VariableProperties` object with blank info.
"""
function VariableProperties(expr)
info = _free_variable_info()
return VariableProperties(info, "", nothing, nothing)
end