int Bchart:: headPosFromItems(Item* lhs, Items& rhs) { int ansPriority = 9999; ECString lhsString(lhs->term()->name()); if(lhsString == "") lhsString = "S1"; int pos = -1; int ans = -1; Items::iterator ii = rhs.begin(); Item *subi; for( ; ii != rhs.end() ; ii++ ) { subi = (*ii); pos++; const Term* trm = subi->term(); int nextPriority = 12; if(trm) { ECString rhsString(subi->term()->name()); if(subi->term() == Term::stopTerm) continue; nextPriority = headPriority(lhsString, rhsString, ansPriority); } if(nextPriority <= ansPriority) { ans = pos; ansPriority = nextPriority; } } return ans; }
QStringList ShopTemplateManager::WriteItems(const Items &items, bool includeBuyoutTag, bool includeNoBuyouts) { Items sorted = items; QStringList result; // Sort to ensure that the template matches even if the item order is different. std::sort(sorted.begin(), sorted.end(), [](const std::shared_ptr<Item> &first, const std::shared_ptr<Item> &second) -> bool { return first->PrettyName() > second->PrettyName(); }); for (auto &item : sorted) { if (item->location().socketed()) continue; if (parent_->buyout_manager().Exists(*item)) { Buyout bo = parent_->buyout_manager().Get(*item); QString temp = QString::fromStdString(item->location().GetForumCode(parent_->league())); if (includeBuyoutTag) temp += BuyoutManager::Generate(bo); result << temp; } else if (includeNoBuyouts) { result << QString::fromStdString(item->location().GetForumCode(parent_->league())); } } return result; }
inline ConfigItem* Configuration::find(const char* key) { for(Items::iterator i = items_.begin(); i != items_.end(); ++i) { ConfigItem* item = *i; if(item->equal_p(key)) return item; } return 0; }
inline bool Configuration::import(const char* key, const char* val) { for(Items::iterator i = items_.begin(); i != items_.end(); ++i) { ConfigItem* item = *i; if(item->set_maybe(key, val)) return true; } return false; }
inline void Configuration::print(bool desc) { for(Items::iterator i = items_.begin(); i != items_.end(); ++i) { ConfigItem* item = *i; std::cout << item->name() << ": "; item->print_value(std::cout); std::cout << "\n"; if(desc) { if(const char* desc = item->description()) { std::cout << " " << desc << "\n"; } std::cout << "\n"; } } }
Item * ChartBase:: get_S() const { const Term * sterm = Term::rootTerm; Item *itm; Items il = regs[wrd_count_ - 1][0]; Items::iterator ili = il.begin(); for(; ili != il.end(); ili++ ) { itm = *ili; if( itm->term() == sterm ) return itm; } return NULL; }
void Persist::saveItems(Items& library) { Items::iterator iterator; const char* fileName = Library::FILE_NAME.c_str(); std::ofstream file(fileName, std::ios::out); if (!file) { std::cerr << "Error while opening " << fileName << std::endl; exit(EXIT_FAILURE); } for (iterator = library.begin(); iterator != library.end(); ++iterator) { Item item = (*iterator).second; file.write(reinterpret_cast<const char*>(&item), sizeof(Item)); } file.close(); }
void get_items_at(const Rectf& rect, std::vector<C>& out_items) const { // If rect overlaps with the given quadrant, recursivly check the quadrant if (m_nw.get() && rect.left < m_center.x && rect.top < m_center.y) { m_nw->get_items_at(rect, out_items); } if (m_ne.get() && rect.right > m_center.x && rect.top < m_center.y) { m_ne->get_items_at(rect, out_items); } if (m_sw.get() && rect.left < m_center.x && rect.bottom > m_center.y) { m_sw->get_items_at(rect, out_items); } if (m_se.get() && rect.right > m_center.x && rect.bottom > m_center.y) { m_se->get_items_at(rect, out_items); } // Check all overlapping items for(typename Items::const_iterator i = m_items.begin(); i != m_items.end(); ++i) { if (i->rect.is_overlapped(rect)) { out_items.push_back(i->data); } } }
void Client::processPersistentRequests(_Store& store) { // create a typedef for the vector holding the correct type of items typedef std::vector<typename _Store::Item> Items; // get the items that need to be reconstructed Items items = store.getBadItems(); if (items.size() > 0) logger_->debug("A total of %d persistent requests need to be re-processed", items.size()); // loop through the items and process them // (We don't have to care about the Status result of the processRequest function, // since processPersistentRequests() is called automatically by a thread, and this // thread doesn't perform any actions in case of failures.) for (typename Items::iterator it = items.begin(); it != items.end(); ++it) processRequest<typename _Store::ServiceType>( it->request, it->badTargetsMask, it->result); }
void Space::UpdateChunk( Vec2i index, float dt ) { // The chunk we're at Chunks::iterator it = chunks.find( index ); if( it != chunks.end() ) { Chunk &chunk = it->second; // Update our chunk and everything in it chunk.Update( dt ); // Check intersections Items items = chunk.GetItems(); for( Items::iterator it = items.begin(); it != items.end(); ++it ) { if( (*it)->BoundingBox().Intersects( satellite.BoundingBox() ) ) { Intersects( *it ); } } } else { //L_("couldn't find %d index chunk for updating\n"); } }
/* static */ void Module_DMAP::generic_worker_single_thr(Module_DMAP * search, int id) { Mask * sequences; int read_seq; vector<Mask> printable_solutions; Transmitting_Result received; if (search->my_rank == 0) { sequences = new Mask[SEQUENCES_FOR_BLOCK]; read_seq = read_sequences(search->input_file1, SEQUENCES_FOR_BLOCK, sequences, search->fastqformat, search->gui_output); } else { received = search->receive_from_previous(id); sequences = received.first; read_seq = received.second; } while (read_seq != 0) { Items solutions; //ItemsGapped solutions_gapped; t_errors calculated_errors; for (int i = 0; i < read_seq; i++) { Mask & s = sequences[i]; if (search->my_rank == 0 and search->trim) { // check_routine(sequences[i], 0); s.quality_trimming_MOTT(search->min_phred_value_MOTT,search->min_mean_quality,search->min_size); } if (s.status_discarded()) { if (s.status_low_complexity()) s.low_complexity =true; //s.set_type(low_complexity); else s.low_quality = true; //s.set_type(quality_discarded); printable_solutions.push_back(s); continue; } if (search->auto_errors) calculated_errors = round((double)s.get_good_length() / search->errors_rate); else calculated_errors = search->common_errors_allowed; if (search->my_rank != 0 and s.algn > 0 and s.NM < calculated_errors) calculated_errors = s.NM; t_errors count = 0; for (t_pattern_length i = s.get_good_region_start()-1; (i < s.get_good_region_stop()) and (count <= calculated_errors); i++) if (s.sequence[i] == 'N' or s.sequence[i] == 'n') count++; if (count > calculated_errors) { //s.set_type(alignments_not_found); printable_solutions.push_back(s); continue; } /** ALIGNMENT **/ solutions.clear(); if (search->my_rank == 0 and search->contamination_check) { search->CR.search(s.get_good_sequence(),solutions,calculated_errors); if (solutions.size() > 0) s.contaminated = true; } if (not s.contaminated) search->H.search(s.get_good_sequence(),solutions,calculated_errors); if (solutions.size() == 0) { /** Try gapped **/ /* solutions_gapped.clear(); if (search->gap) search->H.search_gapped(s.get_good_sequence(),solutions_gapped,search->seed_sizes,search->seed_errors,calculated_errors,search->max_gap); */ /* if (solutions_gapped.size() == 0) {// size 0 means no alignment found */ //s.set_type(alignments_not_found); printable_solutions.push_back(s); continue; /* } else { if (not search->printAll) { Random_Choice_Result r; bool improved = (s.NM + s.NM_gap) > (solutions_gapped.at(0).errors1 + solutions_gapped.at(0).errors2); if (improved) r = Search_MPI::random_choice_from_previous(0,solutions_gapped.size()); else r = Search_MPI::random_choice_from_previous(s.algn,solutions_gapped.size()); if (not improved and r.first) { // take the previous solution s.algn += solutions_gapped.size(); } else { // update solution const ResultItemGapped & HM = solutions_gapped.at(r.second); s.globalPosition = HM.GlobalPosition1; if (improved) s.algn = solutions_gapped.size(); else s.algn += solutions_gapped.size(); s.HI = 1; s.IH = 1; s.primary = true; s.strand = HM.strand; s.NM = HM.errors1; s.NM_gap = HM.errors2; s.contig = HM.contig; s.position = HM.GlobalPosition1 - search->H.globaltolocal.startPositions[HM.contig] + 1 ; s.position_gap = HM.GlobalPosition2 - search->H.globaltolocal.startPositions[HM.contig] + 1 ; s.length1_gap = HM.length1; s.length2_gap = HM.length2; s.contig = search->contig_conversion.convert(s.contig); } printable_solutions.push_back(s); } else { // printALL */ /* unsigned int processed=0; unsigned int alignments; (search->toBePrinted < solutions_gapped.size()) ? alignments = search->toBePrinted : alignments = solutions_gapped.size() ; while(processed < alignments) { const ResultItemGapped & HM = solutions_gapped.at(processed); s.globalPosition = HM.GlobalPosition1; s.algn = alignments; s.HI =1; s.IH =1; (processed == 0 ) ? s.primary = true : s.primary = false; s.strand = HM.strand; s.NM = HM.errors1; s.NM_gap = HM.errors2; s.contig = HM.contig ; s.position = HM.GlobalPosition1 - search->H.globaltolocal.startPositions[HM.contig] + 1 ; s.position_gap = HM.GlobalPosition2 - search->H.globaltolocal.startPositions[HM.contig] + 1 ; s.length1_gap = HM.length1; s.length2_gap = HM.length2; s.contaminated = contaminated; printable_solutions.push_back(s); processed++; } */ /* ERROR_CHANNEL << "--print-all option not implemented yet!" << endl; exit(3); } } */ } else if (not search->printAll) { sort(solutions.begin(), solutions.end(), ResultItem::less()); // sort solutions solutions.erase(unique(solutions.begin(), solutions.end(), ResultItem::equal()), solutions.end()); Random_Choice_Result r; bool improved = (s.NM + s.NM_gap) > (solutions.at(0).errors); if (improved) r = Module_DMAP::random_choice_from_previous(0,solutions.size()); else { r = Module_DMAP::random_choice_from_previous(s.algn,solutions.size()); s.algn += solutions.size(); } if (not r.first) { const ResultItem & HM = solutions.at(r.second); s.HI = 1; s.IH = 1; s.primary = true; s.globalPosition = HM.globalPosition; s.strand = HM.strand; s.NM = HM.errors; s.NM_gap = 0; if ((search->my_rank == 0) and s.contaminated) { s.contig = search->CR.globalToLocal.searchContig(HM.globalPosition); // find the contig/scaffold s.position = HM.globalPosition - search->CR.globalToLocal.startPositions[s.contig] + 1; s.contig = search->contig_conversion.convert(s.contig); } else { s.contig = search->H.globalToLocal.searchContig(HM.globalPosition); // find the contig/scaffold s.position = HM.globalPosition - search->H.globalToLocal.startPositions[s.contig] + 1; s.contig = search->contig_conversion.convert(s.contig); } } printable_solutions.push_back(s); continue; } else { // printAll /* // memorize all printable solutions sort(solutions.begin(), solutions.end(), ResultItem::less()); // sort solutions solutions.erase(unique(solutions.begin(), solutions.end(), ResultItem::equal()), solutions.end()); unsigned int processed=0; unsigned int alignments; (search->toBePrinted < solutions.size()) ? alignments = search->toBePrinted : alignments = solutions.size() ; while(processed < alignments) { // while I print enough solution or there are no more solutions const ResultItem & HM = solutions.at(processed); s.globalPosition = HM.GlobalPosition; s.algn = solutions.size(); s.IH = alignments; s.HI = processed+1; (processed == 0 ) ? s.primary = true : s.primary = false; s.strand = HM.strand; s.NM = HM.errors; if (contaminated) { s.contig = search->CR.globaltolocal.searchContig(HM.GlobalPosition); // find the contig/scaffold s.position = HM.GlobalPosition - search->CR.globaltolocal.startPositions[s.contig] + 1; } else { s.contig = search->H.globaltolocal.searchContig(HM.GlobalPosition); // find the contig/scaffold s.position = HM.GlobalPosition - search->H.globaltolocal.startPositions[s.contig] + 1; } s.contaminated = contaminated; printable_solutions.push_back(s); } */ ERROR_CHANNEL << "--print-all option not implemented yet!" << endl; exit(3); } } if (search->my_rank == (search->nprocs-1)) { // now print all for(unsigned int i=0; i < printable_solutions.size(); i++) search->output_samfile.print_output(printable_solutions.at(i)); search->processed += read_seq; } else // send data to next node search->send_to_next(printable_solutions,id); delete [] sequences; printable_solutions.clear(); if (search->my_rank == 0) { sequences = new Mask[SEQUENCES_FOR_BLOCK]; read_seq = read_sequences(search->input_file1, SEQUENCES_FOR_BLOCK, sequences, search->fastqformat, search->gui_output); if (read_seq == 0) delete [] sequences; } else { received = search->receive_from_previous(id); sequences = received.first; read_seq = received.second; } } }
Items::iterator items_end() { return items_.end(); }
void ChartBase:: set_Alphas() { Item *snode = get_S(); double tempAlpha[400]; //400 has no particular meaning, just large enough. if( !snode || snode->prob() == 0.0 ) { warn( "estimating the counts on a zero-probability sentence" ); return; } double sAlpha = 1.0/snode->prob(); snode->poutside() = sAlpha; /* for each position in the 2D chart, starting at top*/ /* look at every bucket of length j */ for (int j = wrd_count_-1 ; j >= 0 ; j--) { for (int i = 0 ; i <= wrd_count_ - j ; i++) { Items il = regs[j][i]; list<Item*>::iterator ili = il.begin(); Item* itm; for(; ili != il.end(); ili++ ) { itm = *ili; if(itm != snode) itm->poutside() = 0; //init outside probs to 0; } bool valuesChanging = true; /* do alpha calulcations until values settle down */ ili = il.begin(); while(valuesChanging) { valuesChanging = false; int tempPos = 0; //position in tempAlpha; ili = il.begin(); for(; ili != il.end(); ili++ ) { itm = *ili; if(itm == snode) continue; double itmalpha = 0; NeedmeIter nmi(itm); Edge* e; while( nmi.next(e) ) { const Item* lhsItem = e->finishedParent(); if(lhsItem) itmalpha += lhsItem->poutside() * e->prob(); } assert(tempPos < 400); double val = itmalpha/itm->prob(); tempAlpha[tempPos++] = val; } /* at this point the new alpha values are stored in tempAlpha */ int temppos = 0; ili = il.begin(); for(; ili != il.end(); ili++ ) { itm = *ili; if(itm == snode) continue; /* the start symbol for the entire sentence has poutside =1*/ if(i == 0 && j ==wrd_count_-1 && itm->term()->name() == "S1") itm->poutside() = sAlpha; else { double oOutside = itm->poutside(); double nOutside = tempAlpha[temppos]; if(nOutside == 0) { if(oOutside != 0) error("Alpha went down"); } else if(oOutside/nOutside < .95) { itm->poutside() = nOutside; valuesChanging = true; //cerr << "alpha*beta " << *itm << " = " //<< (itm->poutside() * itm->prob()) << endl; } } temppos++; } if(temppos != tempPos) { cerr << "temppos = " << temppos << " and tempPos = " << tempPos << " "; error("Funnly situation in setAlphas"); } } } } }
// adds all items in the Items vector void PopupMenu::addItems( Items& in, Items& items ) { for( PopupMenu::Items::iterator i = items.begin(); i != items.end(); ++i ) in.push_back( *i ); }