Skip to content

Commit

Permalink
Manual cleanup of graph2mat.js
Browse files Browse the repository at this point in the history
  • Loading branch information
curran committed Jan 2, 2021
1 parent 815c7fc commit bc30a3c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/graph2mat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,37 @@ export function graph2mat(graph, directed) {
const nodes = graph.nodes();
const links = graph.links();
const n = nodes.length;
let i;
let l;
let mat;

if (!directed) directed = graph.directed();
if (directed) {
let rows = n,
cols = n;
let rows = n;
let cols = n;

for (i = n - 1; i >= 0; i--) {
for (let i = n - 1; i >= 0; i--) {
if (graph.inEdges(i).length !== 0) break;
else rows--;
}
for (i = n - 1; i >= 0; i--) {
for (let i = n - 1; i >= 0; i--) {
if (graph.outEdges(i).length !== 0) break;
else cols--;
}
//console.log("Rows: "+rows+" Cols: "+cols);
mat = zeroes(rows, cols);

for (i = 0; i < links.length; i++) {
l = links[i];
for (let i = 0; i < links.length; i++) {
const l = links[i];
mat[l.source.index][l.target.index] = l.value ? l.value : 1;
}
} else {
mat = zeroes(n, n);

for (i = 0; i < links.length; i++) {
l = links[i];
for (let i = 0; i < links.length; i++) {
const l = links[i];
mat[l.source.index][l.target.index] = l.value ? l.value : 1;
mat[l.target.index][l.source.index] = l.value ? l.value : 1;
}
}

return mat;
}

0 comments on commit bc30a3c

Please sign in to comment.