def schedule_fitness(schedule, num_machines):
    """Calculate the fitness of a given schedule.
    
    Every day late for any job is +1 to fitness (big fitness is bad,
    this is a minimizing problem).  Every material switch is +0.5 days penalty.
    """
    penalty = 0
    for machine in schedule:
        loaded_material = None
        for assignment in machine:
            penalty += max(assignment.end - assignment.job.due_date, 0)
            if assignment.job.material != loaded_material:
                if loaded_material is not None:
                    penalty += 0.5
                loaded_material = assignment.job.material
    return penalty