本文整理汇总了C++中ugraph::pGraph类的典型用法代码示例。如果您正苦于以下问题:C++ pGraph类的具体用法?C++ pGraph怎么用?C++ pGraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了pGraph类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: GetPSDegreeCorrelation
void scn::GetPSDegreeCorrelation(vector<pair<size_t, double>> &correlation,UGraph::pGraph graph)
{
//get degree distribution
unordered_map<size_t,size_t> degree_dist;
for(auto node = graph->begin(); node != graph->end(); node++)
{
degree_dist[node->GetDegree()]++;
}
//compute degree correlation
unordered_map<size_t, double> degree_corre;
for(auto node = graph->begin(); node != graph->end(); node++)
{
double degree_sum = 0;
for(auto other = node->begin(); other != node->end(); other++)
{
degree_sum += (*graph)[*other]->GetDegree();
}
degree_corre[node->GetDegree()] += degree_sum /
static_cast<double>(node->GetDegree());
}
//normalize
for(auto iter = degree_corre.begin(); iter != degree_corre.end(); iter++)
{
iter->second /= degree_dist[iter->first];
}
correlation.assign(degree_corre.begin(), degree_corre.end());
sort(correlation.begin(), correlation.end());
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:28,代码来源:Feature&Search.cpp
示例2: GetAverageDistance
double scn::GetAverageDistance(UGraph::pGraph graph)
{
size_t sum = 0;
size_t count = 0;
std::unordered_map<size_t,size_t> distance;
//auto& distance = distance_sssp;
distance.clear();
for(auto node = graph->begin(); node != graph->end(); node++)
{
RunSPFA(graph,*node,distance);
//add distance except NaF
for(auto iter = distance.begin(); iter != distance.end(); iter++)
{
if(iter->first == *node)
continue;
if(iter->second < Graph::NaF)
{
sum += iter->second;
count++;
}
}
}
return double(sum) / count;
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:25,代码来源:Feature&Search.cpp
示例3: CreateScene
QUNetwork::QUNetwork(UGraph::pGraph &graph)
:UNetwork(graph)
{
CreateScene(graph->GetNumberOfNodes());
//create draw node
for(auto node = graph->begin(); node != graph->end(); node++)
{
pNode data = new QNodeItem(this);
data->indexOfNode = *node;
data->SetText(QString("%1").arg(*node));
SetNodeData(node, data);
}
//create position
CreateCirclePosition();
//add draw edge
pEdge data;
for(auto node = graph->begin(); node != graph->end(); node++)
{
for(auto other = node->begin(); other != node->end(); other++)
{
data = new QEdgeItem(GetNodeData(node)->pos(),
GetNodeData(*other)->pos());
SetEdgeData(node, *other, data);
}
}
}
开发者ID:petalgem,项目名称:scn,代码行数:28,代码来源:qnetwork.cpp
示例4: GetAverageDistanceByDjikstra
double scn::GetAverageDistanceByDjikstra(UGraph::pGraph graph)
{
std::unordered_map<size_t,size_t> distance;
size_t sum = 0;
size_t count = 0;
//auto& distance = distance_sssp;
distance.clear();
for(auto node = graph->begin(); node != graph->end(); node++)
{
RunDjikstra(graph,*node,distance);
//add distance except NaF
for(auto other = graph->begin(); other != graph->end(); other++)
{
if(node == other)
continue;
if(distance[*other] < Graph::NaF)
{
sum += distance[*other];
count++;
}
}
}
return double(sum) / count;
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:25,代码来源:Feature&Search.cpp
示例5: RunSPFA
void scn::RunSPFA(UGraph::pGraph graph,size_t indexOfSource, std::unordered_map<size_t,size_t> &distance)
{
assert(graph->HasNode(indexOfSource));
// Map<size_t>& distance = distance_sssp;
//distance, stored the distance information of each node
//init
for(auto node = graph->begin(); node != graph->end(); node++)
{
distance[*node] = Graph::NaF;
}
distance[indexOfSource] = 0;
queue<size_t> queue_buffer;
unordered_set<size_t> in_queue;
queue_buffer.push(indexOfSource);//push source node
size_t front;
while(!queue_buffer.empty())
{
front = queue_buffer.front();
queue_buffer.pop();
in_queue.erase(front);
auto node = graph->find(front);
for(auto other = node->begin(); other != node->end(); other++)
{
if(in_queue.find(*other) == in_queue.end() &&
distance[front] + 1 < distance[*other])
{
distance[*other] = distance[front] + 1;
queue_buffer.push(*other);
in_queue.insert(*other);
}
}
}
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:33,代码来源:Feature&Search.cpp
示例6: GetGeodesicMatrix
Matrix scn::GetGeodesicMatrix(UGraph::pGraph graph)
{
Matrix result(graph->GetNumberOfNodes(), graph->GetNumberOfNodes());
std::unordered_map<size_t,size_t> distance;
//auto& distance = distance_sssp;
size_t diameter = 0;
for(auto node = graph->begin(); node != graph->end(); node++)
{
RunSPFA(graph,*node,distance);
for(auto iter = distance.begin(); iter != distance.end(); iter++)
{
result(*node, iter->first) = iter->second;
if(iter->second > diameter)
{
diameter = iter->second;
}
}
}
//result.Print("Matrix:");
for(size_t i = 0; i < result.GetHeight(); i++)
{
result(i, i) = - valarray<double>(result.row(i)).sum();
}
result /= static_cast<double>(diameter);
return result;
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:28,代码来源:Feature&Search.cpp
示例7: GetDiameterAndAverageDistance
void scn::GetDiameterAndAverageDistance(size_t &Diamter,double &APL,UGraph::pGraph graph)
{
size_t sum = 0;
size_t count = 0;
size_t diameter = 0;
std::unordered_map<size_t,size_t> distance;
for(auto node = graph->begin(); node != graph->end(); node++)
{
RunSPFA(graph,*node,distance);
//add distance except NaF
for(auto iter = distance.begin(); iter != distance.end(); iter++)
{
if(iter->first == *node)
continue;
if(iter->second < Graph::NaF)
{
sum += iter->second;
count++;
if(iter->second > diameter)
diameter = iter->second;
}
}
}
//return make_pair(diameter, double(sum) / count);
Diamter=diameter;
APL=double(sum) / count;
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:27,代码来源:Feature&Search.cpp
示例8: MRTofRandomWalk
size_t scn::MRTofRandomWalk(UGraph::pGraph graph)
{
size_t total_steps = 0;
vector<size_t> neighbors;
srand(size_t(time(00)));
//#pragma omp parallel for shared(total_steps) private(neighbors)
for(size_t source = 0; source < graph->GetNumberOfNodes(); source++)
{
// if(omp_get_thread_num() == 0)
// cout<<"Random walk on "<<source<<"/"<<graph->GetNumberOfNodes() / omp_get_num_procs()<<endl;
size_t next = source;
size_t steps = 0;
do
{
neighbors.assign(graph->find(next)->begin(), graph->find(next)->end());
next = neighbors[rand() % neighbors.size()];
steps++;
}while(next != source);
//#pragma omp critical
{
total_steps += steps;
}
}
return static_cast<double>(total_steps) /
static_cast<double>(graph->GetNumberOfNodes());
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:28,代码来源:Feature&Search.cpp
示例9: GenSmallWorldNetworkByNW
UGraph::pGraph scn::GenSmallWorldNetworkByNW(size_t numberOfNodes, size_t k,
double probability)
{
assert(2* k + 1 <= numberOfNodes);
assert(probability >= 0);
assert(probability <= 1);
//generate k-nearest network
UGraph::pGraph graph = GenKNearestNetwork(numberOfNodes, k);
//add edges randomly
size_t numberOfEdges = numberOfNodes * (numberOfNodes - 2 * k - 1) / 2 * probability;
size_t sum_edges = 0;
size_t one, two;
srand(size_t(time(00)));
do
{
one = rand() % numberOfNodes;
two = rand() % numberOfNodes;
if(!(one == two || graph->HasEdge(one, two)))
{
graph->AddEdge(one, two);
sum_edges++;
}
}while(sum_edges < numberOfEdges);
return graph;
}
开发者ID:python27,项目名称:scn,代码行数:28,代码来源:network_generator.cpp
示例10: ComputeAverageDegree
double scn::ComputeAverageDegree(UGraph::pGraph graph)
{
double sum = 0;
for(auto node = graph->begin(); node != graph->end(); node++)
{
sum += node->GetDegree();
}
return sum / graph->GetNumberOfNodes();
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:9,代码来源:Feature&Search.cpp
示例11: GetHideInfo
double scn::GetHideInfo(UGraph::pGraph graph,size_t indexOfNode)
{
double sum = 0;
for(auto node = graph->begin(); node != graph->end(); node++)
{
if(*node == indexOfNode)
continue;
sum += GetSearchInfo(graph,*node, indexOfNode);
}
return sum / static_cast<double>(graph->GetNumberOfNodes());
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:12,代码来源:Feature&Search.cpp
示例12: RunDjikstra
void scn::RunDjikstra(UGraph::pGraph graph,size_t indexOfSource,std::unordered_map<size_t,size_t> &distance)
{
//auto& distance = distance_sssp;//using distance_sssp eariler
assert(graph->HasNode(indexOfSource));
//init
//distance.reserve(graph->GetNumberOfNodes());
for(auto node = graph->begin(); node != graph->end(); node++)
{
distance[*node] = Graph::NaF;
}
distance[indexOfSource] = 0;
list<size_t> queue;
//fill index of nodes into queue
for(size_t i = 0; i < graph->GetNumberOfNodes(); i++)
{
queue.push_back(i);
}
//begin
size_t next_distance;
while(!queue.empty())
{
//get min one
auto min = min_element(queue.begin(), queue.end(),
[&](const size_t &one, const size_t &two)->bool
{
if(distance[one] < distance[two])
return true;
else
return false;
});
auto node = graph->find(*min);
if(distance[*node] < Graph::NaF)
next_distance = distance[*node] + 1;
else
next_distance = Graph::NaF;
//relax neighbors
for(auto other = node->begin(); other != node->end(); other++)
{
if(distance[*other] > next_distance)
{
distance[*other] = next_distance;
}
}
queue.erase(min);
}
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:48,代码来源:Feature&Search.cpp
示例13:
//注意:需要特征值计算,Fortran
void scn::GetLambda2AndRatio(double &lambda2, double &ratio,UGraph::pGraph graph)
{
auto list = graph->GetLaplacianMatrix().GetEigenvalueList();
//return make_pair(list[list.size() - 2], list[0] / list[list.size() - 2]);
lambda2=list[list.size() - 2];
ratio=list[0] / list[list.size() - 2];
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:8,代码来源:Feature&Search.cpp
示例14: GetSearchInfo
double scn::GetSearchInfo(UGraph::pGraph graph,size_t indexOfSource, size_t indexOfTarget)
{
assert(graph->HasNode(indexOfSource));
assert(graph->HasNode(indexOfTarget));
assert(indexOfSource != indexOfTarget);
std::unordered_map<size_t,size_t> distance;
//get shortest distance
//auto& distance = distance_sssp;
RunSPFA(graph,indexOfSource,distance);
double sum = 0;
//search in breadth-first way
queue<pair<size_t, double>> path_queue;//pair : indexOfNode,
//probability of path
path_queue.push(make_pair(indexOfTarget, 1.0));
while(!path_queue.empty())
{
auto current = path_queue.front();
auto node = (*graph)[current.first];
path_queue.pop();
for(auto other = node->begin(); other != node->end(); other++)
{//put all of previous-node in path into queue
if(distance[*other] == distance[*node] - 1)
{
if(distance[*other] == 0)
sum += current.second / static_cast<double>(node->GetDegree());
else
path_queue.push(make_pair(*other, current.second /
static_cast<double>((*graph)[*other]->GetDegree() - 1)));
}
}
}
return - log(sum)/log(2.0);
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:34,代码来源:Feature&Search.cpp
示例15: RandomWalkByURW
size_t scn::RandomWalkByURW(UGraph::pGraph graph,size_t indexOfSource, size_t indexOfTarget)
{
unordered_set<size_t> neighbors_of_target(graph->find(indexOfTarget)->begin(),
graph->find(indexOfTarget)->end());
vector<size_t> neighbors;
size_t steps = 0;
size_t next = indexOfSource;
srand(size_t(time(00)));
do
{
neighbors.assign(graph->find(next)->begin(), graph->find(next)->end());
next = neighbors[rand() % neighbors.size()];
steps++;
}while(neighbors_of_target.find(next) == neighbors_of_target.end());
return steps;
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:17,代码来源:Feature&Search.cpp
示例16: RandomWalkBySARW
size_t scn::RandomWalkBySARW(UGraph::pGraph graph,size_t indexOfSource, size_t indexOfTarget)
{
unordered_set<size_t> neighbors_of_target(graph->find(indexOfTarget)->begin(),
graph->find(indexOfTarget)->end());
vector<size_t> neighbors;
size_t steps = 0;
size_t next = indexOfSource;
unordered_set<size_t> history;
stack<size_t> precessors;
history.insert(indexOfSource);
precessors.push(indexOfSource);
srand(size_t(time(00)));
// judge first
if(graph->HasEdge(indexOfSource, indexOfTarget))
return 1;
do
{
auto other = graph->find(next);
neighbors.clear();
for(auto iter = other->begin(); iter != other->end(); iter++)
{
if(history.find(*iter) == history.end())
neighbors.push_back(*iter);
}
if(neighbors.empty())
{
history.insert(*other);
precessors.pop();
next = precessors.top();
history.insert(next);
steps++;
continue;
}
do
{
next = neighbors[rand() % neighbors.size()];
}while(history.find(next) != history.end());
steps++;
history.insert(next);
precessors.push(next);
}while(neighbors_of_target.find(next) == neighbors_of_target.end());
return steps;
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:46,代码来源:Feature&Search.cpp
示例17: GetEntropyOfDegreeDist
double scn::GetEntropyOfDegreeDist(UGraph::pGraph graph)
{
//get degree distribution
std::unordered_map<size_t,size_t> distribution;
for(auto node = graph->begin(); node != graph->end(); node++)
{
distribution[node->GetDegree()]++;
}
//compute the entropy
double sum = 0;
double pk = 0;
for(auto iter = distribution.begin(); iter != distribution.end(); iter++)
{
pk = static_cast<double>(iter->second) / graph->GetNumberOfNodes();
sum -= pk * log(pk)/log(2.0);
}
return sum;
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:18,代码来源:Feature&Search.cpp
示例18: GetDegreeDistribution
void scn::GetDegreeDistribution(vector<pair<size_t, size_t>> &pairs,UGraph::pGraph graph)
{
std::unordered_map<size_t,size_t> distribution;
for(auto node = graph->begin(); node != graph->end(); node++)
{
distribution[node->GetDegree()]++;
}
//copy and sort
pairs.assign(distribution.begin(), distribution.end());
sort(pairs.begin(), pairs.end(), [&](const pair<size_t, size_t> &one,
const pair<size_t, size_t> &two)->bool
{
if(one.first < two.first)
return true;
else
return false;
});
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:18,代码来源:Feature&Search.cpp
示例19: GetBetweennessCentrality
double scn::GetBetweennessCentrality(UGraph::pGraph graph,size_t indexOfNode)
{
double sum = 0;
for(auto node1 = graph->begin(); node1 != graph->end(); node1++)
{
if(*node1 == indexOfNode)
continue;
for(auto node2 = graph->begin(); node2 != graph->end(); node2++)
{
if(*node2 == indexOfNode || node1 == node2)
continue;
//compute
auto result = GetNumberOfShortestPath(graph,*node1, *node2, indexOfNode);
sum += static_cast<double>(result.second) /
static_cast<double>(result.first);
}
}
return sum;
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:20,代码来源:Feature&Search.cpp
示例20: GetGlobalEfficiency
double scn::GetGlobalEfficiency(UGraph::pGraph graph)
{
double sum = 0;
std::unordered_map<size_t,size_t> distance;
//auto& distance = distance_sssp;
distance.clear();
for(auto node = graph->begin(); node != graph->end(); node++)
{
RunSPFA(graph,*node,distance);
//add distance
for(auto iter = distance.begin(); iter != distance.end(); iter++)
{
if(iter->first == *node)
continue;
sum += 1.0 / static_cast<double>(iter->second);
}
}
double size = static_cast<double>(graph->GetNumberOfNodes());
return size * (size - 1) / sum;
}
开发者ID:petalgem,项目名称:ComplexNet,代码行数:21,代码来源:Feature&Search.cpp
注:本文中的ugraph::pGraph类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论