Skip to content

Commit

Permalink
🚑 🐛 incorrect edge weight
Browse files Browse the repository at this point in the history
- fixed bug with edge eight being misrepresented
  • Loading branch information
rodigu committed Apr 7, 2022
1 parent 884238c commit 3619e7c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ export class Network {
if (!this.is_multigraph && this.hasEdge(args.from, args.to)) return false;
// throw { message: ERROR.NOT_MULTIGRAPH };

if (!this.is_directed) [args.from, args.to] = [args.from, args.to].sort();
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 3619e7c

Please sign in to comment.