Dynamic Clustering in UWAN using MATLAB in NetSim

Dynamic Clustering in UWAN with MATLAB Interfacing

Applies to: NetSim Standard/Pro v15.0.21

This example adapts NetSim MATLAB dynamic clustering from a Wireless Sensor Network (WSN) to an Underwater Acoustic Network (UWAN). It sends node positions and residual energy to MATLAB, forms clusters using K-means or Fuzzy C-Means (FCM), elects cluster heads, and returns the result to modified DSR routing code.

Download the workspace

Workspace: https://github.com/NetSim-TETCOS/Dynamic_Clustering_UWAN_DSR_v15.0/archive/refs/heads/main.zip

The download should contain the modified workspace containing source code, binaries, MATLAB files, example experiments, along with a modified Underwater_device.xml file.

Example topology and routing concept


Figure 1: Annotated clustering concept. Membership and elected heads may change at each clustering interval.

NetSim-MATLAB data flow


Figure 2: Position and energy arrays go to MATLAB; cluster heads, IDs, and sizes return to DSR.

ItemMeaning
Xc, YcUWAN node coordinates.
PwrResidual energy from the ALOHA PHY interface.
AElected cluster-head device IDs.
BCluster ID assigned to each node.
CNumber of nodes in each cluster.

Prerequisites

  • NetSim Standard v15.0.21, 64-bit.
  • A working NetSim-MATLAB interface.
  • The supplied workspace imported with source code and binaries.

Install the UWAN device-property XML

  1. Close NetSim.
  2. Back up:
    C:\Program Files\NetSim\Standard_v15_0\Docs\UI_xml\Device_Properties\Underwater_device.xml
  3. Replace it with the supplied Underwater_device.xml.
  4. Restart NetSim.

The modified XML exposes the routing-protocol property needed by the UWAN devices.

Import the workspace

  1. Download and extract the package.
  2. Open NetSim Home.
  3. Select Your Work > Import Workspaces / Experiments.
  4. Select Dynamic_Clustering_Matlab_v15.0_UWAN.netsimexp.
  5. Import it as a new workspace with source code and binaries included.
  6. Open an included UWAN experiment.

Included examples

ExperimentTrafficTimingPurpose
UWAN-Dynamic-Clustering-3-Flows16 nodes; three CBR flows5-second clustering; 100-second simulationShort interface, routing, metrics, and log check.
UWAN-Dynamic-Clustering-16-Flows16 ring flows; every node sends and receives300-second simulationTraffic-coverage check across all nodes.

Select the MATLAB method

In bin_x64\MATLAB\clustering.m, set Clustering_Method:

ValueMethodInputs used
1K-meansDistance
2Fuzzy C-MeansDistance
3K-meansDistance and energy
4Fuzzy C-MeansDistance and energy
Clustering_Method = 1;

The supplied C source sets four clusters:

#define NUMBEROFCLUSTERS 4

The interval is set in DSR.h:

#define CLUSTER_INTERVAL 5*SECOND

Rebuild DSR and use the resulting workspace libDSR.dll after changing C source or header values.

Run and validate

  1. Select Run Simulation.
  2. Confirm the MATLAB interface starts and invokes clustering.m.
  3. Review Cluster_log.csv in the simulation log folder.
  4. Review Application Metrics, Packet Metrics, Packet Trace, and the energy plot.
  5. For the 16-flow example, confirm every node is a source and destination.

Plot of energy consumption in the UWAN devices

Figure 3: 3D Surface plots showing energy consumption in the UWAN network simulated

A valid log contains one row per cluster at each clustering time:

Time (in us),CLUSTER ID,CLUSTER HEAD,Cluster Members
0,1,14,13,14,15
0,2,10,5,9,10,11
5000000,1,16,11,12,15,16
5000000,2,3,1,2,3,4

Annotation: The change between 0 and 5,000,000 microseconds shows a new result after five seconds. A populated cluster log confirms clustering exchange; verify packet delivery separately.