Taker::Taker (CrossType cross_type, ApplyView& view, AccountID const& account, Amounts const& offer, std::uint32_t flags, beast::Journal journal) : BasicTaker (cross_type, account, offer, Quality(offer), flags, calculateRate(view, offer.in.getIssuer(), account), calculateRate(view, offer.out.getIssuer(), account), journal) , view_ (view) , xrp_flow_ (0) , direct_crossings_ (0) , bridge_crossings_ (0) { assert (issue_in () == offer.in.issue ()); assert (issue_out () == offer.out.issue ()); if (journal_.debug) { journal_.debug << "Crossing as: " << to_string (account); if (isXRP (issue_in ())) journal_.debug << " Offer in: " << format_amount (offer.in); else journal_.debug << " Offer in: " << format_amount (offer.in) << " (issuer: " << issue_in ().account << ")"; if (isXRP (issue_out ())) journal_.debug << " Offer out: " << format_amount (offer.out); else journal_.debug << " Offer out: " << format_amount (offer.out) << " (issuer: " << issue_out ().account << ")"; journal_.debug << " Balance: " << format_amount (get_funds (account, offer.in)); } }
bool BookTip::step (beast::Journal j) { if (m_valid) { if (m_entry) { offerDelete (view_, m_entry, j); m_entry = nullptr; } } for(;;) { // See if there's an entry at or worse than current quality. Notice // that the quality is encoded only in the index of the first page // of a directory. auto const first_page = view_.succ (m_book, m_end); if (! first_page) return false; unsigned int di = 0; std::shared_ptr<SLE> dir; if (dirFirst (view_, *first_page, dir, di, m_index, j)) { m_dir = dir->key(); m_entry = view_.peek(keylet::offer(m_index)); m_quality = Quality (getQuality (*first_page)); m_valid = true; // Next query should start before this directory m_book = *first_page; // The quality immediately before the next quality --m_book; break; } // There should never be an empty directory but just in case, // we handle that case by advancing to the next directory. m_book = *first_page; } return true; }
Quality composed_quality (Quality const& lhs, Quality const& rhs) { Amount const lhs_rate (lhs.rate ()); assert (lhs_rate != zero); Amount const rhs_rate (rhs.rate ()); assert (rhs_rate != zero); Amount const rate (Amount::mulRound (lhs_rate, rhs_rate, true)); std::uint64_t const stored_exponent (rate.getExponent () + 100); std::uint64_t const stored_mantissa (rate.getMantissa ()); assert ((stored_exponent >= 0) && (stored_exponent <= 255)); return Quality ((stored_exponent << (64 - 8)) | stored_mantissa); }
Quality composed_quality (Quality const& lhs, Quality const& rhs) { STAmount const lhs_rate (lhs.rate ()); assert (lhs_rate != zero); STAmount const rhs_rate (rhs.rate ()); assert (rhs_rate != zero); STAmount const rate (mulRound ( lhs_rate, rhs_rate, lhs_rate.issue (), true)); std::uint64_t const stored_exponent (rate.exponent () + 100); std::uint64_t const stored_mantissa (rate.mantissa()); assert ((stored_exponent > 0) && (stored_exponent <= 255)); return Quality ((stored_exponent << (64 - 8)) | stored_mantissa); }
void VectorAttributes::SetFromNode(DataNode *parentNode) { if(parentNode == 0) return; DataNode *searchNode = parentNode->GetNode("VectorAttributes"); if(searchNode == 0) return; DataNode *node; if((node = searchNode->GetNode("glyphLocation")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 2) SetGlyphLocation(GlyphLocation(ival)); } else if(node->GetNodeType() == STRING_NODE) { GlyphLocation value; if(GlyphLocation_FromString(node->AsString(), value)) SetGlyphLocation(value); } } if((node = searchNode->GetNode("useStride")) != 0) SetUseStride(node->AsBool()); if((node = searchNode->GetNode("stride")) != 0) SetStride(node->AsInt()); if((node = searchNode->GetNode("nVectors")) != 0) SetNVectors(node->AsInt()); if((node = searchNode->GetNode("lineStyle")) != 0) SetLineStyle(node->AsInt()); if((node = searchNode->GetNode("lineWidth")) != 0) SetLineWidth(node->AsInt()); if((node = searchNode->GetNode("scale")) != 0) SetScale(node->AsDouble()); if((node = searchNode->GetNode("scaleByMagnitude")) != 0) SetScaleByMagnitude(node->AsBool()); if((node = searchNode->GetNode("autoScale")) != 0) SetAutoScale(node->AsBool()); if((node = searchNode->GetNode("headSize")) != 0) SetHeadSize(node->AsDouble()); if((node = searchNode->GetNode("headOn")) != 0) SetHeadOn(node->AsBool()); if((node = searchNode->GetNode("colorByMag")) != 0) SetColorByMag(node->AsBool()); if((node = searchNode->GetNode("useLegend")) != 0) SetUseLegend(node->AsBool()); if((node = searchNode->GetNode("vectorColor")) != 0) vectorColor.SetFromNode(node); if((node = searchNode->GetNode("colorTableName")) != 0) SetColorTableName(node->AsString()); if((node = searchNode->GetNode("invertColorTable")) != 0) SetInvertColorTable(node->AsBool()); if((node = searchNode->GetNode("vectorOrigin")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 3) SetVectorOrigin(OriginType(ival)); } else if(node->GetNodeType() == STRING_NODE) { OriginType value; if(OriginType_FromString(node->AsString(), value)) SetVectorOrigin(value); } } if((node = searchNode->GetNode("minFlag")) != 0) SetMinFlag(node->AsBool()); if((node = searchNode->GetNode("maxFlag")) != 0) SetMaxFlag(node->AsBool()); if((node = searchNode->GetNode("limitsMode")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 2) SetLimitsMode(LimitsMode(ival)); } else if(node->GetNodeType() == STRING_NODE) { LimitsMode value; if(LimitsMode_FromString(node->AsString(), value)) SetLimitsMode(value); } } if((node = searchNode->GetNode("min")) != 0) SetMin(node->AsDouble()); if((node = searchNode->GetNode("max")) != 0) SetMax(node->AsDouble()); if((node = searchNode->GetNode("lineStem")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 2) SetLineStem(LineStem(ival)); } else if(node->GetNodeType() == STRING_NODE) { LineStem value; if(LineStem_FromString(node->AsString(), value)) SetLineStem(value); } } if((node = searchNode->GetNode("geometryQuality")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 2) SetGeometryQuality(Quality(ival)); } else if(node->GetNodeType() == STRING_NODE) { Quality value; if(Quality_FromString(node->AsString(), value)) SetGeometryQuality(value); } } if((node = searchNode->GetNode("stemWidth")) != 0) SetStemWidth(node->AsDouble()); if((node = searchNode->GetNode("origOnly")) != 0) SetOrigOnly(node->AsBool()); if((node = searchNode->GetNode("glyphType")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 2) SetGlyphType(GlyphType(ival)); } else if(node->GetNodeType() == STRING_NODE) { GlyphType value; if(GlyphType_FromString(node->AsString(), value)) SetGlyphType(value); } } }
VectorAttributes::Quality VectorAttributes::GetGeometryQuality() const { return Quality(geometryQuality); }
void BirchPhase3(Stat **Stats) { char tmpname[MAX_NAME]; char tmpname1[MAX_NAME]; std::ofstream tmpfile; std::ofstream tmpfile1; int i,j,k; Entry *tmpents = new Entry[Paras->ntrees]; for (i=0; i<Paras->ntrees; i++) tmpents[i].Init(Stats[i]->Dimension); for (i=0; i<Paras->ntrees; i++) { sprintf(tmpname,"%s-cluster",Stats[i]->name); sprintf(tmpname1,"Tmp-cluster",Stats[i]->name); tmpfile.open(tmpname); tmpfile1.open(tmpname1); Stats[i]->Phase=3; Stats[i]->NewRoot->free_nonleaf(Stats[i]); Stats[i]->NewRoot=NULL; Stats[i]->Entries=new Entry[Stats[i]->CurrEntryCnt]; for (j=0; j<Stats[i]->CurrEntryCnt; j++) Stats[i]->Entries[j].Init(Stats[i]->Dimension); j=k=0; Stats[i]->OldLeafHead=Stats[i]->NewLeafHead; while (Stats[i]->NextEntryFreeOldLeafHead(j,tmpents[i])!=FALSE) { Stats[i]->Entries[k]=tmpents[i]; tmpfile1 << tmpents[i].n << " "; for (int l=0; l < tmpents[i].Dim(); l++) tmpfile1 << tmpents[i].sx.value[l]/tmpents[i].n << " " ; tmpfile1 << tmpents[i].sxx << std::endl; k++; } tmpfile1.close(); Stats[i]->OldLeafHead=Stats[i]->NewLeafHead=NULL; if (k!=Stats[i]->CurrEntryCnt) print_error(Stats[i]->name,"Entry number not matching"); if (Stats[i]->K==0 && Stats[i]->CurFt>Stats[i]->Ft) Paras->logfile<<Stats[i]->name<<":"<<"CurFt>EndFt"<<std::endl; else if (Stats[i]->K!=0 && Stats[i]->K>Stats[i]->CurrEntryCnt) Paras->logfile<<Stats[i]->name<<":"<<"K>CurEntryCnt"<<std::endl; else { Paras->logfile<<Stats[i]->name<<":" <<"CurFt<EndFt or K<CurrEntryCnt"<<std::endl; switch (Stats[i]->Gtype) { case HIERARCHY0:Hierarchy0(Stats[i]->CurrEntryCnt,Stats[i]->K,&(Stats[i]->Entries),Stats[i]->GDtype,Stats[i]->Ftype,Stats[i]->Ft); break; case HIERARCHY1:Hierarchy1(Stats[i]->CurrEntryCnt,Stats[i]->K,&(Stats[i]->Entries),Stats[i]->GDtype,Stats[i]->Ftype,Stats[i]->Ft); break; case CLARANS0: Clarans0(Stats[i]->CurrEntryCnt,Stats[i]->K,Stats[i]->Entries); break; case CLARANS1: Clarans1(Stats[i]->CurrEntryCnt,Stats[i]->K,Stats[i]->Entries,Stats[i]->GDtype, Stats[i]->Qtype); break; // case LLOYD: Lloyd(Stats[i]->CurrEntryCnt,&(Stats[i]->Entries)); // break; // case KMEANS: Kmeans(Stats[i]->CurrEntryCnt,&(Stats[i]->Entries)); // break; default: print_error("BirchPhase3","Invalid global algorithm"); break; } } Paras->logfile<<Stats[i]->name<<":"<<"Quality of Phase3 " <<Quality(Stats[i]->Qtype,Stats[i]->CurrEntryCnt,Stats[i]->Entries)<<std::endl; for (j=0; j<Stats[i]->CurrEntryCnt; j++) tmpfile<<Stats[i]->Entries[j]<<std::endl; tmpfile.close(); } delete [] tmpents; }
Quality get_quality(std::string in, std::string out) { return Quality (parse_amounts (in, xrp(), out, xrp ())); }