@@ -43,23 +43,35 @@ big_m_reformulation!(constr::AbstractArray{<:ConstraintRef}, bin_var, M, i, j, k
4343Apply interval arithmetic on a constraint to infer the tightest Big-M value from the bounds on the constraint.
4444"""
4545function infer_bigm (constr:: ConstraintRef )
46- # convert constraints into Expr to replace variables with interval sets and determine bounds
47- constr_type, constr_func_expr, constr_rhs = parse_constraint (constr)
46+ constr_obj = constraint_object (constr)
47+ constr_terms = constr_obj. func. terms
48+ constr_set = constr_obj. set
4849 # create a map of variables to their bounds
49- interval_map = Dict ()
50- vars = all_variables (constr. model)# constr.model[:gdp_variable_constrs]
51- obj_dict = object_dictionary (constr. model)
52- bounds_dict = :variable_bounds_dict in keys (obj_dict) ? obj_dict[:variable_bounds_dict ] : Dict () # NOTE: should pass as an keyword argument
53- for var in vars
54- LB, UB = get_bounds (var, bounds_dict)
55- interval_map[string (var)] = LB.. UB
50+ bounds_dict = :variable_bounds_dict in keys (constr. model. ext) ? constr. model. ext[:variable_bounds_dict ] : Dict ()
51+ bounds_map = Dict (
52+ var => get_bounds (var, bounds_dict)
53+ for var in get_constraint_variables (constr)
54+ )
55+ # apply interval arithmetic
56+ if constr_set isa MOI. LessThan
57+ M = - constr_set. upper
58+ for (var,coeff) in constr_terms
59+ if coeff > 0
60+ M += coeff* bounds_map[var][2 ]
61+ else
62+ M += coeff* bounds_map[var][1 ]
63+ end
64+ end
65+ elseif constr_set isa MOI. GreaterThan
66+ M = - constr_st. lower
67+ for (var,coeff) in constr_terms
68+ if coeff < 0
69+ M += coeff* bounds_map[var][2 ]
70+ else
71+ M += coeff* bounds_map[var][1 ]
72+ end
73+ end
5674 end
57- constr_func_expr = replace_intevals! (constr_func_expr, interval_map)
58- # get bounds on the entire expression
59- func_bounds = eval (constr_func_expr)
60- Mlo = func_bounds. lo - constr_rhs
61- Mhi = func_bounds. hi - constr_rhs
62- M = constr_type == :(<= ) ? Mhi : Mlo
6375 isinf (M) && error (" M parameter for $constr cannot be infered due to lack of variable bounds." )
6476 return M
6577end
0 commit comments