You appear to be missing a final parenthesis on the last line. May I ask what editor you use? Most have a feature to indicate matching pairs of parentheses, often as little bars that show under both parentheses if you place the cursor on one of them.
ERROR: LoadError: In `@constraint(Model1, sum(Q[a, w] * x[a, t] - sum((s[a, t] .<= (RHE[w] + OHE[w]) * NE[w] - WH[w, t] for a = A))))`: Constraints must be in one of the following forms:
expr1 <= expr2
expr1 >= expr2
expr1 == expr2
lb <= expr <= ub
I guess what he needs is something like this, although it also produces an out-of-index error.
@anon37204545
I put the constraint for a in A, because of the sums that are indexed to a, Do you know if it really is done like this?
I’ve been trying to reproduce this retribution
@Henrique_Becker
Yes, both sides are scalar
Now the constraint has the following error: Bounds Error: attempet to access 79 elements Array{Int64,1} at index [1.5]
I think the function is correct, but there is an inconsistency in the size of the matrix that I cannot solve.
@constraint(Model1,sum(Q[a,w]*x[a,t] for a in A)-sum(s[a,t] for a in A)<=(RHE[w]+OHE[w])*NE[w]-WH[w,t])
Running the code of the first post with the constraint I suggested in my last reply gives me:
ERROR: LoadError: BoundsError: attempt to access 8-element Array{Int64,1} at index [9, 1]
That comes from the fact that Q is a 1D array of 8 elements, and therefore sum(Q[a,w]*x[a,t] for a in A) will not work, Q needs to be a 2D array (a matrix) of 79x? where ? is at least 1 (but essentially goes up to any value w can assume). The same problem exists with WH that is also a 1D array of 8 elements but is indexed like WH[w,t] for a in A (remembering that t is 18). Replacing both Q and WH by Q = ones(79, 1); WH = ones(1, 18) makes the code execute with no error (but, obviously, probably with the wrong result).
The error message you are giving me say that you tried to index some array with a floating point. I cannot reproduce it with the code you posted here.
@Henrique_Becker
It really is showing this error that you put above. I don’t know how to resolve this restriction
Thank you for your help.
The only thing I saw that is different from the code I put here, is w , which is actually w = 5, but I believe that this will not change anything in relation to the error
using JuMP, Cbc
Model1 = Model(with_optimizer(Cbc.Optimizer))
#size
a = 79 #activity
t = 18 #period of time
w = 5 #work center
A = 1:79
T = 1:18
#parameters
Q = [8780; 11310; 8600; 12500; 925; 1918; 4026; 5076]
RHE = [150; 150; 150; 150; 150]
NE = [14; 53; 24; 58; 115]
OHE = [25; 25; 25; 25; 25]
WH = [2486; 1447; 795; 583; 232; 53; 11073; 5414]
@variable(Model1,s[A,T], lower_bound=0)
@variable(Model1,x[A,T], lower_bound=0)
@constraint(Model1,sum(Q[a,w]*x[a,t] for a in A)-sum(s[a,t] for a in A)<=(RHE[w]+OHE[w])*NE[w]-WH[w,t])
Try replacing your definition of Q with Q = rand(79,18) and WH with WH = rand(5,18). Do you still get the same error?
Also, are you sure the error you’re getting isn’t something like ERROR: LoadError: BoundsError: attempt to access 8-element Array{Int64,1} at index [1, 5]? Note the [1, 5] at the end and not the [1.5] as you wrote in a previous post.
First, prefer the term constraint to restriction, I do believe you are instinctively translating “restrição” from Portuguese in your mind.
Second,
The only thing I saw that is different from the code I put here, is w , which is actually w = 5 , but I believe that this will not change anything in relation to the error
If @chisquared guess is correct, and the error is [1, 5] not [1.5], then w = 5 is exactly what is causing the error. The whole problem you are having is that the constants you are using (Q, WH, …) are incomplete, where their values come from? Seems clear to me that lists of 8 values cannot be indexed with [79, 5] or [5, 18], there are not such positions in a simple 1D list of 8 values. Where come the constraint that you are trying to replicate? It does not describe all of Q and WH values?
All constants are columns in a table, Q is a column of 79 values and WH is a column of 30 values, I tried to reduce the values to put here in julia groups.
All constants of the model are files in the .CSV that I am exporting to Julia
If Q is a column of 79 values, then why it is indexed this way sum(Q[a,w]*x[a,t] for a in A) inside the constraint (where A is 1:79 and w is 5)? If Q is a single column then it can be indexed with two indexes only if one of them is always 1, like pointed by odow in his last reply.