1
0
Fork 0

GraphViewer: Implemented initialisation for Clauset, Newman and Moore's algorithm

This commit is contained in:
Michael Hackstein 2013-05-13 12:48:42 +02:00
parent 8b16ec6e18
commit 3d1bd8dfde
3 changed files with 61 additions and 3 deletions

View File

@ -37,9 +37,50 @@ function NodeReducer(nodes, edges) {
throw "Edges have to be given.";
}
var self = this;
var self = this,
getDegree = function(id) {
return $.grep(nodes, function(e){
return e._id === id;
})[0];
},
// Will Overwrite dQ, a and heap!
populateValues = function(dQ, a, heap) {
var m = edges.length,
twoM = 2 * m,
cFact = 1 / twoM;
_.each(nodes, function(n) {
a[n._id] = (n._outboundCounter + n._inboundCounter) / twoM;
});
_.each(edges, function(e) {
var sID, lID;
if (e.source._id < e.target._id) {
sID = e.source._id;
lID = e.target._id;
} else {
sID = e.target._id;
lID = e.source._id;
}
if (dQ[sID] === undefined) {
dQ[sID] = {};
heap[sID] = {};
heap[sID].val = -1;
}
dQ[sID][lID] = cFact - a[sID] * a[lID];
if (heap[sID].val < dQ[sID][lID]) {
heap[sID].val = dQ[sID][lID];
heap[sID].lID = lID;
}
});
};
self.getCommunity = function(limit, focus) {
var dQ = {},
a = {},
heap = {};
populateValues(dQ, a, heap);
return [];
};
}

View File

@ -48,7 +48,25 @@ var helper = helper || {};
});
return nodes;
};
helper.insertSimpleNodes = function (nodes, ids) {
_.each(ids, function(i) {
nodes.push({
_id: i,
_inboundCounter: 0,
_outboundCounter: 0,
position: {
x: 1,
y: 1,
z: 1
}
});
});
};
helper.createSimpleEdge = function(nodes, s, t) {
nodes[s]._outboundCounter++;
nodes[t]._inboundCounter++;
return {
source: nodes[s],
target: nodes[t]

View File

@ -106,8 +106,7 @@
describe('checking community identification', function() {
it('should be able to identify an obvious community', function() {
nodes = helper.createSimpleNodes([0, 1, 2, 3, 4]);
edges = [];
helper.insertSimpleNodes(nodes, [0, 1, 2, 3, 4]);
edges.push(helper.createSimpleEdge(nodes, 0, 1));
edges.push(helper.createSimpleEdge(nodes, 0, 2));
edges.push(helper.createSimpleEdge(nodes, 0, 3));