woche12 > master: code py - vorberechnungen gemäß modell
This commit is contained in:
@@ -27,16 +27,23 @@ __all__ = [
|
||||
|
||||
class Landscape():
|
||||
_fct: np.ndarray;
|
||||
_labels: list[str];
|
||||
_metric: EnumLandscapeMetric;
|
||||
_radius: float;
|
||||
_one_based: bool;
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
values: DataTypeLandscapeValues,
|
||||
labels: List[str],
|
||||
metric: EnumLandscapeMetric = EnumLandscapeMetric.maximum,
|
||||
one_based: bool = False,
|
||||
):
|
||||
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._one_based = one_based;
|
||||
return;
|
||||
|
||||
@property
|
||||
@@ -47,14 +54,27 @@ class Landscape():
|
||||
def dim(self) -> int:
|
||||
return len(self._fct.shape);
|
||||
|
||||
@property
|
||||
def coords_middle(self) -> tuple:
|
||||
return tuple(math.floor(s/2) for s in self.shape);
|
||||
|
||||
def fitness(self, *x: int) -> float:
|
||||
return self._fct[x];
|
||||
|
||||
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]:
|
||||
r = int(r);
|
||||
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 + 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) ]
|
||||
for xx, s in zip(x, self.shape)
|
||||
];
|
||||
match self._metric:
|
||||
|
||||
Reference in New Issue
Block a user