Exemplo n.º 1
0
    def test(self, parameters):
        flattened = [value for parameter in parameters for value in parameter]
        if any([floor not in flattened for floor in self.draw_pool]):
            return float('inf')

        elevators = [PriorityElevator(i, parameters[i]) for i in range(len(parameters))]
        building = Building(elevators, self.crowd)
        return building.run()
Exemplo n.º 2
0
    def optimize(self):
        """Optimizes by partitioning the parameter list."""
        best_partitions, best_time = None, None
        for order in permutations(range(1, FLOOR_COUNT + 1)):
            part_size = FLOOR_COUNT // ELEVATOR_COUNT
            partitions = [order[i * part_size:(i + 1) * part_size] for i in range(ELEVATOR_COUNT - 1)]
            partitions.append(order[(ELEVATOR_COUNT - 1) * part_size:])

            elevators = [PriorityElevator(i, partitions[i]) for i in range(len(partitions))]
            building = Building(elevators, self.crowd)
            time = building.run()
            if best_partitions is None or time < best_time:
                best_partitions, best_time = partitions, time

        return best_partitions
Exemplo n.º 3
0
partition_priorities = PartitionOptimizer(crowd).optimize()
genetic_priorities = GeneticOptimizer(crowd).optimize()

print("Partition priorities: {}".format(partition_priorities))
print("Genetic priorities: {}\n".format(genetic_priorities))

random_elevators = [RandomElevator(i) for i in range(ELEVATOR_COUNT)]
henry_alpha_elevators = [PriorityElevator(i, henry_alpha_priorities[i]) for i in range(ELEVATOR_COUNT)]
henry_beta_elevators = [PriorityElevator(i, henry_beta_priorities[i]) for i in range(ELEVATOR_COUNT)]
henry_gamma_elevators = [PriorityElevator(i, henry_gamma_priorities[i]) for i in range(ELEVATOR_COUNT)]
partition_elevators = [PriorityElevator(i, partition_priorities[i]) for i in range(ELEVATOR_COUNT)]
genetic_elevators = [PriorityElevator(i, genetic_priorities[i]) for i in range(ELEVATOR_COUNT)]

elevator_lists = {"Random": random_elevators,
                  "Henry Alpha": henry_alpha_elevators,
                  "Henry Beta": henry_beta_elevators,
                  "Henry Gamma": henry_gamma_elevators,
                  "Partition": partition_elevators,
                  "Genetic": genetic_elevators}

for system, elevators in elevator_lists.items():
    building = Building(elevators, crowd)
    times = []

    for i in range(250):
        times.append(building.run())

    print("System: {}".format(system))
    print("Minimum: {}".format(min(times)))
    print("Average: {}".format(sum(times)/len(times)))
    print("Maximum: {}\n".format(max(times)))