This repository contains a Python + Gurobi optimization model that maximizes the network lifetime of a wireless sensor network (WSN) under energy constraints and limited outgoing links per node.
The model generates random sensor deployments in a disc-shaped area, builds a directed communication graph, and solves a mixed-integer optimization problem where the objective is to maximize the lifetime scalar T.
For each iteration (random topology seed):
-
Generates a disc-shaped topology
- Node
0is the base station (sink) at(0,0) - Nodes
1..n-1are sensors uniformly distributed over a disk of radiusRnet
- Node
-
Builds directed links
- Every sensor can transmit to every other node (including sink), excluding self-links
- Link set:
A = {(i,j) | i ∈ sensors, j ∈ all nodes, i ≠ j}
-
Computes energy per transmitted flow
- Distance:
D(i,j) - Transmission energy per unit flow: [ P_{tx}(i,j) = \rho + \epsilon \cdot D(i,j)^\alpha ]
- Reception cost per unit flow:
Prx
- Distance:
-
Solves an optimization model
- Continuous flow variables
f(i,j) - Binary link activation variables
a(i,j) - Lifetime variable
T(objective)
- Continuous flow variables
-
Logs results
- Prints lifetime and solve time
- Writes to
results.txtin the format:iterNo; lifetime; runtime_ms
f(i,j) ≥ 0: flow sent from nodeito nodeja(i,j) ∈ {0,1}: whether link(i,j)is used (activated)T ≥ 0: network lifetime scaling factor
1) Flow balance at each sensor node
[
\sum_{j \in V, j\neq i} f(i,j) - \sum_{j \in W, j\neq i} f(j,i) = S_i \cdot T
]
Each sensor generates S_i units of data per time, scaled by lifetime T.
2) Energy constraint at each sensor node [ \sum_{j \in V, j\neq i} P_{tx}(i,j),f(i,j) ;+; Prx\sum_{j \in W, j\neq i} f(j,i) \le e_i ]
3) Link activation coupling (Big-M) [ f(i,j) \le M \cdot a(i,j) ]
4) Outgoing link limit
[
\sum_{j \in V, j\neq i} a(i,j) \le L_{out}
]
Each sensor can use at most Lout outgoing links.
[ \max ; T ]
- Python 3.9+ recommended
gurobipynumpy
You also need a working Gurobi installation + license.
pip install numpy gurobipy