本文整理汇总了C++中TPt::SetAllEDat方法的典型用法代码示例。如果您正苦于以下问题:C++ TPt::SetAllEDat方法的具体用法?C++ TPt::SetAllEDat怎么用?C++ TPt::SetAllEDat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TPt
的用法示例。
在下文中一共展示了TPt::SetAllEDat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
// Test set edge data
TEST(TNodeEdgeNet, SetEdgeData) {
int NNodes = 10000;
int NEdges = 100000;
TPt <TNodeEdgeNet<TInt, TInt> > Net;
TPt <TNodeEdgeNet<TInt, TInt> > Net1;
TPt <TNodeEdgeNet<TInt, TInt> > Net2;
int i;
int n;
int NCount;
int x,y;
Net = TNodeEdgeNet<TInt, TInt>::New();
EXPECT_EQ(1,Net->Empty());
// create the nodes
for (i = 0; i < NNodes; i++) {
Net->AddNode(i);
}
EXPECT_EQ(0,Net->Empty());
EXPECT_EQ(NNodes,Net->GetNodes());
// create random edges
NCount = NEdges;
while (NCount > 0) {
x = (long) (drand48() * NNodes);
y = (long) (drand48() * NNodes);
n = Net->AddEdge(x, y);
// printf("0a %d %d %d\n",x,y,n);
NCount--;
}
EXPECT_EQ(NEdges,Net->GetEdges());
EXPECT_EQ(0,Net->Empty());
EXPECT_EQ(1,Net->IsOk());
for (i = 0; i < NNodes; i++) {
EXPECT_EQ(1,Net->IsNode(i));
}
EXPECT_EQ(0,Net->IsNode(NNodes));
EXPECT_EQ(0,Net->IsNode(NNodes+1));
EXPECT_EQ(0,Net->IsNode(2*NNodes));
// add data to nodes, square of node ID
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
Net->SetNDat(NI.GetId(), NI.GetId()*NI.GetId());
}
// test node data
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
EXPECT_EQ(NI.GetId()*NI.GetId(), Net->GetNDat(NI.GetId()));
}
// set edge data, source node ID * dest node ID
for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
Net->SetEDat(EI.GetId(),EI.GetSrcNId()*EI.GetDstNId());
}
// verify edge data
for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
EXPECT_EQ(EI.GetSrcNId()*EI.GetDstNId(), Net->GetEDat(EI.GetId()));
}
// set edge data to 42.
Net->SetAllEDat(42);
// verify edge data
for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
EXPECT_EQ(42, Net->GetEDat(EI.GetId()));
}
// test node data again
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
EXPECT_EQ(NI.GetId()*NI.GetId(), Net->GetNDat(NI.GetId()));
}
}
示例2: SetEdgeData
// Test set edge data
void SetEdgeData() {
int NNodes = 10000;
int NEdges = 100000;
TPt <TNodeEDatNet<TInt, TInt> > Net;
TPt <TNodeEDatNet<TInt, TInt> > Net1;
TPt <TNodeEDatNet<TInt, TInt> > Net2;
int i;
int n;
int NCount;
int x,y;
bool t;
int SrcNId;
int DstNId;
int EdgeDat;
int Value;
bool ok;
Net = TNodeEDatNet<TInt, TInt>::New();
t = Net->Empty();
// create the nodes
for (i = 0; i < NNodes; i++) {
Net->AddNode(i);
}
t = Net->Empty();
n = Net->GetNodes();
// create random edges
NCount = NEdges;
while (NCount > 0) {
x = (long) (drand48() * NNodes);
y = (long) (drand48() * NNodes);
// Net->GetEdges() is not correct for the loops (x == y),
// skip the loops in this test
if (x != y && !Net->IsEdge(x,y)) {
n = Net->AddEdge(x, y);
NCount--;
}
}
PrintNStats("SetEdgeData:Net", Net);
// set edge data, source node ID * dest node ID
for (TNodeEDatNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
Net->SetEDat(EI.GetSrcNId(),EI.GetDstNId(),EI.GetSrcNId()*EI.GetDstNId());
}
// verify edge data
ok = true;
for (TNodeEDatNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
SrcNId = EI.GetSrcNId();
DstNId = EI.GetDstNId();
EdgeDat = Net->GetEDat(SrcNId, DstNId);
Value = SrcNId*DstNId;
if (EdgeDat != Value) {
ok = false;
}
}
printf("network SetEdgeData:Net, status1 %s\n", (ok == true) ? "ok" : "ERROR");
// set edge data to 42.
Net->SetAllEDat(42);
// verify edge data
ok = true;
for (TNodeEDatNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
SrcNId = EI.GetSrcNId();
DstNId = EI.GetDstNId();
EdgeDat = Net->GetEDat(SrcNId, DstNId);
if (EdgeDat != 42) {
ok = false;
}
}
printf("network SetEdgeData:Net, status2 %s\n", (ok == true) ? "ok" : "ERROR");
}