本文整理汇总了C++中PNEANet::BegNAFltI方法的典型用法代码示例。如果您正苦于以下问题:C++ PNEANet::BegNAFltI方法的具体用法?C++ PNEANet::BegNAFltI怎么用?C++ PNEANet::BegNAFltI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PNEANet
的用法示例。
在下文中一共展示了PNEANet::BegNAFltI方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ManipulateNodeEdgeAttributes
// Test node attribute functionality
void ManipulateNodeEdgeAttributes() {
int NNodes = 1000;
int NEdges = 1000;
const char *FName = "demo.graph.dat";
PNEANet Graph;
PNEANet Graph1;
int i;
int x, y;
bool t;
Graph = TNEANet::New();
t = Graph->Empty();
// create the nodes
for (i = 0; i < NNodes; i++) {
Graph->AddNode(i);
}
// create the edges
for (i = 0; i < NEdges; i++) {
x = rand() % NNodes;
y = rand() % NNodes;
Graph->AddEdge(x, y, i);
}
// create attributes and fill all nodes
TStr attr1 = "str";
TStr attr2 = "int";
TStr attr3 = "float";
TStr attr4 = "default";
// Test vertical int iterator for node 3, 50, 700, 900
// Check if we can set defaults to 0 for Int data.
Graph->AddIntAttrN(attr2, 0);
Graph->AddIntAttrDatN(3, 3*2, attr2);
Graph->AddIntAttrDatN(50, 50*2, attr2);
Graph->AddIntAttrDatN(700, 700*2, attr2);
Graph->AddIntAttrDatN(900, 900*2, attr2);
int NodeId = 0;
for (TNEANet::TAIntI NI = Graph->BegNAIntI(attr2);
NI < Graph->EndNAIntI(attr2); NI++) {
// Check if defaults are now 0.
if (NI.GetDat()() != 0) {
printf("Attribute: %s, Node: %i, Val: %i\n", attr2(), NodeId, NI.GetDat()());
NodeId++;
}
}
// Test vertical flt iterator for node 3, 50, 700, 900
Graph->AddFltAttrDatN(5, 3.41, attr3);
Graph->AddFltAttrDatN(50, 2.718, attr3);
Graph->AddFltAttrDatN(300, 150.0, attr3);
Graph->AddFltAttrDatN(653, 653, attr3);
NodeId = 0;
for (TNEANet::TAFltI NI = Graph->BegNAFltI(attr3);
NI < Graph->EndNAFltI(attr3); NI++) {
if (NI.GetDat() != TFlt::Mn) {
printf("Attribute: %s, Node: %i, Val: %f\n", attr3(), NodeId, NI.GetDat()());
NodeId++;
}
}
// Test vertical str iterator for node 3, 50, 700, 900
Graph->AddStrAttrDatN(10, "abc", attr1);
Graph->AddStrAttrDatN(20, "def", attr1);
Graph->AddStrAttrDatN(400, "ghi", attr1);
// this does not show since ""=null
Graph->AddStrAttrDatN(455, "", attr1);
NodeId = 0;
for (TNEANet::TAStrI NI = Graph->BegNAStrI(attr1);
NI < Graph->EndNAStrI(attr1); NI++) {
if (NI.GetDat() != TStr::GetNullStr()) {
printf("Attribute: %s, Node: %i, Val: %s\n", attr1(), NodeId, NI.GetDat()());
NodeId++;
}
}
// Test vertical iterator over many types (must skip default/deleted attr)
int NId = 55;
Graph->AddStrAttrDatN(NId, "aaa", attr1);
Graph->AddIntAttrDatN(NId, 3*2, attr2);
Graph->AddFltAttrDatN(NId, 3.41, attr3);
Graph->AddStrAttrDatN(80, "dont appear", attr4); // should not show up
TStrV NIdAttrName;
Graph->AttrNameNI(NId, NIdAttrName);
int AttrLen = NIdAttrName.Len();
for (int i = 0; i < AttrLen; i++) {
printf("Vertical Node: %i, Attr: %s\n", NId, NIdAttrName[i]());
}
Graph->DelAttrDatN(NId, attr2);
Graph->AttrNameNI(NId, NIdAttrName);
AttrLen = NIdAttrName.Len();
for (int i = 0; i < AttrLen; i++) {
printf("Vertical Node (no int) : %i, Attr: %s\n", NId, NIdAttrName[i]());
}
//.........这里部分代码省略.........
示例2: FOut
// Test node, edge attribute functionality
TEST(TNEANet, ManipulateNodesEdgeAttributes) {
int NNodes = 1000;
int NEdges = 1000;
const char *FName = "demo.graph.dat";
PNEANet Graph;
PNEANet Graph1;
int i;
int x, y;
bool t;
Graph = TNEANet::New();
t = Graph->Empty();
// create the nodes
for (i = NNodes - 1; i >= 0; i--) {
Graph->AddNode(i);
}
EXPECT_EQ(NNodes, Graph->GetNodes());
// create the edges
for (i = NEdges - 1; i >= 0; i--) {
x = (long) (drand48() * NNodes);
y = (long) (drand48() * NNodes);
Graph->AddEdge(x, y, i);
}
// create attributes and fill all nodes
TStr attr1 = "str";
TStr attr2 = "int";
TStr attr3 = "float";
TStr attr4 = "default";
// Test vertical int iterator for node 3, 50, 700, 900
// Check if we can set defaults to 0 for Int data.
Graph->AddIntAttrN(attr2, 0);
Graph->AddIntAttrDatN(3, 3*2, attr2);
Graph->AddIntAttrDatN(50, 50*2, attr2);
Graph->AddIntAttrDatN(700, 700*2, attr2);
Graph->AddIntAttrDatN(900, 900*2, attr2);
EXPECT_EQ(3*2, Graph->GetNAIntI(attr2, 3).GetDat());
EXPECT_EQ(50*2, Graph->GetNAIntI(attr2, 50).GetDat());
int NodeId = 0;
int DefNodes = 0;
TVec<TInt> TAIntIV = TVec<TInt>();
for (TNEANet::TAIntI NI = Graph->BegNAIntI(attr2);
NI < Graph->EndNAIntI(attr2); NI++) {
if (NI.GetDat()() != 0) {
TAIntIV.Add(NI.GetDat());
NodeId++;
} else {
DefNodes++;
}
}
EXPECT_EQ(4, NodeId);
EXPECT_EQ(NNodes - 4, DefNodes);
TAIntIV.Sort();
EXPECT_EQ(3*2, TAIntIV[0]);
EXPECT_EQ(50*2, TAIntIV[1]);
EXPECT_EQ(700*2, TAIntIV[2]);
EXPECT_EQ(900*2, TAIntIV[3]);
// Test vertical flt iterator for node 3, 50, 700, 900
Graph->AddFltAttrDatN(5, 3.41, attr3);
Graph->AddFltAttrDatN(50, 2.718, attr3);
Graph->AddFltAttrDatN(300, 150.0, attr3);
Graph->AddFltAttrDatN(653, 563, attr3);
EXPECT_EQ(3.41, Graph->GetNAFltI(attr3, 5).GetDat());
EXPECT_EQ(2.718, Graph->GetNAFltI(attr3, 50).GetDat());
NodeId = 0;
DefNodes = 0;
TVec<TFlt> TAFltIV = TVec<TFlt>();
for (TNEANet::TAFltI NI = Graph->BegNAFltI(attr3);
NI < Graph->EndNAFltI(attr3); NI++) {
if (NI.GetDat() != TFlt::Mn) {
NodeId++;
TAFltIV.Add(NI.GetDat());
} else {
DefNodes++;
}
}
EXPECT_EQ(4, NodeId);
EXPECT_EQ(NNodes - 4, DefNodes);
TAFltIV.Sort();
EXPECT_EQ(2.718, TAFltIV[0]);
EXPECT_EQ(3.41, TAFltIV[1]);
EXPECT_EQ(150.0, TAFltIV[2]);
EXPECT_EQ(563.0, TAFltIV[3]);
// Test vertical str iterator for node 3, 50, 700, 900
Graph->AddStrAttrDatN(10, "abc", attr1);
//.........这里部分代码省略.........