package util;
import core.Graphs.Graph;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* Nothing software.
*/
public class mOnGraphGenerator implements GraphGenerator {
@Override
public Object generate(int numberOfNodes) {
int listCapacity = numberOfNodes * 2;
List<Integer> arr = new LinkedList<Integer>();
int[][] adjacencyMatrix = new int[numberOfNodes][numberOfNodes];
Integer nodeNumber = 0;
int i = 0;
if (numberOfNodes == 1) {
arr.add(nodeNumber);
arr.add(nodeNumber);
i += 2;
} else {
arr.add(nodeNumber);
arr.add(nodeNumber + 1);
i += 2;
}
for (; i < listCapacity - numberOfNodes; i++) {
arr.add(nodeNumber);
arr.add(nodeNumber + 2);
nodeNumber++;
}
if (numberOfNodes != 1){
arr.add(nodeNumber);
arr.add(nodeNumber + 1);
}
List<Integer> arr1 = new ArrayList<Integer>(arr);
for (int m = 0; m < numberOfNodes; m++) {
for (int n = arr1.indexOf(m); n < arr1.lastIndexOf(m); n++) {
Integer nIndex = arr1.get(n);
adjacencyMatrix[m][nIndex] = 1;
adjacencyMatrix[nIndex][m] = 1;
}
adjacencyMatrix[m][m] = 0;
}
return new Graph(adjacencyMatrix);
}
}