chama.optimize module¶
The optimize module contains high-level solvers for sensor placement optimization.
Contents
Sensor placement based on minimizing average impact across a set of scenarios. |
|
Sensor placement based on maximizing coverage of a set of entities. |
- class chama.optimize.ImpactFormulation[source]¶
Bases:
object
Sensor placement based on minimizing average impact across a set of scenarios.
- solve(impact=None, sensor=None, scenario=None, sensor_budget=None, use_sensor_cost=False, use_scenario_probability=False, impact_col_name='Impact', mip_solver_name='glpk', pyomo_options=None, solver_options=None)[source]¶
Solves the sensor placement optimization by minimizing impact.
- Parameters:
impact (pandas DataFrame) – Impact assessment. Impact is stored as a pandas DataFrame with columns Scenario, Sensor, and Impact. Each row contains a single detection time (or other measure of impact/damage) for a sensor that detects a scenario. The column name for Impact can also be specified by the user using the argument ‘impact_col_name’.
sensor (pandas DataFrame) – Sensor characteristics. Contains sensor cost for each sensor. Sensor characteristics are stored as a pandas DataFrame with columns Sensor and Cost. Cost is used in the sensor placement optimization if the ‘use_sensor_cost’ flag is set to True.
scenario (pandas DataFrame) – Scenario characteristics. Contains scenario probability and the impact for undetected scenarios. Scenario characteristics are stored as a pandas DataFrame with columns Scenario, Undetected Impact, and Probability. Undetected Impact is required for each scenario. Probability is used if the ‘use_scenario_probability’ flag is set to True.
sensor_budget (float) – The total budget available for purchase/installation of sensors. Solution will select a family of sensors whose combined cost is below the sensor_budget. For a simple sensor budget of N sensors, set this to N and the ‘use_sensor_cost’ to False.
use_sensor_cost (bool) – Boolean indicating if sensor cost should be used in the optimization. If False, sensors have equal cost of 1.
use_scenario_probability (bool) – Boolean indicating if scenario probability should be used in the optimization. If False, scenarios have equal probability.
impact_col_name (str) – The name of the column containing the impact data to be used in the objective function.
mip_solver_name (str) – Optimization solver name passed to Pyomo. The solver must be supported by Pyomo and support solution of mixed-integer programming problems.
pyomo_options (dict) – Keyword arguments to be passed to the Pyomo solver .solve method Defaults to an empty dictionary.
solver_options (dict) – Solver specific options to pass through Pyomo to the underlying solver. Defaults to an empty dictionary.
- Returns:
A dictionary with the following keys –
Sensors: A list of the selected sensors
Objective: The mean impact based on the selected sensors
FractionDetected: The fraction of scenarios that were detected
TotalSensorCost: Total cost of the selected sensors
Assessment: The impact value for each sensor-scenario pair. The assessment is stored as a pandas DataFrame with columns Scenario, Sensor, and Impact (same format as the input Impact assessment). If the selected sensors did not detect a particular scenario, the impact is set to the Undetected Impact.
- create_pyomo_model(impact=None, sensor=None, scenario=None, sensor_budget=None, use_sensor_cost=False, use_scenario_probability=False, impact_col_name='Impact')[source]¶
Returns the Pyomo model.
See
ImpactFormulation.solve()
for more information on parameters.- Returns:
Pyomo ConcreteModel ready to be solved
- add_grouping_constraint(sensor_list, select=None, min_select=None, max_select=None)[source]¶
Adds a sensor grouping constraint to the sensor placement model. This constraint forces a certain number of sensors to be selected from a particular subset of all the possible sensors.
The keyword argument ‘select’ enforces an equality constraint, while ‘min_select’ and ‘max_select’ correspond to lower and upper bounds on the grouping constraints, respectively. You can specify one or both of ‘min_select’ and ‘max_select’ OR use ‘select’
- Parameters:
sensor_list (list of strings) – List containing the string names of a subset of the sensors
select (positive integer or None) – The exact number of sensors from the sensor_list that should be selected
min_select (positive integer or None) – The minimum number of sensors from the sensor_list that should be selected
max_select (positive integer or None) – The maximum number of sensors from the sensor_list that should be selected
- solve_pyomo_model(sensor_budget=None, mip_solver_name='glpk', pyomo_options=None, solver_options=None)[source]¶
Solves the Pyomo model created to perform the sensor placement.
See
ImpactFormulation.solve()
for more information on parameters.
- create_solution_summary()[source]¶
Creates a dictionary representing common summary information about the solution from a Pyomo model object that has already been solved.
See
ImpactFormulation.solve()
for more information on the solution summary.- Returns:
Dictionary containing a summary of results.
- class chama.optimize.CoverageFormulation[source]¶
Bases:
object
Sensor placement based on maximizing coverage of a set of entities. An ‘entity’ can represent geographic areas, scenarios, or scenario-time pairs.
- solve(coverage, sensor=None, entity=None, sensor_budget=None, use_sensor_cost=None, use_entity_weight=False, redundancy=0, coverage_col_name='Coverage', mip_solver_name='glpk', pyomo_options=None, solver_options=None)[source]¶
Solves the sensor placement optimization by maximizing coverage.
- Parameters:
coverage (pandas DataFrame) – Coverage data. Coverage is stored as a pandas DataFrame with columns Sensor and Coverage. Each row contains a list of entities that are covered by single sensor. The column name for Coverage can also be specified by the user using the argument ‘coverage_col_name’.
sensor (pandas DataFrame) – Sensor characteristics. Contains sensor cost for each sensor. Sensor characteristics are stored as a pandas DataFrame with columns Sensor and Cost. Cost is used in the sensor placement optimization if the ‘use_sensor_cost’ flag is set to True.
entity (pandas DataFrame) – Entity characteristics. Contains entity weights. Entity characteristics are stored as a pandas DataFrame with columns Entity and Weight. Weight is used if the ‘use_entity_weight’ flag is set to True.
sensor_budget (float) – The total budget available for purchase/installation of sensors. Solution will select a family of sensors whose combined cost is below the sensor_budget. For a simple sensor budget of N sensors, set this to N and the ‘use_sensor_cost’ to False.
use_sensor_cost (bool) – Boolean indicating if sensor cost should be used in the optimization. If False, sensors have equal cost of 1.
use_entity_weight (bool) – Boolean indicating if entity weights should be used in the optimization. If False, entities have equal weight.
redundancy (int) – Redundancy level. A value of 0 means only one sensor is required to covered an entity, whereas a value of 1 means two sensors must cover an entity before it considered covered.
coverage_col_name (str) – The name of the column containing the coverage data to be used in the objective function.
mip_solver_name (str) – Optimization solver name passed to Pyomo. The solver must be supported by Pyomo and support solution of mixed-integer programming problems.
pyomo_options (dict) – Keyword arguments to be passed to the Pyomo solver .solve method. Defaults to an empty dictionary.
solver_options (dict) – Solver specific options to pass through Pyomo to the underlying solver. Defaults to an empty dictionary.
- Returns:
A dictionary with the following keys –
Sensors: A list of the selected sensors
Objective: The mean coverage based on the selected sensors
FractionDetected: the fraction of entities that are detected
TotalSensorCost: Total cost of the selected sensors
EntityAssessment: a dictionary whose keys are the entity names, and values are a list of sensors that detect that entity
SensorAssessment: a dictionary whose keys are the sensor names, and values are the list of entities that are detected by that sensor
- create_pyomo_model(coverage, sensor=None, entity=None, sensor_budget=None, use_sensor_cost=False, use_entity_weight=False, redundancy=0, coverage_col_name='Coverage')[source]¶
Returns the Pyomo model.
See
CoverageFormulation.solve()
for more information on parameters.- Returns:
Pyomo ConcreteModel ready to be solved
- add_grouping_constraint(sensor_list, select=None, min_select=None, max_select=None)[source]¶
Adds a sensor grouping constraint to the sensor placement model. This constraint forces a certain number of sensors to be selected from a particular subset of all the possible sensors.
The keyword argument ‘select’ enforces an equality constraint, while ‘min_select’ and ‘max_select’ correspond to lower and upper bounds on the grouping constraints, respectively. You can specify one or both of ‘min_select’ and ‘max_select’ OR use ‘select’
- Parameters:
sensor_list (list of strings) – List containing the string names of a subset of the sensors
select (positive integer or None) – The exact number of sensors from the sensor_list that should be selected
min_select (positive integer or None) – The minimum number of sensors from the sensor_list that should be selected
max_select (positive integer or None) – The maximum number of sensors from the sensor_list that should be selected
- solve_pyomo_model(sensor_budget=None, mip_solver_name='glpk', pyomo_options=None, solver_options=None)[source]¶
Solves the Pyomo model created to perform the sensor placement.
See
CoverageFormulation.solve()
for more information on parameters.
- create_solution_summary()[source]¶
Creates a dictionary representing common summary information about the solution from a Pyomo model object that has already been solved.
See
CoverageFormulation.solve()
for more information on the solution summary.- Returns:
Dictionary containing a summary of results.