From e1aa04e33cf4d2d2cc39fc11888798c7a0e7a299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Fuhry?= Date: Tue, 16 May 2023 13:17:01 +0200 Subject: [PATCH] findComponents still broken I only have to figure out how to get rid of duplicate components --- src/Graph.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Graph.java b/src/Graph.java index 792690e..7de208a 100644 --- a/src/Graph.java +++ b/src/Graph.java @@ -133,21 +133,30 @@ public class Graph { public void findComponents() { ArrayList tempComponents = new ArrayList<>(1); - int[] component = new int[wegMatrix.getRowLength()]; + ArrayList tempComponent = new ArrayList<>(1); + int[] component; for(int rowIndex = 0; rowIndex < wegMatrix.getRowLength(); rowIndex++) { - for(int columnIndex = 0, index = 0; columnIndex < wegMatrix.getColumnLength(); columnIndex++) { + for(int columnIndex = 0; columnIndex < wegMatrix.getColumnLength(); columnIndex++) { if(wegMatrix.getValueAt(rowIndex, columnIndex) == 1) { - component[index] = columnIndex + 1; - index++; + tempComponent.add(columnIndex + 1); } } + component = new int[tempComponent.size()]; + + for(int index = 0; index < component.length; index++) { + component[index] = tempComponent.get(index); + } + if(tempComponents.contains(component)) { continue; } - tempComponents.add(component); - } + tempComponents.add(component); + + component = null; + tempComponent.clear(); + } components = new int[tempComponents.size()][wegMatrix.getColumnLength()]; for(int rowIndex = 0; rowIndex < components.length; rowIndex++) {