genplanner.ZoneRelationMatrix

class genplanner.ZoneRelationMatrix(zones, _m)[source]

Symmetric matrix of relations between zones. Access is O(1). Default relation is NEUTRAL.

Symmetry invariant:

_m[a][b] == _m[b][a] for all a,b

classmethod from_pairs(zones, *, neighbors=(), forbidden=(), default=Relation.NEUTRAL)[source]

Build from explicit pairs. Input pairs may be non-symmetric — matrix will be symmetric internally anyway.

classmethod from_dataframe(df, *, value_map=None, default=Relation.NEUTRAL, require_symmetric=True)[source]

df must be square.

Requirements: - df.index contains Zone objects - df.columns contains Zone objects - set(index) == set(columns) - (optional) matrix must be symmetric (after mapping values)

with_pairs(pairs, rel)[source]

Applies pairs and enforces symmetry: (a,b) and (b,a) both set to rel.

subset(zones, *, strict=False)[source]

Return a new matrix restricted to the provided zones (if present in this matrix).

  • If strict=False: silently ignores zones not found in current matrix.

  • If strict=True: raises KeyError if any provided zone is missing.

as_dataframe()[source]

Returns a DataFrame with Zone objects as both index and columns.

values:
  • “enum”: Relation enum objects

  • “value”: Relation.value strings