WorkEstimate work = WorkEstimate.getWorkEstimate(str); WorkList list = work.getSortedContainerWork();
WorkList list = WorkEstimate.getWorkEstimate(str).getSortedContainerWork();
    private int fuseAll() {	// how many tiles we have occupied	int count = 0;	// whether or not we're done trying to fuse	boolean done = false;	int aggressive=0;	do {	    // get how many tiles we have	    RawFlattener flattener = new RawFlattener(str);	    count = flattener.getNumTiles();	    System.out.println("Partitioner detects " + count + " tiles.");	    StreamItDot.printGraph(str, "during-fusion.dot");	    if (count>target) {		//boolean tried=false;		// get the containers in the order of work for filters		// immediately contained		StreamItDot.printGraph(str, "partition.dot");		WorkEstimate work = WorkEstimate.getWorkEstimate(str);		WorkList list = work.getSortedContainerWork();		//System.out.println(list);		// work up through this list until we fuse something		for (int i=0; i<list.size(); i++) {		    SIRContainer cont = list.getContainer(i);		    if (cont instanceof SIRSplitJoin) {			System.out.println("trying to fuse " + cont.size() + "-way split " + ((SIRSplitJoin)cont).getName());			List children=cont.getChildren();			if(aggressive==0) {			    boolean attempt=true;			    for(int j=0;j<children.size();j++) {				SIROperator child=(SIROperator)children.get(j);				if((!(child instanceof SIRSplitter))&&(!(child instanceof SIRJoiner))&&(child instanceof SIRIdentity)) {				    //System.out.println("FOUND:"+children.get(j));				    attempt=false;				}			    }			    if(attempt) {				SIRStream newstr = FuseSplit.semiFuse((SIRSplitJoin)cont);				// if we fused something, quit loop				if (newstr!=cont) { 				    aggressive=0;				    //tried=true;				    break;				}			    } /*else				System.out.println("SplitJoin has Identity Child! Ignoring.");*/			} else if(aggressive==1) {			    boolean attempt=false;			    for(int j=0;j<children.size();j++) {				SIROperator child=(SIROperator)children.get(j);				if((!(child instanceof SIRSplitter))&&(!(child instanceof SIRJoiner))&&!(child instanceof SIRIdentity)) {				    //System.out.println("FOUND:"+children.get(j));				    attempt=true;				}			    }			    if(attempt) {				SIRStream newstr = FuseSplit.semiFuse((SIRSplitJoin)cont);				// if we fused something, quit loop				if (newstr!=cont) { 				    aggressive=0;				//tried=true;				    break;				}			    } /*else				System.out.println("SplitJoin has all Identity Children! Ignoring.");*/			} else {			    SIRStream newstr = FuseSplit.semiFuse((SIRSplitJoin)cont);			    // if we fused something, quit loop			    if (newstr!=cont) { 				aggressive=0;				//tried=true;				break;			    }			}		    } else if (cont instanceof SIRPipeline) {			System.out.println("trying to fuse " + (count-target) + " from " 					   + cont.size() + "-long pipe " + ((SIRPipeline)cont).getName());			// fuse the two lightest filters			int num = -1;			if (cont.size()>1) {			int[] childWork = new int[((SIRPipeline)cont).size()-1];			childWork[0] += work.getWork((SIRFilter)cont.get(0));			for (int j=1; j<cont.size()-1; j++) {			    childWork[j-1] += work.getWork((SIRFilter)cont.get(j-1));			    childWork[j] += work.getWork((SIRFilter)cont.get(j));			}			List tried = new LinkedList();			while (true) {			    // try fusing the lightest two			    int selection = -1;			    for (int j=0; j<cont.size()-1;j++) {				int min = Integer.MAX_VALUE;				SIRFilter f = (SIRFilter)((SIRPipeline)cont).get(j);				int fWork = work.getWork(f);				if (fWork < min && !tried.contains((""+j).intern())) {				    min = fWork;				    selection = j;				}			    }			    tried.add((""+selection).intern());			    num = FusePipe.fuseTwo((SIRPipeline)cont, selection);			    if (num!=0 || tried.size()==cont.size()-1) {				break;			    }			}			} else {			    // just do this to lift?			    FusePipe.fuse((SIRPipeline)cont, 1);			}			if (num!=0) {			    aggressive=0;			    break;			}		    }		    // if we made it to the end of the last loop, then		    // we're done trying to fuse (we didn't reach target.)		    if (i==list.size()-1) { 			if(aggressive>=2)			    done=true;			else			    //if(!tried)			    aggressive++;		    }		}	    }	} while (count>target && !done);	return count;    }