Skip to content

Commit

Permalink
Update error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsipher committed Oct 3, 2024
1 parent d77ec04 commit e17a939
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/reformulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ function _reformulate_disjunctions(model::JuMP.AbstractModel, method::AbstractRe
dref = DisjunctionRef(model, idx)
if requires_exactly1(method) && !haskey(gdp_data(model).exactly1_constraints, dref) &&
!any(has_logical_compliment.(disj.constraint.indicators))
error("Reformulation method `$method` requires disjunctions where only 1 disjunct is selected, " *
"but `exactly1 = false` for disjunction `$dref`.")
error("Reformulation method `$method` requires disjunctions where only 1 disjunct is selected, ",
"but `exactly1 = false` or none of the logical variables are logical compliments ",
"for disjunction `$dref`.")
end
if requires_variable_bound_info(method)
for vref in _get_disjunction_variables(model, disj.constraint)
Expand Down
15 changes: 10 additions & 5 deletions src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ function JuMP.build_variable(
elseif info.has_start && !isone(info.start) && !iszero(info.start)
_error("Invalid start value, must be false or true.")
elseif (info.has_start || info.has_fix) && !isnothing(logical_compliment)
_error("Cannot fix or provide a start value for logical variable " *
"that has a logical compliment variable.")
_error("Cannot fix or provide a start value for a logical variable " *
"that is a logical compliment variable. Try adding these " *
"properties to the variable it is the compliment of.")
elseif !isnothing(logical_compliment) && has_logical_compliment(logical_compliment)
_error("Cannot specify a logical compliment that itself is a " *
"logical compliment.")
"logical compliment. For two logical variables that " *
"are the compliment of one another, only use the " *
"`logical_compliment` argument on one of them.")
end

# create the variable
Expand Down Expand Up @@ -227,7 +230,8 @@ function JuMP.set_start_value(
value::Union{Nothing, Bool}
)
if has_logical_compliment(vref)
error("Cannot set the start value of a variable with a logical compliment.")
error("Cannot set the start value of a logical compliment variable. ",
"Try setting the start value of its logical compliment instead.")
end
new_var = LogicalVariable(JuMP.fix_value(vref), value, nothing)
_set_variable_object(vref, new_var)
Expand Down Expand Up @@ -263,7 +267,8 @@ new one.
"""
function JuMP.fix(vref::LogicalVariableRef, value::Bool)
if has_logical_compliment(vref)
error("Cannot fix value of a variable with a logical compliment.")
error("Cannot fix value of a logical variable compliment. ",
"Try fixing its logical compliment instead.")
end
new_var = LogicalVariable(value, JuMP.start_value(vref), nothing)
_set_variable_object(vref, new_var)
Expand Down

0 comments on commit e17a939

Please sign in to comment.