setunionmultiplicationcplex# Cartesian multiplication of two sets where the member of each set is a set

enter link description hereI have two expressions that I want to get a member-by-member union of. But the problem is where the member of each expression is a set.

I have a graph from which I obtained two expressions where the first two terms include all odd subsets of odd nodes (it has 128 members) and the second term includes all even subsets of even nodes (it has 7 members).
I want to define a new expression called Sub_odd_even which contains the union of all the previous two expressions. for example:
`A=[{1,2,3},{4}] B=[{6}] AB = [{1,2,3,6},{4,6}]`

I tried the following codes, but none of them were correct. cplex software itself errors them

` int num_odd_even1 = card(Sub_even_even); int num_odd_even2 = card(Sub_odd_odd); int num_odd_even = odd_even1 * odd_even2

```
{int} Sub_odd_even = {i * j | i in Sub_odd_odd, j in Sub_even_even};
{int} Sub_odd_even = {foreach (i in Sub_odd_odd, j in Sub_even_even) i * j};
{int} Sub_odd_evev[oe in num_odd_even] = {item(Sub_odd, i-1) | i in 1..subr and j in 1..subre};
```

`

Solution

I shared an example in https://github.com/AlexFleischerParis/howtowithopl/blob/master/cartesianproduct2.mod

```
// Cartesian product for a given number of sets
tuple Tset {
{string} members;
}
{Tset} setOfTuples = {<{"1","2"}>,<{"4","5","6"}>,<{"8","9"}>};
// Here we have 3 dimensions
{Tset} result=union (k in item(setOfTuples,2).members,
j in item(setOfTuples,1).members,
i in item(setOfTuples,0).members)
{<{i,j,k}>};
execute
{
writeln(result);
}
/*
which gives
{<{"1" "4" "8"}> <{"2" "4" "8"}> <{"1" "5" "8"}> <{"2" "5" "8"}>
<{"1" "6" "8"}> <{"2" "6" "8"}> <{"1" "4" "9"}>
<{"2" "4" "9"}> <{"1" "5" "9"}> <{"2" "5" "9"}>
<{"1" "6" "9"}> <{"2" "6" "9"}>}
*/
```

and then for your second question about how to do the union:

```
tuple t
{
{int} s1;
{int} s2;
}
{t} s={<{1},{5,6}>};
{int} res[i in s]=i.s1 union i.s2;
execute
{
writeln(res);
}
```

which gives

```
[{1 5 6}]
```

- remove duplicates in Set
- Simplest way to merge ES6 Maps/Sets?
- Opposite of MySQL FIND_IN_SET
- How to add generator elements to a set() without a loop?
- Check if two vectors are equal
- TypeScript object set with unique property
- Is there a way to further optimize this code?
- Static method wrapper for map in Swift
- Agda: Why does the compiler demand Set_1, not Set in a data definition?
- override hive property in sprint hive jdbc
- How to type hint a subset of values from a known set in python
- Java: Enumeration from Set<String>
- Efficiently compare two sets in Python
- error in creation of Set from Points
- Efficient way to count number of Set! in a table
- Which is faster and why? Set or List?
- Converting a list to a set changes element order
- Is there a Python equivalent for C++ "multiset<int>"?
- Count number of ways to pair integers 1-14 under constraint
- Does Python have an ordered set?
- Java Set retain order?
- Why don't Python sets preserve insertion order?
- How to create a std::set with custom comparator in C++?
- JavaScript Set vs. Array performance
- How can I add a property set value "intern" automatically to each new repository on artifactory 7.x?
- std::set comparator - STL Sort based on multiple attributes
- C++ sort cannot sort set of strings?
- How to get first item from a java.util.Set?
- How to get all subsets of a set? (powerset)
- Complexity of converting a set to a frozenset in Python