Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Matched pairs represented by triplets??
Message
 
 
À
10/03/2003 11:22:25
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00763480
Message ID:
00763840
Vues:
17
Neil,

>Please re-read my thread. This does not answer the problem. I am attempting to determine the least number of triplets (a-j) that will cover the 10 matched pairs listed.

So you have 5C2 to generate the 10 pairs and some arbitrary subset (10 of the 720 combinations 10C3) of the pairs as triplets.

Since you have 10 pairs in the list, taken 3 at a time it's going to take at least ceiling( 10 / 3 ) triplets to satisfy having all 10 pairs covered.

I'll restructure your triplets to something that is more SQL friendly.
create cursor triplets ( key c(1) )
create cursor tripletpairs ( key c(1), pair c(3))
InsertData( 'a','1,2','1,3','2,3' )
InsertData( 'b','1,2','1,4','2,4' )
InsertData( 'c','1,2','1,5','2,5' )
InsertData( 'd','1,3','1,4','3,4' )
InsertData( 'e','1,3','1,5','3,5' )
InsertData( 'f','1,4','1,5','4,5' )
InsertData( 'g','2,3','2,4','3,4' )
InsertData( 'h','2,3','2,5','3,5' )
InsertData( 'i','2,4','2,5','4,5' )
InsertData( 'j','3,4','3,5','4,5' )

function InsertData( pcKey, pcVal1, pcVal2, pcVal3 )
insert into triplets values ( pcKey )
insert into tripletpairs values ( pcKey, pcVal1 )
insert into tripletpairs values ( pcKey, pcVal2 )
insert into tripletpairs values ( pcKey, pcVal3 )
return
to test the 4 triplets for a solution using code similar to what I posted earlier:
select triplets.key as key1, triplets2.key as key2, triplets3.key as key3, triplets4.key as key4 ;
   from triplets ;
   left join triplets as triplets2 on triplets.key < triplets2.key ;
   left join triplets as triplets3 on triplets.key < triplets3.key and ;
                                      triplets2.key < triplets3.key ;
   left join triplets as triplets4 on triplets.key < triplets4.key and ;
                                      triplets2.key < triplets4.key and ;
                                      triplets3.key < triplets4.key ;
   into cursor TheCombinations ;
   having ! isnull( key2 ) and ! isnull( key3 ) and ! isnull( key4 )
You now have a cursor of all possible combinations of your triplets taken 4 at a time. Each one needs to be tested as a solution. It is a solution if it covers all 10 of the original pairs.
select TheCombinations
scan
   scatter name thiscombination
   select distinct tripletpairs.pair ;
      from tripletpairs ;
      into cursor testsolution ;
      where key = thiscombination.key1 or ;
            key = thiscombination.key2 or ;
            key = thiscombination.key3 or ;
            key = thiscombination.key4
   if _tally = 10
      * it's a solution
      ? thiscombination.key1, thiscombination.key2, thiscombination.key3, thiscombination.key4
   endif
endscan
I assume the first solution is sufficient so you could exit the loop. Your sample data has 10 solutions. The code can also be made more dynamic with macros to test the 5,6,7,8,9 and 10 triplet combinations if required.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform