Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module algebraic: laplacianMatrix(G) includes deleted nodes #1105

Open
bernlu opened this issue Jul 17, 2023 · 0 comments
Open

Module algebraic: laplacianMatrix(G) includes deleted nodes #1105

bernlu opened this issue Jul 17, 2023 · 0 comments

Comments

@bernlu
Copy link
Contributor

bernlu commented Jul 17, 2023

Given a graph (of size n), adding and then removing a node causes the laplacianMatrix function to return wrong results: The resulting matrix keeps the larger size of n+1 even though the node has been removed. This issue appears in at least two (maybe distinct?) places.

Python

import networkit as nk
G = nk.Graph(4)
G.addEdge(0,1)
G.addEdge(0,2)
G.addEdge(0,3)
G.addEdge(1,2)
nk.algebraic.laplacianMatrix(G).toarray()

[ 3., -1., -1., -1.],
[-1., 2., -1., 0.],
[-1., -1., 2., 0.],
[-1., 0., 0., 1.]

(correct)

newnode = G.addNode()
nk.algebraic.laplacianMatrix(G).toarray()

[ 3., -1., -1., -1., 0.],
[-1., 2., -1., 0., 0.],
[-1., -1., 2., 0., 0.],
[-1., 0., 0., 1., 0.],
[ 0., 0., 0., 0., 0.]

(correct)

G.removeNode(newnode)
nk.algebraic.laplacianMatrix(G).toarray()

[ 3., -1., -1., -1., 0.],
[-1., 2., -1., 0., 0.],
[-1., -1., 2., 0., 0.],
[-1., 0., 0., 1., 0.],
[ 0., 0., 0., 0., 0.]

(wrong) this matrix should be equal to the first.

C++

Graph G(4);
G.addEdge(0, 1);
G.addEdge(0, 2);
G.addEdge(0, 3);
G.addEdge(1, 2);

std::cout << CSRMatrix::laplacianMatrix(G) << std::endl;
node newnode = G.addNode();
std::cout << CSRMatrix::laplacianMatrix(G) << std::endl;
G.removeNode(newnode);
std::cout << CSRMatrix::laplacianMatrix(G) << std::endl;

3, -1, -1, -1
-1, 2, -1, 0
-1, -1, 2, 0
-1, 0, 0, 1

(correct)

3, -1, -1, -1, 0
-1, 2, -1, 0, 0
-1, -1, 2, 0, 0
-1, 0, 0, 1, 0
0, 0, 0, 0, 0

(correct)

3, -1, -1, -1, 0
-1, 2, -1, 0, 0
-1, -1, 2, 0, 0
-1, 0, 0, 1, 0
0, 0, 0, 0, 0

(wrong)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant