本文整理汇总了C++中TIntH::SortByDat方法的典型用法代码示例。如果您正苦于以下问题:C++ TIntH::SortByDat方法的具体用法?C++ TIntH::SortByDat怎么用?C++ TIntH::SortByDat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TIntH
的用法示例。
在下文中一共展示了TIntH::SortByDat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetLangCntryByMajority
// set Language and Country for movies that do not have the value set
// for every movie find the mojority language/country in 1-hop neighborhood and set it
void TImdbNet::SetLangCntryByMajority() {
// set language
while (true) {
TIntPrV NIdToVal;
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
if (NI().GetLang() != 0) { continue; }
int Nbhs=0; TIntH LangCntH;
for (int e = 0; e < NI.GetOutDeg(); e++) {
LangCntH.AddDat(NI.GetOutNDat(e).GetLang()) += 1; Nbhs++; }
for (int e = 0; e < NI.GetInDeg(); e++) {
LangCntH.AddDat(NI.GetInNDat(e).GetLang()) += 1; Nbhs++; }
if (LangCntH.IsKey(0)) { Nbhs-=LangCntH.GetDat(0); LangCntH.GetDat(0)=0; }
LangCntH.SortByDat(false);
if (LangCntH.GetKey(0) == 0) { continue; }
if (LangCntH[0]*2 >= Nbhs) {
NIdToVal.Add(TIntPr(NI.GetId(), LangCntH.GetKey(0))); }
}
if (NIdToVal.Empty()) { break; } // done
for (int i = 0; i < NIdToVal.Len(); i++) {
GetNDat(NIdToVal[i].Val1).Lang = NIdToVal[i].Val2; }
printf(" language set: %d\n", NIdToVal.Len());
}
int cnt=0;
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { if (NI().GetLang()==0) cnt++; }
printf(" NO language: %d\n\n", cnt);
// set country
while (true) {
TIntPrV NIdToVal;
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
if (NI().GetCntry() != 0) { continue; }
int Nbhs=0; TIntH CntryCntH;
for (int e = 0; e < NI.GetOutDeg(); e++) {
CntryCntH.AddDat(NI.GetOutNDat(e).GetCntry()) += 1; Nbhs++; }
for (int e = 0; e < NI.GetInDeg(); e++) {
CntryCntH.AddDat(NI.GetInNDat(e).GetCntry()) += 1; Nbhs++; }
if (CntryCntH.IsKey(0)) { Nbhs-=CntryCntH.GetDat(0); CntryCntH.GetDat(0)=0; }
CntryCntH.SortByDat(false);
if (CntryCntH.GetKey(0) == 0) { continue; }
if (CntryCntH[0]*2 >= Nbhs) {
NIdToVal.Add(TIntPr(NI.GetId(), CntryCntH.GetKey(0))); }
}
if (NIdToVal.Empty()) { break; } // done
for (int i = 0; i < NIdToVal.Len(); i++) {
GetNDat(NIdToVal[i].Val1).Cntry = NIdToVal[i].Val2; }
printf(" country set: %d\n", NIdToVal.Len());
}
cnt=0;
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { if (NI().GetCntry()==0) cnt++; }
printf(" NO country: %d\n\n", cnt);
}
示例2: SetActorCntryLangByMajority
// set actor's language and country
void TImdbNet::SetActorCntryLangByMajority() {
// set language
TIntPrV NIdToVal;
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
if (! NI().IsActor()) { continue; }
IAssert(NI().GetLang() == 0); // no language set
IAssert(NI.GetInDeg() == 0); // actors point to movies
int Nbhs=0; TIntH LangCntH;
for (int e = 0; e < NI.GetOutDeg(); e++) {
LangCntH.AddDat(NI.GetOutNDat(e).GetLang()) += 1; Nbhs++; }
if (LangCntH.IsKey(0)) { Nbhs-=LangCntH.GetDat(0); LangCntH.GetDat(0)=0; }
LangCntH.SortByDat(false);
if (LangCntH.GetKey(0) == 0) { continue; }
if (LangCntH[0]*2 >= Nbhs) {
NIdToVal.Add(TIntPr(NI.GetId(), LangCntH.GetKey(0))); }
}
for (int i = 0; i < NIdToVal.Len(); i++) {
GetNDat(NIdToVal[i].Val1).Lang = NIdToVal[i].Val2; }
printf(" language set: %d\n", NIdToVal.Len());
int cnt=0;
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { if (NI().IsActor() && NI().GetLang()==0) cnt++; }
printf(" Actors NO language: %d\n\n", cnt);
// set country
NIdToVal.Clr(true);
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) {
if (! NI().IsActor()) { continue; }
IAssert(NI().GetCntry() == 0); // no country set
IAssert(NI.GetInDeg() == 0); // actors point to movies
int Nbhs=0; TIntH CntryCntH;
for (int e = 0; e < NI.GetOutDeg(); e++) {
CntryCntH.AddDat(NI.GetOutNDat(e).GetCntry()) += 1; Nbhs++; }
if (CntryCntH.IsKey(0)) { Nbhs-=CntryCntH.GetDat(0); CntryCntH.GetDat(0)=0; }
CntryCntH.SortByDat(false);
if (CntryCntH.GetKey(0) == 0) { continue; }
if (CntryCntH[0]*2 >= Nbhs) {
NIdToVal.Add(TIntPr(NI.GetId(), CntryCntH.GetKey(0))); }
}
for (int i = 0; i < NIdToVal.Len(); i++) {
GetNDat(NIdToVal[i].Val1).Cntry = NIdToVal[i].Val2; }
printf(" country set: %d\n", NIdToVal.Len());
cnt=0;
for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { if (NI().IsActor() && NI().GetCntry()==0) cnt++; }
printf(" Actors NO country: %d\n\n", cnt);
}
示例3: MaxCPGreedyBetter
// Maximum Domination Problem
void MaxCPGreedyBetter(const PUNGraph& Graph, const int k, TIntH& GroupNodes) {
// buildup cpntainer of group nodes
const int n = Graph->GetNodes();
int *NNodes = new int[n]; // container of neighbouring nodes
int NNodes_br = 0;
TIntH Nodes; // nodes sorted by vd
double gc = 0, gc0 = 0;
int addId = 0, addIdPrev = 0;
for (TUNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++){
Nodes.AddDat(NI.GetId(), NI.GetDeg());
}
Nodes.SortByDat(false);
int br = 0;
while (br < k) {
for (THashKeyDatI<TInt, TInt> NI = Nodes.BegI(); NI < Nodes.EndI(); NI++){
if ((NI.GetDat() <= (int)gc0))
break;
gc = NI.GetDat() - Intersect(Graph->GetNI(NI.GetKey()), NNodes, NNodes_br);
if (gc>gc0){
gc0 = gc;
addId = NI.GetKey();
}
}
if (addId != addIdPrev) {
GroupNodes.AddDat(br, addId);
br++;
gc0 = 0;
int nn = addId;
bool nnnew = true;
for (int j = 0; j<NNodes_br; j++)
if (NNodes[j] == nn){
nnnew = false;
j = NNodes_br;
}
if (nnnew){
NNodes[NNodes_br] = nn;
NNodes_br++;
}
for (int i = 0; i<Graph->GetNI(addId).GetDeg(); i++) {
int nn = Graph->GetNI(addId).GetNbrNId(i);
bool nnnew = true;
for (int j = 0; j<NNodes_br; j++) {
if (NNodes[j] == nn){
nnnew = false;
j = NNodes_br;
}
}
if (nnnew){
NNodes[NNodes_br] = nn;
NNodes_br++;
}
}
addIdPrev = addId;
Nodes.DelKey(addId);
}
else {
br = k;
}
printf("%i,", br);
}
delete NNodes;
}
示例4: PaintCatNms
void TVizMapContext::PaintCatNms(PGks Gks, const int& KeyWdFontSize,
TVec<TFltRect>& PointNmRectV) {
// calculate frequency of categories
TIntH CatH; TIntFltPrH CatPosH;
PBowDocBs BowDocBs = VizMapFrame->GetKeyWdBow();
const int Points = VizMapFrame->GetPoints();
for (int PointN = 0; PointN < Points; PointN++) {
PVizMapPoint Point = VizMapFrame->GetPoint(PointN);
const int DId = Point->GetDocId();
const int CIds = BowDocBs->GetDocCIds(DId);
for (int CIdN = 0; CIdN < CIds; CIdN++) {
const int CId = BowDocBs->GetDocCId(DId, CIdN);
CatH.AddDat(CId)++;
CatPosH.AddDat(CId).Val1 += Point->GetPointX();
CatPosH.AddDat(CId).Val2 += Point->GetPointY();
}
}
CatH.SortByDat(false);
// draw the top cats
const int TopCats = Points > 100 ? 6 : 4;
TFltRect ZoomRect = GetZoomRect();
Gks->SetFont(TGksFont::New("ARIAL", KeyWdFontSize + 3, ColorCatNmFont));
TVec<TFltRect> CatNmRectV; TVec<TFltV> CatNmPosV;
const int MnSize = TInt::GetMn(Gks->GetWidth(), Gks->GetHeight());
const int MnDist = TFlt::Round(0.3 * double(MnSize));
int Cats = 0, CatKeyId = CatH.FFirstKeyId();
while (CatH.FNextKeyId(CatKeyId)) {
if (Cats == TopCats) { break; }
if (double(CatH[CatKeyId]) / double(Points) < 0.05) { break; }
const int CId = CatH.GetKey(CatKeyId);
// get name
TStr CatNm = BowDocBs->GetCatNm(CId);
if (CatFullNmH.IsKey(CatNm)) {
CatNm = CatFullNmH.GetDat(CatNm);
} else { continue; }
// get position
TFltPr CatPos = CatPosH.GetDat(CId);
const int CatCount = CatH.GetDat(CId); IAssert(CatCount > 0);
const double CatX = CatPos.Val1 / double(CatCount);
const double CatY = CatPos.Val2 / double(CatCount);
// is it within the zoom?
if (!ZoomRect.IsXYIn(CatX, CatY)) { continue; }
// calculate string size on the screen
const int HalfTxtWidth = Gks->GetTxtWidth(CatNm) / 2;
const int HalfTxtHeight = Gks->GetTxtHeight(CatNm) / 2;
// get coordinates in pixels
const int X = GetScreenCoord(CatX , ZoomRect.GetMnX(),
ZoomRect.GetXLen(), Gks->GetWidth());
const int Y = GetScreenCoord(CatY, ZoomRect.GetMnY(),
ZoomRect.GetYLen(), Gks->GetHeight());
// is it to close to any of the most prominent categories
int CatNmDist = MnSize; TFltV CatNmPos = TFltV::GetV(double(X), double(Y));
for (int CatNmPosN = 0; CatNmPosN < CatNmPosV.Len(); CatNmPosN++) {
const double Dist = TLinAlg::EuclDist(CatNmPosV[CatNmPosN], CatNmPos);
CatNmDist = TInt::GetMn(TFlt::Round(Dist), CatNmDist);
}
if (CatNmDist < MnDist) { continue; }
// does it overlap with any of hte most prominent categories
TFltRect CatNmRect(X - HalfTxtWidth, Y - HalfTxtHeight,
X + HalfTxtWidth, Y + HalfTxtHeight);
bool DoDraw = true; const int Rects = CatNmRectV.Len();
for (int RectN = 0; (RectN < Rects) && DoDraw; RectN++) {
DoDraw = !TFltRect::Intersection(CatNmRect, CatNmRectV[RectN]); }
if (!DoDraw) { continue; }
// draw it!
Gks->PutTxt(CatNm, X - HalfTxtWidth, Y - HalfTxtHeight);
// remember string area
CatNmRectV.Add(CatNmRect); Cats++;
// remember string position
CatNmPosV.Add(CatNmPos);
}
PointNmRectV.AddV(CatNmRectV);
}