Compare commits
3 Commits
2fceaa7d95
...
31134a3dc9
Author | SHA1 | Date | |
---|---|---|---|
31134a3dc9 | |||
24169daacf | |||
d07a76ce5d |
@ -30,3 +30,5 @@ options:
|
|||||||
- TREE
|
- TREE
|
||||||
rucksack:
|
rucksack:
|
||||||
verbose: true
|
verbose: true
|
||||||
|
show:
|
||||||
|
- ALL-WEIGHTS
|
||||||
|
2
code/python/dist/VERSION
vendored
2
code/python/dist/VERSION
vendored
@ -1 +1 @@
|
|||||||
0.1.0
|
0.2.0
|
||||||
|
@ -8,7 +8,7 @@ Name | Type | Description | Notes
|
|||||||
**tarjan** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
**tarjan** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
||||||
**tsp** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
**tsp** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
||||||
**hirschberg** | [**AppOptions_hirschberg**](AppOptions_hirschberg.md) | | [default to null]
|
**hirschberg** | [**AppOptions_hirschberg**](AppOptions_hirschberg.md) | | [default to null]
|
||||||
**rucksack** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [optional] [default to null]
|
**rucksack** | [**AppOptions_rucksack**](AppOptions_rucksack.md) | | [optional] [default to null]
|
||||||
|
|
||||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
10
code/python/docs/config/Models/AppOptionsRucksack.md
Normal file
10
code/python/docs/config/Models/AppOptionsRucksack.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# AppOptionsRucksack
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**verbose** | [**Boolean**](boolean.md) | | [optional] [default to false]
|
||||||
|
**show** | [**List**](EnumRucksackShow.md) | | [optional] [default to []]
|
||||||
|
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
8
code/python/docs/config/Models/EnumRucksackShow.md
Normal file
8
code/python/docs/config/Models/EnumRucksackShow.md
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# EnumRucksackShow
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
@ -15,11 +15,13 @@ Class | Method | HTTP request | Description
|
|||||||
- [AppOptions](.//Models/AppOptions.md)
|
- [AppOptions](.//Models/AppOptions.md)
|
||||||
- [AppOptionsHirschberg](.//Models/AppOptionsHirschberg.md)
|
- [AppOptionsHirschberg](.//Models/AppOptionsHirschberg.md)
|
||||||
- [AppOptionsHirschbergMovePriorities](.//Models/AppOptionsHirschbergMovePriorities.md)
|
- [AppOptionsHirschbergMovePriorities](.//Models/AppOptionsHirschbergMovePriorities.md)
|
||||||
|
- [AppOptionsRucksack](.//Models/AppOptionsRucksack.md)
|
||||||
- [AppOptionsTarjan](.//Models/AppOptionsTarjan.md)
|
- [AppOptionsTarjan](.//Models/AppOptionsTarjan.md)
|
||||||
- [Config](.//Models/Config.md)
|
- [Config](.//Models/Config.md)
|
||||||
- [EnumHirschbergShow](.//Models/EnumHirschbergShow.md)
|
- [EnumHirschbergShow](.//Models/EnumHirschbergShow.md)
|
||||||
- [EnumHirschbergVerbosity](.//Models/EnumHirschbergVerbosity.md)
|
- [EnumHirschbergVerbosity](.//Models/EnumHirschbergVerbosity.md)
|
||||||
- [EnumLogLevel](.//Models/EnumLogLevel.md)
|
- [EnumLogLevel](.//Models/EnumLogLevel.md)
|
||||||
|
- [EnumRucksackShow](.//Models/EnumRucksackShow.md)
|
||||||
- [Info](.//Models/Info.md)
|
- [Info](.//Models/Info.md)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
openapi: 3.0.3
|
openapi: 3.0.3
|
||||||
info:
|
info:
|
||||||
version: 0.1.0
|
version: 0.2.0
|
||||||
title: Schemata for command instructions
|
title: Schemata for command instructions
|
||||||
servers:
|
servers:
|
||||||
- url: "."
|
- url: "."
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
openapi: 3.0.3
|
openapi: 3.0.3
|
||||||
info:
|
info:
|
||||||
version: 0.1.0
|
version: 0.2.0
|
||||||
title: Schemata for config models
|
title: Schemata for config models
|
||||||
servers:
|
servers:
|
||||||
- url: "."
|
- url: "."
|
||||||
@ -53,7 +53,7 @@ components:
|
|||||||
- tsp
|
- tsp
|
||||||
- tarjan
|
- tarjan
|
||||||
- hirschberg
|
- hirschberg
|
||||||
- rucksack-branch-and-bound
|
- rucksack
|
||||||
properties:
|
properties:
|
||||||
log-level:
|
log-level:
|
||||||
$ref: '#/components/schemas/EnumLogLevel'
|
$ref: '#/components/schemas/EnumLogLevel'
|
||||||
@ -117,12 +117,16 @@ components:
|
|||||||
default: []
|
default: []
|
||||||
rucksack:
|
rucksack:
|
||||||
type: object
|
type: object
|
||||||
required:
|
required: []
|
||||||
- verbose
|
|
||||||
properties:
|
properties:
|
||||||
verbose:
|
verbose:
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
show:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/EnumRucksackShow'
|
||||||
|
default: []
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# Enum LogLevel
|
# Enum LogLevel
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@ -148,8 +152,17 @@ components:
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
EnumHirschbergShow:
|
EnumHirschbergShow:
|
||||||
description: |-
|
description: |-
|
||||||
Enumeration of verbosity options for Hirschberg
|
Enumeration of display options for Hirschberg
|
||||||
type: string
|
type: string
|
||||||
enum:
|
enum:
|
||||||
- TREE
|
- TREE
|
||||||
- ATOMS
|
- ATOMS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# Enum Rucksack - display options
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
EnumRucksackShow:
|
||||||
|
description: |-
|
||||||
|
Enumeration of display options for the Rucksack problem
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- ALL-WEIGHTS
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "uni-leipzig-ads-2-2022"
|
name = "uni-leipzig-ads-2-2022"
|
||||||
version = "1.0.0"
|
version = "0.2.0"
|
||||||
description = "Zusatzcode, um Algorithmen und Datenstrukturen im Kurs ADS2 zu demonstrieren."
|
description = "Zusatzcode, um Algorithmen und Datenstrukturen im Kurs ADS2 zu demonstrieren."
|
||||||
authors = [ "Raj Dahya" ]
|
authors = [ "Raj Dahya" ]
|
||||||
maintainers = [ "raj_mathe" ]
|
maintainers = [ "raj_mathe" ]
|
||||||
|
@ -83,7 +83,7 @@ def rucksack_greedy_algorithm(
|
|||||||
|
|
||||||
# verbose output hier behandeln (irrelevant für Algorithmus):
|
# verbose output hier behandeln (irrelevant für Algorithmus):
|
||||||
if verbose:
|
if verbose:
|
||||||
repr_rucksack = display_rucksack(items=items[rucksack], costs=costs[rucksack], values=values[rucksack], choice=np.asarray(choice)[rucksack]);
|
repr_rucksack = display_rucksack(items=items, costs=costs, values=values, choice=choice);
|
||||||
print('\x1b[1mEingeschätzte Lösung\x1b[0m');
|
print('\x1b[1mEingeschätzte Lösung\x1b[0m');
|
||||||
print('');
|
print('');
|
||||||
print(f'Mask: [{", ".join(map(str, soln.choice))}]');
|
print(f'Mask: [{", ".join(map(str, soln.choice))}]');
|
||||||
@ -173,7 +173,7 @@ def rucksack_branch_and_bound_algorithm(
|
|||||||
# verbose output hier behandeln (irrelevant für Algorithmus):
|
# verbose output hier behandeln (irrelevant für Algorithmus):
|
||||||
if verbose:
|
if verbose:
|
||||||
repr = display_branch_and_bound(values=values, steps=logged_steps);
|
repr = display_branch_and_bound(values=values, steps=logged_steps);
|
||||||
repr_rucksack = display_rucksack(items=items[rucksack], costs=costs[rucksack], values=values[rucksack], choice=np.asarray(mask.choice)[rucksack]);
|
repr_rucksack = display_rucksack(items=items, costs=costs, values=values, choice=mask.choice);
|
||||||
print(repr);
|
print(repr);
|
||||||
print('');
|
print('');
|
||||||
print('\x1b[1mLösung\x1b[0m');
|
print('\x1b[1mLösung\x1b[0m');
|
||||||
|
@ -9,6 +9,8 @@ from src.thirdparty.code import *;
|
|||||||
from src.thirdparty.maths import *;
|
from src.thirdparty.maths import *;
|
||||||
from src.thirdparty.types import *;
|
from src.thirdparty.types import *;
|
||||||
|
|
||||||
|
from src.setup import config;
|
||||||
|
from models.generated.config import *;
|
||||||
from src.models.stacks import *;
|
from src.models.stacks import *;
|
||||||
from src.models.rucksack import *;
|
from src.models.rucksack import *;
|
||||||
|
|
||||||
@ -62,9 +64,17 @@ def display_rucksack(
|
|||||||
items: np.ndarray,
|
items: np.ndarray,
|
||||||
costs: np.ndarray,
|
costs: np.ndarray,
|
||||||
values: np.ndarray,
|
values: np.ndarray,
|
||||||
choice: np.ndarray,
|
choice: List[Fraction],
|
||||||
) -> str:
|
) -> str:
|
||||||
|
show_options = config.OPTIONS.rucksack.show;
|
||||||
render = lambda r: f'{r:g}';
|
render = lambda r: f'{r:g}';
|
||||||
|
choice = np.asarray(choice);
|
||||||
|
rucksack = np.where(choice > 0);
|
||||||
|
if not(EnumRucksackShow.all_weights in show_options):
|
||||||
|
items = items[rucksack];
|
||||||
|
costs = costs[rucksack];
|
||||||
|
values = values[rucksack];
|
||||||
|
choice = choice[rucksack];
|
||||||
table = pd.DataFrame({
|
table = pd.DataFrame({
|
||||||
'items': items.tolist() + ['----', '∑'],
|
'items': items.tolist() + ['----', '∑'],
|
||||||
'nr': list(map(str, choice))
|
'nr': list(map(str, choice))
|
||||||
@ -132,15 +142,22 @@ def display_sum(
|
|||||||
indexes: List[int] = [],
|
indexes: List[int] = [],
|
||||||
as_maximum: bool = True,
|
as_maximum: bool = True,
|
||||||
) -> str:
|
) -> str:
|
||||||
|
show_options = config.OPTIONS.rucksack.show;
|
||||||
|
show_all_weights = (EnumRucksackShow.all_weights in show_options);
|
||||||
|
|
||||||
def render(x: Tuple[bool, Fraction, float]):
|
def render(x: Tuple[bool, Fraction, float]):
|
||||||
b, u, value = x;
|
b, u, value = x;
|
||||||
expr = f'\x1b[91m{value:g}\x1b[0m' if b else f'\x1b[2m{value:g}\x1b[0m';
|
expr = f'\x1b[91m{value:g}\x1b[0m' if b else f'\x1b[0m{value:g}\x1b[0m';
|
||||||
return expr if u == 1 else f'\x1b[4;2m{u}\x1b[0m\x1b[2m·\x1b[0m{expr}';
|
if not show_all_weights and u == 1:
|
||||||
|
return expr;
|
||||||
|
return f'\x1b[2m{u}\x1b[0m\x1b[2m·\x1b[0m{expr}';
|
||||||
|
|
||||||
parts = [ (i in indexes, u, x) for i, (u, x) in enumerate(zip(choice, values)) ];
|
parts = [ (i in indexes, u, x) for i, (u, x) in enumerate(zip(choice, values)) ];
|
||||||
if not (order is None):
|
if not (order is None):
|
||||||
parts = [ parts[j] for j in order ];
|
parts = [ parts[j] for j in order ];
|
||||||
parts = list(filter(lambda x: x[1] > 0, parts));
|
if not show_all_weights:
|
||||||
|
parts = list(filter(lambda x: x[1] > 0, parts));
|
||||||
|
|
||||||
value = sum([ u*x for _, u, x in parts ]);
|
value = sum([ u*x for _, u, x in parts ]);
|
||||||
expr = '\x1b[2m+\x1b[0m'.join(map(render, parts));
|
expr = '\x1b[2m+\x1b[0m'.join(map(render, parts));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user