Skip to content

Instantly share code, notes, and snippets.

@bryantp
Created March 24, 2013 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryantp/5232765 to your computer and use it in GitHub Desktop.
Save bryantp/5232765 to your computer and use it in GitHub Desktop.
Java Implementation of Kleinrock's Independence Assumption
package com.gmail.kleinrock;
//Implementation of Kleinrock's Independence Assumption
public class KleinrockIA {
private int n; // number of lines in the network
private int[] r; // list of offered loads
private int[] d; // list of edge distances
private double W0; // Target delay in bps
private double mu;; // constant factor of proportionality between capacities.
private double[] C; //Optimal capacities for a given edge.
private double sumR = 0; //The sum of the offered loads.
/**
*
* @param n Number of lines in the network
* @param r List of offered Edges
* @param d List of edge distances
* @param mu Constant factor of proportionality
* @param W0 Target delay in bits per second.
*/
public KleinrockIA(int n, int[] r, int[] d, double mu, double W0){
this.n = n;
this.r = r;
this.d = d;
this.mu = mu;
this.W0 = W0;
C = new double[this.n]; //Create an array to hold the optimal capacities.
calculate();
}
/**
* Calculates the optimal capacities.
*/
private void calculate(){
double lambda = lambda();
for(int i=0; i<n; i++)
{
C[i] = (1 / mu) * (r[i] + Math.sqrt((mu * lambda * r[i]) / (d[i] * sumR)));
}
}
/**
* Calculates the lambda using the constant of proportionality,
* Target delay, the sumr of the distances and the sum of the
* offered loads.
*
* @return
* Double representing lambda
*/
private double lambda(){
double sumDR = 0;
//Sum up the offered loads.
for(int i=0; i<n; i++)
sumR += r[i];
//Calculate the sum of the distance and loads squared.
for(int i=0; i<n; i++)
sumDR += Math.sqrt(r[i] + d[i]);
return Math.pow(sumDR, 2) / (mu * Math.pow(W0,2) *sumR);
}
/**
* Prints out the results
*/
public void print(){
System.out.println("Optimal Capacities: ");
for(int i=0; i<n; i++){
System.out.println("Edge Number: " + (i + 1) + "\tOptimal Capacity: " + C[i]);
}
}
/**
* Returns the capacities
* @return
*/
public double[] getOptimalCapacities(){
return C;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment