Elements mixing algorithm -
not sure title.
here need.
lets illustration have set of elements 20*a, 10*b, 5*c, 5*d, 2*e, 1*f need mix them there not 2 same elements next each other , can illustration don't want b , c next each other. elements have evenly spread (if there 2 e 1 should near begining/ in firs half , sec near end/in sec half. number of elements can of course of study change.
i haven't done yet. there knowledge-base of kind of algorithms find hints , methods how solve kind of problem or have math myself?
i think solution pretty easy.
start array x initialised empty values such there 1 space each item need place.
then, each (item, frequency) pair in descending order of frequency, assign item values x in alternating slots starting first empty slot.
here's how works example:
20*a a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a 10*b ababababababababababa_a_a_a_a_a_a_a_a_a 5*c ababababababababababacacacacaca_a_a_a_a 2*e ababababababababababacacacacacaeaea_a_a 1*f ababababababababababacacacacacaeaeafa_a at point fail, since x still has empty slot. note have identified right start since need @ to the lowest degree 19 slots between as, have 18 other items.
update
leonidas has explained items should distributed "evenly" (that is, if have k items of particular kind, , n slots fill, each "bucket" of n/k slots must contain 1 item of kind.
we can adapt constraint spreading out our allocations rather going alternating slots. in case (and let's assume 2 fs can solve this), have
20*a a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a 10*b aba_aba_aba_aba_aba_aba_aba_aba_aba_aba 5*c abacaba_abacaba_abacaba_abacaba_abacaba 2*e abacabaeabacaba_abacabaeabacaba_abacaba 2*f abacabaeabacabafabacabaeabacabafabacaba algorithm mixing
No comments:
Post a Comment