Hi! I have a constraint (shown at the photo below) wherein two sets need to be subtracted. I tried introducing another set Kw with a definition of k-Ks but it says subtraction of element valued expressions require the set range to be equal, but the ranges domain set "Subblock" and set "Candidate_Subblocks" differ.

Identifier: Subblock

Index: k

Identifier: Candidate_Subblock

Index: Ks

Identifier: Subblock_Difference

Subset of: Subblock, Candidate_Subblocks

Index: Kw

Definition: k-Ks

above is the current code I have. Do you have any Idea on how I can code my constraint?

# Subtraction of Element Valued Expressions

sum(Kw, x(v,kw))=0 will work.

you can use the index of the subset so it will only apply those elements in the subset.

you can use the index of the subset so it will only apply those elements in the subset.

Making both Candidate_Subblock and Subblock_Difference as a subset of Subblock and change the definition of Subblock_Difference like below should work.

Identifier: Subblock

Index: k

Identifier: Candidate_Subblock

Subset of: Subblock

Index: Ks

Identifier: Subblock_Difference

Subset of: Subblock

Index: Kw

Definition: Subblock - Candidate_Subblock

Identifier: Subblock

Index: k

Identifier: Candidate_Subblock

Subset of: Subblock

Index: Ks

Identifier: Subblock_Difference

Subset of: Subblock

Index: Kw

Definition: Subblock - Candidate_Subblock

Thank you so much! It worked! Now my constraint will be written

sum(Kw, x(v,k))=0

or

sum[(k|Kw, x(v,k))] = 0

?

sum(Kw, x(v,k))=0

or

sum[(k|Kw, x(v,k))] = 0

?

it’s “for which”

😂care for some more explanation on the meaning of the constraint and index? otherwise, I do not know how to help here.

Constraint 7:

YL(k,t) - Binary Variable(set to 1 if subblock k executes loading activity in period t)

x(v,k) - Binary variable(1 if subblock K is reserved for vessel V)

Tv - subset of period/s when vessel v loads or unloads containers

constraint 7: denotes whether a subblock performs a loading/unloading activity

YL(k,t) - Binary Variable(set to 1 if subblock k executes loading activity in period t)

x(v,k) - Binary variable(1 if subblock K is reserved for vessel V)

Tv - subset of period/s when vessel v loads or unloads containers

constraint 7: denotes whether a subblock performs a loading/unloading activity

If Tv is input, which means it does not change depending on variables, what you can do is to introduce parameter As Tv. For example, Valid_v_t(v,t) is 1 if vessel v can load/unload at time t. then (7) can be something like

Identifier: constraint7

index domain: (k,t)

definition: gamma(k,t) = sum(v|Valid_v_t(v,t) , x(v,k))

Identifier: constraint7

index domain: (k,t)

definition: gamma(k,t) = sum(v|Valid_v_t(v,t) , x(v,k))

### Reply

## Sign up

Already have an account? Login

**Please use your business or academic e-mail address to register**

## Login to the community

No account yet? Create an account

Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.