Skip to content

Sensor Placement API Reference

Data

Data model for Sensor Placement use case.

SensorPlacementData

Bases: UcData

Data for the Sensor Placement use case.

Finds the optimal placement of sensors on a network graph to maximize coverage while respecting cost and count constraints.

Attributes:

  • name (Literal['sensor_placement']) –

    Identifier for this data type.

  • adjacency_matrix (AdjMatrix) –

    An n x n weighted adjacency matrix of the network.

  • node_names (list[int] | list[str]) –

    Identifiers for each node. Must be all ints or all strings.

  • costs (NumPyArray) –

    Cost of placing a sensor at each node.

  • n_sensors (int) –

    Number of sensors to place.

plot(*, ax: Axes | None = None) -> Axes

Plot the network graph.

Parameters:

  • ax (Axes | None, default: None ) –

    Matplotlib axes to draw on. Creates a new figure if None.

Returns:

  • Axes

    The axes with the plot.

to_string() -> str

Return a string describing the data.

Returns:

  • str

    String representation of the data.

from_adjacency_matrix(adjacency_matrix: np.ndarray, node_names: list[int] | list[str], costs: list[float], n_sensors: int) -> SensorPlacementData staticmethod

Create a SensorPlacementData instance from an adjacency matrix.

Parameters:

  • adjacency_matrix (ndarray) –

    Symmetric weighted adjacency matrix of the network.

  • node_names (list[int] | list[str]) –

    Node identifiers. Length must match the matrix dimensions.

  • costs (list[float]) –

    Cost of placing a sensor at each node.

  • n_sensors (int) –

    Number of sensors to place.

Returns:

from_graph(graph: nx.Graph, costs: list[float], n_sensors: int) -> SensorPlacementData staticmethod

Create a SensorPlacementData instance from a NetworkX graph.

Parameters:

  • graph (Graph) –

    A NetworkX graph with optional edge weights.

  • costs (list[float]) –

    Cost of placing a sensor at each node.

  • n_sensors (int) –

    Number of sensors to place.

Returns:

generate_random(n_nodes: int = 6, n_sensors: int = 2, seed: int | None = None) -> SensorPlacementData staticmethod

Generate a random Sensor Placement instance.

Parameters:

  • n_nodes (int, default: 6 ) –

    Number of nodes in the network, by default 6.

  • n_sensors (int, default: 2 ) –

    Number of sensors to place, by default 2.

  • seed (int | None, default: None ) –

    Random seed for reproducibility, by default None.

Returns:

Formulation

Formulation for Sensor Placement use case.

SensorPlacementFormulation

Bases: UcFormulation[SensorPlacementData, SensorPlacementSolution]

Constraint-based formulation for Sensor Placement.

Mathematical Formulation

Decision Variables: x_i in {0,1}: 1 if a sensor is placed at node i

Objective: maximize sum_{(i,j) edges} w_ij * (x[i] + x[j] - x[i] * x[j]) - sum_i costs[i] * x[i]

An edge is covered when at least one endpoint has a sensor
(x[i] OR x[j], linearized as x[i] + x[j] - x[i] * x[j]).

Constraints: sum_i x[i] == n_sensors

to_string(data: SensorPlacementData) -> str staticmethod

Return a string describing the formulation.

Parameters:

Returns:

  • str

    String representation of the formulation.

formulate(data: SensorPlacementData) -> Model staticmethod

Formulate the Sensor Placement problem.

Parameters:

Returns:

  • Model

    A Luna Model ready to be solved.

interpret(solution: Solution, data: SensorPlacementData) -> SensorPlacementSolution staticmethod

Extract solution from quantum result.

Parameters:

  • solution (Solution) –

    The quantum solution.

  • data (SensorPlacementData) –

    The problem data.

Returns:

Solution

Solution model for Sensor Placement use case.

SensorPlacementSolution

Bases: UcSolution

Solution for the Sensor Placement use case.

Attributes:

  • name (Literal['sensor_placement']) –

    Identifier for this solution type.

  • sensor_nodes (list[int | str]) –

    Nodes where sensors are placed.

  • coverage_value (float) –

    Total coverage value from edge contributions.

  • total_cost (float) –

    Total cost of placing sensors.

  • is_valid (bool) –

    Whether exactly n_sensors sensors are placed.

plot(data: SensorPlacementData | None = None, *, ax: Axes | None = None) -> Axes

Plot the sensor placement solution.

Parameters:

  • data (SensorPlacementData | None, default: None ) –

    Problem data for context.

  • ax (Axes | None, default: None ) –

    Matplotlib axes to draw on. Creates a new figure if None.

Returns:

  • Axes

    The axes with the plot.

to_string() -> str

Return a string describing the solution.

Returns:

  • str

    String representation of the solution.

Instance

Instance model for SensorPlacement use case.

SensorPlacementInstance

Bases: UcInstance[SensorPlacementData, SensorPlacementFormulation, SensorPlacementSolution]

Instance combining data and formulation for SensorPlacement.

Collection

Collection of Sensor Placement instances.

SensorPlacementCollection

Bases: UcInstanceCollection[SensorPlacementInstance]

Collection of Sensor Placement instances.

from_random(min_size: int, max_size: int, num_instances: int = 1, *, n_sensors: int = 2, seed: int | None = None) -> SensorPlacementCollection classmethod

Generate random Sensor Placement instances.

Parameters:

  • min_size (int) –

    Minimum number of nodes.

  • max_size (int) –

    Maximum number of nodes.

  • num_instances (int, default: 1 ) –

    Number of instances per size, by default 1.

  • n_sensors (int, default: 2 ) –

    Number of sensors, by default 2.

  • seed (int | None, default: None ) –

    Random seed for reproducibility, by default None.

Returns: