Skip to content

Commit

Permalink
fix: adjacency matrix
Browse files Browse the repository at this point in the history
Add no_edge_value in copy, float conversion in ad_edge
  • Loading branch information
rubenperezm committed Oct 7, 2024
1 parent 0c6c39d commit d701651
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pystrukts/graph/adjacency_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def copy(self) -> 'AdjacencyMatrix':
out (AdjacencyMatrix): The copy of the graph.
'''

return AdjacencyMatrix(directed = self.directed, matrix = self.matrix)
return AdjacencyMatrix(directed = self.directed,
matrix = self.matrix, no_edge_value = self.no_edge_value)

def _copy_matrix(self, matrix: list, directed: bool) -> list:
'''
Expand Down Expand Up @@ -170,10 +171,10 @@ def add_edge(self, x: int, y: int, w: float = 1.0) -> None:
self._raise_error_if_invalid_vertex(x)
self._raise_error_if_invalid_vertex(y)

self.matrix[x][y] = w
self.matrix[x][y] = float(w)

if self.directed:
self.matrix[y][x] = w
self.matrix[y][x] = float(w)

def remove_edge(self, x: int, y: int) -> None:
'''
Expand Down
1 change: 1 addition & 0 deletions tests/test_adjacency_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_copy():
assert graph2.num_vertices == 3
assert graph2.directed == False
assert graph2.matrix == matrix
assert graph2.no_edge_value == 0

def test_has_edge():
matrix = [[0, 1, 0], [0, 0, 0], [1, 0, 1]]
Expand Down

0 comments on commit d701651

Please sign in to comment.