Untitled

mail@pastecode.io avatar
unknown
plain_text
8 months ago
2.2 kB
4
Indexable
Never
import json
from utils import generate_morphologies
from evo_process import Algo
import os
import sys

# Runs generalist one all morphology variations
def generalist_experiment_run(config):
    runs = config['runs']
    parameter1_range, parameter2_range = config['parameter1'], config['parameter2']

    for i in range(runs):
        variations = generate_morphologies(parameter1_range, parameter2_range)
        print(variations)
        cluster_count = 0
        generations = config['generations']
        folder_name = config['filename']

        while len(variations) != 0:
            cluster_count += 1
            path = f"{folder_name}/"
            os.makedirs(path, exist_ok=True)
            run = Algo(path=path, variations=variations,
                       config=config, generation=generations, run_id=i, cluster_id=cluster_count)
            generation, variations = run.main()
            generations = generations - generation


# Runs specialist on each morphology variation
def specialists_experiment_run(config):
    runs = config['runs']
    servos, angles = config['parameter1'], config['parameter2']
    morphologies = generate_morphologies(servos, angles)

    for variations in morphologies:
        variations = list([variations])
        print(f'CURRENT MORPHOLOGY: {variations[0][0]} : {variations[0][1]}')
        for i in range(runs):
            cluster_count = 0
            generations = config['generations']
            folder_name = config['filename']

            while len(variations) != 0:
                cluster_count += 1
                path = f"{folder_name}/morphology_{variations[0][0]}_{variations[0][1]}/"
                os.makedirs(path, exist_ok=True)
                run = Algo(path=path, variations=variations,
                           config=config, generation=generations, run_id=i, cluster_id=cluster_count)
                generation, variations = run.main()
                generations = generations - generation


if __name__ == "__main__":
    config = json.load(open('gecko.json'))
    #generalist_experiment_run(config)
    specialists_experiment_run(config)