Postprocessing

This module provides operations for validation structures and correcting invalid ones.

Postprocessor

class gefest.core.opt.postproc.resolve_errors.Postrocessor[source]

Bases: object

Implements logic of structures postprocessing.

static apply_postprocess(structures: Structure | list[Structure], rules: list[StructureRule | PolygonRule], domain: Domain, attempts: int = 3) list[Structure | None][source]

Applys postprocessing rules over all provided structures.

static postprocess_structure(structure: Structure, rules: list[StructureRule | PolygonRule], domain: Domain, attempts: int = 3) Structure | None[source]

Apply postprocessing rules to structure.

Parameters:
  • structure (Structure) – Structure for postprocessing.

  • rules (list[Union[StructureRule, PolygonRule]]) – Postprocessing rules, which expect whole structure or particular polygon for check. This interfaces have check() and corerect() methods.

  • domain (Domain) – domain

  • attempts (int, optional) – Number of attempths to fix errors. Defaults to 3.

Returns:

If structure valid according to the rules,

correct stucture will be returned, else None.

Return type:

Union[Structure, None]

Base rule classes

All new rules shoud use one of this classes as parent.

class gefest.core.opt.postproc.rules_base.PolygonRule[source]

Bases: object

Interface of postprocessing rule for polygon.

Provides validation and correction functions for spicific error, e.g. ‘out of bounds’, ‘self intersection’, ‘unclosed polygon’.

abstract static validate(structure: Structure, idx_poly_with_error: int, domain: Domain) bool[source]

Checks if there is no error in the spicific polygon in structure.

Parameters:
  • structure (Structure) – Structure with error.

  • idx (int) – Index of polygon with error in structure.

Returns:

True if polygon has no spicific problem,

otherwise False.

Return type:

bool

abstract static correct(structure: Structure, idx_poly_with_error: int, domain: Domain) Polygon[source]

Trys to fix spicific error.

The method does not guarantee error correction.

Parameters:
  • structure (Structure) – Structure with error.

  • idx_poly_with_error (int) – Index of polygon with error in structure.

Returns:

Polygon

class gefest.core.opt.postproc.rules_base.StructureRule[source]

Bases: object

Interface of postprocessing rule for whole structure.

Provides validation and correction functions for spicific error, e.g. ‘polygons in structure too close’.

abstract static validate(structure: Structure, domain: Domain) bool[source]

Checks if there is no error in the structure.

Parameters:

structure (Structure) – Structure for validation.

Returns:

True if structure has no spicific problem,

otherwise False.

Return type:

bool

abstract static correct(structure: Structure, domain: Domain) Structure[source]

Trys to fix spicific error.

The method does not guarantee error correction.

Parameters:

structure (Structure) – Structure with error.

Returns:

Structure

Rules

Collection of default rules.

class gefest.core.opt.postproc.rules.PolygonsNotTooClose[source]

Bases: StructureRule

Validated distance between polygons.

static validate(struct: Structure, domain: Domain) bool[source]

Checks distances between polgons.

static correct(struct: Structure, domain: Domain) Structure[source]

Removes one of polygons that are closer than the specified threshold.

class gefest.core.opt.postproc.rules.PointsNotTooClose[source]

Bases: PolygonRule

Validated length of polygon edges.

static validate(structure: Structure, idx_poly_with_error: int, domain: Domain) bool[source]

Checks if each Point in Polygon are placed in valid distance by previous.

Parameters:

structure – the Structure that explore

Returns:

True if any side of poly have incorrect lenght, otherwise - False

static correct(structure: Structure, idx_poly_with_error: int, domain: Domain) Polygon[source]

Corrects polygon.

class gefest.core.opt.postproc.rules.PolygonNotOverlapsProhibited[source]

Bases: PolygonRule

Validates polygon overlapping other objects.

static validate(structure: Structure, idx_poly_with_error: int, domain: Domain) bool[source]

Checks if polygon overlaps other polygons or prohibits.

static correct(structure: Structure, idx_poly_with_error: int, domain: Domain) Polygon[source]

Corrects polygon overlaps.

class gefest.core.opt.postproc.rules.PolygonGeometryIsValid[source]

Bases: PolygonRule

Validates polygon geometry.

A polygon is invalid if its geometry does not match the geometry of the domain.

static validate(structure: Structure, idx_poly_with_error: int, domain: Domain) bool[source]

Validates polygon geometry.

static correct(structure: Structure, idx_poly_with_error: int, domain: Domain) Polygon[source]

Corrects polygon geometry.

class gefest.core.opt.postproc.rules.PolygonNotOutOfBounds[source]

Bases: PolygonRule

Out of bounds rule. Polygon invalid if it out of bounds.

static validate(structure: Structure, idx_poly_with_error: int, domain: Domain) bool[source]

Checks if polygon is out of domain bounds.

static correct(structure: Structure, idx_poly_with_error: int, domain: Domain) Polygon[source]

Corrects out of bound polygon.

class gefest.core.opt.postproc.rules.PolygonNotSelfIntersects[source]

Bases: PolygonRule

Selfintersection rule. Polygon invalid if it have selfintersections.

static validate(structure: Structure, idx_poly_with_error: int, domain: Domain) bool[source]

Validates polygon for selfintersection.

static correct(structure: Structure, idx_poly_with_error: int, domain: Domain) Polygon[source]

Corrects selfintersection in polygon.

class gefest.core.opt.postproc.rules.Rules(value)[source]

Bases: Enum

Enumeration of all defined rules.

not_too_close_polygons = <gefest.core.opt.postproc.rules.PolygonsNotTooClose object>
valid_polygon_geom = <gefest.core.opt.postproc.rules.PolygonGeometryIsValid object>
not_out_of_bounds = <gefest.core.opt.postproc.rules.PolygonNotOutOfBounds object>
not_self_intersects = <gefest.core.opt.postproc.rules.PolygonNotSelfIntersects object>
not_overlaps_prohibited = <gefest.core.opt.postproc.rules.PolygonNotOverlapsProhibited object>
not_too_close_points = <gefest.core.opt.postproc.rules.PointsNotTooClose object>

Validation

Util for run validation part of rules.

gefest.core.opt.postproc.validation.validate(structure: Structure, rules: list[StructureRule | PolygonRule], domain: Domain) bool[source]

Validates single structure.

Parameters:
Returns:

True if valid else False

Return type:

bool