From 3619e7c09a9f58d0b8220cac2fcec93ce75691a7 Mon Sep 17 00:00:00 2001 From: Rodrigo Morais <58960796+rodigu@users.noreply.github.com> Date: Wed, 6 Apr 2022 18:06:59 -0700 Subject: [PATCH] :ambulance: :bug: incorrect edge weight - fixed bug with edge eight being misrepresented --- network.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/network.ts b/network.ts index 8896ec6..8e56e5f 100644 --- a/network.ts +++ b/network.ts @@ -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;