I’m trying to maximize this function
function C_opt(s)
pax, pby = OffsetArray( zeros(Float64, (2,2)), (0:1,0:1) ), OffsetArray( zeros(Float64, (2,2)), (0:1,0:1) )
Cmax = 0
for l=0:15
pax[0,0], pax[0,1], pby[0,0], pby[0,1] = digits(l, base=2, pad=4)
pax[1,0], pax[1,1], pby[1,0], pby[1,1] = 1- pax[0,0], 1- pax[0,1], 1- pby[0,0], 1- pby[0,1]
C = 0
j = 1
for i=0:15
a,b,x,y = digits(i, base=2, pad=4)
C += s[j]*pax[a,x]*pby[b,y]
j += 1
end
C = C + s[j]*pax[0,0] + s[j+1]*pax[1,0]
if Cmax > C
Cmax = C
end
end
return Cmax
end
model = Model(optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0));
@variable(model, -1 <= s[i = 1:18] <= 1, start = rand(Uniform(-1,1)) )
@objective(model, Max, C_opt(s) )
optimize!(model)
@show objective_value(model)
but I’m getting this error
MethodError: no method matching isless(::GenericAffExpr{Float64,VariableRef}, ::Int64)
Closest candidates are:
isless(!Matched::Missing, ::Any) at missing.jl:87
isless(!Matched::AbstractFloat, ::Real) at operators.jl:167
isless(!Matched::ForwardDiff.Dual{Tx,V,N} where N where V, ::Integer) where Tx at
…
Commenting this lines
if Cmax > C
Cmax = C
end
I get something, but it is not the right answer, that "if " statement has to be there
Thanks in advance!