Return inequality direction for normalized constraint

using JuMP

Create a model

model = Model()

Define a variable

@variable(model, x)

Add constraints

@constraint(model, c1, 2x + 3 ≤ 5) # Less than or equal to
@constraint(model, c2, 4x - 2 ≥ 3) # Greater than or equal to
@constraint(model, c3, 5x + 1 == 7) # Equality

Function to get the constraint direction

function get_constraint_direction(con)
set_type = JuMP.constraint_object(con).set
if set_type isa MOI.LessThan
return “≤”
elseif set_type isa MOI.GreaterThan
return “≥”
elseif set_type isa MOI.EqualTo
return “=”
else
return “Unknown Constraint Type”
end
end

Extracting the inequality directions

println("Constraint c1: ", get_constraint_direction(c1)) # Output: ≤
println("Constraint c2: ", get_constraint_direction(c2)) # Output: ≥
println("Constraint c3: ", get_constraint_direction(c3)) # Output: =