@@ -300,6 +300,97 @@ function openPositions(){
300
300
//***************************************************************************
301
301
//OPEN GRAPHS
302
302
//***************************************************************************
303
+ function enumEdges ( ) {
304
+ /*
305
+ Goes through and enumerates the number the number undirected edges between
306
+ each pairs of vertices that have edges between them.
307
+
308
+ OUTPUT
309
+ edgeCount: An object of the form {source: {target: {count: 1, ids: [edgeIdHere]}}}
310
+ */
311
+ var edges = cy . edges ( ) ;
312
+ var edgeCount = { } ;
313
+
314
+ //Enumerate each type of edge
315
+ for ( var i = 0 ; i < edges . length ; i ++ ) {
316
+ var source = edges [ i ] . data ( 'source' ) ,
317
+ target = edges [ i ] . data ( 'target' ) ,
318
+ id = edges [ i ] . data ( 'id' ) ;
319
+
320
+ //Check if our edgeCount dict has an entry for the source or target
321
+ var sourceEntry = source in edgeCount ,
322
+ targetEntry = target in edgeCount ;
323
+
324
+ //If neither entries exist make one
325
+ if ( ! sourceEntry && ! targetEntry ) {
326
+ edgeCount [ source ] = { } ;
327
+ edgeCount [ source ] [ target ] = { count : 1 , ids : [ id ] } ;
328
+ }
329
+ //Otherwise use the existing one already
330
+ else if ( sourceEntry && ! targetEntry ) {
331
+ //Check if our target is in the sourceEntry
332
+ var targetInner = target in edgeCount [ source ] ;
333
+
334
+ if ( ! targetInner ) {
335
+ edgeCount [ source ] [ target ] = { count : 0 , ids : [ ] } ;
336
+ }
337
+
338
+ edgeCount [ source ] [ target ] . count ++ ;
339
+ edgeCount [ source ] [ target ] . ids . push ( id ) ;
340
+ }
341
+ else if ( targetEntry && ! sourceEntry ) {
342
+ //Check if our source is in the targetEntry
343
+ var sourceInner = source in edgeCount [ target ] ;
344
+
345
+ if ( ! sourceInner ) {
346
+ edgeCount [ target ] [ source ] = { count : 0 , ids : [ ] } ;
347
+ }
348
+
349
+ edgeCount [ target ] [ source ] . count ++ ;
350
+ edgeCount [ target ] [ source ] . ids . push ( id ) ;
351
+ }
352
+ else if ( targetEntry && sourceEntry ) {
353
+ //Check if one already has a entry
354
+ var targetInner = target in edgeCount [ source ] ,
355
+ sourceInner = source in edgeCount [ target ] ;
356
+
357
+ if ( targetInner ) {
358
+ edgeCount [ source ] [ target ] . count ++ ;
359
+ edgeCount [ source ] [ target ] . ids . push ( id ) ;
360
+ }
361
+ else if ( sourceInner ) {
362
+ edgeCount [ target ] [ source ] . count ++ ;
363
+ edgeCount [ target ] [ source ] . ids . push ( id ) ;
364
+ }
365
+ else {
366
+ edgeCount [ source ] [ target ] = { count : 1 , ids : id } ;
367
+ }
368
+ }
369
+ }
370
+
371
+ return edgeCount ;
372
+ }
373
+
374
+ function removeDuplicateEdges ( ) {
375
+ /*
376
+ Counts the number of undirected edges of each type and removes half of them.
377
+ */
378
+
379
+ var edgeCount = enumEdges ( ) ;
380
+
381
+ //When the number of a type of edge is divisible by two, we have duplicates
382
+ for ( var source in edgeCount ) {
383
+ for ( var target in edgeCount [ source ] ) {
384
+
385
+ //Check for duplicates and remove
386
+ if ( edgeCount [ source ] [ target ] . count % 2 === 0 ) {
387
+ for ( var i = 0 ; i < edgeCount [ source ] [ target ] . ids . length / 2 ; i ++ ) {
388
+ cy . remove ( cy . $id ( edgeCount [ source ] [ target ] . ids [ i ] ) )
389
+ }
390
+ }
391
+ }
392
+ }
393
+ }
303
394
304
395
function parseGraph ( graph ) {
305
396
/*
@@ -384,6 +475,9 @@ function parseGraph(graph){
384
475
385
476
currentLine += degree ;
386
477
}
478
+
479
+ //The way in which we add adds each edge twice
480
+ removeDuplicateEdges ( ) ;
387
481
}
388
482
389
483
function openGraph ( ) {
0 commit comments