blocksnet.method.annealing_optimizer
Module providing class for simulated annealing optimization of blocks services constrained by land uses.
Classes
|
Services optimizer using simulated annealing to maximize scenario provision objective function by building certain services. |
|
Represents indicators for a block based on land use and spatial indices. |
|
Represents a variable for optimization in a given block with a specific service type and brick. |
- class blocksnet.method.annealing_optimizer.Variable(block: Block, service_type: ServiceType, brick: ServiceBrick, value: int = 0)[source]
Bases:
object
Represents a variable for optimization in a given block with a specific service type and brick.
- Variables:
block (Block) – The block where the service is located.
service_type (ServiceType) – The type of service provided.
brick (ServiceBrick) – The brick representing the service’s characteristics.
value (int, optional) – The quantity of the service brick, by default 0.
- property capacity
Calculates the total capacity of the service brick in the block.
- Returns:
The total capacity of the service brick.
- Return type:
int
- property area
Calculates the total area occupied by the service brick.
- Returns:
The total area occupied by the service brick.
- Return type:
int
- class blocksnet.method.annealing_optimizer.Indicator(block: Block, land_use: LandUse, fsi: float, gsi: float)[source]
Bases:
object
Represents indicators for a block based on land use and spatial indices.
- Variables:
- property site_area
Gets the site area of the block.
- Returns:
The site area of the block.
- Return type:
float
- property footprint_area
Calculates the footprint area of the block based on the GSI.
- Returns:
The footprint area of the block.
- Return type:
float
- property build_floor_area
Calculates the buildable floor area of the block based on the FSI.
- Returns:
The buildable floor area of the block.
- Return type:
float
- property integrated_area
Determines the integrated area of the block based on land use.
- Returns:
The integrated area of the block.
- Return type:
float
- property non_integrated_area
Calculates the non-integrated area of the block.
- Returns:
The non-integrated area of the block.
- Return type:
float
- property living_area
Determines the living area of the block based on land use.
- Returns:
The living area of the block. Returns 0 if land use is not residential.
- Return type:
float
- property population
Estimates the population of the block based on living area and demand.
- Returns:
The estimated population of the block.
- Return type:
int
- class blocksnet.method.annealing_optimizer.AnnealingOptimizer(*, city_model: City, verbose: bool = True, on_iteration: Callable[[int, list[blocksnet.method.annealing_optimizer.Variable], dict[int, blocksnet.method.annealing_optimizer.Indicator], float], None] | None = None)[source]
Bases:
BaseMethod
Services optimizer using simulated annealing to maximize scenario provision objective function by building certain services.
- Variables:
on_iteration (Callable[[int, list[Variable], dict[int, Indicator], float], None] | None) – A callback function to be called after each iteration with the current iteration number, the current list of variables, indicators, and the best value found so far.
- on_iteration: Callable[[int, list[blocksnet.method.annealing_optimizer.Variable], dict[int, blocksnet.method.annealing_optimizer.Indicator], float], None] | None
- _check_constraints(X, indicators) bool [source]
Checks if the current solution satisfies all constraints.
- static _perturb(X: list[blocksnet.method.annealing_optimizer.Variable]) tuple[list[blocksnet.method.annealing_optimizer.Variable], blocksnet.models.service_type.ServiceType] [source]
Perturbs the current solution by modifying a randomly chosen variable.
- Parameters:
X (list[Variable]) – List of variables representing the current solution.
- Returns:
A tuple containing the perturbed list of variables and the service type of the perturbed variable.
- Return type:
tuple[list[Variable], ServiceType]
- _generate_initial_X(blocks_lu: dict[int, blocksnet.models.land_use.LandUse], service_types: dict[str, float]) list[blocksnet.method.annealing_optimizer.Variable] [source]
Generates an initial list of variables for the optimization.
- _generate_indicators(blocks, fsis, gsis) dict[int, blocksnet.method.annealing_optimizer.Indicator] [source]
Generates indicators for each block based on the provided data.
- Parameters:
blocks (dict[int, LandUse]) – Dictionary mapping block IDs to their corresponding land uses.
fsis (dict[int, float]) – Dictionary mapping block IDs to their Floor Space Index (FSI) values.
gsis (dict[int, float]) – Dictionary mapping block IDs to their Ground Space Index (GSI) values.
- Returns:
A dictionary mapping block IDs to their corresponding indicators.
- Return type:
dict[int, Indicator]
- to_gdf(X: list[blocksnet.method.annealing_optimizer.Variable], indicators: dict[int, blocksnet.method.annealing_optimizer.Indicator]) GeoDataFrame [source]
Converts the list of variables and indicators into a GeoDataFrame.
- to_bricks_df(X: list[blocksnet.method.annealing_optimizer.Variable]) DataFrame [source]
Converts the list of variables into a DataFrame representing the bricks.
- Parameters:
X (list[Variable]) – List of variables representing the current solution.
- Returns:
A DataFrame containing data about the bricks in the solution.
- Return type:
pd.DataFrame
- _get_clear_df(blocks: list[int]) DataFrame [source]
Constructs a DataFrame for provision assessment so the blocks being changed are treated as cleared.
- Parameters:
blocks (list[int]) – List of changing blocks ids.
- Returns:
A DataFrame containing information related to blocks being changed for provision assessment.
- Return type:
pd.DataFrame
- to_df(X: list[blocksnet.method.annealing_optimizer.Variable], indicators: dict[int, blocksnet.method.annealing_optimizer.Indicator]) DataFrame [source]
Converts the list of variables and indicators into a DataFrame.
- calculate(blocks_lu: dict[int, blocksnet.models.land_use.LandUse], blocks_fsi: dict[int, float], blocks_gsi: dict[int, float], service_types: dict[str, float], t_max: float = 100, t_min: float = 0.001, rate: float = 0.95, max_iter: int = 1000) tuple [source]
Executes the services optimization process based on simulated annealing for provided service types weights and blocks landuses.
- Parameters:
blocks_lu (dict[int, LandUse]) – Dictionary mapping block IDs to their corresponding land uses.
blocks_fsi (dict[int, float]) – Dictionary mapping block IDs to their Floor Space Index (FSI) values.
blocks_gsi (dict[int, float]) – Dictionary mapping block IDs to their Ground Space Index (GSI) values.
service_types (dict[str, float]) – Dictionary mapping service type names to their weights.
t_max (float, optional) – The maximum temperature for the annealing process, by default 100.
t_min (float, optional) – The minimum temperature for the annealing process, by default 1e-3.
rate (float, optional) – The cooling rate of the temperature, by default 0.95.
max_iter (int, optional) – The maximum number of iterations, by default 1000.
- Returns:
A tuple containing the best solution found, the indicators, the best value, and the provision values for each service type.
- Return type:
tuple
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.