Ejemplo n.º 1
0
def CheckValidSolution(solution, data):
    for nurse in solution:
        schedule = nurse['schedule']

        # Try to fill all schedule
        valid = fillScheduleFunctions.FillSchedule(nurse, data)
        if (valid == False):
            return False

        #Max presence
        presence = nurse['end'] - nurse['ini'] + 1
        if (presence > data.maxPresence):
            return False

        #Max hours
        if (nurse['workingHours'] > data.maxHours):
            return False

        #Min hours
        if (nurse['workingHours'] < data.minHours):
            return False

        #Max consec
        if (checkFunctions.CheckMaxConsecutiveHours(nurse['schedule'],
                                                    data.maxConsec) == False):
            return False

        #Check rest
        if (checkFunctions.CheckRest(nurse['schedule']) == False):
            return False
    return True
Ejemplo n.º 2
0
    plt.plot(evol)
    plt.xlabel('number of generations')
    plt.ylabel('Fitness of best individual')
    plt.axis([0, len(evol), 0, 1 + int(data['nNurses'])])
    plt.show()
    print("nNurses : " + str(bestIndividual['fitness']))

    #Check all constrains
    if Check.CheckDemand(bestIndividual['solution'], data['demand']) == False:
        print(
            '//////////////########################## ERROR DEMAND ########################'
        )

    i = 1
    for nurse in bestIndividual['solution']:
        if Check.CheckMaxConsecutiveHours(nurse['schedule'],
                                          data['maxConsec']) == False:
            print(
                '//////////////########################## ERROR MAXCONSEC ########################'
            )

        if Check.CheckMaxPresence(nurse['schedule'],
                                  data['maxPresence']) == False:
            print(
                '//////////////########################## ERROR MAXPRESENCE ########################'
            )

        if Check.CheckMinAndMaxHours(nurse['schedule'], data['minHours'],
                                     data['maxHours']) == False:
            print(
                '//////////////########################## ERROR MINMAXHOURS ########################'
            )