public void addDepthIndex() {

		List<HierarchyArea> sorted = new ArrayList<HierarchyArea>();
		Stack<HierarchyArea> start = new Stack<HierarchyArea>();
		
		// initialize start group
		for(HierarchyArea ha : hierarchy) {
			if( ha.front.size() == 0 ) {
				start.push(ha);
				ha.depth = 0.0;
			}
		}
		
		// topological sort
		int loopCount = 0;
		while( !start.empty() ) {
			loopCount ++;
			
			HierarchyArea area = start.pop();
			sorted.add(area);
			
			while( area.back.size() > 0 ) {
				HierarchyArea next = area.back.get(0);
				area.back.remove(next);
				next.front.remove(area);
				if( next.front.size() == 0 ) {
					start.add(next);
					next.depth = (double)loopCount;
				}
			}
		}

		// check the loop
		for(HierarchyArea ha : hierarchy) {
			if( ha.front.size() > 0 || ha.back.size() > 0 ) {
				System.out.println("Loop!!");
			}
		}
		
		// append depth index
		for(HierarchyArea ha : sorted) {
			ha.depth = 1.0 - ha.depth / (double)loopCount;
		}
		
		/*
		// prepare stack
		List<HierarchyArea> remain = new ArrayList<HierarchyArea>();
		for(HierarchyArea ha : hierarchy) {
			remain.add(ha);
		}
		
		while( remain.size() > 0 ) {
			// choose most front area
			for( HierarchyArea ha : remain ) {
				if( ha.isDecided() ) {
					remain.remove(ha);
					break;
				}
				if( ha.getUndecidedFront() == null ) {
					double frontDepth, backDepth;
					frontDepth = ha.getFrontDepth();
					backDepth = ha.getBackDepth();
					
					List<HierarchyArea> save = new ArrayList<HierarchyArea>();
					save.add(ha);
					
					// DFS
					HierarchyArea back = ha.getUndecidedBack();
					while( back != null ) {
						save.add(back);
						backDepth = back.getBackDepth();
						back = back.getUndecidedBack();
					}
					
					// decide depth
					double interval = (frontDepth - backDepth) / (double)(save.size()+1);
					for(int i=0; i<save.size(); i++) {
						save.get(i).depth = frontDepth - interval * (i+1);
						remain.remove(save.get(i));
					}
					break;
				}
			}
		}
		*/
	}