CVX Error, indexed "for" loop. Unable to use a value of type 'cvx' as an index

Hello

I am working on a jobshop scheduling problem where machines have different power states. The following code gives me an error:

for i = 1:Nm
for p = 1:Np
for s =4
sum(X(i,:,p)) = sum(W(i,:,p));
end
end
end

The error is as follows:
"
Error using cvx/subsasgn (line 39)

Unable to use a value of type ‘cvx’ as an index.

Error in Model10102019v2 (line 104)
sum(X(i,:,p)) = (W(i,:,p));
"
Nm is number of machines
Np is number of periods
Ns in number of power states
Nj is number of jobs
X is a binary variable indexed over Nm Nj and Np, while W is another binary variable indexed over Nm, Ns, and Np.

The code has to run for every i, and every p, and sum over every j on LHS but only one s on RHS.

What it means to say is for every machine (i) and every period §, when the machine is processing
a job (j), it should be in a certain power state out of the 5 possible power states (for this case its 4).

This is what I want:

X111+X121+X131+X141+X211+X221+X231+X241= W131+W231
OR
X111+X121+X131+X141 = W131
X211+X221+X231+X241 = W231
.
.
.
32x1 matrix = 32x1 matrix OR
64x1 matrix = 64 x 1 matrix
(same goes on for all the time periods p)

I tried every brute force and every logic I could come up with so far but cannot get it to work so any input in this regard is greatly appreciated.

Thank you in advance

Please re-read the CVX Users’ Guide http://cvxr.com/cvx/doc/ to understand the distinction between assignment expression using = , and equality constraint using == . I think you want == not =.

thank you very much for your input!

I had tried the “==” as follows and it gives me error.
{
for i = 1:Nm
for p = 1:Np
for k == 4
sum(X(:,j,:)) <= sum(W(:,k,:));
end
end
end
}

gives me following error:
{
Error using cvx/subsref (line 13)
Index in position 2 is invalid. Array indices must be positive integers
or logical values.
}

However,

following code works (works as in does not give me errors)
{
for i = 1:Nm
for p = 1:Np
sum(X(i,:,p)) <= sum(W(i,4,p));
end
end
}

How can I check if cvx is processing the constraints/variables as I want? Is there some kind of “display” function I can use to check how the constraints and variables are actually being handled? I tried "disp (variable)) but it only displays something along lines of “cvx affine expression”

I really appreciate any advice and help in this regards.

I didn’t mean that for k = 4 shoukd be changed to for k == 4, I meant that sum(X(i,:,p)) = sum(W(i,:,p)); should be changed to sum(X(i,:,p)) == sum(W(i,:,p));.

Now you have changed from (what should be) == to <=, which is mathematically different.

I don;’ know a way to display the constraints CVX formulates, but you can check that any solution satisfies your intended constraints within tolerance. Also, you can formulate your constraints outside of CVX using numerical values of variables for those variables which would be declared as variables in CVX, and check that both sides of constraints are being evaluated as you intended.

Hey

Sorry that was supposed to be “==” in the original post as well.
{
sum(X(i,:,p)) = sum(W(i,:,p));
}

Reason for replacing it with “<=” is to relax the strict equality constraint so the model is feasible.