algorithm - Generate one of many ways of distributing toys among children -
- there n children , finite set t of distinguishable toys;
- each child likes particular subset ti of toys;
- each child needs own exact number ti <= |ti| of toys, toys child likes;
- some toys liked more 1 child.
- a toy can't owned multiple children
there possibly many ways satisfy each child's need toys.
problem: given n, {ti}, {ti} , seeded rng, possible configurations of toys owned children need pick uniformly distributed (or @ least close uniformly distributed) configuration, is, mapping children toys own.
generating possible configurations , picking j-th no go — there may lot of those.
in example below there 4 children: red, blue, green , yellow. red needs own 4 toys, blue — 5, green — 3, yellow — 3. toys children like inside rectangles of corresponding colors.

so need either outline of algorithm generate well-distributed map<child, set<toy>>, or links useful read solving problem.
prepare bipartite graph follows. each child i, make t_i vertices. each toy j, make 1 vertex. whenever child i likes toy j, connect of i's vertices j's vertex. valid assignments of toys children correspond perfect matchings in graph. compute 1 assignment using favorite matching algorithm (e.g., hopcroft--karp) , run markov chain of jerrum , sinclair long desired.
Comments
Post a Comment