I’m new to Julia and working with Julia/JuMP for optimization purposes. I want to use if-else-statements in the constraints I’m defining to write them more compact. When trying so I ran in some strange behaviour.
Im using Julia v1.5.1 and JuMP v0.21.3.
1.) Just Julia: Writing the following into a .jl and running with include()
if 1 == 2
returns the correct value 5 .
But writing the following into a .jl and running with include() gives an error.
if 1 == 2 1 end + 5
The Error is: ERROR: LoadError: MethodError: no method matching +(::Nothing, ::Int64)
2.) Using Julia and JuMP: When defining the following function Test() the resulting constraint con in the .lp file is not like you would expect it
m = Model()
if set_constr == 1
if set_constr == 2
if set_constr == 3
else 0 end
For Test(m,1) we get: con: 1 x_1_ <= 0 like we want to have.
For Test(m,2) we get: con: <= 0 while we would like to get con: 0.1 x_2_ + x_4_ <= 0
For Test(m,3) we get con: 1 x_5_ <= 0 while we would like to get con: x_4_ + x_5_ <= 0
Is my understanding of the if-else-statement false here or is this a bug?