Skip to content

huguryildiz/wsn-opt-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Wireless Sensor Network Lifetime Maximization

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.


What this code does

For each iteration (random topology seed):

  1. Generates a disc-shaped topology

    • Node 0 is the base station (sink) at (0,0)
    • Nodes 1..n-1 are sensors uniformly distributed over a disk of radius Rnet
  2. 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}
  3. 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
  4. Solves an optimization model

    • Continuous flow variables f(i,j)
    • Binary link activation variables a(i,j)
    • Lifetime variable T (objective)
  5. Logs results

    • Prints lifetime and solve time
    • Writes to results.txt in the format:
      iterNo; lifetime; runtime_ms
      

Optimization model (summary)

Decision variables

  • f(i,j) ≥ 0 : flow sent from node i to node j
  • a(i,j) ∈ {0,1} : whether link (i,j) is used (activated)
  • T ≥ 0 : network lifetime scaling factor

Constraints

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.

Objective

[ \max ; T ]


Requirements

  • Python 3.9+ recommended
  • gurobipy
  • numpy

You also need a working Gurobi installation + license.


Installation

pip install numpy gurobipy

About

WSN Lifetime Maximization

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages