本文整理汇总了C++中graph::add_node方法的典型用法代码示例。如果您正苦于以下问题:C++ graph::add_node方法的具体用法?C++ graph::add_node怎么用?C++ graph::add_node使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph
的用法示例。
在下文中一共展示了graph::add_node方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read_edgelist
bool CDLib::read_edgelist(graph& g, const string& filepath) {
g.clear();
ifstream ifs;
ifs.open(filepath.c_str());
if (ifs.is_open()) {
vector<string> units;
double weight;
while (!ifs.eof()) {
weight = 1;
string line;
getline(ifs, line);
if ((line.size() > 0) && (line[0] != '#')) {
split(line, units);
if (units.size() != 0) {
if ((units.size() < 2) || (units.size() > 3)) return false;
if (units.size() == 3) weight = str2T<double>(units[2]);
g.add_node(units[0]);
g.add_node(units[1]);
g.add_edge(units[0], units[1], weight);
}
}
}
g.set_graph_name(filename(filepath));
return true;
}
return false;
}
示例2: init_empty_graph
void CDLib::init_empty_graph(graph& g, size_t size) {
g.clear();
if (g.is_directed()) g.convert_to_undirected();
if (g.is_weighted()) g.convert_to_unweighted(0);
for (id_type i = 0; i < size; i++) g.add_node();
}
示例3: read_adjacencylist
bool CDLib::read_adjacencylist(graph& g, const string& filepath) {
g.clear();
ifstream ifs;
ifs.open(filepath.c_str());
if (ifs.is_open()) {
int type = 0;
id_type nid = 0, estart = 0;
string line;
getline(ifs, line);
vector<id_type> units;
split(line, units);
if ((units.size() > 2) && (units[0] == 0) && (units[1] == units.size() - 2)) {
type = 0;
estart = 2;
} else if ((units.size() > 1) && (units[0] == 0)) {
type = 1;
estart = 1;
} else {
type = 2;
estart = 0;
}
g.add_node(to_string(nid));
for (id_type i = estart; i < units.size(); i++) {
g.add_node(to_string(units[i]));
g.add_edge(to_string(nid), to_string(units[i]), 1);
}
while (!ifs.eof()) {
string line;
getline(ifs, line);
vector<id_type> units;
split(line, units);
if (units.size() > 0) {
if ((type == 0) || (type == 1)) nid = units[0];
else nid++;
g.add_node(to_string(nid));
for (id_type i = estart; i < units.size(); i++) {
g.add_node(to_string(units[i]));
g.add_edge(to_string(nid), to_string(units[i]), 1);
}
}
}
g.set_graph_name(filename(filepath));
return true;
}
return false;
}
示例4: read_matlab_sp
bool CDLib::read_matlab_sp(graph& g, const string& filepath) {
g.clear();
ifstream ifs;
ifs.open(filepath.c_str());
if (ifs.is_open()) {
id_type from, to;
double weight = 1;
while (!ifs.eof()) {
ifs >> from >> to >> weight;
while (max(from, to) > g.get_num_nodes()) {
g.add_node();
}
g.add_edge(from - 1, to - 1, weight);
}
g.set_graph_name(filename(filepath));
return true;
}