Skip to content

Commit

Permalink
🐛 removed addEdge vertex order for undirected
Browse files Browse the repository at this point in the history
  • Loading branch information
rodigu committed Apr 7, 2022
1 parent 3619e7c commit 56c2122
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export class Network {
.reduce((prev, curr) => prev + curr);
}

get product(): number {
return this.edge_list
.map((e) => e.weight)
.reduce((weight1, weight2) => weight1 * weight2);
}

/**
* List of vertices with negative weight.
* @returns Vertex[]
Expand Down Expand Up @@ -206,14 +212,6 @@ export class Network {
if (!this.is_multigraph && this.hasEdge(args.from, args.to)) return false;
// throw { message: ERROR.NOT_MULTIGRAPH };

if (!this.is_directed) {
const sorted_vertices = [args.from, args.to].sort();
const unsorted_vertices = [args.from, args.to];
if (unsorted_vertices[0] !== sorted_vertices[0])
args.weight = 1 / args.weight;
[args.from, args.to] = sorted_vertices;
}

this.edges.set(args.id, new Edge(args));
return true;
}
Expand Down

0 comments on commit 56c2122

Please sign in to comment.