Valid arrangement of non duplicate 1:1 pairs in a row

tschatz

New Member
Joined
Jan 28, 2022
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hello,

given the following data pairs:

A-B
A-C
A-D
A-E
A-F
B-C
B-D
B-E
B-F
C-D
C-E
C-F
D-E
D-F
E-F

with n = 6 being the number of unique single entities. I want to calculate one possible solution for the highest possible parallelisation.

Assuming each element can only exist once at a certain time, I can determine the maximum number of parallel slots as
Excel Formula:
=ROUNDDOWN(n/2,0)
.
I would like to find a possible valid arrangement of the data pairs.

One possible valid (every element is only allowed once per row) solution might look like this:
B - CD - FA - E
C - EA - DB - F
A - BD - EC - F
A - CB - DE - F
A - FB - EC - D

I thought about randomly filling each row with the "left over" data-pairs starting with row 1 and checking their validity, however starting with row 3 you quickly run into solutions where not all columns can be filled out e.g.


B - CD - FA - E
C - EA - DB - F
A - BC - DE - F
A - CB - D
A - FD - E
B - EC - F

Can anyone give me a hint of how to best approach this topic?

Thanks a lot!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Map1.xlsm
ABCDE
1A-B0,8481380,9089660,530637
2A-C0,4580890,9982030,085773
3A-D0,1227520,9896690,491893
4A-E0,205070,7880260,605936
5A-F0,9431090,6453820,849694
6B-C
7B-DB-CA-EC-D
8B-EC-FA-BE-F
9B-FD-FA-CC-E
10C-DD-EB-DB-F
11C-EA-DB-EA-F
12C-F
13D-E
14D-F
15E-F
Blad2
Cell Formulas
RangeFormula
C1:E5C1=RANDARRAY(5,3)
C7:E11C7=INDEX($A$1:$A$15,RANK(C1,$C$1:$E$5))
Dynamic array formulas.
 
Upvote 0
Map1.xlsm
ABCDE
1A-B0,8481380,9089660,530637
2A-C0,4580890,9982030,085773
3A-D0,1227520,9896690,491893
4A-E0,205070,7880260,605936
5A-F0,9431090,6453820,849694
6B-C
7B-DB-CA-EC-D
8B-EC-FA-BE-F
9B-FD-FA-CC-E
10C-DD-EB-DB-F
11C-EA-DB-EA-F
12C-F
13D-E
14D-F
15E-F
Blad2
Cell Formulas
RangeFormula
C1:E5C1=RANDARRAY(5,3)
C7:E11C7=INDEX($A$1:$A$15,RANK(C1,$C$1:$E$5))
Dynamic array formulas.
Hi BSALV,

thanks for your reply, however your proposal does not offer a valid solution.

For example the this row:
1643414797506.png

the letter "C" is not unique.
 
Upvote 0
a little bit more complicated, in average, 4 trials for 1 good parallelisation.
VBA Code:
Sub rand()
     Dim rand2(), result()
     a = ActiveSheet.Range("A1").CurrentRegion.Columns(1)
     Application.ScreenUpdating = False
     Do
          DoEvents
          ptr = ptr + 1
          ReDim result(1 To 5)
          rand1 = WorksheetFunction.RandArray(UBound(a))

          ReDim rand2(1 To UBound(rand1), 1 To 2)
          For i = 1 To UBound(rand2)
               rand2(i, 1) = rand1(i, 1): rand2(i, 2) = a(i, 1)
          Next

          r = 1
          b = True
          Do
               rand3 = Application.Sort(rand2, 1)
               rand2 = rand3
               For i = 1 To UBound(rand2)
                    b = (rand2(i, 1) < 1)
                    If Not b Then Exit For
                    sp = Split(rand2(i, 2), "-")
                    If InStr(result(r), sp(0)) + InStr(result(r), sp(1)) = 0 Then
                         result(r) = result(r) & "," & rand2(i, 2)
                         rand2(i, 1) = 1000000000#
                         If Len(result(r)) > 10 Then
                              result(r) = Mid(result(r), 2): r = r + 1:
                              Exit For
                         End If
                    End If
               Next
          Loop While b
          
          With Range("D1").Resize(UBound(result))
               .Value = Application.Transpose(result)
               Application.DisplayAlerts = False
               .TextToColumns .Range("A1"), xlDelimited, , , , , 1
               Application.DisplayAlerts = True
          End With
     
     Loop While Range("D5") = "" And ptr < 100
     
     Range("F6").Value = ptr & " trials"
     Range("H" & Rows.Count).End(xlUp).Offset(1) = ptr
End Sub
Map1.xlsm
ABCDEF
1A-B1B-EC-DA-F
2A-C1B-FA-DC-E
3A-D1C-FA-BD-E
4A-E1A-CB-DE-F
5A-F1B-CD-FA-E
6B-C15 trials
7B-D1
8B-E1
9B-F1
10C-D1
11C-E1
12C-F1
13D-E1
14D-F1
15E-F1
Blad2
Cell Formulas
RangeFormula
B1:B15B1=COUNTIF($D$1:$F$5,A1)
 
Upvote 0
Solution
Hi BSALV,

that gave me a very good starting point! Thanks a lot for your help!

BR
Tillmann
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,725
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top