def test_fitness(self, argos_xml, seed): argos_util.set_seed(argos_xml, seed) xml_str = etree.tostring(argos_xml) cwd = os.getcwd() tmpf = tempfile.NamedTemporaryFile('w', suffix=".argos", prefix="gatmp", dir=os.path.join( cwd, "experiments"), delete=False) tmpf.write(xml_str) tmpf.close() argos_args = ["argos3", "-n", "-c", tmpf.name] argos_run = subprocess.Popen(argos_args, stdout=subprocess.PIPE) # Wait until argos is finished while argos_run.poll() is None: time.sleep(0.5) if argos_run.returncode != 0: logging.error("Argos failed test") # when argos fails just return fitness 0 return 0 lines = argos_run.stdout.readlines() os.unlink(tmpf.name) print lines[-1] logging.info("partial fitness = %d", int(lines[-1].strip().split(",")[0])) return int(lines[-1].strip().split(",")[0])
def test_fitness(self, argos_xml, seed): argos_util.set_seed(argos_xml, seed) xml_str = etree.tostring(argos_xml) cwd = os.getcwd() tmpf = tempfile.NamedTemporaryFile('w', suffix=".argos", prefix="gatmp", dir=os.path.join(cwd, "experiments"), delete=False) tmpf.write(xml_str) tmpf.close() argos_args = ["argos3", "-n", "-c", tmpf.name] argos_run = subprocess.Popen(argos_args, stdout=subprocess.PIPE) # Wait until argos is finished while argos_run.poll() is None: time.sleep(0.5) if argos_run.returncode != 0: logging.error("Argos failed test") # when argos fails just return fitness 0 return 0 lines = argos_run.stdout.readlines() os.unlink(tmpf.name) print lines[-1] logging.info("partial fitness = %d", int(lines[-1].strip().split(",")[0])) return int(lines[-1].strip().split(",")[0])