Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Own solution not the best, but it is suficient to acomplish the fallowing. Acomplished with combinatorics jar. Hole it helps</p> <pre><code> @SuppressWarnings("unchecked") public static void drawMatrix(Graph g, int tempMatrixSize){ System.out.println(" "); System.out.println("Matrix:"); ArrayList&lt;Node&gt; nodesSet = new ArrayList&lt;&gt;(); nodesSet = (ArrayList&lt;Node&gt;) g.getNodes().clone(); int size = nodesSet.size(); int[][] matrix = new int[size][size]; System.out.print(" "); for (Node node : nodesSet){ System.out.print(" " + node.getName()+ " "); } System.out.println(); for (int i=0; i&lt;size; i++) { System.out.print(nodesSet.get(i).getName()+ " "); for (int j=0; j&lt;size; j++){ if (i == j) { System.out.print(" 1 "); matrix[i][j] = 1; } else{ if (nodesSet.get(i).isFriend(nodesSet.get(j))) { System.out.print(" X "); matrix[i][j] = 1; } else { System.out.print(" 0 "); matrix[i][j] = 0; } } } System.out.println(); } System.out.println(); // temp matrix int[][] tempMatrix = new int[tempMatrixSize][tempMatrixSize]; // Find combinations ArrayList&lt;Integer&gt; al= new ArrayList&lt;&gt;(); for (int i = 0; i&lt;size; i++ ){ al.add(i); } ICombinatoricsVector&lt;Integer&gt; initialVector = Factory.createVector(al); Generator&lt;Integer&gt; gen = Factory.createSimpleCombinationGenerator(initialVector, tempMatrixSize); int index = 0; for (ICombinatoricsVector&lt;Integer&gt; combination : gen) { boolean isConnected = true; System.out.println(combination); List&lt;Integer&gt; comb = combination.getVector(); for(int i=0; i&lt;tempMatrixSize; i++){ for(int j=0; j&lt;tempMatrixSize; j++){ tempMatrix[i][j] = matrix[comb.get(i)][comb.get(j)]; // System.out.print(tempMatrix[i][j]+ " "); } System.out.println(); } // main matrix coordinations System.out.println("main matrix used coords: "); for(int i=0; i&lt;tempMatrixSize; i++){ for(int j=0; j&lt;tempMatrixSize; j++){ tempMatrix[i][j] = matrix[comb.get(i)][comb.get(j)]; System.out.print("["+comb.get(i)+","+comb.get(j)+"] "); } System.out.println(); } System.out.println(); for(int i=0; i&lt;tempMatrixSize; i++){ for(int j=0; j&lt;tempMatrixSize; j++){ if (tempMatrix[i][j] == 0){ isConnected = false; } } } if (isConnected) { System.out.println("Is connected by &gt;" + tempMatrixSize); for (int i=0; i&lt;tempMatrixSize; i++) { System.out.println(" &gt;" +nodesSet.get(comb.get(i)).getName()); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload