if(reversed==false) { for(int times=0; times<1; times++) { int tempLevels[][] = new int[nodeLevels.length][];    copy2DArray(nodeLevels, tempLevels); for(int i=0; i<nodeLevels.length-1; i++) phaseID(i, tempLevels); if(crossings(tempLevels)<crossings(nodeLevels)) nodeLevels = tempLevels;   tempLevels = new int[nodeLevels.length][]; copy2DArray(nodeLevels, tempLevels); for(int i=nodeLevels.length-2; i>=0; i--) phaseIU(i, tempLevels); if(crossings(tempLevels)<crossings(nodeLevels)) nodeLevels = tempLevels;   tempLevels = new int[nodeLevels.length][]; copy2DArray(nodeLevels, tempLevels); for(int i=0; i<nodeLevels.length-1; i++) { phaseIID(i, tempLevels); } if(crossings(tempLevels)<crossings(nodeLevels)) nodeLevels = tempLevels;     tempLevels = new int[nodeLevels.length][]; copy2DArray(nodeLevels, tempLevels); for(int i=nodeLevels.length-2; i>=0; i--) { phaseIIU(i, tempLevels); } if(crossings(tempLevels)<crossings(nodeLevels)) nodeLevels = tempLevels;    } return nodeLevels; } else { for(int times=0; times<1; times++) { int tempLevels[][] = new int[nodeLevels.length][];    copy2DArray(nodeLevels, tempLevels); for(int i=nodeLevels.length-2; i>=0; i--) phaseIU(i, tempLevels); if(crossings(tempLevels)<crossings(nodeLevels)) nodeLevels = tempLevels;    tempLevels = new int[nodeLevels.length][]; copy2DArray(nodeLevels, tempLevels); for(int i=0; i<nodeLevels.length-1; i++) phaseID(i, tempLevels); if(crossings(tempLevels)<crossings(nodeLevels)) nodeLevels = tempLevels;    tempLevels = new int[nodeLevels.length][]; copy2DArray(nodeLevels, tempLevels); for(int i=nodeLevels.length-2; i>=0; i--) { phaseIIU(i, tempLevels); } if(crossings(tempLevels)<crossings(nodeLevels)) nodeLevels = tempLevels;    tempLevels = new int[nodeLevels.length][]; copy2DArray(nodeLevels, tempLevels); for(int i=0; i<nodeLevels.length-1; i++) { phaseIID(i, tempLevels); } if(crossings(tempLevels)<crossings(nodeLevels)) nodeLevels = tempLevels;   } return nodeLevels; }
if(reversed==false) { for(int times=0; times<1; times++) { int tempLevels[][] = new int[nodeLevels.length][];     copy2DArray(nodeLevels, tempLevels); for(int i=0; i<nodeLevels.length-1; i++) phaseID(i, tempLevels); if(crossings(tempLevels)<crossings(nodeLevels)) nodeLevels = tempLevels;    tempLevels = new int[nodeLevels.length][]; copy2DArray(nodeLevels, tempLevels); for(int i=nodeLevels.length-2; i>=0; i--) phaseIU(i, tempLevels); if(crossings(tempLevels)<crossings(nodeLevels)) nodeLevels = tempLevels;    tempLevels = new int[nodeLevels.length][]; copy2DArray(nodeLevels, tempLevels); for(int i=0; i<nodeLevels.length-1; i++) { phaseIID(i, tempLevels); } if(crossings(tempLevels)<crossings(nodeLevels)) nodeLevels = tempLevels;       tempLevels = new int[nodeLevels.length][]; copy2DArray(nodeLevels, tempLevels); for(int i=nodeLevels.length-2; i>=0; i--) { phaseIIU(i, tempLevels); } if(crossings(tempLevels)<crossings(nodeLevels)) nodeLevels = tempLevels;      } return nodeLevels;
    private int[][] minimizeCrossings(boolean reversed, int nodeLevels[][]) {		//Minimizing crossings using Sugiyama's method	if(reversed==false) {	    for(int times=0; times<1; times++) {		int tempLevels[][] = new int[nodeLevels.length][];				//System.out.println("---------------------------------");		//System.out.println("Crossings before PHaseID: "+crossings(nodeLevels));		copy2DArray(nodeLevels, tempLevels);		for(int i=0; i<nodeLevels.length-1; i++)   //Down		    phaseID(i, tempLevels);		if(crossings(tempLevels)<crossings(nodeLevels))		    nodeLevels = tempLevels;	    				//System.out.println("\nCrossings before PHaseIU: "+crossings(nodeLevels));		tempLevels = new int[nodeLevels.length][];		copy2DArray(nodeLevels, tempLevels);		for(int i=nodeLevels.length-2; i>=0; i--)  //Up		    phaseIU(i, tempLevels);		if(crossings(tempLevels)<crossings(nodeLevels))		    nodeLevels = tempLevels;						//System.out.println("\nCrossings before PHaseIID: "+crossings(nodeLevels));			tempLevels = new int[nodeLevels.length][];		copy2DArray(nodeLevels, tempLevels);		for(int i=0; i<nodeLevels.length-1; i++) {   //Down		    phaseIID(i, tempLevels);		}		if(crossings(tempLevels)<crossings(nodeLevels))		    nodeLevels = tempLevels;		//System.out.println("Crossings temp:"+crossings(tempLevels)+" graph:"+crossings(nodeLevels));		//printMatrices(nodeLevels);						//System.out.println("\nCrossings before PHaseIIU: "+crossings(nodeLevels));		tempLevels = new int[nodeLevels.length][];		copy2DArray(nodeLevels, tempLevels);		for(int i=nodeLevels.length-2; i>=0; i--) {   //Up		    phaseIIU(i, tempLevels);		}		if(crossings(tempLevels)<crossings(nodeLevels))		    nodeLevels = tempLevels;		///System.out.println("Crossings temp:"+crossings(tempLevels)+" graph:"+crossings(nodeLevels));		///printMatrices(nodeLevels);		//System.out.println("\nCrossings after phaseIIU: "+crossings(nodeLevels));	    }	    return nodeLevels;	}	else {	    for(int times=0; times<1; times++) {		int tempLevels[][] = new int[nodeLevels.length][];				//System.out.println("---------------------------------");		//System.out.println("\nCrossings before PHaseIU: "+crossings(nodeLevels));		copy2DArray(nodeLevels, tempLevels);		for(int i=nodeLevels.length-2; i>=0; i--)  //Up		    phaseIU(i, tempLevels);		if(crossings(tempLevels)<crossings(nodeLevels))		    nodeLevels = tempLevels;		//printMatrices(nodeLevels);				//System.out.println("Crossings before PHaseID: "+crossings(nodeLevels));		tempLevels = new int[nodeLevels.length][];		copy2DArray(nodeLevels, tempLevels);		for(int i=0; i<nodeLevels.length-1; i++)   //Down		    phaseID(i, tempLevels);		if(crossings(tempLevels)<crossings(nodeLevels))		    nodeLevels = tempLevels;		///printMatrices(nodeLevels);				//System.out.println("\nCrossings before PHaseIIU: "+crossings(nodeLevels));		tempLevels = new int[nodeLevels.length][];		copy2DArray(nodeLevels, tempLevels);		for(int i=nodeLevels.length-2; i>=0; i--) {   //Up		    phaseIIU(i, tempLevels);		}		if(crossings(tempLevels)<crossings(nodeLevels))		    nodeLevels = tempLevels;		//printMatrices(nodeLevels);				//System.out.println("\nCrossings before PHaseIID: "+crossings(nodeLevels));			tempLevels = new int[nodeLevels.length][];		copy2DArray(nodeLevels, tempLevels);		for(int i=0; i<nodeLevels.length-1; i++) {   //Down		    phaseIID(i, tempLevels);		}		if(crossings(tempLevels)<crossings(nodeLevels))		    nodeLevels = tempLevels;		///printMatrices(nodeLevels);		//System.out.println("\nCrossings after phaseIID: "+crossings(nodeLevels));	    }	    return nodeLevels;	}    }