Dear all,
how to type the constraint below in order to avoid an error.
for j in N1
if j>1 && j<7
@constraint(vrpm, sum(x[j,i,k] for i in N5, k in B if i!=j)
-sum(x[i,j,k] for i in N4, k in B, if i!=j) == 0)
end
end
If statement ( if j>1 && j<7) makes that error ( LoadError: MethodError: no method matching isless(::Int64, ::String))
Thanks,
Mamo
Please make it easier to help you by formatting your code and making it self-contained, e.g., here you don’t say what N1
is; see Please read: make it easier to help you.
From what I see, j
is a String
so I guess N1
contains some strings and then you try to compare it with 1
and 7
. Strings cannot be compared to numbers hence the error.
yes, thanks blegat. N1 is the set of strings, by if statement j counter should exclude first and last member of the set N1.
Just do for j in N1[2:6]
if you know that’s the range you’re after?
Thanks nilshg, two additional questions:
What is the command for printing the values of decision variables?
If I want to print the entire model print(model) but what if I want to see only a specific constraint in the derived form? I need to name it?
What is the command for printing the values of decision variables?
Use value
If I want to print the entire model print(model) but what if I want to see only a specific constraint in the derived form? I need to name it?
Not necessarily, you can also do con_ref = @constraint(...)
and use con_ref
to reference the constraint even if it has no name.
Thanks blegat!