@@ -21,40 +21,79 @@ constrdict(model::LinQuadOptimizer, ::SVCI{MOI.Integer}) = cmap(model).integer
2121constrdict (model:: LinQuadOptimizer , :: SVCI{MOI.Semicontinuous{Float64}} ) = cmap (model). semicontinuous
2222constrdict (model:: LinQuadOptimizer , :: SVCI{MOI.Semiinteger{Float64}} ) = cmap (model). semiinteger
2323
24- function set_variable_bound (model:: LinQuadOptimizer , v:: SinVar , set:: LE )
24+ """
25+ change_both_variable_bounds!(model::LinQuadOptimizer, columns::Vector{Int},
26+ lower_bounds::Vector{Float64}, upper_bounds::Vector{Float64})
27+
28+ Set the lower bound of column `columns[i]` to `lower_bounds[i]` and the upper
29+ bound to `upper_bounds[i]`. Alternatively, the lower or upper bound can be left
30+ blank by passing an array of length 0 instead.
31+
32+ Examples:
33+ change_both_variable_bounds!(model, [1, 2], [-0.5, 0.0], [1.0, 2.0])
34+ change_both_variable_bounds!(model, [1, 2], [-0.5, 0.0], Float64[])
35+ change_both_variable_bounds!(model, [1, 2], Float64[], [1.0, 2.0])
36+ """
37+ function change_both_variable_bounds! (
38+ model:: LinQuadOptimizer ,
39+ columns:: Vector{Int} ,
40+ lower_bounds:: Vector{Float64} ,
41+ upper_bounds:: Vector{Float64} )
42+ if length (lower_bounds) > 0 && length (upper_bounds) > 0
43+ columns = vcat (columns, columns)
44+ end
2545 change_variable_bounds! (model,
26- [get_column (model, v)],
27- [set. upper],
28- [backend_type (model, Val {:Upperbound} ())]
46+ columns,
47+ vcat (lower_bounds, upper_bounds),
48+ vcat (
49+ fill (backend_type (model, Val {:Lowerbound} ()), length (lower_bounds)),
50+ fill (backend_type (model, Val {:Upperbound} ()), length (upper_bounds))
51+ )
2952 )
3053end
3154
55+ function set_variable_bound (model:: LinQuadOptimizer , v:: SinVar , set:: LE )
56+ change_both_variable_bounds! (
57+ model, [get_column (model, v)], Float64[], [set. upper])
58+ end
59+
3260function set_variable_bound (model:: LinQuadOptimizer , v:: SinVar , set:: GE )
33- change_variable_bounds! (model,
34- [get_column (model, v)],
35- [set. lower],
36- [backend_type (model, Val {:Lowerbound} ())]
37- )
61+ change_both_variable_bounds! (
62+ model, [get_column (model, v)], [set. lower], Float64[])
3863end
3964
4065function set_variable_bound (model:: LinQuadOptimizer , v:: SinVar , set:: EQ )
41- change_variable_bounds! (model,
42- [get_column (model, v), get_column (model, v)],
43- [set. value, set. value],
44- [backend_type (model, Val {:Upperbound} ()),
45- backend_type (model, Val {:Lowerbound} ())
46- ]
47- )
66+ change_both_variable_bounds! (
67+ model, [get_column (model, v)], [set. value], [set. value])
4868end
4969
5070function set_variable_bound (model:: LinQuadOptimizer , v:: SinVar , set:: IV )
51- change_variable_bounds! (model,
52- [get_column (model, v), get_column (model, v)],
53- [set. upper, set. lower],
54- [backend_type (model, Val {:Upperbound} ()),
55- backend_type (model, Val {:Lowerbound} ())
56- ]
57- )
71+ change_both_variable_bounds! (
72+ model, [get_column (model, v)], [set. lower], [set. upper])
73+ end
74+
75+ function set_variable_bounds (
76+ model:: LinQuadOptimizer , vars:: Vector{SinVar} , sets:: Vector{LE} )
77+ change_both_variable_bounds! (model, get_column .(model, vars), Float64[],
78+ [set. upper for set in sets])
79+ end
80+
81+ function set_variable_bounds (
82+ model:: LinQuadOptimizer , vars:: Vector{SinVar} , sets:: Vector{GE} )
83+ change_both_variable_bounds! (model, get_column .(model, vars),
84+ [set. lower for set in sets], Float64[])
85+ end
86+
87+ function set_variable_bounds (
88+ model:: LinQuadOptimizer , vars:: Vector{SinVar} , sets:: Vector{EQ} )
89+ values = [set. value for set in sets]
90+ change_both_variable_bounds! (model, get_column .(model, vars), values, values)
91+ end
92+
93+ function set_variable_bounds (
94+ model:: LinQuadOptimizer , vars:: Vector{SinVar} , sets:: Vector{IV} )
95+ change_both_variable_bounds! (model, get_column .(model, vars),
96+ [set. lower for set in sets], [set. upper for set in sets])
5897end
5998
6099"""
@@ -80,6 +119,27 @@ function MOI.add_constraint(model::LinQuadOptimizer, variable::SinVar, set::S) w
80119 return index
81120end
82121
122+ function MOI. add_constraints (model:: LinQuadOptimizer , variables:: Vector{SinVar} ,
123+ sets:: Vector{S} ) where S <: LinSets
124+ __assert_supported_constraint__ (model, SinVar, S)
125+ for variable in variables
126+ variable_type = model. variable_type[variable. variable]
127+ if ! (variable_type == Continuous || variable_type == Integer)
128+ error (" Cannot set bounds because variable is of type: $(variable_type) ." )
129+ end
130+ end
131+ set_variable_bounds (model, variables, sets)
132+ indices = SVCI{S}[]
133+ for variable in variables
134+ model. last_constraint_reference += 1
135+ index = SVCI {S} (model. last_constraint_reference)
136+ dict = constrdict (model, index)
137+ dict[index] = variable. variable
138+ push! (indices, index)
139+ end
140+ return indices
141+ end
142+
83143function MOI. delete (model:: LinQuadOptimizer , index:: SVCI{S} ) where S <: LinSets
84144 __assert_valid__ (model, index)
85145 delete_constraint_name (model, index)
0 commit comments