Strategies

StrategyInput dataclass

Represents the input data structure for a strategy.

reinforcement_min_cluster: int property

Returns the minimum length of a reinforcement type along a traject, usually named as cluster throughout the code.

Returns:

Name Type Description
int int

Total length

StrategyLocationInput dataclass

available_measures: list[type[ReinforcementProfileProtocol]] property

Gets all the available reinforcement types in strategy_location_reinforcements. It is called available_measures to match the StrategyLocationReinforcement definition.

Returns:

Type Description
list[type[ReinforcementProfileProtocol]]

list[Type[ReinforcementProfileProtocol]]: resulting list.

cheapest_reinforcement: StrategyReinforcementTypeCosts property

Gets the StrategyLocationReinforcementCosts with the lowest total_costs_with_surtax value.

Returns:

Name Type Description
StrategyLocationReinforcementCosts StrategyReinforcementTypeCosts

The cheapest reinforcement for this location.

get_infrastructure_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> tuple[float, float]

Get the infrastructure costs for the given reinforcement type.

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

The reinforcement type.

required

Raises:

Type Description
ValueError

The reinforcement type is not available.

Returns:

Type Description
tuple[float, float]

tuple[float, float]: Tuple containing the infrastructure costs without and with surtax.

get_reinforcement_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> float

Get the costs for the given reinforcement type.

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

The reinforcement type.

required

Raises:

Type Description
ValueError

The reinforcement type is not available.

Returns:

Name Type Description
float float

The reinforcement costs with surtax.

PointSurroundings dataclass

Object representing a meter with x, y coordinates in a polder (or else).

__eq__(__value: object) -> bool

Overriding of the "magic" equality operator required so that PointSurroundings can be used as a key in a python dict.

__hash__() -> int

Overriding of the "magic" hash operator required so that PointSurroundings can be used as a key in a python dict.

closest_obstacle: float property

Distance to the closest (obstacle) surrounding. When no surroundings are given the value will be NaN (Not A Number), so that the value 0 is reserved for buildings at distance 0.

Returns:

Name Type Description
float float

Distance to the closest surrounding.

get_total_infrastructure_per_zone(*zone_limit_collection: tuple[float, float]) -> list[float]

Gets the total infrastructure width at each of the provided zones zone_limit_collection (tuple[float, float]). The zone limits are matched by rounding up their upper limit to the surroundings_matrix keys (distances to the location in the real world). When two zones have overlapping limits (as expected) the lower one will "claim" the corresponding surrounding distance.

Example
  • zone_limit_collection = (0, 4), (4, 11)
  • surroundings_matrix = {5: 1.5, 10: 3, 15: 6}
  • "Taken" distances per zone:
    • (0, 4) takes key 5.
    • (4, 11) takes key(s) 10 and 15 because 5 was already taken.
  • Total infrastructure width at zones = (1.5, 9)

Returns:

Type Description
list[float]

list[float]: list with total width corresponding to each provided zone.

ReinforcementProfileProtocol

Bases: KoswatProfileProtocol, Protocol

Extension of the KoswatProfileProtocol to define the properties of a calculated reinforcement.

StrategyLocationInput dataclass

available_measures: list[type[ReinforcementProfileProtocol]] property

Gets all the available reinforcement types in strategy_location_reinforcements. It is called available_measures to match the StrategyLocationReinforcement definition.

Returns:

Type Description
list[type[ReinforcementProfileProtocol]]

list[Type[ReinforcementProfileProtocol]]: resulting list.

cheapest_reinforcement: StrategyReinforcementTypeCosts property

Gets the StrategyLocationReinforcementCosts with the lowest total_costs_with_surtax value.

Returns:

Name Type Description
StrategyLocationReinforcementCosts StrategyReinforcementTypeCosts

The cheapest reinforcement for this location.

get_infrastructure_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> tuple[float, float]

Get the infrastructure costs for the given reinforcement type.

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

The reinforcement type.

required

Raises:

Type Description
ValueError

The reinforcement type is not available.

Returns:

Type Description
tuple[float, float]

tuple[float, float]: Tuple containing the infrastructure costs without and with surtax.

get_reinforcement_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> float

Get the costs for the given reinforcement type.

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

The reinforcement type.

required

Raises:

Type Description
ValueError

The reinforcement type is not available.

Returns:

Name Type Description
float float

The reinforcement costs with surtax.

StrategyReinforcementTypeCosts dataclass

total_costs_with_surtax: float property

The simple addition of the base costs and the possible related infrastructure costs, both including surtax.

Returns:

Name Type Description
float float

The total costs with surtax when applying this reinforcement.

PointSurroundings dataclass

Object representing a meter with x, y coordinates in a polder (or else).

__eq__(__value: object) -> bool

Overriding of the "magic" equality operator required so that PointSurroundings can be used as a key in a python dict.

__hash__() -> int

Overriding of the "magic" hash operator required so that PointSurroundings can be used as a key in a python dict.

closest_obstacle: float property

Distance to the closest (obstacle) surrounding. When no surroundings are given the value will be NaN (Not A Number), so that the value 0 is reserved for buildings at distance 0.

Returns:

Name Type Description
float float

Distance to the closest surrounding.

get_total_infrastructure_per_zone(*zone_limit_collection: tuple[float, float]) -> list[float]

Gets the total infrastructure width at each of the provided zones zone_limit_collection (tuple[float, float]). The zone limits are matched by rounding up their upper limit to the surroundings_matrix keys (distances to the location in the real world). When two zones have overlapping limits (as expected) the lower one will "claim" the corresponding surrounding distance.

Example
  • zone_limit_collection = (0, 4), (4, 11)
  • surroundings_matrix = {5: 1.5, 10: 3, 15: 6}
  • "Taken" distances per zone:
    • (0, 4) takes key 5.
    • (4, 11) takes key(s) 10 and 15 because 5 was already taken.
  • Total infrastructure width at zones = (1.5, 9)

Returns:

Type Description
list[float]

list[float]: list with total width corresponding to each provided zone.

ReinforcementProfileProtocol

Bases: KoswatProfileProtocol, Protocol

Extension of the KoswatProfileProtocol to define the properties of a calculated reinforcement.

StrategyLocationInput dataclass

available_measures: list[type[ReinforcementProfileProtocol]] property

Gets all the available reinforcement types in strategy_location_reinforcements. It is called available_measures to match the StrategyLocationReinforcement definition.

Returns:

Type Description
list[type[ReinforcementProfileProtocol]]

list[Type[ReinforcementProfileProtocol]]: resulting list.

cheapest_reinforcement: StrategyReinforcementTypeCosts property

Gets the StrategyLocationReinforcementCosts with the lowest total_costs_with_surtax value.

Returns:

Name Type Description
StrategyLocationReinforcementCosts StrategyReinforcementTypeCosts

The cheapest reinforcement for this location.

get_infrastructure_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> tuple[float, float]

Get the infrastructure costs for the given reinforcement type.

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

The reinforcement type.

required

Raises:

Type Description
ValueError

The reinforcement type is not available.

Returns:

Type Description
tuple[float, float]

tuple[float, float]: Tuple containing the infrastructure costs without and with surtax.

get_reinforcement_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> float

Get the costs for the given reinforcement type.

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

The reinforcement type.

required

Raises:

Type Description
ValueError

The reinforcement type is not available.

Returns:

Name Type Description
float float

The reinforcement costs with surtax.

StrategyLocationReinforcement dataclass

Represents a location and the different reinforcements that can be applied to it as well their costs. This class is used to show the final chosen state for a location.

current_cost: float property

Estimates the costs with surtax at this location for the given current_selected_measure.

current_selected_measure: type[ReinforcementProfileProtocol] property

Exposes the current selected measure for this object.

get_infrastructure_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> tuple[float, float]

Returns the infrastructure costs for the given reinforcement type (without and with surtax).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type.

required

Returns:

Type Description
tuple[float, float]

tuple[float, float]: Tuple containing the infrastructure costs without and with surtax.

get_selected_measure_steps() -> tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

Outputs the selected measure following the domain (expected) steps: - Initial step, - Order step, - Infrastructure step

Returns:

Type Description
tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

tuple[ type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]: Resulting tuple.

set_selected_measure(reinforcement_type: type[ReinforcementProfileProtocol], step: StrategyStepEnum)

Changes the value reprsented in current_selected_measure and updates the dictionary of selections (history).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type

required
step StrategyStepsEnum

Step whose

required

StrategyReinforcementTypeCosts dataclass

total_costs_with_surtax: float property

The simple addition of the base costs and the possible related infrastructure costs, both including surtax.

Returns:

Name Type Description
float float

The total costs with surtax when applying this reinforcement.

ReinforcementProfileProtocol

Bases: KoswatProfileProtocol, Protocol

Extension of the KoswatProfileProtocol to define the properties of a calculated reinforcement.

ReinforcementProfileProtocol

Bases: KoswatProfileProtocol, Protocol

Extension of the KoswatProfileProtocol to define the properties of a calculated reinforcement.

StrategyReinforcementTypeCosts dataclass

total_costs_with_surtax: float property

The simple addition of the base costs and the possible related infrastructure costs, both including surtax.

Returns:

Name Type Description
float float

The total costs with surtax when applying this reinforcement.

StrategyInput dataclass

Represents the input data structure for a strategy.

reinforcement_min_cluster: int property

Returns the minimum length of a reinforcement type along a traject, usually named as cluster throughout the code.

Returns:

Name Type Description
int int

Total length

StrategyOutput dataclass

Represents the output data structure for a strategy.

StrategyProtocol

Bases: Protocol

apply_strategy(strategy_input: StrategyInput) -> StrategyOutput

Applies a specific strategy by matching each location (PointSurroundings) to a valid reinforcement type (ReinforcementProfileProtocol).

Parameters:

Name Type Description Default
strategy_input `StrategyInput`

Input data structure containing locations and available reinforcements for each of them.

required

Returns:

Name Type Description
StrategyOutput StrategyOutput

Output data structure containing the selected reinforcements for each location.

Order Strategy

OrderStrategy

Bases: StrategyProtocol

get_default_order_for_reinforcements() -> list[type[ReinforcementProfileProtocol]] staticmethod

Give the default order for reinforcements types, assuming they are sorted from cheapest to most expensive and least to most restrictive.

Returns:

Type Description
list[type[ReinforcementProfileProtocol]]

list[type[ReinforcementProfileProtocol]]: list of reinforcement types

get_strategy_order_for_reinforcements(strategy_reinforcements: list[StrategyReinforcementInput]) -> list[type[ReinforcementProfileProtocol]]

Give the ordered reinforcement types for this strategy, from cheapest to most expensive, possibly removing reinforcement types that are more expensive and more restrictive than others. Cofferdam should always be the last reinforcement type.

Input

strategy_reinforcements (list[StrategyReinforcementInput]): list of reinforcement types with costs and surface

Returns:

Type Description
list[type[ReinforcementProfileProtocol]]

list[type[ReinforcementProfileProtocol]]: list of reinforcement types

get_strategy_reinforcements(strategy_locations: list[StrategyLocationInput], selection_order: list[type[ReinforcementProfileProtocol]]) -> list[StrategyLocationReinforcement] staticmethod

Gets the strategy representation of the locations with their available measures ordered filtered and order by the provided selection_order. It also sets their initial state.

Parameters:

Name Type Description Default
strategy_locations list[StrategyLocationInput]

Locations to map into reinforcement locations.

required
selection_order list[type[ReinforcementProfileProtocol]]

Priority order to assign a reinforcement.

required

Returns:

Type Description
list[StrategyLocationReinforcement]

list[StrategyLocationReinforcement]: Mapped location reinforcements.

OrderStrategyBuffering dataclass

Bases: OrderStrategyBase

Applies buffering, through masks, to each location's pre-assigned reinforcement. The result of the apply method will be the locations with the best reinforcement fit (lowest index from reinforcement_order) that fulfills the reinforcement_min_buffer requirement.

OrderStrategyClustering dataclass

Bases: OrderStrategyBase

Applies clustering, to the whole collection of reinforcements (location_reinforcements: list[StrategyLocationReinforcement]). The result of the apply method will be the locations with the best reinforcement fit (lowest index from reinforcement_order) that fulfills the reinforcement_min_length requirement.

ReinforcementProfileProtocol

Bases: KoswatProfileProtocol, Protocol

Extension of the KoswatProfileProtocol to define the properties of a calculated reinforcement.

StrategyInput dataclass

Represents the input data structure for a strategy.

reinforcement_min_cluster: int property

Returns the minimum length of a reinforcement type along a traject, usually named as cluster throughout the code.

Returns:

Name Type Description
int int

Total length

StrategyLocationInput dataclass

available_measures: list[type[ReinforcementProfileProtocol]] property

Gets all the available reinforcement types in strategy_location_reinforcements. It is called available_measures to match the StrategyLocationReinforcement definition.

Returns:

Type Description
list[type[ReinforcementProfileProtocol]]

list[Type[ReinforcementProfileProtocol]]: resulting list.

cheapest_reinforcement: StrategyReinforcementTypeCosts property

Gets the StrategyLocationReinforcementCosts with the lowest total_costs_with_surtax value.

Returns:

Name Type Description
StrategyLocationReinforcementCosts StrategyReinforcementTypeCosts

The cheapest reinforcement for this location.

get_infrastructure_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> tuple[float, float]

Get the infrastructure costs for the given reinforcement type.

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

The reinforcement type.

required

Raises:

Type Description
ValueError

The reinforcement type is not available.

Returns:

Type Description
tuple[float, float]

tuple[float, float]: Tuple containing the infrastructure costs without and with surtax.

get_reinforcement_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> float

Get the costs for the given reinforcement type.

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

The reinforcement type.

required

Raises:

Type Description
ValueError

The reinforcement type is not available.

Returns:

Name Type Description
float float

The reinforcement costs with surtax.

StrategyLocationReinforcement dataclass

Represents a location and the different reinforcements that can be applied to it as well their costs. This class is used to show the final chosen state for a location.

current_cost: float property

Estimates the costs with surtax at this location for the given current_selected_measure.

current_selected_measure: type[ReinforcementProfileProtocol] property

Exposes the current selected measure for this object.

get_infrastructure_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> tuple[float, float]

Returns the infrastructure costs for the given reinforcement type (without and with surtax).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type.

required

Returns:

Type Description
tuple[float, float]

tuple[float, float]: Tuple containing the infrastructure costs without and with surtax.

get_selected_measure_steps() -> tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

Outputs the selected measure following the domain (expected) steps: - Initial step, - Order step, - Infrastructure step

Returns:

Type Description
tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

tuple[ type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]: Resulting tuple.

set_selected_measure(reinforcement_type: type[ReinforcementProfileProtocol], step: StrategyStepEnum)

Changes the value reprsented in current_selected_measure and updates the dictionary of selections (history).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type

required
step StrategyStepsEnum

Step whose

required

StrategyOutput dataclass

Represents the output data structure for a strategy.

StrategyProtocol

Bases: Protocol

apply_strategy(strategy_input: StrategyInput) -> StrategyOutput

Applies a specific strategy by matching each location (PointSurroundings) to a valid reinforcement type (ReinforcementProfileProtocol).

Parameters:

Name Type Description Default
strategy_input `StrategyInput`

Input data structure containing locations and available reinforcements for each of them.

required

Returns:

Name Type Description
StrategyOutput StrategyOutput

Output data structure containing the selected reinforcements for each location.

ReinforcementProfileProtocol

Bases: KoswatProfileProtocol, Protocol

Extension of the KoswatProfileProtocol to define the properties of a calculated reinforcement.

StrategyLocationReinforcement dataclass

Represents a location and the different reinforcements that can be applied to it as well their costs. This class is used to show the final chosen state for a location.

current_cost: float property

Estimates the costs with surtax at this location for the given current_selected_measure.

current_selected_measure: type[ReinforcementProfileProtocol] property

Exposes the current selected measure for this object.

get_infrastructure_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> tuple[float, float]

Returns the infrastructure costs for the given reinforcement type (without and with surtax).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type.

required

Returns:

Type Description
tuple[float, float]

tuple[float, float]: Tuple containing the infrastructure costs without and with surtax.

get_selected_measure_steps() -> tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

Outputs the selected measure following the domain (expected) steps: - Initial step, - Order step, - Infrastructure step

Returns:

Type Description
tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

tuple[ type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]: Resulting tuple.

set_selected_measure(reinforcement_type: type[ReinforcementProfileProtocol], step: StrategyStepEnum)

Changes the value reprsented in current_selected_measure and updates the dictionary of selections (history).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type

required
step StrategyStepsEnum

Step whose

required

OrderStrategyBuffering dataclass

Bases: OrderStrategyBase

Applies buffering, through masks, to each location's pre-assigned reinforcement. The result of the apply method will be the locations with the best reinforcement fit (lowest index from reinforcement_order) that fulfills the reinforcement_min_buffer requirement.

ReinforcementProfileProtocol

Bases: KoswatProfileProtocol, Protocol

Extension of the KoswatProfileProtocol to define the properties of a calculated reinforcement.

StrategyLocationReinforcement dataclass

Represents a location and the different reinforcements that can be applied to it as well their costs. This class is used to show the final chosen state for a location.

current_cost: float property

Estimates the costs with surtax at this location for the given current_selected_measure.

current_selected_measure: type[ReinforcementProfileProtocol] property

Exposes the current selected measure for this object.

get_infrastructure_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> tuple[float, float]

Returns the infrastructure costs for the given reinforcement type (without and with surtax).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type.

required

Returns:

Type Description
tuple[float, float]

tuple[float, float]: Tuple containing the infrastructure costs without and with surtax.

get_selected_measure_steps() -> tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

Outputs the selected measure following the domain (expected) steps: - Initial step, - Order step, - Infrastructure step

Returns:

Type Description
tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

tuple[ type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]: Resulting tuple.

set_selected_measure(reinforcement_type: type[ReinforcementProfileProtocol], step: StrategyStepEnum)

Changes the value reprsented in current_selected_measure and updates the dictionary of selections (history).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type

required
step StrategyStepsEnum

Step whose

required

OrderCluster dataclass

extend_cluster(other: OrderCluster)

Extends the current cluster with the reinforcements (list[StrategyLocationReinforcement]) from another cluster. Modifies the current_selected_measure property of those measures being merged but it does not remove them from their source cluster.

Parameters:

Name Type Description Default
other OrderCluster

Cluster whose contents will be used to extend self.

required

Raises:

Type Description
ValueError

When trying to extend from an unrelated cluster.

get_stronger_cluster() -> OrderCluster

Gets the neighbor with the lowest reinforcement type value greater than the current cluster's value (self.reinforcement_idx).

Returns:

Name Type Description
OrderCluster OrderCluster

Neighbor with a stronger ReinforcementProfileProtocol.

is_compliant(min_length: float, strongest_reinforcement: int) -> bool

Checks whether this OrderCluster instance is compliant within a cluster group. This method does not check for exceptions, such as, the cluster's neighbors are of lower strength than the current.

Parameters:

Name Type Description Default
min_length float

Minimal length a reinforcement measure is required for a cluster.

required
strongest_reinforcement int

What is the reinforcement index which cannot be futher 'strengthen'.

required

Returns:

Name Type Description
bool bool

if the cluster is compliant within its neighbors context.

OrderStrategyClustering dataclass

Bases: OrderStrategyBase

Applies clustering, to the whole collection of reinforcements (location_reinforcements: list[StrategyLocationReinforcement]). The result of the apply method will be the locations with the best reinforcement fit (lowest index from reinforcement_order) that fulfills the reinforcement_min_length requirement.

ReinforcementProfileProtocol

Bases: KoswatProfileProtocol, Protocol

Extension of the KoswatProfileProtocol to define the properties of a calculated reinforcement.

StrategyLocationReinforcement dataclass

Represents a location and the different reinforcements that can be applied to it as well their costs. This class is used to show the final chosen state for a location.

current_cost: float property

Estimates the costs with surtax at this location for the given current_selected_measure.

current_selected_measure: type[ReinforcementProfileProtocol] property

Exposes the current selected measure for this object.

get_infrastructure_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> tuple[float, float]

Returns the infrastructure costs for the given reinforcement type (without and with surtax).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type.

required

Returns:

Type Description
tuple[float, float]

tuple[float, float]: Tuple containing the infrastructure costs without and with surtax.

get_selected_measure_steps() -> tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

Outputs the selected measure following the domain (expected) steps: - Initial step, - Order step, - Infrastructure step

Returns:

Type Description
tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

tuple[ type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]: Resulting tuple.

set_selected_measure(reinforcement_type: type[ReinforcementProfileProtocol], step: StrategyStepEnum)

Changes the value reprsented in current_selected_measure and updates the dictionary of selections (history).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type

required
step StrategyStepsEnum

Step whose

required

OrderCluster dataclass

extend_cluster(other: OrderCluster)

Extends the current cluster with the reinforcements (list[StrategyLocationReinforcement]) from another cluster. Modifies the current_selected_measure property of those measures being merged but it does not remove them from their source cluster.

Parameters:

Name Type Description Default
other OrderCluster

Cluster whose contents will be used to extend self.

required

Raises:

Type Description
ValueError

When trying to extend from an unrelated cluster.

get_stronger_cluster() -> OrderCluster

Gets the neighbor with the lowest reinforcement type value greater than the current cluster's value (self.reinforcement_idx).

Returns:

Name Type Description
OrderCluster OrderCluster

Neighbor with a stronger ReinforcementProfileProtocol.

is_compliant(min_length: float, strongest_reinforcement: int) -> bool

Checks whether this OrderCluster instance is compliant within a cluster group. This method does not check for exceptions, such as, the cluster's neighbors are of lower strength than the current.

Parameters:

Name Type Description Default
min_length float

Minimal length a reinforcement measure is required for a cluster.

required
strongest_reinforcement int

What is the reinforcement index which cannot be futher 'strengthen'.

required

Returns:

Name Type Description
bool bool

if the cluster is compliant within its neighbors context.

StrategyLocationReinforcement dataclass

Represents a location and the different reinforcements that can be applied to it as well their costs. This class is used to show the final chosen state for a location.

current_cost: float property

Estimates the costs with surtax at this location for the given current_selected_measure.

current_selected_measure: type[ReinforcementProfileProtocol] property

Exposes the current selected measure for this object.

get_infrastructure_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> tuple[float, float]

Returns the infrastructure costs for the given reinforcement type (without and with surtax).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type.

required

Returns:

Type Description
tuple[float, float]

tuple[float, float]: Tuple containing the infrastructure costs without and with surtax.

get_selected_measure_steps() -> tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

Outputs the selected measure following the domain (expected) steps: - Initial step, - Order step, - Infrastructure step

Returns:

Type Description
tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

tuple[ type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]: Resulting tuple.

set_selected_measure(reinforcement_type: type[ReinforcementProfileProtocol], step: StrategyStepEnum)

Changes the value reprsented in current_selected_measure and updates the dictionary of selections (history).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type

required
step StrategyStepsEnum

Step whose

required

Infra Priority Strategy

InfraCluster dataclass

This dataclass represents the subset of locations sharing the same reinforcement type (type[ReinforcementProfileProtocol]).

current_cost: float property

Calculates the cost of applying the reinforcement_type to all locations present in the cluster.

Returns:

Name Type Description
float float

The total (current) cost of this cluster.

fits_subclusters() -> bool

Validates whether this cluster can be split into subclusters. For that it requires to have at least twice the required length.

Returns:

Name Type Description
bool bool

Whether subclusters can be generated from this one.

is_valid() -> bool

Validates the length of this cluster.

Returns:

Name Type Description
bool bool

The cluster has the minimal required length.

set_cheapest_common_available_measure(measure_costs: dict[type[ReinforcementProfileProtocol], float]) -> None

Updates all the location reinforcements with the cheapest reinforcement type from the measure_costs.

Parameters:

Name Type Description Default
measure_costs dict[type[ReinforcementProfileProtocol]]

dictionary with the total costs per reinforcement type.

required

InfraClusterOption dataclass

Represents one set of subclusters the strategy could select for costs optimization.

add_cluster(infra_cluster: InfraCluster, cluster_costs: dict)

Adds the infra cluster into the collection as well as its reinforcement costs.

Parameters:

Name Type Description Default
infra_cluster InfraCluster

Cluster to add to this collection option.

required
cluster_costs dict

Reinforcement costs for the given cluster.

required

cluster_collection: list[InfraCluster] property

Read-only property to expose the stored subclusters.

cluster_costs: list[dict[ReinforcementProfileProtocol, float]] property

Read-only property to expose the stored costs.

set_cheapest_option()

Sets the subclusters defined in this option to their most optimal (cheapest) reinforcement possible.

valid_option() -> bool

Validates the collection of clusters based on the required minimun length.

Returns:

Name Type Description
bool bool

Validation result.

InfraPriorityStrategy

Bases: StrategyProtocol

This strategy works under the assumption that StrategyLocationReinforcement.available_measures ARE NOT ordered by "compatibility". Thus we need to check first which are the compatible reinforcements per cluster.

generate_subcluster_options(from_cluster: InfraCluster, min_length: int) -> list[list[InfraCluster]] staticmethod

Generates all possible combinations of (sub) clusters based on the locations of this cluster. These are also referred as "options".

Parameters:

Name Type Description Default
min_length int

Minimum length for a cluster to be valid.

required

Returns:

Type Description
list[list[InfraCluster]]

list[list[InfraCluster]]: Collection of "options" with valid length.

get_common_available_measures_costs(infra_cluster: InfraCluster, order_strategy_reinforcements: list[type[ReinforcementProfileProtocol]]) -> dict[type[ReinforcementProfileProtocol], float] staticmethod

Gets a dictionary with the reinforcements available at all locations of the cluster (infra_cluster) as well as their total cost if said reinforcement is applied at them.

Parameters:

Name Type Description Default
infra_cluster InfraCluster

Cluster being analyzed.

required
order_strategy_reinforcements list[type[ReinforcementProfileProtocol]]

Reinforcements ordered by base cost (ground surface).

required

Returns:

Type Description
dict[type[ReinforcementProfileProtocol], float]

dict[type[ReinforcementProfileProtocol], float]: Resulting reinforcement type - costs dictionary.

OrderStrategy

Bases: StrategyProtocol

get_default_order_for_reinforcements() -> list[type[ReinforcementProfileProtocol]] staticmethod

Give the default order for reinforcements types, assuming they are sorted from cheapest to most expensive and least to most restrictive.

Returns:

Type Description
list[type[ReinforcementProfileProtocol]]

list[type[ReinforcementProfileProtocol]]: list of reinforcement types

get_strategy_order_for_reinforcements(strategy_reinforcements: list[StrategyReinforcementInput]) -> list[type[ReinforcementProfileProtocol]]

Give the ordered reinforcement types for this strategy, from cheapest to most expensive, possibly removing reinforcement types that are more expensive and more restrictive than others. Cofferdam should always be the last reinforcement type.

Input

strategy_reinforcements (list[StrategyReinforcementInput]): list of reinforcement types with costs and surface

Returns:

Type Description
list[type[ReinforcementProfileProtocol]]

list[type[ReinforcementProfileProtocol]]: list of reinforcement types

get_strategy_reinforcements(strategy_locations: list[StrategyLocationInput], selection_order: list[type[ReinforcementProfileProtocol]]) -> list[StrategyLocationReinforcement] staticmethod

Gets the strategy representation of the locations with their available measures ordered filtered and order by the provided selection_order. It also sets their initial state.

Parameters:

Name Type Description Default
strategy_locations list[StrategyLocationInput]

Locations to map into reinforcement locations.

required
selection_order list[type[ReinforcementProfileProtocol]]

Priority order to assign a reinforcement.

required

Returns:

Type Description
list[StrategyLocationReinforcement]

list[StrategyLocationReinforcement]: Mapped location reinforcements.

ReinforcementProfileProtocol

Bases: KoswatProfileProtocol, Protocol

Extension of the KoswatProfileProtocol to define the properties of a calculated reinforcement.

StrategyInput dataclass

Represents the input data structure for a strategy.

reinforcement_min_cluster: int property

Returns the minimum length of a reinforcement type along a traject, usually named as cluster throughout the code.

Returns:

Name Type Description
int int

Total length

StrategyLocationReinforcement dataclass

Represents a location and the different reinforcements that can be applied to it as well their costs. This class is used to show the final chosen state for a location.

current_cost: float property

Estimates the costs with surtax at this location for the given current_selected_measure.

current_selected_measure: type[ReinforcementProfileProtocol] property

Exposes the current selected measure for this object.

get_infrastructure_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> tuple[float, float]

Returns the infrastructure costs for the given reinforcement type (without and with surtax).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type.

required

Returns:

Type Description
tuple[float, float]

tuple[float, float]: Tuple containing the infrastructure costs without and with surtax.

get_selected_measure_steps() -> tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

Outputs the selected measure following the domain (expected) steps: - Initial step, - Order step, - Infrastructure step

Returns:

Type Description
tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

tuple[ type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]: Resulting tuple.

set_selected_measure(reinforcement_type: type[ReinforcementProfileProtocol], step: StrategyStepEnum)

Changes the value reprsented in current_selected_measure and updates the dictionary of selections (history).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type

required
step StrategyStepsEnum

Step whose

required

StrategyOutput dataclass

Represents the output data structure for a strategy.

StrategyProtocol

Bases: Protocol

apply_strategy(strategy_input: StrategyInput) -> StrategyOutput

Applies a specific strategy by matching each location (PointSurroundings) to a valid reinforcement type (ReinforcementProfileProtocol).

Parameters:

Name Type Description Default
strategy_input `StrategyInput`

Input data structure containing locations and available reinforcements for each of them.

required

Returns:

Name Type Description
StrategyOutput StrategyOutput

Output data structure containing the selected reinforcements for each location.

InfraCluster dataclass

This dataclass represents the subset of locations sharing the same reinforcement type (type[ReinforcementProfileProtocol]).

current_cost: float property

Calculates the cost of applying the reinforcement_type to all locations present in the cluster.

Returns:

Name Type Description
float float

The total (current) cost of this cluster.

fits_subclusters() -> bool

Validates whether this cluster can be split into subclusters. For that it requires to have at least twice the required length.

Returns:

Name Type Description
bool bool

Whether subclusters can be generated from this one.

is_valid() -> bool

Validates the length of this cluster.

Returns:

Name Type Description
bool bool

The cluster has the minimal required length.

set_cheapest_common_available_measure(measure_costs: dict[type[ReinforcementProfileProtocol], float]) -> None

Updates all the location reinforcements with the cheapest reinforcement type from the measure_costs.

Parameters:

Name Type Description Default
measure_costs dict[type[ReinforcementProfileProtocol]]

dictionary with the total costs per reinforcement type.

required

ReinforcementProfileProtocol

Bases: KoswatProfileProtocol, Protocol

Extension of the KoswatProfileProtocol to define the properties of a calculated reinforcement.

StrategyLocationReinforcement dataclass

Represents a location and the different reinforcements that can be applied to it as well their costs. This class is used to show the final chosen state for a location.

current_cost: float property

Estimates the costs with surtax at this location for the given current_selected_measure.

current_selected_measure: type[ReinforcementProfileProtocol] property

Exposes the current selected measure for this object.

get_infrastructure_costs(reinforcement_type: type[ReinforcementProfileProtocol]) -> tuple[float, float]

Returns the infrastructure costs for the given reinforcement type (without and with surtax).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type.

required

Returns:

Type Description
tuple[float, float]

tuple[float, float]: Tuple containing the infrastructure costs without and with surtax.

get_selected_measure_steps() -> tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

Outputs the selected measure following the domain (expected) steps: - Initial step, - Order step, - Infrastructure step

Returns:

Type Description
tuple[type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]

tuple[ type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol], type[ReinforcementProfileProtocol]]: Resulting tuple.

set_selected_measure(reinforcement_type: type[ReinforcementProfileProtocol], step: StrategyStepEnum)

Changes the value reprsented in current_selected_measure and updates the dictionary of selections (history).

Parameters:

Name Type Description Default
reinforcement_type type[ReinforcementProfileProtocol]

Reinforcement type

required
step StrategyStepsEnum

Step whose

required

InfraCluster dataclass

This dataclass represents the subset of locations sharing the same reinforcement type (type[ReinforcementProfileProtocol]).

current_cost: float property

Calculates the cost of applying the reinforcement_type to all locations present in the cluster.

Returns:

Name Type Description
float float

The total (current) cost of this cluster.

fits_subclusters() -> bool

Validates whether this cluster can be split into subclusters. For that it requires to have at least twice the required length.

Returns:

Name Type Description
bool bool

Whether subclusters can be generated from this one.

is_valid() -> bool

Validates the length of this cluster.

Returns:

Name Type Description
bool bool

The cluster has the minimal required length.

set_cheapest_common_available_measure(measure_costs: dict[type[ReinforcementProfileProtocol], float]) -> None

Updates all the location reinforcements with the cheapest reinforcement type from the measure_costs.

Parameters:

Name Type Description Default
measure_costs dict[type[ReinforcementProfileProtocol]]

dictionary with the total costs per reinforcement type.

required

InfraClusterOption dataclass

Represents one set of subclusters the strategy could select for costs optimization.

add_cluster(infra_cluster: InfraCluster, cluster_costs: dict)

Adds the infra cluster into the collection as well as its reinforcement costs.

Parameters:

Name Type Description Default
infra_cluster InfraCluster

Cluster to add to this collection option.

required
cluster_costs dict

Reinforcement costs for the given cluster.

required

cluster_collection: list[InfraCluster] property

Read-only property to expose the stored subclusters.

cluster_costs: list[dict[ReinforcementProfileProtocol, float]] property

Read-only property to expose the stored costs.

set_cheapest_option()

Sets the subclusters defined in this option to their most optimal (cheapest) reinforcement possible.

valid_option() -> bool

Validates the collection of clusters based on the required minimun length.

Returns:

Name Type Description
bool bool

Validation result.

ReinforcementProfileProtocol

Bases: KoswatProfileProtocol, Protocol

Extension of the KoswatProfileProtocol to define the properties of a calculated reinforcement.

Strategy step

ReinforcementProfileProtocol

Bases: KoswatProfileProtocol, Protocol

Extension of the KoswatProfileProtocol to define the properties of a calculated reinforcement.