Networking and Packet Delivery Simulation Project in C++

Verified

Added on  2022/08/18

|7
|764
|10
Project
AI Summary
This assignment involves developing a C++ program to simulate packet delivery in a sensor network. The program utilizes an adjacency matrix to represent the network topology, where the numbers denote the Euclidean distance between nodes. The core objective is to determine the paths for routing a packet from a source node (S) to a destination node (D) with both minimum and maximum energy costs. The program calculates these costs by considering the cost of packet transmission (1 joule per meter) and reception (5 joules). The solution provides the minimum and maximum cost paths, along with the respective energy costs. The provided code implements a function to find the minimum energy cost path, demonstrating the application of graph algorithms to optimize network performance. The solution also outlines the minimum and maximum cost paths, and their calculations based on the given network topology and cost parameters. The program displays the paths and the calculated energy costs.
Document Page
Running head: NETWORKING AND PACKET DELIVERY SIMULATION
Networking and packet Delivery simulation
Name of the Student
Name of the University
Authors note
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1NETWORKING AND PACKET DELIVERY SIMULATION
For the given problem of delivering the packets from the vertex S to Vertex D. The
branches or the edges outwards to the other edges helps to grow the number of connected
components. While adding the edges from one node to another the smallest weight is considered
to the next node. The process continues until the final destination node is reached and connected.
With every iteration in order to add to the path the edge with the lowest cost is fast
considered. Initially the process starts with lowest cost edge as an example for this case 2 that
connects to A node from the source. After this the next edge is added with the lowest weighted
edge with the weight 2. Here it can be mentioned that, the selected two edges are completely
disjoint. Now, in the consecutive iterations next edges are added according the lowest weighted
edges. Here it can be stated that the edges that creates cycles needs to be ignored.
In the program it is tried to maintain two distinct disjoint sets of nodes. One set contains
the nodes that are added to the path and another one includes the nodes that are remaining and
needs to be added to the path.
After every iteration a check is done in order to detect the cycles that are formed with the
redundant edges to the same node. In order to do that, the simplest method is about scanning the
previously edges with increasing order of the costs. While computing the time complexity is
found to be O (n log n). After the scan, the cost for the delivering the packets is calculated by
avoiding the cycles as well as avoiding the two already connected nodes from the path.
Code
Document Page
2NETWORKING AND PACKET DELIVERY SIMULATION
#include <iostream>
#include <limits>
#include <vector>
using namespace std;
int netnd(int p, int kval[], bool nets[]) {
int mincst = numeric_limits<int>::max();
int mincst_index;
for (int i = 0; i < p; i++) {
if (nets[i] == false && kval[i] < mincst) {
mincst = kval[i], mincst_index = i;
//mincst = kval[i+1], mincst_index = i+1;
}
Document Page
3NETWORKING AND PACKET DELIVERY SIMULATION
}
return mincst_index;
}
void costnodes(int l, vector<vector<int>> netnodev) {
int pnode[l];
int keyval[l];
bool nets[l];
for (int i = 0; i < l; i++) {
keyval[i] = numeric_limits<int>::max();
nets[i] = false;
}
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4NETWORKING AND PACKET DELIVERY SIMULATION
pnode[0] = -1;
keyval[0] = 0;
for (int i = 0; i < l - 1; i++) {
int u = netnd(l, keyval, nets);
nets[u] = true;
for (int v = 0; v < l; v++) {
if (netnodev[u][v] && nets[v] == false &&
netnodev[u][v] < keyval[v]) {
keyval[v] = netnodev[u][v];
//cout << keyval[v] << endl;
pnode[v] = u;
}
Document Page
5NETWORKING AND PACKET DELIVERY SIMULATION
}
}
int cost = 0;
for (int i = 1; i < l; i++)
cost += netnodev[pnode[i]][i];
//cout << pnode[i][i] <<endl;
cout << cost << endl;
}
int main() {
int n3=3;
Document Page
6NETWORKING AND PACKET DELIVERY SIMULATION
vector<vector<int>> netnodev3 = {{0,3, 2},
{3, 0, 5},
{2, 5, 0}
};
costnodes(n3, netnodev3);
return 0;
}
chevron_up_icon
1 out of 7
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]