consider this program
H=4
J=3
m = Model(GLPK.Optimizer)
@variable(m, x[ 1:H , 1:J ], Bin)
I am trying to model this constraint:
Where 1.() is an indicator function.
After a few hours of playing this is the best I can do:
m = Model(GLPK.Optimizer)
@variable(m ,x[1:H , 1:J])
Hᵖ = [[2, 3], [1, 3, 4], [1, 2, 4]]
@expression(m, f[j in 1:J], sum(x[h,j] for h in Hᵖ[j] ) )
function indicate(x)
y =0.0
if x>0.0
y=1.0
end
return y
end
@constraint(m, sum( indicate( f[j] ) for j in 1:J) ≥ 0)
and this is the error I get
MethodError: no method matching isless(::Float64, ::AffExpr)
Closest candidates are:
isless(::AbstractFloat, ::ForwardDiff.Dual{Ty, V, N} where {V, N}) where Ty at C:\Users\e29115\.julia\packages\ForwardDiff\PBzup\src\dual.jl:145
isless(::Real, ::ForwardDiff.Dual{Ty, V, N} where {V, N}) where Ty at C:\Users\e29115\.julia\packages\ForwardDiff\PBzup\src\dual.jl:145
isless(::Any, ::Missing) at missing.jl:88
I know he says, he expects to see a number but sees an expression. But I don’t know how to fix this.
Any comment is appreciated.