本文整理汇总了C++中TIntV::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ TIntV::Add方法的具体用法?C++ TIntV::Add怎么用?C++ TIntV::Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TIntV
的用法示例。
在下文中一共展示了TIntV::Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindAugV
/// Returns the amount the flow can be augmented over the paths, 0 if no path can be found. ##TSnap::FindAugV
int FindAugV (const PNEANet &Net, const int& CapIndex, TIntV &Flow, TIntQ &FwdNodeQ, TIntH &PredEdgeH, TIntQ &BwdNodeQ, TIntH &SuccEdgeH, TIntV &MidToSrcAugV, TIntV &MidToSnkAugV, const int& SrcNId, const int& SnkNId) {
int MidPtNId = IntFlowBiDBFS(Net, CapIndex, Flow, FwdNodeQ, PredEdgeH, BwdNodeQ, SuccEdgeH, SrcNId, SnkNId);
if (MidPtNId == -1) { return 0; }
int MinAug = TInt::Mx, NId = MidPtNId, AugFlow = 0;
// Build the path from the midpoint back to the source by tracing through the PredEdgeH
for (int EId = PredEdgeH.GetDat(NId); NId != SrcNId; EId = PredEdgeH.GetDat(NId)) {
MidToSrcAugV.Add(EId);
const TNEANet::TEdgeI &EI = Net->GetEI(EId);
if (EI.GetSrcNId() == NId) {
NId = EI.GetDstNId();
AugFlow = Flow[EId];
} else {
NId = EI.GetSrcNId();
AugFlow = Net->GetIntAttrIndDatE(EId, CapIndex) - Flow[EId];
}
if (AugFlow < MinAug) { MinAug = AugFlow; }
}
NId = MidPtNId;
// Build the path from the midpoint back to the sink by tracing through the SuccEdgeH
for (int EId = SuccEdgeH.GetDat(NId); NId != SnkNId; EId = SuccEdgeH.GetDat(NId)) {
MidToSnkAugV.Add(EId);
const TNEANet::TEdgeI &EI = Net->GetEI(EId);
if (EI.GetDstNId() == NId) {
NId = EI.GetSrcNId();
AugFlow = Flow[EId];
} else {
NId = EI.GetDstNId();
AugFlow = Net->GetIntAttrIndDatE(EId, CapIndex) - Flow[EId];
}
if (AugFlow < MinAug) { MinAug = AugFlow; }
}
return MinAug;
}
示例2: main
int main(){
TTableContext Context;
// create scheme
Schema AnimalS;
AnimalS.Add(TPair<TStr,TAttrType>("Animal", atStr));
AnimalS.Add(TPair<TStr,TAttrType>("Size", atStr));
AnimalS.Add(TPair<TStr,TAttrType>("Location", atStr));
AnimalS.Add(TPair<TStr,TAttrType>("Number", atInt));
TIntV RelevantCols;
RelevantCols.Add(0);
RelevantCols.Add(1);
RelevantCols.Add(2);
// create table
PTable T = TTable::LoadSS("Animals", AnimalS, "tests/animals.txt", Context, RelevantCols);
//PTable T = TTable::LoadSS("Animals", AnimalS, "animals.txt");
T->Unique("Animal");
TTable Ts = *T; // did we fix problem with copy-c'tor ?
//PTable Ts = TTable::LoadSS("Animals_s", AnimalS, "../../testfiles/animals.txt", RelevantCols);
//Ts->Unique(AnimalUnique);
// test Select
// create predicate tree: find all animals that are big and african or medium and Australian
TPredicate::TAtomicPredicate A1(atStr, true, EQ, "Location", "", 0, 0, "Africa");
TPredicate::TPredicateNode N1(A1); // Location == "Africa"
TPredicate::TAtomicPredicate A2(atStr, true, EQ, "Size", "", 0, 0, "big");
TPredicate::TPredicateNode N2(A2); // Size == "big"
TPredicate::TPredicateNode N3(AND);
N3.AddLeftChild(&N1);
N3.AddRightChild(&N2);
TPredicate::TAtomicPredicate A4(atStr, true, EQ, "Location", "", 0, 0, "Australia");
TPredicate::TPredicateNode N4(A4);
TPredicate::TAtomicPredicate A5(atStr, true, EQ, "Size", "", 0, 0, "medium");
TPredicate::TPredicateNode N5(A5);
TPredicate::TPredicateNode N6(AND);
N6.AddLeftChild(&N4);
N6.AddRightChild(&N5);
TPredicate::TPredicateNode N7(OR);
N7.AddLeftChild(&N3);
N7.AddRightChild(&N6);
TPredicate Pred(&N7);
TIntV SelectedRows;
Ts.Select(Pred, SelectedRows);
TStrV GroupBy;
GroupBy.Add("Location");
T->Group(GroupBy, "LocationGroup");
GroupBy.Add("Size");
T->Group(GroupBy, "LocationSizeGroup");
T->Count("LocationCount", "Location");
PTable Tj = T->Join("Location", Ts, "Location");
TStrV UniqueAnimals;
UniqueAnimals.Add("Animals_1.Animal");
UniqueAnimals.Add("Animals_2.Animal");
Tj->Unique(UniqueAnimals, false);
//print table
T->SaveSS("tests/animals_out_T.txt");
Ts.SaveSS("tests/animals_out_Ts.txt");
Tj->SaveSS("tests/animals_out_Tj.txt");
return 0;
}
示例3: TestSubTNEGraphs
// Test subgraphs
void TestSubTNEGraphs() {
PNEGraph Graph;
PNEGraph Graph1;
PNEGraph Graph2;
PNEGraph Graph3;
int i;
TIntV NIdV;
TIntV NIdV1;
TIntV EIdV;
Graph = GetTestTNEGraph();
PrintGraph("TNEGraph", Graph);
for (i = 10; i < 15; i++) {
NIdV.Add(i);
}
Graph1 = TSnap::GetSubGraph(Graph, NIdV);
PrintGraph("TNEGraph1", Graph1);
for (i = 0; i < 20; i += 2) {
NIdV1.Add(i);
}
Graph2 = TSnap::GetSubGraph(Graph, NIdV1);
PrintGraph("TNEGraph2", Graph2);
for (i = 0; i < 120; i += 2) {
EIdV.Add(i);
}
Graph3 = TSnap::GetESubGraph(Graph, EIdV);
PrintGraph("TNEGraph3", Graph3);
}
示例4: GetWordUStrV
void TUStr::GetWordUStrV(TUStrV& WordUStrV){
// clear word vector
WordUStrV.Clr();
// create boundaries
TBoolV WordBoundPV; GetWordBoundPV(WordBoundPV);
IAssert(Len()==WordBoundPV.Len()-1);
IAssert((WordBoundPV.Len()>0)&&(WordBoundPV.Last()));
// traverse characters and bounds
int UniChs=Len(); TIntV WordUniChV;
for (int UniChN=0; UniChN<=UniChs; UniChN++){
if ((UniChN==UniChs)||(WordBoundPV[UniChN+1])){ // finish or word-boundary
if (UniChN<UniChs){ // if not finish
// if last-word-char or single-alphabetic-char
if ((!WordUniChV.Empty())||(IsAlphabetic(UniChV[UniChN]))){
WordUniChV.Add(UniChV[UniChN]); // add char
}
}
if (!WordUniChV.Empty()){ // add current word to vector
TUStr WordUStr(WordUniChV); // construct word from char-vector
WordUStrV.Add(WordUStr); // add word to word-vector
WordUniChV.Clr(false); // clear char-vector
}
} else {
// add character to char-vector
WordUniChV.Add(UniChV[UniChN]);
}
}
}
示例5: Q
TEST(TQQueueTest, Unlimited2) {
try {
TQQueue<TInt> Q(64, -1);
ASSERT_TRUE(Q.Empty());
TIntV Vec;
Vec.Add(1);
Vec.Add(2);
Vec.Add(3);
Q.PushV(Vec);
ASSERT_EQ(Q.Front(), 1);
ASSERT_EQ(Q.Back(), 3);
ASSERT_EQ(Q.Len(), 3);
TIntV Vec2; Q.GetSubValVec(0, 2, Vec2);
ASSERT_EQ(Vec.Len(), Vec2.Len());
for (int i = 0; i < 3; i++) {
ASSERT_EQ(Vec[i], Vec2[i]);
ASSERT_EQ(Q[i], Vec[i]);
}
} catch (PExcept& Except) {
printf("Error: %s", Except->GetStr());
throw Except;
}
}
示例6: main
int main(int argc, char* argv[]){
//test1();
TTableContext Context;
// create scheme
Schema PostS;
PostS.Add(TPair<TStr,TAttrType>("Id", atInt));
PostS.Add(TPair<TStr,TAttrType>("OwnerUserId", atInt));
PostS.Add(TPair<TStr,TAttrType>("AcceptedAnswerId", atInt));
PostS.Add(TPair<TStr,TAttrType>("CreationDate", atStr));
PostS.Add(TPair<TStr,TAttrType>("Score", atInt));
TIntV RelevantCols;
RelevantCols.Add(0); RelevantCols.Add(1); RelevantCols.Add(2); RelevantCols.Add(3); RelevantCols.Add(4);
PTable P = TTable::LoadSS("Posts", PostS, "/dfs/ilfs2/0/ringo/StackOverflow_2/posts.tsv", Context, RelevantCols);
printf("Load done\n");
TStrV cols;
cols.Add("OwnerUserId");
struct timeval begin, end;
gettimeofday(&begin, NULL);
P->Aggregate(cols, aaSum, "Score", "Sum");
gettimeofday(&end, NULL);
double diff = (end.tv_sec * 1000000 + end.tv_usec) - (begin.tv_sec * 1000000 + begin.tv_usec);
printf("Elapsed time:%.3lfs\n", diff / 1000000);
if (atoi(argv[1]) == 0) return 0;
P->SaveSS("tests/p3.txt");
return 0;
}
示例7: GetTestTNGraph
// Test edge subgraph conversion
TEST(subgraph, TestConvertESubGraphs) {
PNEGraph NEGraph;
PNGraph NGraph;
TIntV NIdV;
TIntV EIdV;
int i;
NGraph = GetTestTNGraph();
EXPECT_EQ(20,NGraph->GetNodes());
EXPECT_EQ(60,NGraph->GetEdges());
for (i = 0; i < 20; i += 2) {
NIdV.Add(i);
}
// TODO: fix TSnap::ConvertSubGraph<PUNGraph>(NGraph, NIdV, true), it fails
// UNGraph = TSnap::ConvertSubGraph<PUNGraph>(NGraph, NIdV, true);
NEGraph = TSnap::ConvertGraph<PNEGraph>(NGraph);
EXPECT_EQ(20,NEGraph->GetNodes());
EXPECT_EQ(60,NEGraph->GetEdges());
// select every second edge
i = 0;
for (TNEGraph::TEdgeI EI = NEGraph->BegEI(); EI < NEGraph->EndEI(); EI++) {
if (i == 0) {
EIdV.Add(EI.GetId());
}
i = (i + 1) % 2;
}
NGraph = TSnap::ConvertESubGraph<PNGraph>(NEGraph, EIdV);
EXPECT_EQ(20,NGraph->GetNodes());
EXPECT_EQ(30,NGraph->GetEdges());
}
示例8: GetNIdV
void TBPGraph::GetNIdV(TIntV& NIdV) const {
NIdV.Gen(GetNodes(), 0);
for (int N=LeftH.FFirstKeyId(); LeftH.FNextKeyId(N); ) {
NIdV.Add(LeftH.GetKey(N)); }
for (int N=RightH.FFirstKeyId(); RightH.FNextKeyId(N); ) {
NIdV.Add(RightH.GetKey(N)); }
}
示例9: GetAllStaticTriangles
void TempMotifCounter::GetAllStaticTriangles(TIntV& Us, TIntV& Vs, TIntV& Ws) {
Us.Clr();
Vs.Clr();
Ws.Clr();
// Get degree ordering of the graph
int max_nodes = static_graph_->GetMxNId();
TVec<TIntPair> degrees(max_nodes);
degrees.PutAll(TIntPair(0, 0));
// Set the degree of a node to be the number of nodes adjacent to the node in
// the undirected graph.
TIntV nodes;
GetAllNodes(nodes);
#pragma omp parallel for schedule(dynamic)
for (int node_id = 0; node_id < nodes.Len(); node_id++) {
int src = nodes[node_id];
TIntV nbrs;
GetAllNeighbors(src, nbrs);
degrees[src] = TIntPair(nbrs.Len(), src);
}
degrees.Sort();
TIntV order = TIntV(max_nodes);
#pragma omp parallel for schedule(dynamic)
for (int i = 0; i < order.Len(); i++) {
order[degrees[i].Dat] = i;
}
// Get triangles centered at a given node where that node is the smallest in
// the degree ordering.
#pragma omp parallel for schedule(dynamic)
for (int node_id = 0; node_id < nodes.Len(); node_id++) {
int src = nodes[node_id];
int src_pos = order[src];
// Get all neighbors who come later in the ordering
TIntV nbrs;
GetAllNeighbors(src, nbrs);
TIntV neighbors_higher;
for (int i = 0; i < nbrs.Len(); i++) {
int nbr = nbrs[i];
if (order[nbr] > src_pos) { neighbors_higher.Add(nbr); }
}
for (int ind1 = 0; ind1 < neighbors_higher.Len(); ind1++) {
for (int ind2 = ind1 + 1; ind2 < neighbors_higher.Len(); ind2++) {
int dst1 = neighbors_higher[ind1];
int dst2 = neighbors_higher[ind2];
// Check for triangle formation
if (static_graph_->IsEdge(dst1, dst2) || static_graph_->IsEdge(dst2, dst1)) {
#pragma omp critical
{
Us.Add(src);
Vs.Add(dst1);
Ws.Add(dst2);
}
}
}
}
}
}
示例10: BurnExpFire
// burn each link independently (forward with FwdBurnProb, backward with BckBurnProb)
void TForestFire::BurnExpFire() {
const double OldFwdBurnProb = FwdBurnProb;
const double OldBckBurnProb = BckBurnProb;
const int NInfect = InfectNIdV.Len();
const TNGraph& G = *Graph;
TIntH BurnedNIdH; // burned nodes
TIntV BurningNIdV = InfectNIdV; // currently burning nodes
TIntV NewBurnedNIdV; // nodes newly burned in current step
bool HasAliveNbrs; // has unburned neighbors
int NBurned = NInfect, NDiedFire=0;
for (int i = 0; i < InfectNIdV.Len(); i++) {
BurnedNIdH.AddDat(InfectNIdV[i]); }
NBurnedTmV.Clr(false); NBurningTmV.Clr(false); NewBurnedTmV.Clr(false);
for (int time = 0; ; time++) {
NewBurnedNIdV.Clr(false);
// for each burning node
for (int node = 0; node < BurningNIdV.Len(); node++) {
const int& BurningNId = BurningNIdV[node];
const TNGraph::TNodeI Node = G.GetNI(BurningNId);
HasAliveNbrs = false;
NDiedFire = 0;
// burn forward links (out-links)
for (int e = 0; e < Node.GetOutDeg(); e++) {
const int OutNId = Node.GetOutNId(e);
if (! BurnedNIdH.IsKey(OutNId)) { // not yet burned
HasAliveNbrs = true;
if (Rnd.GetUniDev() < FwdBurnProb) {
BurnedNIdH.AddDat(OutNId); NewBurnedNIdV.Add(OutNId); NBurned++; }
}
}
// burn backward links (in-links)
if (BckBurnProb > 0.0) {
for (int e = 0; e < Node.GetInDeg(); e++) {
const int InNId = Node.GetInNId(e);
if (! BurnedNIdH.IsKey(InNId)) { // not yet burned
HasAliveNbrs = true;
if (Rnd.GetUniDev() < BckBurnProb) {
BurnedNIdH.AddDat(InNId); NewBurnedNIdV.Add(InNId); NBurned++; }
}
}
}
if (! HasAliveNbrs) { NDiedFire++; }
}
NBurnedTmV.Add(NBurned);
NBurningTmV.Add(BurningNIdV.Len() - NDiedFire);
NewBurnedTmV.Add(NewBurnedNIdV.Len());
//BurningNIdV.AddV(NewBurnedNIdV); // node is burning eternally
BurningNIdV.Swap(NewBurnedNIdV); // node is burning just 1 time step
if (BurningNIdV.Empty()) break;
FwdBurnProb = FwdBurnProb * ProbDecay;
BckBurnProb = BckBurnProb * ProbDecay;
}
BurnedNIdV.Gen(BurnedNIdH.Len(), 0);
for (int i = 0; i < BurnedNIdH.Len(); i++) {
BurnedNIdV.Add(BurnedNIdH.GetKey(i)); }
FwdBurnProb = OldFwdBurnProb;
BckBurnProb = OldBckBurnProb;
}
示例11: GetAllNeighbors
void TempMotifCounter::GetAllNeighbors(int node, TIntV& nbrs) {
nbrs = TIntV();
TNGraph::TNodeI NI = static_graph_->GetNI(node);
for (int i = 0; i < NI.GetOutDeg(); i++) { nbrs.Add(NI.GetOutNId(i)); }
for (int i = 0; i < NI.GetInDeg(); i++) {
int nbr = NI.GetInNId(i);
if (!NI.IsOutNId(nbr)) { nbrs.Add(nbr); }
}
}
示例12: if
void TMultimodalGraphImplB::TNodeI::GetAdjacentModes(TIntV &AdjacentModes) const {
int ModeId = NodeToModeMapping->GetDat(GetId());
for (TGraphs::TIter it = Graphs->BegI(); it < Graphs->EndI(); it++) {
if (it.GetKey().GetVal1() == ModeId) {
AdjacentModes.Add(it.GetKey().GetVal2());
} else if (it.GetKey().GetVal2() == ModeId) {
AdjacentModes.Add(it.GetKey().GetVal1());
}
}
}
示例13: Defrag
void TTable::Defrag() {
TInt FreeIndex = 0;
TIntV Mapping; // Mapping[old_index] = new_index/invalid
for (TInt i = 0; i < Next.Len(); i++) {
if (Next[i] != Invalid) {
// "first row" properly set beforehand
if (FreeIndex == 0) {
Assert (i == FirstValidRow);
FirstValidRow = 0;
}
if (Next[i] != Last) {
Next[FreeIndex] = FreeIndex + 1;
Mapping.Add(FreeIndex);
} else {
Next[FreeIndex] = Last;
Mapping.Add(Last);
}
for (TInt j = 0; j < IntCols.Len(); j++) {
IntCols[j][FreeIndex] = IntCols[j][i];
}
for (TInt j = 0; j < FltCols.Len(); j++) {
FltCols[j][FreeIndex] = FltCols[j][i];
}
for (TInt j = 0; j < StrColMaps.Len(); j++) {
StrColMaps[j][FreeIndex] = StrColMaps[j][i];
}
FreeIndex++;
} else {
NumRows--;
Mapping.Add(Invalid);
}
}
for(THash<TStr,THash<TInt,TIntV> >::TIter it = GroupMapping.BegI(); it < GroupMapping.EndI(); it++){
THash<TInt,TIntV>& G = it->Dat;
for(THash<TInt,TIntV>::TIter iit = G.BegI(); iit < G.EndI(); iit++) {
TIntV& Group = iit->Dat;
TInt FreeIndex = 0;
for (TInt j=0; j < Group.Len(); j++) {
if (Mapping[Group[j]] != Invalid) {
Group[FreeIndex] = Mapping[Group[j]];
FreeIndex++;
}
}
// resize to get rid of end values
Group.Trunc(FreeIndex);
}
}
// should match, or bug somewhere
Assert (NumValidRows == NumRows);
}
示例14: FindComsByCV
/// estimate number of communities using cross validation
int TAGMFast::FindComsByCV(const int NumThreads, const int MaxComs, const int MinComs, const int DivComs, const TStr OutFNm, const double StepAlpha, const double StepBeta) {
double ComsGap = exp(TMath::Log((double) MaxComs / (double) MinComs) / (double) DivComs);
TIntV ComsV;
ComsV.Add(MinComs);
while (ComsV.Len() < DivComs) {
int NewComs = int(ComsV.Last() * ComsGap);
if (NewComs == ComsV.Last().Val) { NewComs++; }
ComsV.Add(NewComs);
}
if (ComsV.Last() < MaxComs) { ComsV.Add(MaxComs); }
return FindComsByCV(ComsV, 0.1, NumThreads, OutFNm + ".CV.likelihood", StepAlpha, StepBeta);
}
示例15: GetWIdV
void TStrUtil::GetWIdV(const TStrHash<TInt>& StrH, const char *CStr, TIntV& WIdV) {
const int NotWId = -1;
TChA ChA(CStr);
TVec<char *> WrdV;
TInt WId;
TStrUtil::SplitWords(ChA, WrdV);
WIdV.Clr(false);
for (int w = 0; w < WrdV.Len(); w++) {
if (StrH.IsKeyGetDat(WrdV[w], WId)) { WIdV.Add(WId); }
else { WIdV.Add(NotWId); }
}
}