Optimization placement module

In this script, a class called SensorPlacement is defined to solve the sensor placement problem, which is a network optimization problem. The script also includes several functions to convert the network data into dataframes, add attributes to the network, generate different factors such as centrality factor and accessibility factor, and plot the network.

Here is a brief description of each function in the script:

  1. convert_oopnet_junctions_to_df(net): Converts the junctions in an oopnet network to a dataframe.

  2. convert_oopnet_nodes_to_df(net, default_elevation=0, default_demand=0): Converts the nodes in an oopnet network to a dataframe with default elevation and demand values.

  3. drop_y(df): Drops columns with a '_y' suffix from the dataframe.

  4. add_attributes(G, nodes): Adds attributes such as xcoord, ycoord, demand, and elevation to a graph from a dataframe of nodes.

  5. generate_centrality_factor(G, edges_attr): Generates the centrality factor for each edge in the graph.

  6. diameter_length_factor(edges_attr): Generates the diameter-length factor for each edge in the graph.

  7. create_edge_weight(edges_attr, A, B): Creates the edge weight for each edge in the graph based on the input parameters A and B.

  8. generate_accessibility_factor(edges_attr, P): Generates the accessibility factor for each edge in the graph based on the input probability P.

  9. plot_network(G, plot_name="Sensors graph"): Plots the network.

The SensorPlacement class has methods to run different optimization algorithms such as QAOA and VQE, as well as classical optimization algorithms to solve the sensor placement problem. The class also has a SensorPlacementResults class to manage the optimization results.

class optimization_placement.SensorPlacement(params)

Bases: object

Class for the sensor placement problem

REQUIRED_PARAMS = ['nodes', 'edge', 'nb_sensors']
gen_quadratic_program() QuadraticProgram
generate_coefficent() Tuple[Dict[str, float], Dict[Tuple[str, str], float], float]
property lin_terms: Dict[str, float]
property offset: float
property quadratic_program: QuadraticProgram
property quadratic_terms: Dict[Tuple[str, str], float]
class optimization_placement.SensorPlacementResults(results: Any)

Bases: object

A class to manage the results of sensor placement optimization using various algorithms.

_results

The results of the optimization.

Type:

Any

property results: Any

Returns the optimization results.

run_classical(label: str = 'classical') SensorPlacementResults

Runs the classical algorithm to solve the sensor placement problem.

Parameters:

label (str, optional) -- The label for the optimization results. Default is "classical".

Returns:

The optimization results.

Return type:

SensorPlacementResults

run_qaoa(quantum_instance: QuantumInstance | None = None, label: str = 'qaoa') SensorPlacementResults

Runs the QAOA algorithm to solve the sensor placement problem.

Parameters:
  • quantum_instance (Optional[QuantumInstance]) -- The quantum instance to run the optimization on.

  • label (str, optional) -- The label for the optimization results. Default is "qaoa".

Returns:

The optimization results.

Return type:

SensorPlacementResults

run_vqe(quantum_instance: QuantumInstance | None = None, label: str = 'vqe') SensorPlacementResults

Runs the VQE algorithm to solve the sensor placement problem.

Parameters:
  • quantum_instance (Optional[QuantumInstance]) -- The quantum instance to run the optimization on.

  • label (str, optional) -- The label for the optimization results. Default is "vqe".

Returns:

The optimization results.

Return type:

SensorPlacementResults

optimization_placement.add_attributes(G, nodes)

Adds attributes to a graph from a dataframe of nodes

optimization_placement.convert_oopnet_junctions_to_df(net)

Converts the junctions in an oopnet network to a dataframe

optimization_placement.convert_oopnet_nodes_to_df(net, default_elevation=0, default_demand=0)

Converts the nodes in an oopnet network to a dataframe

optimization_placement.convert_oopnet_pipes_to_df(net)

Converts the pipes in an oopnet network to a dataframe

optimization_placement.create_edge_weight(edges_attr, A, B)

Creates the edge weight for each edge in the graph

optimization_placement.create_graph(edges)

Creates a graph from a dataframe of edges

optimization_placement.diameter_length_factor(edges_attr)

Generates the diameter-length factor for each edge in the graph

optimization_placement.drop_y(df)

Drop columns with _y suffix

optimization_placement.generate_accessibility_factor(edges_attr, P)

Generates the accessibility factor for each edge in the graph

optimization_placement.generate_centrality_factor(G, edges_attr)

Generates the centrality factor for each edge in the graph

optimization_placement.get_df_from_oopnet_nodes(net)

Converts the nodes in an oopnet network to a dataframe

optimization_placement.plot_network(G, plot_name='Sensors graph')

Plots the network

optimization_placement.rename_x(df)

Rename columns with _x suffix