I am working on a music synthesis. I have to generate certain musical notes and let us say total number of notes equals to $t$. I have $m$ number of methods (functions) named $m_1, m_2, m_3, \cdots$ and each of them generate specific kind of musical phrases (group of musical notes) consisting of $x_n$ musical notes. Let us name these count of musical notes as $x_1, x_2, x_3,$ etc. corresponding to methods $m_1$, $m_2$ $m_3$ etc.
That means $t = x_1+x_2+x_3+ \dots = 100\%$ Each method is also associated with % allocation of musical notes they have to generate and $100\%$ means $t$.
One method will not generate all required $x_n$ counts in one iteration and we may have to go for several iterations to reach their allocated $\%$.

Also once one method is called, the same method cannot be called immediately unless it has very high %. So we need to go for round robin concept and I will name each iteration $i$. Also number of notes generated in each iteration by each method ($=x_{ni}$) is known only after calling the method.

$x_n = x_{n1} + x_{n2} + x_{n3}+\dots$

It is assumed that number of notes in one iteration of respective method is always less than total allocated notes for that method ($x_{n_i} < x_n$)

Assuming 3 methods, distribution could be something like: $t= x_{11} + x_{21} + x_{31} + x_{12} + x_{32} + x_{13}+ x_{22} + x_{14} + x_{33} + x_{15} + x_{23} = 100\%$
That means every method may not be called in every iterations.

Since number of notes generated by each method is known only after calling a method, we can not distribute in advance. After each iteration, we have to consolidate % notes distributed to that method and evaluate % allocation.

I thought of using knapsack algorithm, considering total weight $= 100\% = t$. But having difficulty with round robin distribution and due to iterative process.

Can anyone suggest best algorithm to handle this? Also any support is available to code in Java?

  • $\begingroup$ Questions about Java are off-topic here. $\endgroup$ – Yuval Filmus Aug 25 '17 at 21:43
  • $\begingroup$ I don't see how the knapsack algorithm is relevant here, since you don't know the number of notes generated in advance. $\endgroup$ – Yuval Filmus Aug 25 '17 at 21:44
  • 1
    $\begingroup$ The question seems to be difficult to answer, since you haven't explained what your goal is. Also, a constraint of the form "once one method is called, the same method cannot be called immediately unless it has very high %" is a bit too vague. I suggest using some naive heuristic approach. $\endgroup$ – Yuval Filmus Aug 25 '17 at 21:47
  • $\begingroup$ Corrected typo (me to m2 ). I guess the algorithm is close to weighted round robin with some constrains such as same method may not be selected immediately unless its % is high and all other methods are already reached their allocated percentage. Also I need to verify allocation after each iteration. I need to see if dynamic round robin algorithm is suitable here. $\endgroup$ – Rajesh Aug 26 '17 at 3:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.