From 22801148a652fcafa21e8887fcd212e889f2a5db Mon Sep 17 00:00:00 2001 From: raj_mathe Date: Wed, 15 Jun 2022 10:07:37 +0200 Subject: [PATCH] master > master: code py - enum option zum Anzeigen aller Summen --- code/python/assets/config.yaml | 1 + code/python/models/config-schema.yaml | 1 + code/python/src/algorithms/rucksack/display.py | 11 +++++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/code/python/assets/config.yaml b/code/python/assets/config.yaml index f137272..71fc71e 100644 --- a/code/python/assets/config.yaml +++ b/code/python/assets/config.yaml @@ -32,3 +32,4 @@ options: verbose: true show: - ALL-WEIGHTS + - ALL-SUMS diff --git a/code/python/models/config-schema.yaml b/code/python/models/config-schema.yaml index d85481f..8829837 100644 --- a/code/python/models/config-schema.yaml +++ b/code/python/models/config-schema.yaml @@ -166,3 +166,4 @@ components: type: string enum: - ALL-WEIGHTS + - ALL-SUMS diff --git a/code/python/src/algorithms/rucksack/display.py b/code/python/src/algorithms/rucksack/display.py index 3a175eb..87877f2 100644 --- a/code/python/src/algorithms/rucksack/display.py +++ b/code/python/src/algorithms/rucksack/display.py @@ -98,16 +98,19 @@ def display_rucksack( # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def display_branch_and_bound(values: np.ndarray, steps: List[Step]) -> str: - # füge Summen-Ausdrücke für Greedy-Alg hinzu: + show_options = config.OPTIONS.rucksack.show; + show_all_sums = (EnumRucksackShow.all_sums in show_options); + rows = []; used_choices = []; index_soln = max([-1] + [ i for i, step in enumerate(steps) if step.move == EnumBranchAndBoundMove.BOUND ]); for i, step in enumerate(steps): - if step.choice in used_choices: - expr = f'{step.bound_subtree:g}'; - else: + if show_all_sums or step.choice not in used_choices: + # Füge Summen-Ausdrücke für Greedy-Alg hinzu: used_choices.append(step.choice); expr = display_sum(choice=step.choice, values=values, as_maximum=False, order=step.order, indexes=step.indexes); + else: + expr = f'{step.bound_subtree:g}'; pad_str = ('' if step.pad == MaskValue.UNSET else step.pad.value); move_str = ('' if step.move == EnumBranchAndBoundMove.NONE else step.move.value); if i == index_soln: