Skip to content

Commit

Permalink
Support specifying target arrays that contain arrays of values
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-falco committed Feb 27, 2021
1 parent feb4d15 commit 5f99b6a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
16 changes: 16 additions & 0 deletions eat/core/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,22 @@ def get_ternary_descriminator_target_array(self):
target_array.append([a])
return target_array

def get_filled_target_array(self, target, target_free_count):
"""
Returns a target solution with output values filled to accept any
possible input value (specified by target_free_count). This is designed
to make it possible to specify easier targets for groupoids with very
large search spaces.
"""
if target_free_count > len(target):
raise ValueError("Specified a target free count ({}) greater than "
"the length of the target array ({})."
.format(target_free_count, len(target)))
for idx, row in enumerate(target):
if idx < target_free_count:
target[idx] = list(range(0, self.groupoid.size))
return target

def get_term_variable_mapping(self, input_row, term_variables=None):
"""
Returns a mapping of input values to term variables
Expand Down
19 changes: 14 additions & 5 deletions runeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ def parse_argments():
help="Ternary descriminator target output (default)",
action='store_true')
group.add_argument('-trt', '--target-random',
help="Random target output (default)", action='store_true')
help="Random target output (default)",
action='store_true')
group.add_argument('-t', '--target', help="Custom target output",
nargs='+', type=int)
nargs='+', type=str)
parser.add_argument('-tfc', '--target_free_count',
help=("Number of target values to force to accept any "
"input value"), type=int, default=0)
parser.add_argument('-tv', '--term-variables',
help="Term variables to use. (default=['x','y',z'])",
nargs='+', type=str, default=["x", "y", "z"])
Expand Down Expand Up @@ -69,17 +73,22 @@ def main():

# setup term operation
to_options = {}
if args.target:
to_options["target"] = [[t] for t in args.target]
if args.term_variables:
to_options["term_variables"] = args.term_variables
to = TermOperation(grp,
**to_options)
if args.target_random:
if args.target:
to.target = \
[[int(v) for v in t.split(",")] for t in args.target]
elif args.target_random:
to.target = to.get_random_target_array()
elif args.target_ternary_descriminator:
to.target = to.get_ternary_descriminator_target_array()

if args.target_free_count > 0:
to.target = to.get_filled_target_array(to.target,
args.target_free_count)

mtgm = args.male_term_generation_method

verbose = args.verbose
Expand Down

0 comments on commit 5f99b6a

Please sign in to comment.