From 1a91aef78b10ce62dd70bcbe0e5af9584e7587b0 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Mon, 8 Jul 2013 13:22:05 +0200 Subject: [PATCH] GraphViewer: The ModularityJoiner properly reacts to insertion / deletion of edges --- .../js/graphViewer/graph/modularityJoiner.js | 23 +++++ .../specNodeReducer/modularityJoinerSpec.js | 88 +++++++++++++++++-- 2 files changed, 103 insertions(+), 8 deletions(-) diff --git a/html/admin/js/graphViewer/graph/modularityJoiner.js b/html/admin/js/graphViewer/graph/modularityJoiner.js index 96b1688c1b..066a44d6bc 100644 --- a/html/admin/js/graphViewer/graph/modularityJoiner.js +++ b/html/admin/js/graphViewer/graph/modularityJoiner.js @@ -324,6 +324,27 @@ function ModularityJoiner() { revM = Math.pow(m, -1); }, + deleteEdge = function(s, t) { + if (matrix[s]) { + delete matrix[s][t]; + delete backwardMatrix[t][s]; + degrees[s]._out--; + degrees[t]._in--; + m--; + revM = Math.pow(m, -1); + if (_.isEmpty(matrix[s])) { + delete matrix[s]; + delete backwardMatrix[t]; + } + if (degrees[s]._in === 0 && degrees[s]._out === 0) { + delete degrees[s]; + } + if (degrees[t]._in === 0 && degrees[t]._out === 0) { + delete degrees[t]; + } + } + }, + makeInitialDegrees = function() { a = {}; _.each(degrees, function (n, id) { @@ -596,6 +617,8 @@ function ModularityJoiner() { this.insertEdge = insertEdge; + this.deleteEdge = deleteEdge; + this.getAdjacencyMatrix = getAdjacencyMatrix; this.getHeap = getHeap; diff --git a/html/admin/js/graphViewer/jasmine_test/specNodeReducer/modularityJoinerSpec.js b/html/admin/js/graphViewer/jasmine_test/specNodeReducer/modularityJoinerSpec.js index 96847173b5..e102f229b8 100644 --- a/html/admin/js/graphViewer/jasmine_test/specNodeReducer/modularityJoinerSpec.js +++ b/html/admin/js/graphViewer/jasmine_test/specNodeReducer/modularityJoinerSpec.js @@ -135,7 +135,7 @@ }; }); - /* + describe('getters', function() { beforeEach(function() { @@ -199,6 +199,12 @@ expect(joiner.insertEdge.length).toEqual(2); }); + it('should offer a function to delete an edge', function() { + expect(joiner.deleteEdge).toBeDefined(); + expect(joiner.deleteEdge).toEqual(jasmine.any(Function)); + expect(joiner.deleteEdge.length).toEqual(2); + }); + it('should offer a setup function', function() { expect(joiner.setup).toBeDefined(); expect(joiner.setup).toEqual(jasmine.any(Function)); @@ -248,6 +254,75 @@ } }); }); + + it('should react to insert edge', function() { + joiner.insertEdge("a", "b"); + + expect(joiner.getAdjacencyMatrix()).toEqual({ + "0": { + "1": 1, + "3": 1 + }, + "1": { + "2": 1 + }, + "2": { + "1": 1, + "3": 1 + }, + "3": { + "0": 1, + "1": 1, + "2": 1 + }, + "a": { + "b": 1 + } + }); + }); + + it('should react to delete edge', function() { + joiner.deleteEdge("0", "1"); + + expect(joiner.getAdjacencyMatrix()).toEqual({ + "0": { + "3": 1 + }, + "1": { + "2": 1 + }, + "2": { + "1": 1, + "3": 1 + }, + "3": { + "0": 1, + "1": 1, + "2": 1 + } + }); + }); + + it('should remove empty lines on delete', function() { + joiner.deleteEdge("1", "2"); + + expect(joiner.getAdjacencyMatrix()).toEqual({ + "0": { + "1": 1, + "3": 1 + }, + "2": { + "1": 1, + "3": 1 + }, + "3": { + "0": 1, + "1": 1, + "2": 1 + } + }); + }); + }); @@ -601,7 +676,7 @@ }); - */ + describe('checking direct community identification', function() { it('should be able to identify an obvious community', function() { @@ -670,7 +745,6 @@ */ }); - /* describe('checking the zachary karate club', function() { beforeEach(function() { @@ -882,8 +956,7 @@ }); }); - */ - /* + describe('checking consistency after join', function() { beforeEach(function() { @@ -1041,8 +1114,7 @@ }); }); - */ - /* + describe('checking large networks', function() { it('should be able to handle 1000 nodes', function() { @@ -1601,7 +1673,7 @@ }); }); - */ + /* it('should be able to handle 10000 nodes', function() {