What I have done
Firstly, this may not be the best forum, so apologies if that's the case. I am creating a Pyomo model, where I have created a binary matrix as follows:
model.binMat = Var(range(6),range(6),domain=Binary)
My model solves for this matrix, with a typical output like this:
binaryMatrix = [[0 1 0 1 0 0]
[1 0 1 0 0 0]
[0 1 0 0 0 1]
[1 0 0 0 1 0]
[0 0 0 1 0 1]
[0 0 1 0 1 0]]
Results are interpreted as the coordinates of the 1's, i.e. (1,2),(1,4),(2,1),(2,3),(3,2),(3,6),(4,1),(4,5),(5,4),(5,6),(6,3),(6,5) in this example.
This is then thought of in terms of groups of connected elements. In this case, there would only be 1 unique group: (1,2,3,4,5,6).
What I need
I would like help to create a new constraint to only allow 2 unique groups that are equally sized by referencing the values in model.binMat.
An example of what these final groups could look like is: (1,5,6) and (2,3,4). The corresponding coordinates for this could be: (1,5),(1,6),(2,3),(2,4),(3,2),(3,4),(4,2),(4,3),(5,1),(5,6),(6,1),(6,5)
I am currently attempting to solve this using Pyomo sets, but as these are new to me, I haven't had any luck.
Edit
For those interested in alternative approaches to the same problem, I also posted this here