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:
  • 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:

cheapest_reinforcement: StrategyReinforcementTypeCosts property

Gets the StrategyLocationReinforcementCosts with the lowest total_costs_with_surtax value.

Returns:

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

Get the infrastructure costs for the given reinforcement type.

Parameters:
Raises:
  • ValueError

    The reinforcement type is not available.

Returns:
  • 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:
Raises:
  • ValueError

    The reinforcement type is not available.

Returns:
  • 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:
Returns:
  • 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:

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:

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:
  • float( float ) –

    The total costs with surtax when applying this reinforcement.

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:
  • strategy_input (`StrategyInput`) –

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

Returns:
  • 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:

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. Inactive reinforcements are ignored. Cofferdam should always be the last reinforcement type.

Input

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

Returns:

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:
Returns:

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.

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:
  • other (OrderCluster) –

    Cluster whose contents will be used to extend self.

Raises:
  • 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:
  • 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:
  • min_length (float) –

    Minimal length a reinforcement measure is required for a cluster.

  • strongest_reinforcement (int) –

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

Returns:
  • bool( bool ) –

    if the cluster is compliant within its neighbors context.

Infra Priority Strategy

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:
  • min_length (int) –

    Minimum length for a cluster to be valid.

Returns:
  • 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:
Returns:
  • dict[type[ReinforcementProfileProtocol], float]

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

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:
  • 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:
  • bool( bool ) –

    Whether subclusters can be generated from this one.

is_valid() -> bool

Validates the length of this cluster.

Returns:
  • 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:

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:
  • infra_cluster (InfraCluster) –

    Cluster to add to this collection option.

  • cluster_costs (dict) –

    Reinforcement costs for the given cluster.

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:
  • bool( bool ) –

    Validation result.

Strategy step