Esempio n. 1
0
def final_report():

    alloc_gen, alloc_conf = importer.restore_genome("best_allocation_genome",
                                                    exp_dir)
    alloc_ann = neat.nn.FeedForwardNetwork.create(alloc_gen, alloc_conf)

    seq_gen, seq_conf = importer.restore_genome("best_sequencing_genome",
                                                exp_dir)
    seq_ann = neat.nn.FeedForwardNetwork.create(seq_gen, seq_conf)

    print(
        "\n### FINAL REPORT ###",
        "\n\nBest allocation genome:\n{!s}".format(alloc_gen),
        "\n\nBest sequencing genome:\n{!s}".format(seq_gen),
    )

    for dataset in all_datasets.items():
        model = run_simulation(dataset[1], alloc_ann, seq_ann)
        print(
            "\n--- Performance on {} ------------------------".format(
                dataset[0]),
            "\nMakespan: ",
            model.makespan,
            "\nTotal tardiness: ",
            model.total_tardiness,
            "\nMajor setups: ",
            model.num_major_setups,
            "\nJobs processed: ",
            model.jobs_processed,
            "\n-----------------------------------------------------",
        )

    print(
        "\nComputational time: ",
        timeit.default_timer() - start,
        "\nApproximal number of simulation runs (allocation | sequencing | overall): {} | {} | {}\n"
        .format(num_runs_alloc, num_runs_seq, num_runs_alloc + num_runs_seq),
    )

    # visualize.draw_net(alloc_conf, alloc_gen, False, filename="alloc_net", objective=ALLOCATION_OBJECTIVE) # works only of graphviz binaries are installed
    visualize.plot_stats(stats_alloc,
                         ylog=False,
                         view=False,
                         filename="avg_fitness_alloc.svg")
    visualize.plot_species(stats_alloc,
                           view=False,
                           filename="speciation_alloc.svg")

    # visualize.draw_net(seq_conf, seq_gen, False, filename="seq_net", objective=SEQUENCING_OBJECTIVE) # works only of graphviz binaries are installed
    visualize.plot_stats(stats_seq,
                         ylog=False,
                         view=False,
                         filename="avg_fitness_seq.svg")
    visualize.plot_species(stats_seq,
                           view=False,
                           filename="speciation_seq.svg")
Esempio n. 2
0
def eval_fitness_seq(genome, config):

    # Parse ANN
    neat_ann = neat.nn.FeedForwardNetwork.create(genome, config)

    # If possible: Parse allocation ANN from best genome of last session
    try:
        gen, conf = importer.restore_genome("best_allocation_genome", exp_dir)
        alloc_ann = neat.nn.FeedForwardNetwork.create(gen, conf)
    except:
        alloc_ann = None

    # Initialize fitness
    fitness_overall = 0

    # Evaluate NEAT genomes on datasets for training
    for dataset in train_datasets.values():
        model = run_simulation(dataset, alloc_ann, neat_ann)
        fitness_overall += FITNESS_FUNCTION(model)

    return fitness_overall
Esempio n. 3
0
    SMD_ALLOCATION_FUNCTION = alloc.smd_allocation_min_workload
    if __name__ == "__main__":
        print(
            "\n-------------------------------------------------------------------------------------------------------------",
            "\nSMD_ALLOCATION_FUNCTION automatically set to {}, because ANN_FOR_ALLOCATION is not"
            .format(SMD_ALLOCATION_FUNCTION.__name__),
            "\ngiven. The user selected SMD_ALLOCATION_FUNCTION is only valid if ANN_FOR_SEQUENCING is not None",
            "\nor if the OBJECTIVE is '{}'".format(required_mode),
            "\n-------------------------------------------------------------------------------------------------------------",
        )

# pylint: enable=E1135

# Create ANNs
if ANN_FOR_SEQUENCING is not None:
    gen, conf = importer.restore_genome(ANN_FOR_SEQUENCING, this_dir)
    sequencing_ann = neat.nn.FeedForwardNetwork.create(gen, conf)
else:
    sequencing_ann = None

if ANN_FOR_ALLOCATION is not None:
    gen, conf = importer.restore_genome(ANN_FOR_ALLOCATION, this_dir)
    allocation_ann = neat.nn.FeedForwardNetwork.create(gen, conf)
else:
    allocation_ann = None

if __name__ == "__main__":
    # Get config file
    config_file = "config_{}".format(OBJECTIVE)
    config_path = os.path.join(this_dir, config_file)
    # Get current datetime