Postprocessing
This module provides operations for validation structures and correcting invalid ones.
Postprocessor
- class gefest.core.opt.postproc.resolve_errors.Postrocessor[source]
Bases:
objectImplements 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:
objectInterface 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:
objectInterface of postprocessing rule for whole structure.
Provides validation and correction functions for spicific error, e.g. ‘polygons in structure too close’.
Rules
Collection of default rules.
- class gefest.core.opt.postproc.rules.PolygonsNotTooClose[source]
Bases:
StructureRuleValidated distance between polygons.
- class gefest.core.opt.postproc.rules.PointsNotTooClose[source]
Bases:
PolygonRuleValidated length of polygon edges.
- class gefest.core.opt.postproc.rules.PolygonNotOverlapsProhibited[source]
Bases:
PolygonRuleValidates polygon overlapping other objects.
- class gefest.core.opt.postproc.rules.PolygonGeometryIsValid[source]
Bases:
PolygonRuleValidates polygon geometry.
A polygon is invalid if its geometry does not match the geometry of the domain.
- class gefest.core.opt.postproc.rules.PolygonNotOutOfBounds[source]
Bases:
PolygonRuleOut of bounds rule. Polygon invalid if it out of bounds.
- class gefest.core.opt.postproc.rules.PolygonNotSelfIntersects[source]
Bases:
PolygonRuleSelfintersection rule. Polygon invalid if it have selfintersections.
- class gefest.core.opt.postproc.rules.Rules(value)[source]
Bases:
EnumEnumeration 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:
structure (Structure) – Structure.
rules (list[Union[StructureRule, PolygonRule]]) – Validation rules.
domain (Domain) – Task domain.
- Returns:
True if valid else False
- Return type:
bool