Solved

# Use single Variable defined with two sets (Matrix)

• 4 replies
• 115 views

• Enthusiast
• 6 replies

Hello everybody,

I have a little question regarding an optimization problem. In the problem I define my binary variables by use of two sets (matrix). Rows: Set 1, Columns: Set 2.

The first set contains different parts (Set1 contains: Part 1, Part 2, Part 3… and so on)

The second set contains different variants for each part (Set 2 contains: Version 1, Version 2, Version 3 and so on).

The definition of the indices is no problem. Later in the model I want to use not the whole Matrix (Set1 X Set2) but just a Single vector. For example the vector should have the size of Set 1, and of Set 2 just the colum Version 2. So in the constraint I just want to use the yellow colum. Is this possible or do I have to define for every Element of Set 2 an own Set?

icon

Best answer by Marcel Hunting 5 April 2022, 10:25

View original

### 4 replies

Userlevel 5
+4

Hi @Simon Küter. You can define sets using a set expression (as long as the definition attribute of the set is empty or uses initial data). So you can use something like:

Set2 := { Version1 };

solve MP;

Set2 := { Version2 };

solve MP;

The supported set expressions are described here. (Set2 might be a subset of some other set containing all possible versions.)

Hi @Marcel Hunting ,

I guess my best choice is to create In the Set 2 the Subsets (Version1, Version2, Version3). This elements of the set are fixed and do not change.

In a constraint I wand to do a skalar vector mulitplication. Until now I did a summation of the whole matrix like sum((Set1, Set2) Variables(Set1,Set2)*Parameter(Set1,Set2)).

Now I want to rebuild that Formula. like.

sum((Set1,Version2)Variables(Set1,Version2)*Parameter(Set1,Version2)) - do I have to define each header of the colums as as Subset or can I use the name of the colums to use the values below?

Userlevel 5
+4

I think the best approach would be to create a superset of Set2 containing the power set of (Version1, Version2, Version3), and then define Set2 using set expressions. Then there is no need to adjust expression

sum((Set1, Set2) Variables(Set1,Set2)*Parameter(Set1,Set2)).

because the contents of Set2 is defined by a set expression:

Set2 := { Version2 };

sum((Set1, Set2) Variables(Set1,Set2)*Parameter(Set1,Set2)).

This sum will be evaluated for elements in Version2 only.

Hi @Simon Küter,

Just wanted to check back - did you find the help you needed in this thread, or maybe you found another solution you could share with us? Thank you so much!:)