int edgeOcrnce[] = new int[m_nodes.size()];
for(int j=0,uidx=0,lidx=0; j<(levels[i].length+levels[i+1].length); j++) {
if((j%2==0 && uidx<levels[i].length) || lidx>=levels[i+1].length) {
int k1=0, k2=0, k3=0;
GraphNode n = (GraphNode) m_nodes.elementAt(levels[i][uidx]);
//Deactivating and counting crossings for all edges ending in it
//coming from bottom left
if(lastOcrnce[levels[i][uidx]]!=null) {
MyListNode temp = new MyListNode(-1); temp.next = upper.first;
try {
do {
temp = temp.next;
if(levels[i][uidx]==temp.n) {
k1 = k1+1;
k3 = k3+k2;
//System.out.println("Removing from upper: "+temp.n);
upper.remove(temp);
}
else
k2 = k2+1;
} while(temp!=lastOcrnce[levels[i][uidx]]);
}
catch(NullPointerException ex) {
System.out.println(Messages.getInstance().getString("HierarchicalBCEngine_Crossings_Exception_Text_First") + levels[i][uidx]+
Messages.getInstance().getString("HierarchicalBCEngine_Crossings_Exception_Text_Second") + ((GraphNode)m_nodes.elementAt(levels[i][uidx])).ID+
Messages.getInstance().getString("HierarchicalBCEngine_Crossings_Exception_Text_Third") + temp+
Messages.getInstance().getString("HierarchicalBCEngine_Crossings_Exception_Text_Fourth") + upper.first);
ex.printStackTrace();
System.exit(-1);}
lastOcrnce[levels[i][uidx]]=null;
sum = sum + k1*lower.size() + k3;
}
//Activating all the edges going out towards the bottom
//and bottom right
for(int k=0; k<n.edges.length; k++) {
if(n.edges[k][1]>0)
try {
if( indexOfElementInLevel(n.edges[k][0], levels[i+1]) >= uidx) {
edgeOcrnce[n.edges[k][0]]=1;
}
}
catch(Exception ex) {
ex.printStackTrace();
}
}
for(int k=0; k<levels[i+1].length; k++) {
if(edgeOcrnce[levels[i+1][k]]==1) {
MyListNode temp = new MyListNode(levels[i+1][k]); //new MyListNode(n.edges[k][0]);
lower.add(temp);
lastOcrnce[levels[i+1][k]] = temp;
edgeOcrnce[levels[i+1][k]] = 0;
//System.out.println("Adding to lower: "+levels[i+1][k]+
//" which is: "+((GraphNode)m_nodes.elementAt(levels[i+1][k])).ID+
//" first's n is: "+lower.first.n);
}
}
uidx++;
}
else {
int k1=0, k2=0, k3=0;
GraphNode n = (GraphNode) m_nodes.elementAt(levels[i+1][lidx]);
//Deactivating and counting crossings for all edges ending in it
//coming from up and upper left
if(lastOcrnce[levels[i+1][lidx]]!=null) {
MyListNode temp = new MyListNode(-1); temp.next = lower.first;