# C++ Programming

Network Communication Simulation using multidimensional vector

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

+ Due: September 27th, 1:00pm +

Please only submit [url removed, login to view]

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1. Model the network .

We want to simulate the communication cost between different nodes in a network.

How to model the network nodes and communication cost? what does the data

looks like? how to find the most economical way to communicate?

The answer is: you can use multidimensional vector (array) to represent the

communication cost of the network, the index of the 2D vector indicate different

nodes. For example, if you have 5 nodes in the network, you will use a 5 * 5 two

dimensional vector. In computer science, we call it weight matrix.

Following is how to get weight matrix:

As above examples, the graph indicates the networks. It has notes, each edge is a

direct connection for two nodes. The value for each edge is the communication cost

(weight). The weight for node its self is 0, as w[i][i]. If there is no direct connection for

two nodes, we use weight 999.

2. How to calculate the communication cost for every pair of nodes.

Although there may be no direct connection for two nodes, (like the node 0 and 3 on

right picture), they still can connect through other node (like 0 ->2->3 or 0->1->2->3).

It is very important to find the most efficient way to communicate, which means the

cost of the whole path cost less. We can use Floyd-Warshall method to calculate.

The code for this function will be provide in this lab, you can directly call this function.

For the path information: we need to 3D vector to store the cost information of each

pair of nodes. Like path[n][n][n]. The final result of the most efficient path is located

on path[n-1][ ][ ] 2D vector. The first n-1 2D vector of this 3D vector are the history of

how each pair are updated step by step to the final result.

Use above 3 nodes network as example the final result of all pair cost will be shown

in path[2][ ][ ] as

0 1 3

1 0 2

3 2 0

3. What you need to do.

Part of the code has been provide in main.cpp. The weight matrix and path matrix

are created after the user input the size of the network, that is why we use vector

instead of array. The size of network is stored in a global integer “nodes”. You need

to finish the code for the following functions.

void loadWeight(matrix &w); //load the data into weight matrix

void printWeightMatrix(matrix w);// print out the current

weight matrix

void pathReport(matrix w, matrix3D p);//generate the path

report

void checkConnection(matrix3D p); //check the Connection for

two nodes

void updateWeight(matrix &w, matrix3D &p); //update the direct

connection for two nodes

4. Output report.

The pathReport(matrix w, matrix3D p) function will generate

a report for the current weight matrix and path matrix.

Please see the example output to follow the same output

format.

5. Update Weight

The updateWeight(matrix &w, matrix3D &p) will ask user to

input two indexes of nodes, and the new weight to replace

the old weight. You also need to update the path matrix

after updating weight, because the path matrix is related

to the weight matrix.

6. checkConnection(matrix3D p) function will ask user to input

two indexes of nodes. Then check if these two nodes has a

valid path. If yes, print out the cost. If not, print out

there is no connection.

7. loadWeight(matrix &w)function process the data file. The

data file contains an integer first which is the size of

network. You need to first compare with the network you

just created. If the size does not match, you should stop

reading the file and print out message to show user that

the file is wrong.

Skills: C++ Programming