import java.util.HashMap;
import java.util.LinkedList;
public class GraphJava {
private static class Node
{
Node edgeTo;
Node iteratorNext;
int id=-1;
int numIncomingEdges = 0;
int cycleID = -1;
boolean hasSelfEdge;
Node(int id)
{
this.id = id;
}
}
public int n = 10 * 1000 * 1000;
public int numItems[] = {10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};
public int numCycles = 0;
public int maxCycleLength = 0;
int genRandom()
{
double r = Math.random() * n;
return (int) Math.floor(r);
}
Node[] generateGraphs()
{
LinkedList<Node> nodesList = new LinkedList<Node>();
Node[] nodes = new Node[n];
for (int i=0; i < n; i++)
{
Node node = new Node(i);
nodes[i] = node;
nodesList.add(node);
}
int minIndex = n;
int maxIndex = 0;
int numSelfMatches = 0;
// create random connections
for (int i=0; i < n; i++)
{
int pointToIndex = genRandom();
nodes[i].edgeTo = nodes[pointToIndex];
if (pointToIndex > maxIndex)
maxIndex = pointToIndex;
if (pointToIndex < minIndex)
minIndex = pointToIndex;
if (pointToIndex == i)
{
nodes[i].hasSelfEdge = true;
numSelfMatches++;
}
// set iterator
if (i==n-1)
{
nodes[i].iteratorNext = null;
}
else
{
nodes[i].iteratorNext = nodes[i+1];
}
}
// print out some stats
System.out.println ("Some Stats:");
System.out.println ("Min Index: " + minIndex);
System.out.println ("Max Index: " + maxIndex);;
System.out.println ("Self Matches: " + numSelfMatches);
return nodes;
}
/**
* @param args
*/
public static void main(String[] args) {
GraphJava g = new GraphJava();
Node[] nodes=g.generateGraphs();
g.findCycles(nodes);
System.out.println( "Hello, World!");
}
private void findCycles(Node[] nodes) {
boolean foundCycle = false;
int startingPoint = 0;
int currentCycleID = 0;
HashMap<Integer, Integer> cycleLengths = new HashMap<Integer, Integer>();
HashMap<Integer, Integer> cycleWeights = new HashMap<Integer, Integer>();
// this hashmap stores the id of the node that was visited and at what
// was the position of this node in the order of nodes traversed using the
// outgoing edges
HashMap<Integer, Integer> nodesVisited = new HashMap<Integer, Integer>();
nodesVisited.put(0, 0);
Node currNode = nodes[0];
int currentCount = 0;
while(!foundCycle)
{
currNode = currNode.edgeTo;
currentCount++;
if (nodesVisited.containsKey(currNode.id))
{
int cycleLength
}
else
{
nodesVisited.put(currNode.id, currentCount);
}
}
}
}