I am at a bit of a loss to determine the best way to code a constraint

based on an uncontrolled variable. Hoping someone can help me out

The problem is dropping marbles into pails… I have 12 different

colored marbles and 3 pails. Distributing the marbles equally, I want

to put marbles of the same color in the same pail if possible.

SETS m marbles /m1…m12/

p pail /p1…p3/

c colour /red, blue, green/;

TABLE marblebag(m,c) Marble Values

red blue green

m1 1 0 0

m2 1 0 0

m3 1 0 0

m4 1 0 0

m5 1 0 0

m6 0 1 0

m7 0 1 0

m8 0 1 0

m9 0 1 0

m10 0 0 1

m11 0 0 1

m12 0 0 1

PARAMETER goal(c) Side calculation of Goal for colour in bucket

/red 4 blue 4 green 3/;

BINARY VARIABLE

x(m,p) Drop marble m into pail p

POSITIVE VARIABLES

overgoal(c,p) Amount over goal for colour in pail p

undergoal(c,p) Amount under goal for colour in pail p

… [ REMOVING UNNECESSARY CODE TO GET TO CRUX OF THE ISSUE]

drop(m)… sum(p, x(m,p)) =e=

1; /marble can only be in one

pail/

capacity(p)… sum(m, x(m,p)) =e=

4; /no more than 4 marbles per

pail/

… [WHAT I WOULD LIKE TO CODE IS THE FOLLOWING, BUT OBVIOUSLY I GET

ERROR 149 TREATING UNCONTROLLED VARIABLE AS A CONSTANT]

- No colour penalty for a specific colour if there are no marbles of

that colour in pail, otherwise the penalty is the amount over or under

the goal

penalty(c,p)$(sum(m, marblebag(m,c)*x(m,p)) ne 0)… sum(m,

marblebag(m,c)*x(m,p)) =e= goal(c) + overgoal(c,g) - undergoal(c,g);

obj… totalpenalty =e= overgoal + undergoal;

MODEL sortmarbles /ALL/;

SOLVE sortmarbles using MIP minimizing totalpenalty;

Any suggestions? Am I missing the obvious?

Thanks

\