Changeset 1091 for framspy


Ignore:
Timestamp:
02/24/21 13:41:24 (3 years ago)
Author:
Maciej Komosinski
Message:

Allowed to override settings of the simulation using a file with the file name provided as an argument

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksLib.py

    r1090 r1091  
    2424
    2525        GENOTYPE_INVALID = "/*invalid*/"  # this is how genotype invalidity is represented in Framsticks
    26         EVALUATION_SETTINGS_FILE = "eval-allcriteria.sim"  # MUST be compatible with standard-eval expdef
     26        EVALUATION_SETTINGS_FILE = "eval-allcriteria.sim"  # MUST be compatible with the standard-eval expdef
    2727
    2828
    29         def __init__(self, frams_path, frams_lib_name):
     29        def __init__(self, frams_path, frams_lib_name, simsettings):
    3030                if frams_lib_name is None:
    3131                        frams.init(frams_path)  # could add support for setting alternative directories using -D and -d
     
    4646                        frams.Math.randomize();
    4747                frams.Simulator.expdef = "standard-eval"  # this expdef must be used by EVALUATION_SETTINGS_FILE
     48                if simsettings is not None:
     49                        self.EVALUATION_SETTINGS_FILE = simsettings
    4850
    4951
     
    6668                frams.GenePools[0].clear()
    6769                frams.Simulator.ximport(self.EVALUATION_SETTINGS_FILE, 2 + 4 + 8 + 16)
     70
    6871                for g in genotype_list:
    6972                        frams.GenePools[0].add(g)
     
    120123                assert isinstance(genotype_list, list)  # because in python str has similar capabilities as list and here it would pretend to work too, so to avoid any ambiguity
    121124
    122                 frams.SimilMeasure.type = 1  # adjust to your needs. Set here because loading EVALUATION_SETTINGS_FILE during evaluation may overwrite these parameters
    123                 frams.SimilMeasureHungarian.simil_weightedMDS = 1
    124                 frams.SimilMeasureHungarian.simil_partgeom = 1
     125                # if you want to override what EVALUATION_SETTINGS_FILE sets, you can do it below:
     126                # frams.SimilMeasure.type = 1
     127                # frams.SimilMeasureHungarian.simil_partgeom = 1
     128                # frams.SimilMeasureHungarian.simil_weightedMDS = 1
    125129
    126130                n = len(genotype_list)
     
    152156        parser.add_argument('-path', type=ensureDir, required=True, help='Path to the Framsticks library (.dll or .so) without trailing slash.')
    153157        parser.add_argument('-lib', required=False, help='Library name. If not given, "frams-objects.dll" or "frams-objects.so" is assumed depending on the platform.')
     158        parser.add_argument('-simsettings', required=False, help='The name of the .sim file with settings for evaluation, mutation, crossover, and similarity estimation. If not given, "eval-allcriteria.sim" is assumed by default. Must be compatible with the "standard-eval" expdef.')
    154159        parser.add_argument('-genformat', required=False, help='Genetic format for the demo run, for example 4, 9, or S. If not given, f1 is assumed.')
    155160        return parser.parse_args()
     
    171176
    172177        parsed_args = parseArguments()
    173         framsDLL = FramsticksLib(parsed_args.path, parsed_args.lib)
     178        framsDLL = FramsticksLib(parsed_args.path, parsed_args.lib, parsed_args.simsettings)
    174179
    175180        print("Sending a direct command to Framsticks CLI that calculates \"4\"+2 yields", frams.Simulator.eval("return \"4\"+2;"))
Note: See TracChangeset for help on using the changeset viewer.