Skip to content

Commit

Permalink
Add file bash for evaluation, Makefile idea discarded
Browse files Browse the repository at this point in the history
  • Loading branch information
saccuz committed Nov 8, 2023
1 parent 0919780 commit 1e69036
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
23 changes: 23 additions & 0 deletions examples/onemax/onemax-mips/evaluate_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
#################################|###|#####################################
# __ | | #
# | |--.--.--.----.-----.-----. |===| This file is part of Byron v0.8 #
# | _ | | | _| _ | | |___| An evolutionary optimizer & fuzzer #
# |_____|___ |__| |_____|__|__| ).( https://pypi.org/project/byron/ #
# |_____| \|/ #
################################## ' ######################################
# Copyright 2023 Giovanni Squillero and Alberto Tonda
# SPDX-License-Identifier: Apache-2.0

# Compiles and runs a genome, kills it if it does not terminate swiftly
# (GNU timeout is /opt/homebrew/bin/gtimeout on my system)
TIMEOUT_CMD=gtimeout
ALLOWED_TIME=1

for file in "$@"; do
mipsel-linux-gnu-gcc -static onemax.s main.c -o "$file"
$TIMEOUT_CMD $ALLOWED_TIME qemu-mipsel onemax.out || ( cp "$file" "problem-$file"; echo -1 )
grep -q 'nNone' "$file" && cp "$file" "nNone-$file"
done

exit 0
5 changes: 4 additions & 1 deletion examples/onemax/onemax-mips/library_mips.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ def define_frame():

prologue_sub = byron.f.macro(
r"""# [prologue sub]
.global {_node}
{_node}
addiu $sp,$sp,-8
sw $fp,4($sp)
move $fp,$sp
# [end-prologue sub]
"""
""",
_label='', # No automatic creation of the label -- it's embedded as "{_node}:"
)
epilogue_sub = byron.f.macro(
r"""# [epilogue sub]
Expand Down
6 changes: 3 additions & 3 deletions examples/onemax/onemax-mips/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

#include <stdio.h>

unsigned int onemax(void);
unsigned long int onemax(void);

int main(void)
{
unsigned int result = onemax();
unsigned long int result = onemax();

int fitness = 0;
for(unsigned int b=1; b; b <<= 1)
for(unsigned long int b=1; b; b <<= 1)
fitness += !!(result & b);
printf("%d\n", fitness);

Expand Down
7 changes: 6 additions & 1 deletion examples/onemax/onemax-mips/onemax-mips.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@

import logging
import argparse
import platform

import byron
import library_mips as library

SCRIPT_NAME = {"Linux": "./evaluate_all.sh", "Darwin": "./evaluate_all.sh"}

def main():
top_frame = library.define_frame()

evaluator = byron.evaluator.MakefileEvaluator('onemax.s', required_files=['main.o'], timeout=5)
#evaluator = byron.evaluator.MakefileEvaluator('onemax.s', required_files=['main.o'], timeout=5)
evaluator = byron.evaluator.ScriptEvaluator(SCRIPT_NAME[platform.system()], filename_format="individual{i:06}.s")

final_population = byron.ea.vanilla_ea(
top_frame,
evaluator,
Expand Down

0 comments on commit 1e69036

Please sign in to comment.