Compare commits
21 Commits
4001551c9c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 32ef695c87 | |||
| 1ee5e7415b | |||
| b1a467b2e4 | |||
| 9f807d2a21 | |||
| de4bd64e77 | |||
| 0c61a29375 | |||
| bd355098cc | |||
| 278e3713c8 | |||
| de238fede9 | |||
| 3c965eda7b | |||
| 56c22a568c | |||
| c1f346b80e | |||
|
|
2d96666bec | ||
| 7d07f4317e | |||
| 2bd07544f3 | |||
| 7b456d177e | |||
| 1e934dc3ef | |||
| a7c7179edb | |||
| 5c43419890 | |||
| c2cb11a141 | |||
| 01ef8c5758 |
@@ -115,15 +115,86 @@
|
|||||||
]
|
]
|
||||||
costs: [30, 10, 50, 10, 80]
|
costs: [30, 10, 50, 10, 80]
|
||||||
values: [17, 14, 17, 5, 25]
|
values: [17, 14, 17, 5, 25]
|
||||||
|
- name: RUCKSACK
|
||||||
|
algorithm: BRANCH-AND-BOUND
|
||||||
|
max-cost: 900
|
||||||
|
items: [
|
||||||
|
'Sellerie',
|
||||||
|
'Sonnenblumenkerne',
|
||||||
|
'Rote Beete',
|
||||||
|
'Hirse',
|
||||||
|
'Buchweizen',
|
||||||
|
]
|
||||||
|
costs: [600, 100, 800, 100, 200]
|
||||||
|
values: [10, 15, 20, 5, 15]
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# Beispiele für Seminarwoche 12
|
# Beispiele für Seminarwoche 12
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
- name: RANDOM-WALK
|
||||||
|
algorithm: GRADIENT
|
||||||
|
one-based: true
|
||||||
|
coords-init: [3, 3]
|
||||||
|
landscape: &ref_landscape1
|
||||||
|
neighbourhoods:
|
||||||
|
radius: 1
|
||||||
|
# metric: MANHATTAN
|
||||||
|
metric: MAXIMUM
|
||||||
|
labels:
|
||||||
|
- x
|
||||||
|
- y
|
||||||
|
values:
|
||||||
|
- [5, 2, 1, 3, 4, 7]
|
||||||
|
- [8, 4, 3, 5, 5, 6]
|
||||||
|
- [9, 1, 2, 6, 8, 4]
|
||||||
|
- [7, 4, 4, 3, 7, 3]
|
||||||
|
- [6, 4, 2, 1, 0, 7]
|
||||||
|
- [4, 3, 5, 2, 1, 8]
|
||||||
|
optimise: MAX
|
||||||
|
- name: RANDOM-WALK
|
||||||
|
algorithm: ADAPTIVE
|
||||||
|
one-based: true
|
||||||
|
coords-init: [3, 3]
|
||||||
|
landscape: *ref_landscape1
|
||||||
|
optimise: MAX
|
||||||
|
- name: RANDOM-WALK
|
||||||
|
algorithm: METROPOLIS
|
||||||
|
annealing: false
|
||||||
|
temperature-init: 3.
|
||||||
|
one-based: true
|
||||||
|
coords-init: [5, 3]
|
||||||
|
landscape: *ref_landscape1
|
||||||
|
optimise: MAX
|
||||||
|
- name: RANDOM-WALK
|
||||||
|
algorithm: METROPOLIS
|
||||||
|
annealing: false
|
||||||
|
temperature-init: 3.
|
||||||
|
one-based: false
|
||||||
|
coords-init: [0]
|
||||||
|
landscape:
|
||||||
|
neighbourhoods:
|
||||||
|
radius: 1
|
||||||
|
metric: MANHATTAN
|
||||||
|
labels:
|
||||||
|
- x
|
||||||
|
values: [4, 6.5, 2]
|
||||||
|
optimise: MAX
|
||||||
|
- name: GENETIC
|
||||||
|
population:
|
||||||
|
- [3, 5, 4, 1, 6, 7, 2, 8, 9]
|
||||||
|
- [4, 5, 3, 2, 1, 6, 7, 8, 9]
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# Beispiele für Seminarwoche 13
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
- name: EUKLID
|
- name: EUKLID
|
||||||
numbers:
|
numbers:
|
||||||
- 2017
|
- 2017
|
||||||
- 58
|
- 58
|
||||||
- name: POLLARD-RHO
|
- name: POLLARD-RHO
|
||||||
|
growth: LINEAR
|
||||||
|
# growth: EXPONENTIAL
|
||||||
number: 534767
|
number: 534767
|
||||||
x-init: 5
|
x-init: 5
|
||||||
|
|||||||
2
code/python/dist/VERSION
vendored
2
code/python/dist/VERSION
vendored
@@ -1 +1 @@
|
|||||||
0.3.0
|
0.3.1
|
||||||
|
|||||||
10
code/python/docs/commands/Models/CommandGenetic.md
Normal file
10
code/python/docs/commands/Models/CommandGenetic.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# CommandGenetic
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**name** | [**EnumAlgorithmNames**](EnumAlgorithmNames.md) | | [default to null]
|
||||||
|
**population** | [**List**](array.md) | | [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)
|
||||||
|
|
||||||
@@ -5,6 +5,7 @@ Name | Type | Description | Notes
|
|||||||
------------ | ------------- | ------------- | -------------
|
------------ | ------------- | ------------- | -------------
|
||||||
**name** | [**EnumAlgorithmNames**](EnumAlgorithmNames.md) | | [default to null]
|
**name** | [**EnumAlgorithmNames**](EnumAlgorithmNames.md) | | [default to null]
|
||||||
**number** | [**Integer**](integer.md) | | [default to null]
|
**number** | [**Integer**](integer.md) | | [default to null]
|
||||||
|
**growth** | [**EnumPollardGrowthRate**](EnumPollardGrowthRate.md) | | [default to null]
|
||||||
**xMinusinit** | [**Integer**](integer.md) | | [optional] [default to 2]
|
**xMinusinit** | [**Integer**](integer.md) | | [optional] [default to 2]
|
||||||
|
|
||||||
[[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)
|
||||||
|
|||||||
16
code/python/docs/commands/Models/CommandRandomWalk.md
Normal file
16
code/python/docs/commands/Models/CommandRandomWalk.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# CommandRandomWalk
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**name** | [**EnumAlgorithmNames**](EnumAlgorithmNames.md) | | [default to null]
|
||||||
|
**algorithm** | [**EnumWalkMode**](EnumWalkMode.md) | | [default to null]
|
||||||
|
**landscape** | [**DataTypeLandscapeGeometry**](DataTypeLandscapeGeometry.md) | | [default to null]
|
||||||
|
**optimise** | [**EnumOptimiseMode**](EnumOptimiseMode.md) | | [default to null]
|
||||||
|
**coordsMinusinit** | [**List**](integer.md) | Initial co-ordinates to start the algorithm. | [optional] [default to null]
|
||||||
|
**temperatureMinusinit** | [**Float**](float.md) | | [optional] [default to null]
|
||||||
|
**annealing** | [**Boolean**](boolean.md) | | [optional] [default to false]
|
||||||
|
**oneMinusbased** | [**Boolean**](boolean.md) | | [optional] [default to false]
|
||||||
|
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# DataTypeLandscapeGeometry
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**neighbourhoods** | [**DataTypeLandscapeNeighbourhoods**](DataTypeLandscapeNeighbourhoods.md) | | [default to null]
|
||||||
|
**labels** | [**List**](string.md) | | [default to null]
|
||||||
|
**values** | [**DataTypeLandscapeValues**](DataTypeLandscapeValues.md) | | [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)
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# DataTypeLandscapeNeighbourhoods
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**radius** | [**BigDecimal**](number.md) | | [optional] [default to 1]
|
||||||
|
**metric** | [**EnumLandscapeMetric**](EnumLandscapeMetric.md) | | [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)
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# DataTypeLandscapeValues
|
||||||
|
## 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)
|
||||||
|
|
||||||
8
code/python/docs/commands/Models/EnumLandscapeMetric.md
Normal file
8
code/python/docs/commands/Models/EnumLandscapeMetric.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# EnumLandscapeMetric
|
||||||
|
## 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)
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# EnumPollardGrowthRate
|
||||||
|
## 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)
|
||||||
|
|
||||||
8
code/python/docs/commands/Models/EnumWalkMode.md
Normal file
8
code/python/docs/commands/Models/EnumWalkMode.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# EnumWalkMode
|
||||||
|
## 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)
|
||||||
|
|
||||||
@@ -14,14 +14,22 @@ Class | Method | HTTP request | Description
|
|||||||
|
|
||||||
- [Command](.//Models/Command.md)
|
- [Command](.//Models/Command.md)
|
||||||
- [CommandEuklid](.//Models/CommandEuklid.md)
|
- [CommandEuklid](.//Models/CommandEuklid.md)
|
||||||
|
- [CommandGenetic](.//Models/CommandGenetic.md)
|
||||||
- [CommandHirschberg](.//Models/CommandHirschberg.md)
|
- [CommandHirschberg](.//Models/CommandHirschberg.md)
|
||||||
- [CommandPollard](.//Models/CommandPollard.md)
|
- [CommandPollard](.//Models/CommandPollard.md)
|
||||||
|
- [CommandRandomWalk](.//Models/CommandRandomWalk.md)
|
||||||
- [CommandRucksack](.//Models/CommandRucksack.md)
|
- [CommandRucksack](.//Models/CommandRucksack.md)
|
||||||
- [CommandTarjan](.//Models/CommandTarjan.md)
|
- [CommandTarjan](.//Models/CommandTarjan.md)
|
||||||
- [CommandTsp](.//Models/CommandTsp.md)
|
- [CommandTsp](.//Models/CommandTsp.md)
|
||||||
|
- [DataTypeLandscapeGeometry](.//Models/DataTypeLandscapeGeometry.md)
|
||||||
|
- [DataTypeLandscapeNeighbourhoods](.//Models/DataTypeLandscapeNeighbourhoods.md)
|
||||||
|
- [DataTypeLandscapeValues](.//Models/DataTypeLandscapeValues.md)
|
||||||
- [EnumAlgorithmNames](.//Models/EnumAlgorithmNames.md)
|
- [EnumAlgorithmNames](.//Models/EnumAlgorithmNames.md)
|
||||||
|
- [EnumLandscapeMetric](.//Models/EnumLandscapeMetric.md)
|
||||||
- [EnumOptimiseMode](.//Models/EnumOptimiseMode.md)
|
- [EnumOptimiseMode](.//Models/EnumOptimiseMode.md)
|
||||||
|
- [EnumPollardGrowthRate](.//Models/EnumPollardGrowthRate.md)
|
||||||
- [EnumRucksackAlgorithm](.//Models/EnumRucksackAlgorithm.md)
|
- [EnumRucksackAlgorithm](.//Models/EnumRucksackAlgorithm.md)
|
||||||
|
- [EnumWalkMode](.//Models/EnumWalkMode.md)
|
||||||
|
|
||||||
|
|
||||||
<a name="documentation-for-authorization"></a>
|
<a name="documentation-for-authorization"></a>
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ Name | Type | Description | Notes
|
|||||||
**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_rucksack**](AppOptions_rucksack.md) | | [default to null]
|
**rucksack** | [**AppOptions_rucksack**](AppOptions_rucksack.md) | | [default to null]
|
||||||
|
**randomMinuswalk** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
||||||
|
**genetic** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
||||||
**euklid** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
**euklid** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
||||||
**pollardMinusrho** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
**pollardMinusrho** | [**AppOptions_tarjan**](AppOptions_tarjan.md) | | [default to null]
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
set shell := [ "bash", "-uc" ]
|
# set shell := [ "bash", "-uc" ]
|
||||||
_default:
|
_default:
|
||||||
@- just --unsorted --choose
|
@- just --unsorted --choose
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|||||||
@@ -44,4 +44,6 @@ def enter(*args: str):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.tracebacklimit = 0;
|
sys.tracebacklimit = 0;
|
||||||
|
# NOTE: necessary for Windows, to ensure that console output is rendered correctly:
|
||||||
|
os.system('');
|
||||||
enter(*sys.argv[1:]);
|
enter(*sys.argv[1:]);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
openapi: 3.0.3
|
openapi: 3.0.3
|
||||||
info:
|
info:
|
||||||
version: 0.3.0
|
version: 0.3.1
|
||||||
title: Schemata for command instructions
|
title: Schemata for command instructions
|
||||||
servers:
|
servers:
|
||||||
- url: "."
|
- url: "."
|
||||||
@@ -170,9 +170,21 @@ components:
|
|||||||
$ref: '#/components/schemas/DataTypeLandscapeGeometry'
|
$ref: '#/components/schemas/DataTypeLandscapeGeometry'
|
||||||
optimise:
|
optimise:
|
||||||
$ref: '#/components/schemas/EnumOptimiseMode'
|
$ref: '#/components/schemas/EnumOptimiseMode'
|
||||||
|
coords-init:
|
||||||
|
description: Initial co-ordinates to start the algorithm.
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: integer
|
||||||
|
minItems: 1
|
||||||
|
temperature-init:
|
||||||
|
type: float
|
||||||
|
default: 1.
|
||||||
annealing:
|
annealing:
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
one-based:
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# Algorithm: Genetic Algorithm
|
# Algorithm: Genetic Algorithm
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@@ -223,6 +235,7 @@ components:
|
|||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
- name
|
- name
|
||||||
|
- growth
|
||||||
- number
|
- number
|
||||||
properties:
|
properties:
|
||||||
name:
|
name:
|
||||||
@@ -230,6 +243,8 @@ components:
|
|||||||
number:
|
number:
|
||||||
type: integer
|
type: integer
|
||||||
exclusiveMinimum: 0
|
exclusiveMinimum: 0
|
||||||
|
growth:
|
||||||
|
$ref: '#/components/schemas/EnumPollardGrowthRate'
|
||||||
x-init:
|
x-init:
|
||||||
type: integer
|
type: integer
|
||||||
default: 2
|
default: 2
|
||||||
@@ -243,10 +258,16 @@ components:
|
|||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
- neighbourhoods
|
- neighbourhoods
|
||||||
|
- labels
|
||||||
- values
|
- values
|
||||||
properties:
|
properties:
|
||||||
neighbourhoods:
|
neighbourhoods:
|
||||||
$ref: '#/components/schemas/DataTypeLandscapeNeighbourhoods'
|
$ref: '#/components/schemas/DataTypeLandscapeNeighbourhoods'
|
||||||
|
labels:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
minItems: 1
|
||||||
values:
|
values:
|
||||||
$ref: '#/components/schemas/DataTypeLandscapeValues'
|
$ref: '#/components/schemas/DataTypeLandscapeValues'
|
||||||
DataTypeLandscapeNeighbourhoods:
|
DataTypeLandscapeNeighbourhoods:
|
||||||
@@ -309,6 +330,21 @@ components:
|
|||||||
- GREEDY
|
- GREEDY
|
||||||
- BRANCH-AND-BOUND
|
- BRANCH-AND-BOUND
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# Enum Type for choice of growth rate in Pollard Algorithm
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
EnumPollardGrowthRate:
|
||||||
|
description: |-
|
||||||
|
Via the 'tail-chasing' period finding method in Pollard's rho algorithm,
|
||||||
|
the difference between the indexes of the pseudo-random sequence
|
||||||
|
can be chosen to growth according to different rates, e.g.
|
||||||
|
|
||||||
|
- `LINEAR` - choose `x[k]` and `x[2k]`
|
||||||
|
- `EXPONENTIAL` - choose `x[k]` and `x[2^{k}]`
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- LINEAR
|
||||||
|
- EXPONENTIAL
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# Enum Type of walk mode for fitness walk algorithm
|
# Enum Type of walk mode for fitness walk algorithm
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
EnumWalkMode:
|
EnumWalkMode:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
openapi: 3.0.3
|
openapi: 3.0.3
|
||||||
info:
|
info:
|
||||||
version: 0.3.0
|
version: 0.3.1
|
||||||
title: Schemata for config models
|
title: Schemata for config models
|
||||||
servers:
|
servers:
|
||||||
- url: "."
|
- url: "."
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "uni-leipzig-ads-2-2022"
|
name = "uni-leipzig-ads-2-2022"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
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" ]
|
||||||
|
|||||||
@@ -12,5 +12,6 @@ from src.algorithms.pollard_rho.algorithms import *;
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'pollard_rho_algorithm',
|
'pollard_rho_algorithm_linear',
|
||||||
|
'pollard_rho_algorithm_exponential',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -18,40 +18,110 @@ from src.algorithms.pollard_rho.display import *;
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'pollard_rho_algorithm',
|
'pollard_rho_algorithm_linear',
|
||||||
|
'pollard_rho_algorithm_exponential',
|
||||||
];
|
];
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# METHOD pollard's rho algorithm
|
# METHOD pollard's rho algorithm - with linear grwoth
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
def pollard_rho_algorithm(
|
def pollard_rho_algorithm_linear(
|
||||||
n: int,
|
n: int,
|
||||||
x_init: int = 2,
|
x_init: int = 2,
|
||||||
verbose: bool = False,
|
verbose: bool = False,
|
||||||
):
|
):
|
||||||
d = 1;
|
|
||||||
x = y = x_init;
|
|
||||||
steps = [];
|
steps = [];
|
||||||
steps.append(Step(x=x, y=y));
|
|
||||||
success = False;
|
success = False;
|
||||||
f = lambda _: fct(_, n=n);
|
f = lambda _: fct(_, n=n);
|
||||||
|
|
||||||
|
d = 1;
|
||||||
|
x = y = x_init;
|
||||||
|
steps.append(Step(x=x));
|
||||||
|
k = 0;
|
||||||
|
k_next = 1;
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
# aktualisiere x: x = f(x_prev):
|
||||||
x = f(x);
|
x = f(x);
|
||||||
|
# aktualisiere y: y = f(f(y_prev)):
|
||||||
y = f(f(y));
|
y = f(f(y));
|
||||||
|
|
||||||
|
# ggT berechnen:
|
||||||
d = math.gcd(abs(x-y), n);
|
d = math.gcd(abs(x-y), n);
|
||||||
steps.append(Step(x=x, y=y, d=d));
|
steps.append(Step(x=x, y=y, d=d));
|
||||||
if d == 1:
|
|
||||||
|
# Abbruchkriterien prüfen:
|
||||||
|
if d == 1: # weitermachen, solange d == 1
|
||||||
|
k += 1;
|
||||||
continue;
|
continue;
|
||||||
elif d < n:
|
elif d == n: # versagt
|
||||||
success = True;
|
success = False;
|
||||||
break;
|
break;
|
||||||
else:
|
else:
|
||||||
success = False;
|
success = True;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
repr = display_table(steps=steps);
|
repr = display_table_linear(steps=steps);
|
||||||
|
print('');
|
||||||
|
print('\x1b[1mEuklidescher Algorithmus\x1b[0m');
|
||||||
|
print('');
|
||||||
|
print(repr);
|
||||||
|
print('');
|
||||||
|
if success:
|
||||||
|
print('\x1b[1mBerechneter Faktor:\x1b[0m');
|
||||||
|
print('');
|
||||||
|
print(f'd = \x1b[1m{d}\x1b[0m.');
|
||||||
|
else:
|
||||||
|
print('\x1b[91mKein (Prim)faktor erkannt!\x1b[0m');
|
||||||
|
print('');
|
||||||
|
return d;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# METHOD pollard's rho algorithm - with exponential grwoth
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
def pollard_rho_algorithm_exponential(
|
||||||
|
n: int,
|
||||||
|
x_init: int = 2,
|
||||||
|
verbose: bool = False,
|
||||||
|
):
|
||||||
|
steps = [];
|
||||||
|
success = False;
|
||||||
|
f = lambda _: fct(_, n=n);
|
||||||
|
|
||||||
|
d = 1;
|
||||||
|
x = y = x_init;
|
||||||
|
steps.append(Step(x=x));
|
||||||
|
k = 0;
|
||||||
|
k_next = 1;
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# aktualisiere x: x = f(x_prev):
|
||||||
|
x = f(x);
|
||||||
|
# aktualisiere y, wenn k = 2^j: y = x[j] = f(y_prev):
|
||||||
|
if k == k_next:
|
||||||
|
k_next = 2*k_next;
|
||||||
|
y = f(y);
|
||||||
|
|
||||||
|
# ggT berechnen:
|
||||||
|
d = math.gcd(abs(x-y), n);
|
||||||
|
steps.append(Step(x=x, y=y, d=d));
|
||||||
|
|
||||||
|
# Abbruchkriterien prüfen:
|
||||||
|
if d == 1: # weitermachen, solange d == 1
|
||||||
|
k += 1;
|
||||||
|
continue;
|
||||||
|
elif d == n: # versagt
|
||||||
|
success = False;
|
||||||
|
break;
|
||||||
|
else:
|
||||||
|
success = True;
|
||||||
|
break;
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
repr = display_table_exponential(steps=steps);
|
||||||
print('');
|
print('');
|
||||||
print('\x1b[1mEuklidescher Algorithmus\x1b[0m');
|
print('\x1b[1mEuklidescher Algorithmus\x1b[0m');
|
||||||
print('');
|
print('');
|
||||||
|
|||||||
@@ -16,25 +16,48 @@ from src.models.pollard_rho import *;
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'display_table',
|
'display_table_linear',
|
||||||
|
'display_table_exponential',
|
||||||
];
|
];
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# METHOD display table
|
# METHOD display table - linear
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
def display_table(steps: List[Step]) -> str:
|
def display_table_linear(steps: List[Step]) -> str:
|
||||||
table = pd.DataFrame({
|
table = pd.DataFrame({
|
||||||
'i': [i for i in range(len(steps))],
|
'i': [i for i in range(len(steps))],
|
||||||
'x': [step.x for step in steps],
|
'x': [step.x for step in steps],
|
||||||
'y': [step.y for step in steps],
|
'y': [step.y or '-' for step in steps],
|
||||||
'd': [step.d or '-' for step in steps],
|
'd': [step.d or '-' for step in steps],
|
||||||
}) \
|
}) \
|
||||||
.reset_index(drop=True);
|
.reset_index(drop=True);
|
||||||
# benutze pandas-Dataframe + tabulate, um schöner darzustellen:
|
# benutze pandas-Dataframe + tabulate, um schöner darzustellen:
|
||||||
repr = tabulate(
|
repr = tabulate(
|
||||||
table,
|
table,
|
||||||
headers=['i', 'x[i]', 'y[i] = x[2i]', 'gcd(|x - y|,n)'],
|
headers=['i', 'x(i)', 'y(i) = x(2i)', 'gcd(|x - y|,n)'],
|
||||||
|
showindex=False,
|
||||||
|
colalign=('right', 'right', 'right', 'center'),
|
||||||
|
tablefmt='simple',
|
||||||
|
);
|
||||||
|
return repr;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# METHOD display table - exponential
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
def display_table_exponential(steps: List[Step]) -> str:
|
||||||
|
table = pd.DataFrame({
|
||||||
|
'i': [i for i in range(len(steps))],
|
||||||
|
'x': [step.x for step in steps],
|
||||||
|
'y': [step.y or '-' for step in steps],
|
||||||
|
'd': [step.d or '-' for step in steps],
|
||||||
|
}) \
|
||||||
|
.reset_index(drop=True);
|
||||||
|
# benutze pandas-Dataframe + tabulate, um schöner darzustellen:
|
||||||
|
repr = tabulate(
|
||||||
|
table,
|
||||||
|
headers=['i', 'x(i)', 'y(i) = x([log₂(i)])', 'gcd(|x - y|,n)'],
|
||||||
showindex=False,
|
showindex=False,
|
||||||
colalign=('right', 'right', 'right', 'center'),
|
colalign=('right', 'right', 'right', 'center'),
|
||||||
tablefmt='simple',
|
tablefmt='simple',
|
||||||
|
|||||||
@@ -5,8 +5,9 @@
|
|||||||
# IMPORTS
|
# IMPORTS
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
from src.thirdparty.types import *;
|
|
||||||
from src.thirdparty.maths import *;
|
from src.thirdparty.maths import *;
|
||||||
|
from src.thirdparty.plots import *;
|
||||||
|
from src.thirdparty.types import *;
|
||||||
|
|
||||||
from models.generated.config import *;
|
from models.generated.config import *;
|
||||||
from models.generated.commands import *;
|
from models.generated.commands import *;
|
||||||
@@ -25,6 +26,12 @@ __all__ = [
|
|||||||
'metropolis_walk_algorithm',
|
'metropolis_walk_algorithm',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# CONSTANTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
MAX_ITERATIONS = 1000; # um endlose Schleifen zu verhindern
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# METHOD adaptive walk
|
# METHOD adaptive walk
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@@ -32,14 +39,58 @@ __all__ = [
|
|||||||
def adaptive_walk_algorithm(
|
def adaptive_walk_algorithm(
|
||||||
landscape: Landscape,
|
landscape: Landscape,
|
||||||
r: float,
|
r: float,
|
||||||
|
coords_init: tuple,
|
||||||
optimise: EnumOptimiseMode,
|
optimise: EnumOptimiseMode,
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
):
|
):
|
||||||
'''
|
'''
|
||||||
Führt den Adapative-Walk Algorithmus aus, um ein lokales Minimum zu bestimmen.
|
Führt den Adapative-Walk Algorithmus aus, um ein lokales Minimum zu bestimmen.
|
||||||
'''
|
'''
|
||||||
log_warn('Noch nicht implementiert!');
|
|
||||||
return;
|
# lege Fitness- und Umgebungsfunktionen fest:
|
||||||
|
match optimise:
|
||||||
|
case EnumOptimiseMode.max:
|
||||||
|
f = lambda x: -landscape.fitness(*x);
|
||||||
|
case _:
|
||||||
|
f = lambda x: landscape.fitness(*x);
|
||||||
|
nbhd = lambda x: landscape.neighbourhood(*x, r=r, strict=True);
|
||||||
|
label = lambda x: landscape.label(*x);
|
||||||
|
|
||||||
|
# initialisiere
|
||||||
|
steps = [];
|
||||||
|
x = coords_init;
|
||||||
|
fx = f(x);
|
||||||
|
fy = fx;
|
||||||
|
N = nbhd(x);
|
||||||
|
|
||||||
|
# führe walk aus:
|
||||||
|
k = 0;
|
||||||
|
while k < MAX_ITERATIONS:
|
||||||
|
# Wähle zufälligen Punkt und berechne fitness-Wert:
|
||||||
|
y = uniform_random_choice(N);
|
||||||
|
fy = f(y);
|
||||||
|
|
||||||
|
# Nur dann aktualisieren, wenn sich f-Wert verbessert:
|
||||||
|
if fy < fx:
|
||||||
|
# Punkt + Umgebung + f-Wert aktualisieren
|
||||||
|
x = y;
|
||||||
|
fx = fy;
|
||||||
|
N = nbhd(x);
|
||||||
|
step = Step(coords=x, label=label(x), improved=True, changed=True);
|
||||||
|
else:
|
||||||
|
# Nichts (außer logging) machen!
|
||||||
|
step = Step(coords=x, label=label(x));
|
||||||
|
|
||||||
|
# Nur dann (erfolgreich) abbrechen, wenn f-Wert lokal Min:
|
||||||
|
if fx <= min([f(y) for y in N], default=fx):
|
||||||
|
step.stopped = True;
|
||||||
|
steps.append(step);
|
||||||
|
break;
|
||||||
|
|
||||||
|
steps.append(step);
|
||||||
|
k += 1;
|
||||||
|
|
||||||
|
return x;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# METHOD gradient walk
|
# METHOD gradient walk
|
||||||
@@ -48,14 +99,64 @@ def adaptive_walk_algorithm(
|
|||||||
def gradient_walk_algorithm(
|
def gradient_walk_algorithm(
|
||||||
landscape: Landscape,
|
landscape: Landscape,
|
||||||
r: float,
|
r: float,
|
||||||
|
coords_init: tuple,
|
||||||
optimise: EnumOptimiseMode,
|
optimise: EnumOptimiseMode,
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
):
|
):
|
||||||
'''
|
'''
|
||||||
Führt den Gradient-Descent (bzw. Ascent) Algorithmus aus, um ein lokales Minimum zu bestimmen.
|
Führt den Gradient-Descent (bzw. Ascent) Algorithmus aus, um ein lokales Minimum zu bestimmen.
|
||||||
'''
|
'''
|
||||||
log_warn('Noch nicht implementiert!');
|
|
||||||
return;
|
# lege Fitness- und Umgebungsfunktionen fest:
|
||||||
|
match optimise:
|
||||||
|
case EnumOptimiseMode.max:
|
||||||
|
f = lambda x: -landscape.fitness(*x);
|
||||||
|
case _:
|
||||||
|
f = lambda x: landscape.fitness(*x);
|
||||||
|
nbhd = lambda x: landscape.neighbourhood(*x, r=r, strict=True);
|
||||||
|
label = lambda x: landscape.label(*x);
|
||||||
|
|
||||||
|
# initialisiere
|
||||||
|
steps = [];
|
||||||
|
x = coords_init;
|
||||||
|
fx = landscape.fitness(*x);
|
||||||
|
fy = fx;
|
||||||
|
N = nbhd(x);
|
||||||
|
f_values = [f(y) for y in N];
|
||||||
|
fmin = min(f_values);
|
||||||
|
Z = [y for y, fy in zip(N, f_values) if fy == fmin];
|
||||||
|
|
||||||
|
# führe walk aus:
|
||||||
|
k = 0;
|
||||||
|
while k < MAX_ITERATIONS:
|
||||||
|
# Wähle zufälligen Punkt mit steilstem Abstieg und berechne fitness-Wert:
|
||||||
|
y = uniform_random_choice(Z);
|
||||||
|
fy = fmin;
|
||||||
|
|
||||||
|
# Nur dann aktualisieren, wenn sich f-Wert verbessert:
|
||||||
|
if fy < fx:
|
||||||
|
# Punkt + Umgebung + f-Wert aktualisieren
|
||||||
|
x = y;
|
||||||
|
fx = fy;
|
||||||
|
N = nbhd(y);
|
||||||
|
f_values = [f(y) for y in N];
|
||||||
|
fmin = min(f_values);
|
||||||
|
Z = [y for y, fy in zip(N, f_values) if fy == fmin];
|
||||||
|
step = Step(coords=x, label=label(x), improved=True, changed=True);
|
||||||
|
else:
|
||||||
|
# Nichts (außer logging) machen!
|
||||||
|
step = Step(coords=x, label=label(x));
|
||||||
|
|
||||||
|
# Nur dann (erfolgreich) abbrechen, wenn f-Wert lokal Min:
|
||||||
|
if fx <= min([f(y) for y in N], default=fx):
|
||||||
|
step.stopped = True;
|
||||||
|
steps.append(step);
|
||||||
|
break;
|
||||||
|
|
||||||
|
steps.append(step);
|
||||||
|
k += 1;
|
||||||
|
|
||||||
|
return x;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# METHOD metropolis walk
|
# METHOD metropolis walk
|
||||||
@@ -64,6 +165,8 @@ def gradient_walk_algorithm(
|
|||||||
def metropolis_walk_algorithm(
|
def metropolis_walk_algorithm(
|
||||||
landscape: Landscape,
|
landscape: Landscape,
|
||||||
r: float,
|
r: float,
|
||||||
|
coords_init: tuple,
|
||||||
|
T: float,
|
||||||
annealing: bool,
|
annealing: bool,
|
||||||
optimise: EnumOptimiseMode,
|
optimise: EnumOptimiseMode,
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
@@ -71,5 +174,74 @@ def metropolis_walk_algorithm(
|
|||||||
'''
|
'''
|
||||||
Führt den Metropolis-Walk Algorithmus aus, um ein lokales Minimum zu bestimmen.
|
Führt den Metropolis-Walk Algorithmus aus, um ein lokales Minimum zu bestimmen.
|
||||||
'''
|
'''
|
||||||
log_warn('Noch nicht implementiert!');
|
|
||||||
return;
|
# lege Fitness- und Umgebungsfunktionen fest:
|
||||||
|
match optimise:
|
||||||
|
case EnumOptimiseMode.max:
|
||||||
|
f = lambda x: -landscape.fitness(*x);
|
||||||
|
case _:
|
||||||
|
f = lambda x: landscape.fitness(*x);
|
||||||
|
nbhd = lambda x: landscape.neighbourhood(*x, r=r, strict=True);
|
||||||
|
label = lambda x: landscape.label(*x);
|
||||||
|
|
||||||
|
# definiere anzahl der hinreichenden Schritt für Stabilität:
|
||||||
|
n_stable = 2*(3**(landscape.dim) - 1);
|
||||||
|
|
||||||
|
# initialisiere
|
||||||
|
x = coords_init;
|
||||||
|
fx = f(x);
|
||||||
|
fy = fx;
|
||||||
|
nbhd_x = nbhd(x);
|
||||||
|
steps = [];
|
||||||
|
step = Step(coords=x, label=label(x));
|
||||||
|
|
||||||
|
# führe walk aus:
|
||||||
|
k = 0;
|
||||||
|
n_unchanged = 0;
|
||||||
|
while k < MAX_ITERATIONS:
|
||||||
|
# Wähle zufälligen Punkt und berechne fitness-Wert:
|
||||||
|
y = uniform_random_choice(nbhd_x);
|
||||||
|
fy = f(y);
|
||||||
|
p = math.exp(-abs(fy-fx)/T);
|
||||||
|
u = random_binary(p);
|
||||||
|
|
||||||
|
# Aktualisieren, wenn sich f-Wert verbessert
|
||||||
|
# oder mit einer Wahrscheinlichkeit von p:
|
||||||
|
if fy < fx or u:
|
||||||
|
# Punkt + Umgebung + f-Wert aktualisieren
|
||||||
|
x = y;
|
||||||
|
fx = fy;
|
||||||
|
nbhd_x = nbhd(x);
|
||||||
|
n_unchanged = 0;
|
||||||
|
step = Step(coords=x, label=label(x), improved=(fy < fx), chance=u, probability=p, changed=True);
|
||||||
|
else:
|
||||||
|
# Nichts (außer logging) machen!
|
||||||
|
n_unchanged += 1;
|
||||||
|
step = Step(coords=x, label=label(x));
|
||||||
|
|
||||||
|
# »Temperatur« ggf. abkühlen:
|
||||||
|
if annealing:
|
||||||
|
T = cool_temperature(T, k);
|
||||||
|
|
||||||
|
# Nur dann (erfolgreich) abbrechen, wenn f-Wert lokal Min:
|
||||||
|
if n_unchanged >= n_stable:
|
||||||
|
step.stopped = True;
|
||||||
|
steps.append(step);
|
||||||
|
break;
|
||||||
|
|
||||||
|
steps.append(step);
|
||||||
|
k += 1;
|
||||||
|
|
||||||
|
if verbose:
|
||||||
|
for step in steps:
|
||||||
|
print(step);
|
||||||
|
|
||||||
|
return x;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# AUXILIARY METHODS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
def cool_temperature(T: float, k: int, const: float = 2.) -> float:
|
||||||
|
harm = const*(k + 1);
|
||||||
|
return T/(1 + T/harm);
|
||||||
|
|||||||
@@ -26,9 +26,21 @@ __all__ = [
|
|||||||
|
|
||||||
@run_safely()
|
@run_safely()
|
||||||
def endpoint_pollard_rho(command: CommandPollard) -> Result[CallResult, CallError]:
|
def endpoint_pollard_rho(command: CommandPollard) -> Result[CallResult, CallError]:
|
||||||
result = pollard_rho_algorithm(
|
match command.growth:
|
||||||
|
case EnumPollardGrowthRate.linear:
|
||||||
|
result = pollard_rho_algorithm_linear(
|
||||||
n = command.number,
|
n = command.number,
|
||||||
x_init = command.x_init,
|
x_init = command.x_init,
|
||||||
verbose = config.OPTIONS.pollard_rho.verbose,
|
verbose = config.OPTIONS.pollard_rho.verbose,
|
||||||
);
|
);
|
||||||
|
pass;
|
||||||
|
case EnumPollardGrowthRate.exponential:
|
||||||
|
result = pollard_rho_algorithm_exponential(
|
||||||
|
n = command.number,
|
||||||
|
x_init = command.x_init,
|
||||||
|
verbose = config.OPTIONS.pollard_rho.verbose,
|
||||||
|
);
|
||||||
|
pass;
|
||||||
|
case _ as growth:
|
||||||
|
raise Exception(f'No algorithm implemented for \x1b[1m{growth.value}\x1b[0m as growth rate.');
|
||||||
return Ok(CallResult(action_taken=True, message=result));
|
return Ok(CallResult(action_taken=True, message=result));
|
||||||
|
|||||||
@@ -27,15 +27,28 @@ __all__ = [
|
|||||||
|
|
||||||
@run_safely()
|
@run_safely()
|
||||||
def endpoint_random_walk(command: CommandRandomWalk) -> Result[CallResult, CallError]:
|
def endpoint_random_walk(command: CommandRandomWalk) -> Result[CallResult, CallError]:
|
||||||
|
# Compute landscape (fitness fct + topology) + initial co-ordinates:
|
||||||
|
one_based = command.one_based;
|
||||||
landscape = Landscape(
|
landscape = Landscape(
|
||||||
values = command.landscape.values,
|
values = command.landscape.values,
|
||||||
|
labels = command.landscape.labels,
|
||||||
metric = command.landscape.neighbourhoods.metric,
|
metric = command.landscape.neighbourhoods.metric,
|
||||||
|
one_based = one_based,
|
||||||
);
|
);
|
||||||
|
if isinstance(command.coords_init, list):
|
||||||
|
coords_init = tuple(command.coords_init);
|
||||||
|
if one_based:
|
||||||
|
coords_init = tuple(xx - 1 for xx in coords_init);
|
||||||
|
assert len(coords_init) == landscape.dim, 'Dimension of initial co-ordinations inconsistent with landscape!';
|
||||||
|
else:
|
||||||
|
coords_init = landscape.coords_middle;
|
||||||
|
|
||||||
match command.algorithm:
|
match command.algorithm:
|
||||||
case EnumWalkMode.adaptive:
|
case EnumWalkMode.adaptive:
|
||||||
result = adaptive_walk_algorithm(
|
result = adaptive_walk_algorithm(
|
||||||
landscape = landscape,
|
landscape = landscape,
|
||||||
r = command.landscape.neighbourhoods.radius,
|
r = command.landscape.neighbourhoods.radius,
|
||||||
|
coords_init = coords_init,
|
||||||
optimise = command.optimise,
|
optimise = command.optimise,
|
||||||
verbose = config.OPTIONS.random_walk.verbose
|
verbose = config.OPTIONS.random_walk.verbose
|
||||||
);
|
);
|
||||||
@@ -43,6 +56,7 @@ def endpoint_random_walk(command: CommandRandomWalk) -> Result[CallResult, CallE
|
|||||||
result = gradient_walk_algorithm(
|
result = gradient_walk_algorithm(
|
||||||
landscape = landscape,
|
landscape = landscape,
|
||||||
r = command.landscape.neighbourhoods.radius,
|
r = command.landscape.neighbourhoods.radius,
|
||||||
|
coords_init = coords_init,
|
||||||
optimise = command.optimise,
|
optimise = command.optimise,
|
||||||
verbose = config.OPTIONS.random_walk.verbose
|
verbose = config.OPTIONS.random_walk.verbose
|
||||||
);
|
);
|
||||||
@@ -50,6 +64,8 @@ def endpoint_random_walk(command: CommandRandomWalk) -> Result[CallResult, CallE
|
|||||||
result = metropolis_walk_algorithm(
|
result = metropolis_walk_algorithm(
|
||||||
landscape = landscape,
|
landscape = landscape,
|
||||||
r = command.landscape.neighbourhoods.radius,
|
r = command.landscape.neighbourhoods.radius,
|
||||||
|
coords_init = coords_init,
|
||||||
|
T = command.temperature_init,
|
||||||
annealing = command.annealing,
|
annealing = command.annealing,
|
||||||
optimise = command.optimise,
|
optimise = command.optimise,
|
||||||
verbose = config.OPTIONS.random_walk.verbose
|
verbose = config.OPTIONS.random_walk.verbose
|
||||||
|
|||||||
@@ -22,5 +22,5 @@ __all__ = [
|
|||||||
@dataclass
|
@dataclass
|
||||||
class Step():
|
class Step():
|
||||||
x: int = field();
|
x: int = field();
|
||||||
y: int = field();
|
y: Optional[int] = field(default=None);
|
||||||
d: Optional[int] = field(default=None);
|
d: Optional[int] = field(default=None);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
from src.models.random_walk.landscape import *;
|
from src.models.random_walk.landscape import *;
|
||||||
|
from src.models.random_walk.logging import *;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# EXPORTS
|
# EXPORTS
|
||||||
@@ -13,4 +14,5 @@ from src.models.random_walk.landscape import *;
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'Landscape',
|
'Landscape',
|
||||||
|
'Step',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -27,16 +27,23 @@ __all__ = [
|
|||||||
|
|
||||||
class Landscape():
|
class Landscape():
|
||||||
_fct: np.ndarray;
|
_fct: np.ndarray;
|
||||||
|
_labels: list[str];
|
||||||
_metric: EnumLandscapeMetric;
|
_metric: EnumLandscapeMetric;
|
||||||
_radius: float;
|
_radius: float;
|
||||||
|
_one_based: bool;
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
values: DataTypeLandscapeValues,
|
values: DataTypeLandscapeValues,
|
||||||
|
labels: List[str],
|
||||||
metric: EnumLandscapeMetric = EnumLandscapeMetric.maximum,
|
metric: EnumLandscapeMetric = EnumLandscapeMetric.maximum,
|
||||||
|
one_based: bool = False,
|
||||||
):
|
):
|
||||||
self._fct = convert_to_nparray(values);
|
self._fct = convert_to_nparray(values);
|
||||||
|
assert len(labels) == self.dim, 'A label is required for each axis/dimension!';
|
||||||
|
self._labels = labels;
|
||||||
self._metric = metric;
|
self._metric = metric;
|
||||||
|
self._one_based = one_based;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -47,10 +54,37 @@ class Landscape():
|
|||||||
def dim(self) -> int:
|
def dim(self) -> int:
|
||||||
return len(self._fct.shape);
|
return len(self._fct.shape);
|
||||||
|
|
||||||
|
@property
|
||||||
|
def coords_middle(self) -> tuple:
|
||||||
|
return tuple(math.floor(s/2) for s in self.shape);
|
||||||
|
|
||||||
|
@property
|
||||||
|
def values(self) -> np.ndarray:
|
||||||
|
return self._fct;
|
||||||
|
|
||||||
def fitness(self, *x: int) -> float:
|
def fitness(self, *x: int) -> float:
|
||||||
return self._fct[x];
|
return self._fct[x];
|
||||||
|
|
||||||
|
def axis_label(self, i: int, x: int) -> str:
|
||||||
|
if self._one_based:
|
||||||
|
x = x + 1;
|
||||||
|
name = self._labels[i];
|
||||||
|
return f'{name}{x}';
|
||||||
|
|
||||||
|
def axis_labels(self, i: int) -> str:
|
||||||
|
s = self.shape[i];
|
||||||
|
return [ self.axis_label(i, x) for x in range(s) ];
|
||||||
|
|
||||||
|
def label(self, *x: int) -> str:
|
||||||
|
if self._one_based:
|
||||||
|
x = tuple(xx + 1 for xx in x);
|
||||||
|
expr = ','.join([ f'{name}{xx}' for name, xx in zip(self._labels, x)]);
|
||||||
|
if self.dim > 1:
|
||||||
|
expr = f'({expr})';
|
||||||
|
return expr;
|
||||||
|
|
||||||
def neighbourhood(self, *x: int, r: float, strict: bool = False) -> List[tuple]:
|
def neighbourhood(self, *x: int, r: float, strict: bool = False) -> List[tuple]:
|
||||||
|
r = int(r);
|
||||||
sides = [
|
sides = [
|
||||||
[ xx - j for j in range(1, r+1) if xx - j in range(s) ]
|
[ xx - j for j in range(1, r+1) if xx - j in range(s) ]
|
||||||
+ ([ xx ] if xx in range(s) else [])
|
+ ([ xx ] if xx in range(s) else [])
|
||||||
|
|||||||
32
code/python/src/models/random_walk/logging.py
Normal file
32
code/python/src/models/random_walk/logging.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# IMPORTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
from src.thirdparty.types import *;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# EXPORTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'Step',
|
||||||
|
];
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# CLASS Step
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Step():
|
||||||
|
coords: tuple = field();
|
||||||
|
label: str = field();
|
||||||
|
|
||||||
|
improved: bool = field(default=False);
|
||||||
|
chance: bool = field(default=False);
|
||||||
|
probability: float = field(default=0.);
|
||||||
|
|
||||||
|
changed: bool = field(default=False);
|
||||||
|
stopped: bool = field(default=False);
|
||||||
8
code/python/src/thirdparty/maths.py
vendored
8
code/python/src/thirdparty/maths.py
vendored
@@ -8,8 +8,12 @@
|
|||||||
from fractions import Fraction;
|
from fractions import Fraction;
|
||||||
import math;
|
import math;
|
||||||
import numpy as np;
|
import numpy as np;
|
||||||
|
from numpy.random import binomial as random_binomial;
|
||||||
|
random_binary = lambda p: (random_binomial(1, p) == 1);
|
||||||
import pandas as pd;
|
import pandas as pd;
|
||||||
import random;
|
import random;
|
||||||
|
from random import uniform;
|
||||||
|
from random import choice as uniform_random_choice;
|
||||||
from tabulate import tabulate;
|
from tabulate import tabulate;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@@ -20,7 +24,11 @@ __all__ = [
|
|||||||
'Fraction',
|
'Fraction',
|
||||||
'math',
|
'math',
|
||||||
'np',
|
'np',
|
||||||
|
'random_binomial',
|
||||||
|
'random_binary',
|
||||||
'pd',
|
'pd',
|
||||||
'random',
|
'random',
|
||||||
|
'uniform',
|
||||||
|
'uniform_random_choice',
|
||||||
'tabulate',
|
'tabulate',
|
||||||
];
|
];
|
||||||
|
|||||||
22
code/python/src/thirdparty/plots.py
vendored
Normal file
22
code/python/src/thirdparty/plots.py
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# IMPORTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
from matplotlib import pyplot as mplt;
|
||||||
|
from matplotlib import animation as mplt_animation;
|
||||||
|
from matplotlib import colors as mplt_colours;
|
||||||
|
from matplotlib import patches as mplt_patches;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# EXPORTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'mplt',
|
||||||
|
'mplt_colours',
|
||||||
|
'mplt_patches',
|
||||||
|
'mplt_animation',
|
||||||
|
];
|
||||||
1
notes/.gitignore
vendored
1
notes/.gitignore
vendored
@@ -16,6 +16,7 @@
|
|||||||
!/notes.tex
|
!/notes.tex
|
||||||
!/notes.pdf
|
!/notes.pdf
|
||||||
!/woche*.pdf
|
!/woche*.pdf
|
||||||
|
!/*.csv
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
# Git Keep
|
# Git Keep
|
||||||
|
|||||||
34
notes/merfachesrucksack.csv
Normal file
34
notes/merfachesrucksack.csv
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
;;;i (Kosten);;;;;;;;;;;;;;;;;
|
||||||
|
j;Objekt[j];;0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17
|
||||||
|
;;value;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0
|
||||||
|
;;cost;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-
|
||||||
|
;;;;;;;;;;;;;;;;;;;;
|
||||||
|
1;A;value[i – cost[j]];;;;0;1;2;3;4;5;6;7;8;9;10;11;12;13;14
|
||||||
|
cost[j];3;… + value[j];;;;4;4;4;8;8;8;12;12;12;16;16;16;20;20;20
|
||||||
|
value[j];4;besser?;;;;WAHR;WAHR;WAHR;WAHR;WAHR;WAHR;WAHR;WAHR;WAHR;WAHR;WAHR;WAHR;WAHR;WAHR;WAHR
|
||||||
|
;;best-value;0;0;0;4;4;4;8;8;8;12;12;12;16;16;16;20;20;20
|
||||||
|
;;best-object;-;-;-;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A
|
||||||
|
;;;;;;;;;;;;;;;;;;;;
|
||||||
|
2;B;value[i – cost[j]];;;;;0;1;2;3;4;5;6;7;8;9;10;11;12;13
|
||||||
|
cost[j];4;… + value[j];;;;;5;5;5;9;10;10;13;14;15;17;18;19;21;22
|
||||||
|
value[j];5;besser?;;;;;WAHR;WAHR;;WAHR;WAHR;;WAHR;WAHR;;WAHR;WAHR;;WAHR;WAHR
|
||||||
|
;;value;0;0;0;4;5;5;8;9;10;12;13;14;16;17;18;20;21;22
|
||||||
|
;;cost;-;-;-;A;B;B;A;B;B;A;B;B;A;B;B;A;B;B
|
||||||
|
;;;;;;;;;;;;;;;;;;;;
|
||||||
|
3;C;value[i – cost[j]];;;;;;;;0;1;2;3;4;5;6;7;8;9;10
|
||||||
|
cost[j];7;… + value[j];;;;;;;;10;10;10;14;15;15;18;20;20;22;24
|
||||||
|
value[j];10;besser?;;;;;;;;WAHR;;;WAHR;WAHR;;WAHR;WAHR;;WAHR;WAHR
|
||||||
|
;;value;0;0;0;4;5;5;8;10;10;12;14;15;16;18;20;20;22;24
|
||||||
|
;;cost;-;-;-;A;B;B;A;C;B;A;C;C;A;C;C;A;C;C
|
||||||
|
;;;;;;;;;;;;;;;;;;;;
|
||||||
|
4;D;value[i – cost[j]];;;;;;;;;0;1;2;3;4;5;6;7;8;9
|
||||||
|
cost[j];8;… + value[j];;;;;;;;;11;11;11;15;16;16;19;21;22;23
|
||||||
|
value[j];11;besser?;;;;;;;;;WAHR;;;;;;;WAHR;;
|
||||||
|
;;value;0;0;0;4;5;5;8;10;11;12;14;15;16;18;20;21;22;24
|
||||||
|
;;cost;-;-;-;A;B;B;A;C;D;A;C;C;A;C;C;D;C;C
|
||||||
|
;;;;;;;;;;;;;;;;;;;;
|
||||||
|
5;E;value[i – cost[j]];;;;;;;;;;0;1;2;3;4;5;6;7;8
|
||||||
|
cost[j];9;… + value[j];;;;;;;;;;13;13;13;17;18;18;21;23;24
|
||||||
|
value[j];13;besser?;;;;;;;;;;WAHR;;;WAHR;;;;WAHR;
|
||||||
|
;;value;0;0;0;4;5;5;8;10;11;13;14;15;17;18;20;21;23;24
|
||||||
|
;;cost;-;-;-;A;B;B;A;C;D;E;C;C;E;C;C;D;E;C
|
||||||
|
@@ -15,8 +15,7 @@ Inhaltsverzeichnis
|
|||||||
-->
|
-->
|
||||||
- [Vorlesungswoche 10](./woche10.md)
|
- [Vorlesungswoche 10](./woche10.md)
|
||||||
- [Vorlesungswoche 11](./woche11.md)
|
- [Vorlesungswoche 11](./woche11.md)
|
||||||
<!--
|
|
||||||
- [Vorlesungswoche 12](./woche12.md)
|
- [Vorlesungswoche 12](./woche12.md)
|
||||||
- [Vorlesungswoche 13](./woche13.md)
|
- [Vorlesungswoche 13](./woche13.md)
|
||||||
- [Vorlesungswoche 14](./woche14.md)
|
- [Vorlesungswoche 14](./woche14.md)
|
||||||
-->
|
- [Vorlesungswoche 15](./woche15.md)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Agenda ##
|
## Agenda ##
|
||||||
|
|
||||||
- [ ] Rucksackproblem
|
- [x] Rucksackproblem
|
||||||
- Greedyalgorithmus
|
- Greedyalgorithmus
|
||||||
- Branch & Bound
|
- Branch & Bound
|
||||||
|
|
||||||
|
|||||||
6
protocol/woche12.md
Normal file
6
protocol/woche12.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Vorlesungswoche 12 (20.–26. Juni 2022) #
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- [x] Adaptive, Gradient, Metropolis Walks
|
||||||
|
- [x] Motivation und Erklärung der Bestandteile
|
||||||
29
protocol/woche13.md
Normal file
29
protocol/woche13.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Vorlesungswoche 13 (27. Juni – 3. Juli 2022) #
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- [x] ein wenig Algebra:
|
||||||
|
- [x] modulare Arithmetik
|
||||||
|
- [x] zyklische (Unter)gruppen; Anwendung `ф(n) := ord((ℤ/nℤ)ˣ)`.
|
||||||
|
- [x] der kleine Fermat: `a^ф(n) ≡ 1 mod n`.
|
||||||
|
- [x] Euklid:
|
||||||
|
- [x] Rekursives Ausrechnen von `d := ggT(a,b)`.
|
||||||
|
- [x] Extrahieren der Koeffizienten für die Gleichung `d = xa + yb`.
|
||||||
|
- [x] Anwendung auf Sonderfall `d = 1` für Inversion modulo `n`.
|
||||||
|
- [x] Pollard-Rho
|
||||||
|
- [x] Was liefert der Algorithmus?
|
||||||
|
- [x] Was garantiert das?
|
||||||
|
- Referenzen:
|
||||||
|
- Algorithmus im Kurs (exp-Abstände), siehe:
|
||||||
|
</br>
|
||||||
|
<http://staff.ustc.edu.cn/~csli/graduate/algorithms/book6/chap33.htm>
|
||||||
|
- Andere Variante (lineare Abstände), siehe:
|
||||||
|
</br>
|
||||||
|
<https://link.springer.com/article/10.1007/BF01933667>
|
||||||
|
und
|
||||||
|
</br>
|
||||||
|
<https://www.cambridge.org/core/journals/mathematical-proceedings-of-the-cambridge-philosophical-society/article/theorems-on-factorization-and-primality-testing/6762E84DBD34AEF13E6B1D1A8334A989>
|
||||||
|
|
||||||
|
### Nächste Woche/n ###
|
||||||
|
|
||||||
|
- Wiederholung zur Klausurvorbereitung
|
||||||
15
protocol/woche14.md
Normal file
15
protocol/woche14.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Vorlesungswoche 14 (4.–10. Juli 2022) #
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- Wiederholung
|
||||||
|
- Netze/Flüsse: Restgraphen, Push, Relabel.
|
||||||
|
- Gomory-Hu
|
||||||
|
- Branch & Bound: Rucksack, TSP.
|
||||||
|
- Matrixmultkiplikation
|
||||||
|
- Matroiden, Greedy
|
||||||
|
- Genetischer Algorithmus
|
||||||
|
|
||||||
|
### Nächste Woche/n ###
|
||||||
|
|
||||||
|
- Wiederholung zur Klausurvorbereitung
|
||||||
83
protocol/woche15.md
Normal file
83
protocol/woche15.md
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
# Vorlesungswoche 15 (11.–17. Juli 2022) #
|
||||||
|
|
||||||
|
## Agenda ##
|
||||||
|
|
||||||
|
- Wiederholung
|
||||||
|
- Alle genetischen Algorithmen im Kurs, inkl. letzter VL, Bsp. aus freiwilligen Übungsblättern.
|
||||||
|
- Branch & Bound: Rucksack, TSP.
|
||||||
|
- Dynamisches Programmieren.
|
||||||
|
- Matroiden: Versprecher letzte Woche
|
||||||
|
</br>
|
||||||
|
```
|
||||||
|
Ich sagte:
|
||||||
|
|A| < |B| ==> es gibt x ∈ E s.d. A u {x} ∈ M
|
||||||
|
|
||||||
|
Das ist zwar nicht falsch, aber nicht die ganze Aussage.
|
||||||
|
Es hätte so lauten sollen:
|
||||||
|
|A| < |B| ==> es gibt x ∈ B\A s.d. A u {x} ∈ M
|
||||||
|
```
|
||||||
|
- Pollard-Rho: Die Rolle der Primzahlen und die Funktion `φ(n)`.
|
||||||
|
|
||||||
|
### Anmerkung ###
|
||||||
|
|
||||||
|
Wir haben mal kurz über Editoren für Notizen geredet. Einerseits gibt es Word (iiiiii) und **LaTeX** (schönes Rendering, nicht so schöne Syntax).
|
||||||
|
Dann gibt es immer plaintext. Aber eine Stufe besser ist **Markdown**. Markdown hat die folgenden Vorteile:
|
||||||
|
|
||||||
|
- Nur plaintext Dateien (d.h. keine riesige XML-Objekte im Hintergrund).
|
||||||
|
- Sehr simple Syntax (bspw. `**fett**`, `_kursiv_`, usw.).
|
||||||
|
- **Keine Kompilation** nötig—nur ein guter Renderer.
|
||||||
|
- Komplexe Textformats mit sehr intuitiver Syntax möglich:
|
||||||
|
- Überschriften
|
||||||
|
- Listen
|
||||||
|
- Tabellen. Z. B. man gibt
|
||||||
|
```
|
||||||
|
| Objekt | Kosten | Wert |
|
||||||
|
| :----: | -----: | ---: |
|
||||||
|
| Apfel | 1,30€ | 301 |
|
||||||
|
| Orange | 2€ | 440 |
|
||||||
|
```
|
||||||
|
ein und bekommt
|
||||||
|
|
||||||
|
| Objekt | Kosten | Wert |
|
||||||
|
| :----: | -----: | ---: |
|
||||||
|
| Apfel | 1,30€ | 301 |
|
||||||
|
| Orange | 2€ | 440 |
|
||||||
|
|
||||||
|
raus.
|
||||||
|
- Code Blocks (in diversen Sprachen). Z. B. man gibt
|
||||||
|
```
|
||||||
|
'''java
|
||||||
|
public class HelloWorld {
|
||||||
|
public static void main (String[] args) {
|
||||||
|
System.out.println("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
```
|
||||||
|
(mit Backticks statt `'''`) und bekommt
|
||||||
|
```java
|
||||||
|
public class HelloWorld {
|
||||||
|
public static void main (String[] args) {
|
||||||
|
System.out.println("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
raus.
|
||||||
|
|
||||||
|
- URIs
|
||||||
|
- interne Verlinkungen!
|
||||||
|
- sogar Mathe-Formeln mit (simplem) LaTeX-Code
|
||||||
|
|
||||||
|
Man braucht lediglich einen Renderer für Vorschau-Zwecken.
|
||||||
|
Hier ein paar Empfehlungen:
|
||||||
|
|
||||||
|
- VSCode + passende markdown Extensions (alles gratis)
|
||||||
|
- Typora (nicht gratis, aber für mich hat es sich gelohnt). Siehe bspw. <https://support.typora.io/Math>. Der Editor rendert sogar LaTeX-Formeln, und hat einen WYSIWYG-Modus.
|
||||||
|
- online Editoren wie
|
||||||
|
- https://cryptpad.linxx.net -> Markdown-Folien
|
||||||
|
- https://dillinger.io
|
||||||
|
- In Git-Repos (wie dieser hier!) werden **md**-Dateien automatisch gerendert!
|
||||||
|
|
||||||
|
### Nächste Woche/n ###
|
||||||
|
|
||||||
|
- Keine Übung, sondern die Klausur! Viel Erfolg!
|
||||||
Reference in New Issue
Block a user