import distanceMatrix[routerId][routerId] = 0; for( Integer router :

import java.util.HashMap;public class Router { private int routerId; private Integer distanceMatrix; private HashMap neighbours; private Integer outgoingDistanceVector; private int totalRouters; public Router(int routerId, int totalRouters, HashMap neighbours) { this.routerId = routerId; this.

totalRouters = totalRouters; this.neighbours = neighbours; initializeDistanceMatrix(); createOutgoingVector(); } // Updates a weight on an edge to a neighbour public void updateWeightToNeighbours(Integer neighbour, Integer newWeight) { neighbours.put(neighbour, newWeight); distanceMatrixneighbourrouterId = newWeight; } // Setting up initial distance matrix private void initializeDistanceMatrix() { distanceMatrix = new IntegertotalRouterstotalRouters; distanceMatrixrouterIdrouterId = 0; for( Integer router : neighbours.keySet()) { distanceMatrixrouterrouterId = neighbours.get(router); } } // Extracts the distance vector from the distance matrix private void createOutgoingVector() { outgoingDistanceVector = new IntegertotalRouters; for( int i = 0; i < totalRouters; i++) { outgoingDistanceVectori = distanceMatrixirouterId; } } /* Receive a distance vector from another router. * Uses this to update distanceMatrix. Later calculateDistanceMatrix() will use the new matrix * to calculate new distance vector for this router * i.

e. multiple distance vectors can be received, before the router calculates and ‘sends’ * its distance vector */ public void incomingDistanceVector(Integer from, Integer distances) { // TODO Must be implemented } /* Calculates the new distance vector, and examines if there are changes that * should be sent for the other routers. If there are, prepare the distance vector for sending, * i.e. it is polled in outgoingDistanceVector() */ public void calculateDistanceMatrix() { // Calculate own distance vector using Bellmann Ford equation // If there are changes, prepare outgoingDistanceVector with the new vector, otherwise, set it to null // TODO Must be implemented } /* Returns a distance vector, if there are changes since last call to this method.

* If there are no changes, null must be returned */ public Integer outgoingDistanceVector() { // TODO Must be implemented return null; } public int getRouterId() { return routerId; } public void printDistanceVector() { System.out.println(“—– Distance matrix ——“); System.out.print(“id:” + routerId + ” “); for( int i = 0; i < distanceMatrix.length; i++) { System.out.print( i + " "); } System.out.println(""); for( int i = 0; i < distanceMatrix.length; i++) { System.out.print( i + " "); for( int j = 0; j < distanceMatrix.length; j++) { if( distanceMatrixji == null ) { System.out.print("- "); } else { System.out.print( distanceMatrixji + " "); } } System.out.println(""); } }}

Best services for writing your paper according to Trustpilot

Premium Partner
From $18.00 per page
4,8 / 5
4,80
Writers Experience
4,80
Delivery
4,90
Support
4,70
Price
Recommended Service
From $13.90 per page
4,6 / 5
4,70
Writers Experience
4,70
Delivery
4,60
Support
4,60
Price
From $20.00 per page
4,5 / 5
4,80
Writers Experience
4,50
Delivery
4,40
Support
4,10
Price
* All Partners were chosen among 50+ writing services by our Customer Satisfaction Team