26 #include <basic/Tracer.hh>
31 #include <utility/vector1.hh>
35 namespace frag_picker {
39 "protocols.frag_picker.quota.QuotaSelector");
44 trQuotaSelector.Trace <<
"Selector set up for pos. "<<pos_in_query<<std::endl;
51 if( recently_taken >= pool.size() )
55 for(
Size i=recently_taken;i<=pool.size();i++) {
56 if ( pool[i].first == 0 ) {
58 <<
" from a pool is null - nothing to select\n"
59 <<
" maybe your vall database is to small?" << std::endl;
62 if( in_use.find( pool[i].first->key() ) == in_use.end() ) {
63 in_use.insert( pool[i].first->key() );
73 bool operator() (std::pair<Size,Size> i,std::pair<Size,Size> j) {
return (i.second>j.second); }
77 bool operator() (std::pair<Size,Size> i,std::pair<Size,Size> j) {
return (i.second<j.second); }
81 bool operator() (std::pair<Size,Real> i,std::pair<Size,Real> j) {
return (i.second>j.second); }
89 for(
Size i=1;i<=q_limits.size();i++) {
91 tmp.push_back( std::pair<Size,Size>(i,q_limits[i]) );
93 Size diff = target_total - total;
95 trQuotaSelector.Trace <<
"Pushing the quota limits from total "<<total<<
" to "<<target_total
96 <<
", the first pool has size "<<tmp[1].second<<std::endl;
98 for(
Size i=1;i<=q_limits.size();i++) {
101 q_limits[ tmp[i].first ] ++;
112 for(
Size i=1;i<=q_limits.size();i++) {
113 total += q_limits[i];
114 tmp.push_back( std::pair<Size,Size>(i,q_limits[i]) );
116 Size diff = target_total - total;
118 trQuotaSelector.Trace <<
"Pushing the quota limits from total "<<total<<
" to "<<target_total
119 <<
", the first pool has size "<<tmp[1].second<<
" and takes extra "<<diff<<std::endl;
120 q_limits[ tmp[1].first ] += diff;
128 for(
Size i=1;i<=q_limits.size();i++) {
129 total += q_limits[i];
131 Size diff = target_total - total;
133 trQuotaSelector.Trace <<
"Pushing the quota limits from total "<<total<<
" to "<<target_total
139 for(
Size i=1;i<=q_limits.size();i++) {
140 Real missing = q_fractions[i] - ((
Real) q_limits[i]) / target_total;
141 tmp.push_back( std::pair<Size,Real>(i,missing) );
144 q_limits[ tmp[1].first ] ++;
160 std::set<Size> nice_collection;
161 bool something_taken =
false;
179 something_taken =
false;
182 if ( q_cnt[i] == q_limits[i] )
186 output_selection.push_back( fs[ifrag] );
188 something_taken =
true;
193 trQuotaSelector.Trace<<
"Position "<<
q_pos_<<
" done, "<< output_selection.size()<<
" fragments selected."<<std::endl;
206 std::set<Size> nice_collection;
207 bool something_taken =
false;
214 total = 25.0 / total;
223 trQuotaSelector.Trace<<
"Position: "<<
q_pos_<<
" frag_size:"<<frag_size<<
" pool allowances for the first 25 fragments are:\n";
230 something_taken =
false;
232 if( q_cnt[i] == q_limits[i] )
238 fs[ifrag].second->set_quota_score( the_pool->quota_score( fs[ifrag] ) );
239 fs[ifrag].first->set_pool_name( the_pool->get_pool_name() );
241 output_selection.push_back( fs[ifrag] );
243 something_taken =
true;
247 }
while((n < 25) && (something_taken==
true));
260 total = ((
Real) fr_per_pos) / total;
273 something_taken =
false;
275 if( q_cnt[i] == q_limits[i] )
280 last_selected[i] = ifrag;
282 fs[ifrag].second->set_quota_score( the_pool->quota_score( fs[ifrag] ) );
283 fs[ifrag].first->set_pool_name( the_pool->get_pool_name() );
284 output_selection.push_back( fs[ifrag] );
286 something_taken =
true;
290 }
while((n < fr_per_pos) && (something_taken==
true));