103 std::size_t numStates = m_probabilities.size();
104 m_q.resize(numStates);
105 m_J.resize(numStates);
106 m_probabilities/=sum(m_probabilities);
110 std::deque<std::size_t> smaller;
111 std::deque<std::size_t> larger;
112 for(std::size_t i = 0;i != numStates; ++i){
113 m_q(i) = numStates*m_probabilities(i);
115 smaller.push_back(i);
122 while(!smaller.empty() && !larger.empty()){
123 std::size_t smallIndex = smaller.front();
124 std::size_t largeIndex = larger.front();
128 m_J[smallIndex] = largeIndex;
129 m_q[largeIndex] -= 1.0 - m_q[smallIndex];
131 if(m_q[largeIndex] < 1.0)
132 smaller.push_back(largeIndex);
134 larger.push_back(largeIndex);
136 for(std::size_t i = 0; i != larger.size(); ++i){
137 m_q[larger[i]]=std::min(m_q[larger[i]],1.0);