0

Before I put my code, that I built it based on Thomas Draper code, and thanks to Jarod42

I will explain it in example:

Let this data in txt file: where each integer numbers associated with probability 
    1 0.933 2 0.865 3 0.919 4 0.726
    3 0.906 2 0.854 4 0.726
    4 0.865 3 0.933 5 0.919
Let the use input threshold = 1.5

I want to apply (next_combination) on my data in loop from k=1 until there is no more combination

When k =1, the result will be:

First step: generate all set of size 1, where the frequency of item can be represented by the summation of its probability.

{1}= 0.933
{2}= 0.865 + 0.854= 1.719
{3}= 0.919 + 0.906 + 0.933 = 2.758
{4}= 0.726 + 0.726 + 0.865 = 2.317
{5}= 0.919

Second step: ears all set of size 1, that has frequency of < threshold ==> We erased set {1}, {5}. And save the deleted item in another set

Repeat the steps when k=2

First step: generate all set of size 2,

We check to see if the generated set is superset from set that in erased set

we know that {1}, {5} already erased, So no need to generate any superset include {1}, {5}

The rest generated superset will be:

{2,3} = (0.865 * 0.919 ) + (0.906 * 0.854) = 1.56774
{2,4}= (0.865 * 0.726) + (0.854 * 0.726)= 1.247994
{3,4}=  (0.919 * 0.726) + (0.906 * 0.726) + (0.865 *0.933)= 2.131995

Second step: ears all set of size 2, that has frequency of < threshold ==> We erased set {2,4} And save the deleted item in erased set, {1}, {5}, {2,4}

Repeat the steps when k=3 From the previous step we only have: {2,3}, and {3,4} The new generated set will be

{2,3,4} = (0.865 * 0.919 * 0.726) + (0.906 * 0.854 * 0.726)= 1.138846434 < threshold

I have done this code before with vector of vector of integer, it gives me correct answer but worst time. (code)

here where i need help, I got a lot of errors can't deal with them because i don't know how to employ next_combination with struct (code)

Community
  • 1
  • 1
phoenix
  • 89
  • 7
  • Your compilation error with the second example is that you did not implement `operator<` for your struct. You also include several headers you do not need including one that is deprecated causing other warning spam. – Retired Ninja Jun 02 '14 at 17:24
  • I add this code: `bool operator<(const Trans &a, const Trans &b) { return a.Item < b.Item; }` and it seems work, but still struggling with the performance/run time. thanks – phoenix Jun 02 '14 at 23:38

0 Answers0