@@ -902,6 +902,7 @@ export class Cycle extends Network {
902
902
private loop_vertex : base_id ;
903
903
private tip_vertex : base_id ;
904
904
private is_closed : boolean ;
905
+ private dynamic_product : number ;
905
906
906
907
constructor ( args : {
907
908
is_directed : boolean ;
@@ -922,6 +923,8 @@ export class Cycle extends Network {
922
923
this . tip_vertex = this . edge_list [ 0 ] . pairVertex ( loop_vertex ) ! ;
923
924
}
924
925
this . is_closed = false ;
926
+ this . dynamic_product = 1 ;
927
+ this . updateProduct ( initial_edge ) ;
925
928
}
926
929
927
930
/**
@@ -936,6 +939,11 @@ export class Cycle extends Network {
936
939
return this . loop_vertex ;
937
940
}
938
941
942
+ get product ( ) : number {
943
+ if ( this . is_closed ) return this . dynamic_product ;
944
+ return 0 ;
945
+ }
946
+
939
947
/**
940
948
* Returns true if the cycle is closed, otherwise returns false.
941
949
* @returns boolean
@@ -961,6 +969,8 @@ export class Cycle extends Network {
961
969
this . tip_vertex = edge . from ;
962
970
else this . tip_vertex = edge . to ;
963
971
972
+ this . updateProduct ( edge ) ;
973
+
964
974
return true ;
965
975
}
966
976
@@ -978,6 +988,7 @@ export class Cycle extends Network {
978
988
super . addEdge ( edge ) ;
979
989
this . is_closed = true ;
980
990
this . tip_vertex = this . loop_vertex ;
991
+ this . updateProduct ( edge ) ;
981
992
return true ;
982
993
}
983
994
@@ -1004,6 +1015,11 @@ export class Cycle extends Network {
1004
1015
} ) ;
1005
1016
}
1006
1017
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
+
1007
1023
private canCloseWith ( edge : EdgeArgs ) : boolean {
1008
1024
const edge_has_tip_and_loop_vertex =
1009
1025
( edge . from === this . tip_vertex && edge . to === this . loop_vertex ) ||
0 commit comments