Skip to content

Instantly share code, notes, and snippets.

@bryantp
Last active December 15, 2015 09:19
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/5238013 to your computer and use it in GitHub Desktop.
Save bryantp/5238013 to your computer and use it in GitHub Desktop.
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 static double sumR;
/**
* Calculates the optimal capacities for a given network.
* @return
*/
public static double[] getOptimalCapacities(int n, int[] r, int[] d, double mu, double W0){
double lambda = lambda(n,r,d,mu,W0);
double[] C = new double[n];
for(int i=0; i<n; i++)
{
C[i] = (1 / mu) * (r[i] + Math.sqrt((mu * lambda * r[i]) / (d[i] * sumR)));
}
return C;
}
/**
* 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 static double lambda(int n,int[] r, int[] d, double mu,double W0 ){
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment