Searching for algorithm to generate combinations ordered by preference

Tim Dean

I am trying to find an algorithm to identify ordered combinations of outcomes as follows:

  • There are N contests, where each contest has 3 mutually exclusive outcomes (win, loss, or tie) for a total of 3N outcomes and 3^N combinations
  • Each of the 3N possible outcomes has been assigned a unique rank, with the most preferable outcome having a rank of 1 and the least preferable outcome having a rank of 3N
  • Find the first M combinations of outcomes for each contest, starting with the combinations that include the most preferably ranked outcomes.

For example, assume that N = 3 and the outcomes are ranked as follows:

Contest 1 Win = 1
Contest 1 Tie = 4
Contest 1 Loss = 7
Contest 2 Win = 2
Contest 2 Tie = 5
Contest 2 Loss = 8
Contest 3 Win = 3
Contest 3 Tie = 6
Contest 3 Loss = 9

Given these rankings, the combinations should be ordered as follows:

Contest 1 Win  (1), Contest 2 Win  (2), Contest 3 Win  (3)
Contest 1 Win  (1), Contest 2 Win  (2), Contest 3 Tie  (6)
Contest 1 Win  (1), Contest 2 Win  (2), Contest 3 Loss (9)
Contest 1 Win  (1), Contest 2 Tie  (5), Contest 3 Win  (3)
Contest 1 Win  (1), Contest 2 Loss (8), Contest 3 Win  (3)
Contest 1 Win  (1), Contest 2 Tie  (5), Contest 3 Tie  (6)
Contest 1 Win  (1), Contest 2 Tie  (5), Contest 3 Loss (9)
Contest 1 Win  (1), Contest 2 Loss (8), Contest 3 Win  (6)
Contest 1 Win  (1), Contest 2 Loss (8), Contest 3 Loss (9)
Contest 1 Tie  (4), Contest 2 Win  (2), Contest 3 Win  (3)
Contest 1 Loss (7), Contest 2 Win  (2), Contest 3 Win  (3)
Contest 1 Tie  (4), Contest 2 Win  (2), Contest 3 Tie  (6)
Contest 1 Tie  (4), Contest 2 Win  (2), Contest 3 Loss (9)
Contest 1 Loss (7), Contest 2 Win  (2), Contest 3 Tie  (6)
Contest 1 Loss (7), Contest 2 Win  (2), Contest 3 Loss (9)
Contest 1 Tie  (4), Contest 2 Tie  (5), Contest 3 Win  (3)
Contest 1 Tie  (4), Contest 2 Loss (8), Contest 3 Win  (3)
Contest 1 Loss (7), Contest 2 Tie  (5), Contest 3 Win  (3)
Contest 1 Loss (7), Contest 2 Loss (8), Contest 3 Win  (3)
Contest 1 Tie  (4), Contest 2 Tie  (5), Contest 3 Tie  (6)
Contest 1 Tie  (4), Contest 2 Tie  (5), Contest 3 Loss (9)
Contest 1 Tie  (4), Contest 2 Loss (8), Contest 3 Tie  (6)
Contest 1 Tie  (4), Contest 2 Loss (8), Contest 3 Loss (9)
Contest 1 Loss (7), Contest 2 Tie  (5), Contest 3 Tie  (6)
Contest 1 Loss (7), Contest 2 Tie  (5), Contest 3 Loss (9)
Contest 1 Loss (7), Contest 2 Loss (8), Contest 3 Tie  (6)
Contest 1 Loss (7), Contest 2 Loss (8), Contest 3 Loss (9)

I am looking for a way to generate these combinations in order for arbitrary large values of N, although I don't expect to ever get all combinations. For example, with N=256 and a total of 3^256 combinations I am looking to find the first 500 combinations.

naitoon

First, let's rephrase the problem in order to abstract the details and to be sure that we are talking about the same problem.

There are 3^N tuples of length N. The components a_i of each tuple (a_1,a_2,...,a_N) are different integers between 1 and 3N inclusive, and for a fixed i, a_i can only take values in a subset S_i, of cardinality 3. For every value in [1,3N] there is one and only one position in the tuple that can assume that value.

Now, denote by sorted(S) the tuple resulting from sorting the components of tuple S in the natural order of integers. We say that a tuple S is less than a tuple T iff sorted(S) is less than sorted(T) in lexicographic order.

The problem consists in finding the first M tuples in the given order, among the 3^N existing ones, where M << 3^N.

The solution principle that I see is essentially backtracking with pruning.

To prune the search space in a critical manner, compute the highest power of 3 not greater than M. Let's say this power is H. We have 3^(H+1) > M >= 3^H. At that point, you know that your M tuples lie in a set where (N-H-1) tuple components take their smallest-possible value. These components can be found and fixed as follows: first, take the component i that can take value 1, and fix it to 1. Then, among the values of [1,3N] not taken by component i, choose the smallest, and fix the only component j able to take that value, to that same value. Continue in the same way, fixing (N-H-1) components. After that, you have determined a set of at most 3M tuples. You can generate that complete set of tuples (by exhaustive search over the remaining H+1 components) and then sort this set, obtaining the first M tuples.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PHP algorithm to generate all combinations of a specific size from a single set

From Dev

Which is the better Searching algorithm ??

From Dev

Algorithm for unique combinations

From Dev

Combinations Recursive Algorithm

From Dev

Algorithm to find "ordered combinations"

From Dev

Generate combinations of elements with echo

From Dev

Dynamic Programing to generate combinations

From Dev

Algorithm for searching for patterns in trees

From Dev

Algorithm to Generate number letter combinations with a twist

From Dev

Generate all possible combinations

From Dev

Efficient PHP algorithm to generate all combinations / permutations of inputs

From Dev

Algorithm for ordered set of partitions

From Dev

How to generate combinations

From Dev

Javascript algorithm to generate all possible unique combinations of any length of Sub-Arrays within an Array

From Dev

Grouping algorithm for combinations

From Dev

Ordered combinations without repetition in php?

From Dev

PHP algorithm to generate all combinations of a specific size from a single set

From Dev

Algorithm to find "ordered combinations"

From Dev

Searching for letter combinations in a string php

From Dev

Generate combinations of elements with echo

From Dev

Hashing Algorithm Usage in Searching

From Dev

Generate Combinations in Excel

From Dev

Generate a Preference Matrix in R?

From Dev

Efficient PHP algorithm to generate all combinations / permutations of inputs

From Dev

Algorithm for ordered set of partitions

From Dev

Scalable searching algorithm SQL

From Dev

Generate all ordered combinations of a list, where each combination includes all items

From Dev

Searching Algorithm using listbox

From Dev

Restricted combinations (algorithm)

Related Related

  1. 1

    PHP algorithm to generate all combinations of a specific size from a single set

  2. 2

    Which is the better Searching algorithm ??

  3. 3

    Algorithm for unique combinations

  4. 4

    Combinations Recursive Algorithm

  5. 5

    Algorithm to find "ordered combinations"

  6. 6

    Generate combinations of elements with echo

  7. 7

    Dynamic Programing to generate combinations

  8. 8

    Algorithm for searching for patterns in trees

  9. 9

    Algorithm to Generate number letter combinations with a twist

  10. 10

    Generate all possible combinations

  11. 11

    Efficient PHP algorithm to generate all combinations / permutations of inputs

  12. 12

    Algorithm for ordered set of partitions

  13. 13

    How to generate combinations

  14. 14

    Javascript algorithm to generate all possible unique combinations of any length of Sub-Arrays within an Array

  15. 15

    Grouping algorithm for combinations

  16. 16

    Ordered combinations without repetition in php?

  17. 17

    PHP algorithm to generate all combinations of a specific size from a single set

  18. 18

    Algorithm to find "ordered combinations"

  19. 19

    Searching for letter combinations in a string php

  20. 20

    Generate combinations of elements with echo

  21. 21

    Hashing Algorithm Usage in Searching

  22. 22

    Generate Combinations in Excel

  23. 23

    Generate a Preference Matrix in R?

  24. 24

    Efficient PHP algorithm to generate all combinations / permutations of inputs

  25. 25

    Algorithm for ordered set of partitions

  26. 26

    Scalable searching algorithm SQL

  27. 27

    Generate all ordered combinations of a list, where each combination includes all items

  28. 28

    Searching Algorithm using listbox

  29. 29

    Restricted combinations (algorithm)

HotTag

Archive