Browse Source

master > master: code py - enum option zum Anzeigen aller Summen

RD 2 months ago
parent
commit
22801148a6
  1. 1
      code/python/assets/config.yaml
  2. 1
      code/python/models/config-schema.yaml
  3. 11
      code/python/src/algorithms/rucksack/display.py

1
code/python/assets/config.yaml

@ -32,3 +32,4 @@ options:
verbose: true
show:
- ALL-WEIGHTS
- ALL-SUMS

1
code/python/models/config-schema.yaml

@ -166,3 +166,4 @@ components:
type: string
enum:
- ALL-WEIGHTS
- ALL-SUMS

11
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:

Loading…
Cancel
Save