@Override
	public void run(double frac) {
		logger.trace("run -> begin of method");
		try {
			workingDataset = new GranularityAggregationTree(sourceDataset.getDataColumnSchema(),granularities.length+1);
			ArrayList<TemporalObject> currentBranches = new ArrayList<TemporalObject>();
			ArrayList<ArrayList<TemporalObject>> currentLeaves = new ArrayList<ArrayList<TemporalObject>>();
			for(TemporalObject iO : sourceDataset.temporalObjects()) {
				long inf = iO.getTemporalElement().asGeneric().getGranule().getInf();
				int i = 0;
				for(TemporalObject iB : currentBranches) {
					if (iB.getTemporalElement().asGeneric().getGranule().contains(inf)) {
		    			currentLeaves.get(i).add(iO);
		    			break;
					}
					i++;
				}
				if(i >= currentBranches.size()) {
			    	Granule newGranule = new Granule(inf,inf,granularities[0]); 
			    	Instant newTe = workingDataset.addInstant(newGranule);
			    	currentBranches.add(workingDataset.addTemporalObject(newTe));
			    	ArrayList<TemporalObject> leaves = new ArrayList<TemporalObject>();
			    	leaves.add(iO);
			    	currentLeaves.add(leaves);
				}
			}
			long[] roots = new long[currentBranches.size()];
			for(int i=0; i<currentBranches.size(); i++)
				roots[i] = currentBranches.get(i).getId();
			if (granularities.length > 1) {			
				for(int i=1; i<granularities.length;i++) {
					ArrayList<ArrayList<TemporalObject>> futureLeaves = new ArrayList<ArrayList<TemporalObject>>();
					ArrayList<TemporalObject> futureBranches = new ArrayList<TemporalObject>(); 
					int whichChild = 0;
					for(int k=0; k<currentLeaves.size();k++) {
						ArrayList<TemporalObject> iCurrentLeaves = currentLeaves.get(k);
						while(iCurrentLeaves.size() > 0) {
							TemporalObject currentLeave = iCurrentLeaves.get(0);
							iCurrentLeaves.remove(0);
							TemporalObject targetBranch = null;
							long inf = currentLeave.getTemporalElement().asGeneric().getInf();
							long sup = currentLeave.getTemporalElement().asGeneric().getSup();
							whichChild = 0;
							for(int l=0; l<k; l++)
								whichChild += currentBranches.get(l).getChildCount();
							for(TemporalObject potentialBranch : currentBranches.get(k).childObjects()) {
								if (potentialBranch.getTemporalElement().asGeneric().getGranule().contains(inf)) {
									targetBranch = potentialBranch;
									break;
								}
								whichChild++;
							}
							if (targetBranch == null) {
								Granule newGranule = new Granule(inf,sup,granularities[i]); 
								Instant newTe = workingDataset.addInstant(newGranule);
								targetBranch = workingDataset.addTemporalObject(newTe);
								futureBranches.add(targetBranch);
								futureLeaves.add(new ArrayList<TemporalObject>());					    	
								whichChild = futureLeaves.size() - 1;
								currentBranches.get(k).linkWithChild(targetBranch);
							}
							futureLeaves.get(whichChild).add(currentLeave);
						}
					}
					if(i==granularities.length-1) {
						for(int j=0; j<futureBranches.size(); j++ ) {
							aggregate(futureBranches.get(j),futureLeaves.get(j),granularities.length-1);
						}
					} else {
						currentBranches = futureBranches;
						currentLeaves = futureLeaves;
					}
				}
				for(long iRoot : roots)
					aggregate(workingDataset.getTemporalObject(iRoot),0);
			} else {
				for(int i=0; i<roots.length; i++)
					aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0);
			}
			// TODO this could be cleaned
			for (long rootId : roots) {
			    workingDataset.getTemporalObject(rootId).setRoot(true);
			}
		} catch (TemporalDataException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
@Override
	public void run(double frac) {
		logger.trace("run -> begin of method");
		try {
			workingDataset = new GranularityAggregationTree(sourceDataset.getDataColumnSchema(),granularities.length+1);
			ArrayList<TemporalObject> currentBranches = new ArrayList<TemporalObject>();
			ArrayList<ArrayList<TemporalObject>> currentLeaves = new ArrayList<ArrayList<TemporalObject>>();
			for(TemporalObject iO : sourceDataset.temporalObjects()) {
				long inf = iO.getTemporalElement().asGeneric().getGranule().getInf();
				int i = 0;
				for(TemporalObject iB : currentBranches) {
					if (iB.getTemporalElement().asGeneric().getGranule().contains(inf)) {
		    			currentLeaves.get(i).add(iO);
		    			break;
					}
					i++;
				}
				if(i >= currentBranches.size()) {
			    	Granule newGranule = new Granule(inf,inf,granularities[0]); 
			    	Instant newTe = workingDataset.addInstant(newGranule);
			    	currentBranches.add(workingDataset.addTemporalObject(newTe));
			    	ArrayList<TemporalObject> leaves = new ArrayList<TemporalObject>();
			    	leaves.add(iO);
			    	currentLeaves.add(leaves);
				}
			}
			long[] roots = new long[currentBranches.size()];
			for(int i=0; i<currentBranches.size(); i++)
				roots[i] = currentBranches.get(i).getId();
			if (granularities.length > 1) {			
				for(int i=1; i<granularities.length;i++) {
					ArrayList<ArrayList<TemporalObject>> futureLeaves = new ArrayList<ArrayList<TemporalObject>>();
					ArrayList<TemporalObject> futureBranches = new ArrayList<TemporalObject>(); 
					int whichChild = 0;
					for(int k=0; k<currentLeaves.size();k++) {
						ArrayList<TemporalObject> iCurrentLeaves = currentLeaves.get(k);
						while(iCurrentLeaves.size() > 0) {
							TemporalObject currentLeave = iCurrentLeaves.get(0);
							iCurrentLeaves.remove(0);
							TemporalObject targetBranch = null;
							long inf = currentLeave.getTemporalElement().asGeneric().getInf();
							long sup = currentLeave.getTemporalElement().asGeneric().getSup();
							whichChild = 0;
							for(int l=0; l<k; l++)
								whichChild += currentBranches.get(l).getChildCount();
							for(TemporalObject potentialBranch : currentBranches.get(k).childObjects()) {
								if (potentialBranch.getTemporalElement().asGeneric().getGranule().contains(inf)) {
									targetBranch = potentialBranch;
									break;
								}
								whichChild++;
							}
							if (targetBranch == null) {
								Granule newGranule = new Granule(inf,sup,granularities[i]); 
								Instant newTe = workingDataset.addInstant(newGranule);
								targetBranch = workingDataset.addTemporalObject(newTe);
								futureBranches.add(targetBranch);
								futureLeaves.add(new ArrayList<TemporalObject>());					    	
								whichChild = futureLeaves.size() - 1;
								currentBranches.get(k).linkWithChild(targetBranch);
							}
							futureLeaves.get(whichChild).add(currentLeave);
						}
					}
					if(i==granularities.length-1) {
						for(int j=0; j<futureBranches.size(); j++ ) {
							aggregate(futureBranches.get(j),futureLeaves.get(j),granularities.length-1);
						}
					} else {
						currentBranches = futureBranches;
						currentLeaves = futureLeaves;
					}
				}
				for(long iRoot : roots)
					aggregate(workingDataset.getTemporalObject(iRoot),0);
			} else {
				for(int i=0; i<roots.length; i++)
					aggregate(workingDataset.getTemporalObject(roots[i]),currentLeaves.get(i),0);
			}
		
			for (long rootId : roots) {
			    workingDataset.getTemporalObject(rootId).setRoot(true);
			}
		} catch (TemporalDataException e1) {
		
			e1.printStackTrace();
		}
	}
@override public void run(double frac) { logger.trace("run -> begin of method"); try { workingdataset = new granularityaggregationtree(sourcedataset.getdatacolumnschema(),granularities.length+1); arraylist<temporalobject> currentbranches = new arraylist<temporalobject>(); arraylist<arraylist<temporalobject>> currentleaves = new arraylist<arraylist<temporalobject>>(); for(temporalobject io : sourcedataset.temporalobjects()) { long inf = io.gettemporalelement().asgeneric().getgranule().getinf(); int i = 0; for(temporalobject ib : currentbranches) { if (ib.gettemporalelement().asgeneric().getgranule().contains(inf)) { currentleaves.get(i).add(io); break; } i++; } if(i >= currentbranches.size()) { granule newgranule = new granule(inf,inf,granularities[0]); instant newte = workingdataset.addinstant(newgranule); currentbranches.add(workingdataset.addtemporalobject(newte)); arraylist<temporalobject> leaves = new arraylist<temporalobject>(); leaves.add(io); currentleaves.add(leaves); } } long[] roots = new long[currentbranches.size()]; for(int i=0; i<currentbranches.size(); i++) roots[i] = currentbranches.get(i).getid(); if (granularities.length > 1) { for(int i=1; i<granularities.length;i++) { arraylist<arraylist<temporalobject>> futureleaves = new arraylist<arraylist<temporalobject>>(); arraylist<temporalobject> futurebranches = new arraylist<temporalobject>(); int whichchild = 0; for(int k=0; k<currentleaves.size();k++) { arraylist<temporalobject> icurrentleaves = currentleaves.get(k); while(icurrentleaves.size() > 0) { temporalobject currentleave = icurrentleaves.get(0); icurrentleaves.remove(0); temporalobject targetbranch = null; long inf = currentleave.gettemporalelement().asgeneric().getinf(); long sup = currentleave.gettemporalelement().asgeneric().getsup(); whichchild = 0; for(int l=0; l<k; l++) whichchild += currentbranches.get(l).getchildcount(); for(temporalobject potentialbranch : currentbranches.get(k).childobjects()) { if (potentialbranch.gettemporalelement().asgeneric().getgranule().contains(inf)) { targetbranch = potentialbranch; break; } whichchild++; } if (targetbranch == null) { granule newgranule = new granule(inf,sup,granularities[i]); instant newte = workingdataset.addinstant(newgranule); targetbranch = workingdataset.addtemporalobject(newte); futurebranches.add(targetbranch); futureleaves.add(new arraylist<temporalobject>()); whichchild = futureleaves.size() - 1; currentbranches.get(k).linkwithchild(targetbranch); } futureleaves.get(whichchild).add(currentleave); } } if(i==granularities.length-1) { for(int j=0; j<futurebranches.size(); j++ ) { aggregate(futurebranches.get(j),futureleaves.get(j),granularities.length-1); } } else { currentbranches = futurebranches; currentleaves = futureleaves; } } for(long iroot : roots) aggregate(workingdataset.gettemporalobject(iroot),0); } else { for(int i=0; i<roots.length; i++) aggregate(workingdataset.gettemporalobject(roots[i]),currentleaves.get(i),0); } for (long rootid : roots) { workingdataset.gettemporalobject(rootid).setroot(true); } } catch (temporaldataexception e1) { e1.printstacktrace(); } }