protected boolean scheduleGridlet(SSGridlet sgl) {
    	int reqPE = sgl.getNumPE();
    	int queueId = sgl.getPartitionID();
    	EasyBackFillingPartition partition = getPartition(queueId);

    	// if partition has a pivot already, then check whether the job appears
    	// before in the queue after reordering. If it does, then the job
    	// to be scheduled becomes the new pivot
    	if(partition.pivot != null) {
    		int indPivot = waitingJobs.indexOf(partition.pivot);
    		int indexNewGrl = waitingJobs.indexOf(sgl);
    		
    		if(indPivot < indexNewGrl) {
    			return false;
    		} else {
    			removeGridlet(partition.pivot);
    			partition.pivot.setStartTime(-1);
    			partition.pivot.setActualFinishTime(-1);
    			partition.pivot = null;
    		}
    	}

    	long runTime = forecastExecutionTime(ratingPE, sgl.getRemainingLength());

        // check when enough PEs will be available at the partition
        ProfileEntry entryPart = profile.findPartStartTime(queueId, reqPE, runTime);

        // check when enough PEs will be available in all partitions
        ProfileEntry entry = profile.findStartTime(reqPE, runTime);

        double startPart = 
        	(entryPart == null || entryPart.getNumPE() < reqPE) ? 
        			Double.MAX_VALUE : 
        				entryPart.getTime();

        double startAll = !allowBorrowing ? Double.MAX_VALUE : entry.getTime();
        
    	PERangeList ranges = null;
    	double startTime = -1;	
    	double finishTime = -1;	
        
        // Compare which option has the best start time
        if(startPart < Double.MAX_VALUE && startPart <= startAll) {
        	ranges = entryPart.getAvailRanges();
           	ranges = ranges.selectPEs(reqPE);
           	
            startTime = startPart;
            finishTime = startTime + runTime;
            profile.allocatePartPERanges(queueId, ranges, startTime, finishTime);
        }
        // Try to borrow resources from another partition
        else if (startAll < Double.MAX_VALUE) {
        	PERangeList addRanges = entry.getAvailRanges();
            startTime = startAll;
            finishTime = startTime + runTime;
            
            // checks what PEs already belong to the job's partition
            entryPart = profile.checkPartAvailability(queueId, startTime, runTime);
            ranges = entryPart.getAvailRanges();
       		addRanges.remove(ranges);
        	addRanges = addRanges.selectPEs(reqPE - ranges.getNumPE());

        	ranges.addAll(addRanges);
            profile.allocatePERanges(ranges, startTime, finishTime);
        }
        else {
        	return false;
        }
        
        partition.pivot = sgl;
        sgl.setPERangeList(ranges);
        sgl.setStartTime(startTime);
        sgl.setActualFinishTime(finishTime);
        
        //------------------ FOR DEBUGGING PURPOSES ONLY ----------------
        visualizer.notifyListeners(this.get_id(), ActionType.ITEM_SCHEDULED, true, sgl);
    	//---------------------------------------------------------------
        return true;
    }