def resourceLeveling(listActivities, projectResources):
    
    projectDur = projectDuration(listActivities)
    listNonCriticalAct = findNonCriticalAct(listActivities)
    
    listResources = buildResources(listActivities, projectDur)
    
    # Calculate totalFloat of each activity and sort by totalFloat
    for activity in listNonCriticalAct:
        activity.totalFloat = totalFloatLate(activity, projectDur)
    
    firstSortNCA =  sorted(listNonCriticalAct, key=lambda activity: activity.totalFloat, reverse=True)
    # Sort the activities by finishing time
    sortedNCA = sorted(firstSortNCA, key=lambda activity: activity.startTime + activity.duration, reverse=True)
    
    #Initialisation with the current list of resources 
    minimizedList = listResources
    
    for act in sortedNCA:
        if (act.ident == -1 or act.ident == -2):
            continue
        
        totalFloat = totalFloatLate(act, projectDur)        
                
        # Try every position (sequenciation) available until we reach the end of
        # the total float (holgura total)
       
        oldListRSD = evaluateResourceList(minimizedList)
                
        for seq in range(act.startTime + 1, act.startTime + totalFloat + 1):
            
            # Build the list with the new resources
            newList = buildNewResourceList(minimizedList, act, seq, projectResources)
            
            if not newList is None: 
            # If newList is None, it means sequencing the activity at this day
            # overuse the resources of the project 
                
                # Evaluate the new list of resources
                newListRSD = evaluateResourceList(newList)
                
                # If the new sequenciation is better
                # The activity startTime and the oldListRSD and minimizedList are updated
                if sum(newListRSD) < sum(oldListRSD):
                    minimizedList = newList
                    oldListRSD = newListRSD
                    act.startTime = seq
Пример #2
0
def analyseActivity(listActivities, act, projectResources):
    
    projectDur = projectDuration(listActivities)
    
    # Build a table of resources per day 
    
    listResources = buildResources(listActivities, projectDur)
        
    listDelays = []
    print "The activity " + act.name + " is supposed to start the day " + str(act.startTime)
    
    # Processing the total float for each side
    totalRightFloat = totalFloatLate(act, projectDur)
    totalLeftFloat = totalFloatEarly(act)
    print "float on the left = " + str(totalLeftFloat) 
    print "float on the right = " + str(totalRightFloat)
    
    # We ask the user if he wants to move the activity on the right or 
    # on the left
    
    while (True):
        answer = raw_input("Do you want to move the activity on the right or on the left (L/R):")
        if answer == "R" or answer == "L":
            break    
    if answer == "L":
        listSeqLeft = [] # List of possible sequenciation
        
        # For each potentiel position, we build a new list of resources 
        # if the building returns None, it means that this position 
        # overuse the resources of the project resources
        for i in range(act.startTime - totalLeftFloat, act.startTime):
            newResList = buildNewResourceList(listResources, act, i, projectResources)
            if not newResList is None:
                listSeqLeft.append(i)
        if len(listSeqLeft) == 0:
            print "Sorry you can't delay this activity on the left with the actual resources"
            return 
        else: 
            print "These are the delays on the left available"
            for newDate in listSeqLeft:
                print str(act.startTime - newDate) + " days"
                listDelays.append(act.startTime - newDate)
        while True:
            newSeq = input("type the delay that satisfies you (integer) : ")
            if newSeq in listDelays:
                act.startTime = newSeq
                break
    else:            
        listSeqRight = [] # List of posible sequenciation
        for i in range(act.startTime + 1, act.startTime + totalRightFloat + 1):
            newResList = buildNewResourceList(listResources, act, i, projectResources)
            if not newResList is None:
                listSeqRight.append(i)
        if len(listSeqRight) == 0:
            print "Sorry you can't delay this activity on the right with the actual resources"
            return 
        else: 
            print "These are the delays on the right available"
            for newDate in listSeqRight:
                print str(newDate - act.startTime) + " days" 
                listDelays.append(newDate - act.startTime)
        while True:
            newSeq = input("type the delay that satisfies you (integer) : ")
            if newSeq in listDelays:
                act.startTime = newSeq
                break