Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ set(CORE_HEADERS
src/core/inc/NearestNeighborsDegree.h
src/core/inc/WeightedNearestNeighborsDegree.h
src/core/inc/GraphGenerator.h
src/core/inc/DirectedBetweenness.h
src/core/inc/Betweenness.h
src/core/inc/IBetweenness.h
src/core/inc/Boxplotentry.h
src/core/inc/WeightedGraphFactory.h
src/core/inc/WeightedClusteringCoefficient.h
Expand Down
2 changes: 1 addition & 1 deletion src/core/inc/Betweenness.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Betweenness : public IBetweenness<Graph, Vertex>

Betweenness(Graph& g)
{
initMap(g, 1, betweenness, 0.0, 0.0);
initMap(g, (*g.verticesIterator())->getVertexId(), betweenness, 0.0, 0.0);
calculateBetweenness(g);
}

Expand Down
131 changes: 131 additions & 0 deletions src/core/inc/DirectedBetweenness.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#pragma once

#include <list>
#include <queue>
#include <stack>
#include <vector>


#include "IBetweenness.h"
#include "mili/mili.h"
#include "typedefs.h"

namespace graphpp
{
template <class Graph, class Vertex>
class DirectedBetweenness : public IBetweenness<Graph, Vertex>
{
public:
typedef typename IBetweenness<Graph, Vertex>::BetweennessContainer BetweennessContainer;
typedef typename IBetweenness<Graph, Vertex>::BetweennessIterator BetweennessIterator;

DirectedBetweenness(DirectedGraph& g)
{
initMap(g, (*g.verticesIterator())->getVertexId(), betweenness, 0.0, 0.0);
calculateBetweenness(g);
}

virtual BetweennessIterator iterator()
{
return BetweennessIterator(betweenness);
}

private:
void calculateBetweenness(DirectedGraph& g)
{
auto iter = g.verticesIterator();

while (!iter.end())
{
DirectedVertex* s = *iter;
std::stack<DirectedVertex*> stack;
std::queue<DirectedVertex*> queue;
std::map<typename DirectedVertex::VertexId, std::list<typename Vertex::VertexId>> p;
std::map<typename DirectedVertex::VertexId, double> sigma;
std::map<typename DirectedVertex::VertexId, double> d;
std::map<typename DirectedVertex::VertexId, double> delta;

initMap(g, s->getVertexId(), sigma, 0.0, 1.0);
initMap(g, s->getVertexId(), d, -1.0, 0.0);
initMap(g, s->getVertexId(), delta, 0.0, 0.0);

queue.push(s);

while (!queue.empty())
{
DirectedVertex* v = queue.front();
queue.pop();
stack.push(v);

// iterate through v's neighbors
auto neighbourIter = v->outNeighborsIterator();

while (!neighbourIter.end())
{
Vertex* w = (Vertex*)*neighbourIter;
// w found for the first time?
double wValue = d[w->getVertexId()];
// double vValue = d[v->getVertexId()];
if (wValue < 0)
{
queue.push(w);
d[w->getVertexId()] = d[v->getVertexId()] + 1;
}
// shortest path to w via v?
if (d[w->getVertexId()] == (d[v->getVertexId()] + 1))
{
sigma[w->getVertexId()] = sigma[w->getVertexId()] + sigma[v->getVertexId()];
p[w->getVertexId()].push_back(v->getVertexId());
}

++neighbourIter;
}
}

// S returns vertices in order of non-increasing distance from s
while (!stack.empty())
{
Vertex* w = stack.top();
stack.pop();

std::list<typename Vertex::VertexId> vertices = p[w->getVertexId()];

for (const auto& v : vertices)
{
delta[v] = delta[v] + ((1 + delta[w->getVertexId()]) *
(sigma[v] / sigma[w->getVertexId()]));
}

if (w->getVertexId() != s->getVertexId())
{
betweenness[w->getVertexId()] += delta[w->getVertexId()];
}
}

++iter;
}
}

void initMap(
DirectedGraph& g,
unsigned int vertexId,
std::map<typename Vertex::VertexId, double>& m,
double commonValue,
double distinguishedValue)
{
auto it = g.verticesIterator();

// initialize all elements in zero, except for the current vertex
while (!it.end())
{
Vertex* v = *it;
m.insert(std::pair<typename Vertex::VertexId, double>(v->getVertexId(), commonValue));
++it;
}
// modify the value associated to key 'vertexId'
m[vertexId] = distinguishedValue;
}

BetweennessContainer betweenness;
};
} // namespace graphpp
7 changes: 3 additions & 4 deletions src/core/inc/DirectedGraphFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "DirectedNearestNeighborsDegree.h"
#include "GraphReader.h"
#include "IGraphFactory.h"
#include "DirectedBetweenness.h"

namespace graphpp
{
Expand All @@ -16,11 +17,9 @@ class DirectedGraphFactory : public IGraphFactory<Graph, Vertex>
{
return new GraphReader<Graph, Vertex>();
}
virtual IBetweenness<Graph, Vertex>* createBetweenness(Graph&)
virtual IBetweenness<Graph, Vertex>* createBetweenness(DirectedGraph& g)
{
// TODO Implement this
// return new DirectedBetweenness<Graph,Vertex>();
return nullptr;
return new DirectedBetweenness<Graph,Vertex>(g);
}
virtual IClusteringCoefficient<Graph, Vertex>* createClusteringCoefficient()
{
Expand Down
1 change: 1 addition & 0 deletions src/core/inc/IGraphFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "IShellIndex.h"
#include "MaxClique.h"
#include "StrengthDistribution.h"
#include "typedefs.h"

namespace graphpp
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/inc/WeightedBetweenness.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class WeightedBetweenness : public IBetweenness<Graph, Vertex>

WeightedBetweenness(Graph& g)
{
initMap(g, 1, betweenness, 0.0, 0.0);
initMap(g, (*g.verticesIterator())->getVertexId(), betweenness, 0.0, 0.0);
calculateBetweenness(g);
}

Expand Down
112 changes: 83 additions & 29 deletions src/gui/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ void MainWindow::onNetworkLoad(const bool weightedgraph, const bool digraph, con

if (digraph)
{
ui->actionBetweenness->setEnabled(true);
ui->actionClustering_coefficient->setEnabled(true);
ui->actionNearest_neighbors_degree->setEnabled(true);
ui->actionConfigure_Directed_Degree_sign->setEnabled(true);
Expand Down Expand Up @@ -770,29 +771,42 @@ void MainWindow::computeBetweenness()

if (this->weightedgraph)
{
// TODO Asumes there are no directed wieghted graphs
auto betweenness = weightedFactory->createBetweenness(weightedGraph);
auto it = betweenness->iterator();

while (!it.end())
{
propertyMap.addProperty<double>(
"betweenness", to_string<unsigned int>(it->first), it->second);
"betweenness", to_string<unsigned int>(it->first), (it->second)/2);
++it;
}
delete betweenness;
}
else
{
auto betweenness = factory->createBetweenness(graph);
auto it = betweenness->iterator();

while (!it.end())
{
propertyMap.addProperty<double>(
"betweenness", to_string<unsigned int>(it->first), it->second);
++it;
if(digraph) {
auto betweenness = directedFactory->createBetweenness(directedGraph);
auto it = betweenness->iterator();
while (!it.end())
{
propertyMap.addProperty<double>(
"betweenness", to_string<unsigned int>(it->first), (it->second));
++it;
}
delete betweenness;
}
else {
auto betweenness = factory->createBetweenness(graph);
auto it = betweenness->iterator();
while (!it.end())
{
propertyMap.addProperty<double>(
"betweenness", to_string<unsigned int>(it->first), (it->second) / 2);
++it;
}
delete betweenness;
}
delete betweenness;
}
}

Expand All @@ -803,7 +817,7 @@ void MainWindow::computeDegreeDistribution()

if (this->weightedgraph)
{
auto degreeDistribution = weightedFactory->createStrengthDistribution(weightedGraph);
auto degreeDistribution = weightedFactory->createDegreeDistribution(weightedGraph);
auto it = degreeDistribution->iterator();

while (!it.end())
Expand Down Expand Up @@ -1835,7 +1849,7 @@ void MainWindow::on_actionNewErdosRenyi_triggered()
{
this->onNetworkLoad(false, false, false);
buildGraphFactory(false, false);

propertyMap.clear();
graph = *(GraphGenerator::getInstance()->generateErdosRenyiGraph(n, p));

QString text("Network created using Erdos-Renyi algorithm");
Expand Down Expand Up @@ -1873,6 +1887,7 @@ void MainWindow::on_actionNewHiperbolic_triggered()
{
this->onNetworkLoad(false, false, false);
buildGraphFactory(false, false);
propertyMap.clear();

QString text("Creating a network using a Papadopoulos hyperbolic graph algorithm...");
text.append("\nexpected avg node deg: ");
Expand Down Expand Up @@ -1918,6 +1933,7 @@ void MainWindow::on_actionNewBarabasiAlbert_triggered()

try
{
propertyMap.clear();
this->onNetworkLoad(false, false, false);
buildGraphFactory(false, false);

Expand Down Expand Up @@ -1970,7 +1986,7 @@ void MainWindow::on_actionNewExtendedHOT_triggered()

// The default parameters are taken from the paper
// (http://cnet.fi.uba.ar/ignacio.alvarez-hamelin/pdf/model_internet_jiah_ns.pdf)

propertyMap.clear();
unsigned int m = 1;
unsigned int n = 50;
unsigned int q = 1;
Expand Down Expand Up @@ -2043,6 +2059,7 @@ void MainWindow::on_actionNewMolloyReed_triggered()
{
try
{
propertyMap.clear();
this->onNetworkLoad(false, false, false);
buildGraphFactory(false, false);

Expand Down Expand Up @@ -2390,27 +2407,64 @@ graphpp::Boxplotentry MainWindow::computeTotalBpEntriesKnn()

graphpp::Boxplotentry MainWindow::computeTotalBpEntriesBetweenness()
{
Graph& g = graph;
auto vit = g.verticesIterator();
std::vector<double> bCoefs;

auto betweenness = factory->createBetweenness(g);
// TODO: replace with smart pointer
delete betweenness;

double coefSums = 0.0;
unsigned int count = 0;

while (!vit.end())
{
Vertex* v = *vit;
double c = propertyMap.getProperty<double>(
"betweenness", to_string<unsigned int>(v->getVertexId()));
bCoefs.push_back(c);
coefSums += c;
++vit;
count++;
if(weightedgraph) {
WeightedGraph& wg = weightedGraph;
auto vit = weightedGraph.verticesIterator();
if (! propertyMap.containsPropertySet("betweenness")) {
auto betweenness = weightedFactory->createBetweenness(wg);
delete betweenness;
}
while (!vit.end())
{
Vertex* v = *vit;
double c = propertyMap.getProperty<double>(
"betweenness", to_string<unsigned int>(v->getVertexId()));
bCoefs.push_back(c);
coefSums += c;
++vit;
count++;
}
}
else if(digraph) {
DirectedGraph& dg = directedGraph;
auto vit = directedGraph.verticesIterator();
if (! propertyMap.containsPropertySet("betweenness")) {
auto betweenness = directedFactory->createBetweenness(dg);
delete betweenness;
}
while (!vit.end())
{
Vertex* v = *vit;
double c = propertyMap.getProperty<double>(
"betweenness", to_string<unsigned int>(v->getVertexId()));
bCoefs.push_back(c);
coefSums += c;
++vit;
count++;
}
} else {
Graph& g = graph;
auto vit = graph.verticesIterator();
if (! propertyMap.containsPropertySet("betweenness")) {
auto betweenness = factory->createBetweenness(g);
delete betweenness;
}
while (!vit.end())
{
Vertex* v = *vit;
double c = propertyMap.getProperty<double>(
"betweenness", to_string<unsigned int>(v->getVertexId()));
bCoefs.push_back(c);
coefSums += c;
++vit;
count++;
}
}

std::sort(bCoefs.begin(), bCoefs.end());
graphpp::Boxplotentry entry;
if (bCoefs.size() > 0)
Expand Down