package util;
import core.Graphs.Graph;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Nothing software.
*/
public class RandomIntervalGraphGenerator 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;
for (int i = 0; i < listCapacity; i = i + 2) {
arr.add(nodeNumber);
arr.add(nodeNumber);
nodeNumber++;
}
Collections.shuffle(arr);
List<Integer> arr1 = new ArrayList<Integer>(arr);
for (int i = 0; i < numberOfNodes; i++) {
for (int j = arr1.indexOf(i); j < arr1.lastIndexOf(i); j++) {
Integer jIndex = arr1.get(j);
adjacencyMatrix[i][jIndex] = 1;
adjacencyMatrix[jIndex][i] = 1;
}
adjacencyMatrix[i][i] = 0;
}
return new Graph(adjacencyMatrix);
}
}