File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -45,17 +45,17 @@ def to_matrix(self, **kwargs):
4545 Convert the graph to adjacency matrix.
4646 **kwargs(Keyword args):
4747 int default = -1 -> the default value when the edge does not exist.
48- Any output( Edge)
49- = lambda edge: edge.weight
50- -> the mapping from edges to values in matrix.
48+ Any merge(Any, Edge)
49+ = lambda val, edge: edge.weight
50+ -> the mapping from the old values in matrix and the edges to the new values in matrix.
5151 Note that the index start from 0 and the values in the Column 0 or the Row 0 are always the default.
5252 """
5353 default = kwargs .get ("default" , - 1 )
54- output = kwargs .get ("output " , lambda edge : edge .weight )
54+ merge = kwargs .get ("merge " , lambda val , edge : edge .weight )
5555 n = len (self .edges )
5656 matrix = [[default for _ in range (n )] for _ in range (n )]
5757 for edge in self .iterate_edges ():
58- matrix [edge .start ][edge .end ] = output ( edge )
58+ matrix [edge .start ][edge .end ] = merge ( matrix [ edge . start ][ edge . end ], edge )
5959 return matrix
6060
6161 def to_str (self , ** kwargs ):
You can’t perform that action at this time.
0 commit comments