1
- # function big_m_reformulation!(constr, bin_var, i, k, M)
2
- # if ismissing(k)
3
- # ref = constr
4
- # elseif k isa CartesianIndex
5
- # ref = constr[k]
6
- # else
7
- # ref = constr[k...]
8
- # end
9
- # if ismissing(M)
10
- # M = apply_interval_arithmetic(ref)
11
- # # @warn "No M value passed for $ref. M = $M was inferred from the variable bounds."
12
- # elseif !ismissing(k) && !isa(M,Real)
13
- # M = M[k]
14
- # end
15
- # if ref isa NonlinearConstraintRef
16
- # nonlinear_bigM(ref, bin_var, M, i)
17
- # elseif ref isa ConstraintRef
18
- # linear_bigM(ref, bin_var, M, i)
19
- # end
20
- # end
1
+ """
2
+ big_m_reformulation!(constr::ConstraintRef, bin_var, M, i, j, k)
21
3
4
+ Perform Big-M reformulation on a linear or quadratic constraint at index k of constraint j in disjunct i.
5
+
6
+ big_m_reformulation!(constr::NonlinearConstraintRef, bin_var, M, i, j, k)
7
+
8
+ Perform Big-M reformulaiton on a nonlinear constraint at index k of constraint j in disjunct i.
9
+
10
+ big_m_reformulation!(constr::AbstractArray, bin_var, M, i, j, k)
11
+
12
+ Perform Big-M reformulation on a constraint at index k of constraint j in disjunct i.
13
+ """
22
14
function big_m_reformulation! (constr:: ConstraintRef , bin_var, M, i, j, k)
23
15
M = get_reform_param (M, i, j, k; constr)
24
- linear_bigM (constr, bin_var, M, i)
16
+ bin_var_ref = constr. model[bin_var][i]
17
+ add_to_function_constant (constr, - M)
18
+ set_normalized_coefficient (constr, bin_var_ref , M)
25
19
end
26
20
function big_m_reformulation! (constr:: NonlinearConstraintRef , bin_var, M, i, j, k)
27
21
M = get_reform_param (M, i, j, k; constr)
28
- nonlinear_bigM (constr, bin_var, M, i)
29
- end
30
- big_m_reformulation! (constr:: AbstractArray , bin_var, M, i, j, k) =
31
- big_m_reformulation (constr[k], bin_var, M, i, j, k)
32
-
33
- function linear_bigM (ref, bin_var, M, i)
34
- bin_var_ref = ref. model[bin_var][i]
35
- add_to_function_constant (ref, - M)
36
- set_normalized_coefficient (ref, bin_var_ref , M)
37
- end
38
-
39
- function nonlinear_bigM (ref, bin_var, M, i)
40
22
# create symbolic variables (using Symbolics.jl)
41
- for var_ref in ref . model[:gdp_variable_refs ]
23
+ for var_ref in constr . model[:gdp_variable_refs ]
42
24
var_sym = Symbol (var_ref)
43
25
eval (:(Symbolics. @variables ($ var_sym)[1 ]))
44
26
end
45
27
bin_var_sym = Symbol (" $bin_var [$i ]" )
46
28
λ = Num (Symbolics. Sym {Float64} (bin_var_sym))
47
29
48
- # parse ref
49
- op, lhs, rhs = parse_NLconstraint (ref )
50
- replace_Symvars! (lhs, ref . model) # convert JuMP variables into Symbolic variables
30
+ # parse constr
31
+ op, lhs, rhs = parse_constraint (constr )
32
+ replace_Symvars! (lhs, constr . model) # convert JuMP variables into Symbolic variables
51
33
gx = eval (lhs) # convert the LHS of the constraint into a Symbolic expression
52
34
gx = gx - M* (1 - λ) # add bigM
53
35
54
36
# update constraint
55
- replace_NLconstraint (ref, gx, op, rhs)
56
- end
37
+ replace_constraint (constr, gx, op, rhs)
38
+ end
39
+ big_m_reformulation! (constr:: AbstractArray , bin_var, M, i, j, k) =
40
+ big_m_reformulation (constr[k], bin_var, M, i, j, k)
0 commit comments