Skip to content

Commit b992a3b

Browse files
committed
🐛✨ cycle product now part of Cycle
1 parent 56c2122 commit b992a3b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

network.ts

+16
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ export class Cycle extends Network {
902902
private loop_vertex: base_id;
903903
private tip_vertex: base_id;
904904
private is_closed: boolean;
905+
private dynamic_product: number;
905906

906907
constructor(args: {
907908
is_directed: boolean;
@@ -922,6 +923,8 @@ export class Cycle extends Network {
922923
this.tip_vertex = this.edge_list[0].pairVertex(loop_vertex)!;
923924
}
924925
this.is_closed = false;
926+
this.dynamic_product = 1;
927+
this.updateProduct(initial_edge);
925928
}
926929

927930
/**
@@ -936,6 +939,11 @@ export class Cycle extends Network {
936939
return this.loop_vertex;
937940
}
938941

942+
get product(): number {
943+
if (this.is_closed) return this.dynamic_product;
944+
return 0;
945+
}
946+
939947
/**
940948
* Returns true if the cycle is closed, otherwise returns false.
941949
* @returns boolean
@@ -961,6 +969,8 @@ export class Cycle extends Network {
961969
this.tip_vertex = edge.from;
962970
else this.tip_vertex = edge.to;
963971

972+
this.updateProduct(edge);
973+
964974
return true;
965975
}
966976

@@ -978,6 +988,7 @@ export class Cycle extends Network {
978988
super.addEdge(edge);
979989
this.is_closed = true;
980990
this.tip_vertex = this.loop_vertex;
991+
this.updateProduct(edge);
981992
return true;
982993
}
983994

@@ -1004,6 +1015,11 @@ export class Cycle extends Network {
10041015
});
10051016
}
10061017

1018+
private updateProduct(edge: EdgeArgs) {
1019+
const weight = edge.weight ?? 1;
1020+
this.dynamic_product *= this.tip_vertex === edge.to ? weight : 1 / weight;
1021+
}
1022+
10071023
private canCloseWith(edge: EdgeArgs): boolean {
10081024
const edge_has_tip_and_loop_vertex =
10091025
(edge.from === this.tip_vertex && edge.to === this.loop_vertex) ||

0 commit comments

Comments
 (0)