diff --git a/src/main/java/models/MM1KQueueModel.java b/src/main/java/models/MM1KQueueModel.java
index 29262a7..30807d3 100644
--- a/src/main/java/models/MM1KQueueModel.java
+++ b/src/main/java/models/MM1KQueueModel.java
@@ -2,10 +2,6 @@
import static java.lang.Math.*;
-/**
- * Created by Omar
- * Date: 18-Dec-17.
- */
public final class MM1KQueueModel extends QueueModel {
@Override
protected PerformanceMetrics calculatePerformanceMetrics(QueueSystemInput input) throws QueueModelException {
diff --git a/src/main/java/models/MMCKQueueModel.java b/src/main/java/models/MMCKQueueModel.java
index d9824c7..e00cd6a 100644
--- a/src/main/java/models/MMCKQueueModel.java
+++ b/src/main/java/models/MMCKQueueModel.java
@@ -5,10 +5,10 @@
import static utils.MathUtils.fact;
import static utils.MathUtils.pow;
-public class MMCKQueueModel extends QueueModel{
+public final class MMCKQueueModel extends QueueModel {
- double lambda, lambdaDash, mue, r, rho, P0;
- int servers, capacity, C, K;
+ private double lambda, lambdaDash, mue, r, rho, P0;
+ private int servers, capacity, C, K;
@Override
protected PerformanceMetrics calculatePerformanceMetrics(QueueSystemInput input) throws QueueModelException {
@@ -28,7 +28,6 @@ protected PerformanceMetrics calculatePerformanceMetrics(QueueSystemInput input)
double L, Lq, W, Wq;
-
//Lambda(dash) calculation
{
lambdaDash = lambda * (1 - getP(K));
@@ -37,7 +36,7 @@ protected PerformanceMetrics calculatePerformanceMetrics(QueueSystemInput input)
//Lq calculation
{
Lq = 0.0;
- for(int n = C + 1; n <= K; ++n){
+ for (int n = C + 1; n <= K; ++n) {
double Pn = getP(n);
Lq += (n - C) * Pn;
}
@@ -48,8 +47,8 @@ protected PerformanceMetrics calculatePerformanceMetrics(QueueSystemInput input)
L = Lq + C;
double neg = 0;
- for(int n = 0; n <= C - 1; ++n){
- neg += (C - n) * pow(r, n) / fact(n);
+ for (int n = 0; n <= C - 1; ++n) {
+ neg += ((C - n) * pow(r, n)) / fact(n);
}
L -= P0 * neg;
@@ -70,40 +69,41 @@ protected PerformanceMetrics calculatePerformanceMetrics(QueueSystemInput input)
//Calculates P(n)
- double getP(int n){
+ double getP(int n) {
double P = Double.NaN;
- if(n >= 0 && n < C){
- P = pow(r, n) / fact(n) * P0;
- }
- else if(n >= C && n <= K){
- P = pow(r, n) / (pow(C, n - C) * fact(C)) * P0;
+ if (n >= 0 && n < C) {
+ P = (pow(r, n) / fact(n)) * P0;
+ } else if (n >= C && n <= K) {
+ P = (pow(r, n) / (pow(C, n - C) * fact(C))) * P0;
}
return P;
}
//Calculates P(0)
- double getP0(){
+ double getP0() {
double P0_inv = 0.0;
- MathUtils.prepareFact(C);
+ MathUtils.prepareFact(Math.max(C, K));
- if(rho == 1){
+ if (rho == 1.0) {
- for(int n = 0; n <= C - 1; ++n){
- P0_inv += (pow(r, n) / fact(n)) + (pow(r, C) / fact(C) * (K - C + 1));
+ for (int n = 0; n <= C - 1; ++n) {
+ P0_inv += (pow(r, n) / fact(n));
}
- }
- else{
+ P0_inv += (pow(r, C) / fact(C)) * (K - C + 1);
+
+ } else {
- for(int n = 0; n <= C - 1; ++n){
- P0_inv += (pow(r, n) / fact(n)) + (pow(r, C) / fact(C) * ((1 - pow(rho, K - C + 1)) / (1 - rho)));
+ for (int n = 0; n <= C - 1; ++n) {
+ P0_inv += (pow(r, n) / fact(n));
}
+ P0_inv += (pow(r, C) / fact(C)) * ((1 - pow(rho, K - C + 1)) / (1 - rho));
}
- return 1 / P0_inv;
+ return 1 / P0_inv;
}
}
diff --git a/src/main/java/models/MMCQueueModel.java b/src/main/java/models/MMCQueueModel.java
new file mode 100644
index 0000000..3182541
--- /dev/null
+++ b/src/main/java/models/MMCQueueModel.java
@@ -0,0 +1,44 @@
+package models;
+
+import utils.MathUtils;
+import static java.lang.Math.*;
+
+public class MMCQueueModel extends QueueModel {
+ @Override
+ protected PerformanceMetrics calculatePerformanceMetrics(QueueSystemInput inputs) throws QueueModelException {
+ double lambda = inputs.getArrivalRate();
+ double mue = inputs.getServiceRate();
+ double c = inputs.getNumberOfServers();
+ double r = lambda / mue;
+
+ MathUtils.prepareFact((int) (c + 1));
+
+ double p0 = calculateP0(c, r);
+ double Lq = calculateLq(lambda, mue, c, r, p0);
+
+ double Wq = Lq / lambda;
+ double W = Wq + (1 / mue);
+ double L = Lq + r;
+
+ return new PerformanceMetrics(L, Lq, W, Wq);
+ }
+
+ private double calculateLq(double lambda, double mue, double c, double r, double p0) {
+ double numerator = pow(r, c) * lambda * mue;
+ double denominator = MathUtils.fact((int) (c - 1)) * pow((c * mue) - lambda, 2);
+ return (numerator / denominator) * p0;
+ }
+
+ private double calculateP0(double c, double r) {
+ double firstTerm = 0;
+ double secondTerm = ((c * pow(r, c)) / (MathUtils.fact((int) c) * (c - r)));
+
+ for (int n = 0; n <= c - 1; n++) {
+ firstTerm += (pow(r, n) / MathUtils.fact(n));
+ }
+
+ double result = firstTerm + secondTerm;
+
+ return 1 / result;
+ }
+}
diff --git a/src/main/java/ui/DD1KOutputScreen.java b/src/main/java/ui/DD1KOutputScreen.java
index f18eee8..a29f07e 100644
--- a/src/main/java/ui/DD1KOutputScreen.java
+++ b/src/main/java/ui/DD1KOutputScreen.java
@@ -1,8 +1,33 @@
package ui;
-/**
- * Created by Omar
- * Date: 18-Dec-17.
- */
+import javafx.fxml.FXML;
+import javafx.scene.control.Label;
+import javafx.scene.input.MouseEvent;
+import javafx.scene.layout.BorderPane;
+
public class DD1KOutputScreen {
+
+ @FXML
+ private BorderPane root;
+
+ @FXML
+ private Label labelL;
+
+ @FXML
+ private Label labelLq;
+
+ @FXML
+ private Label labelW;
+
+ @FXML
+ private Label labelWq;
+
+ @FXML
+ private Label backButton;
+
+ @FXML
+ void onBackClicked(MouseEvent event) {
+
+ }
+
}
diff --git a/src/main/java/utils/InputFieldValidation.java b/src/main/java/utils/InputFieldValidation.java
index 116ddf2..5b1ea6d 100644
--- a/src/main/java/utils/InputFieldValidation.java
+++ b/src/main/java/utils/InputFieldValidation.java
@@ -3,10 +3,6 @@
import com.jfoenix.validation.base.ValidatorBase;
import javafx.scene.control.TextInputControl;
-/**
- * Created by Omar
- * Date: 17-Dec-17.
- */
public class InputFieldValidation extends ValidatorBase {
@Override
protected void eval() {
diff --git a/src/main/java/utils/MathUtils.java b/src/main/java/utils/MathUtils.java
index 6e9b1d3..3e1eb28 100644
--- a/src/main/java/utils/MathUtils.java
+++ b/src/main/java/utils/MathUtils.java
@@ -21,29 +21,37 @@ public static Double eval(String expressionStr) throws Exception {
}
- static long f[];
- public static void prepareFact(int MX){
+ private static long f[];
+
+ public static void prepareFact(int MX) {
f = new long[MX + 1];
f[0] = 1;
- for(int i = 1; i <= MX; ++i) f[i] = f[i - 1] * i;
+ for (int i = 1; i <= MX; ++i) f[i] = f[i - 1] * i;
}
//O(1) factorial query
- public static long fact(int x){
+ public static long fact(int x) {
return f[x];
}
//Binary exponentiation O(log2(exponent)) runtime
- public static double pow(double base, int exponent){
+ public static double pow(double base, int exponent) {
+
+ double res = 1.0;
- double res = 1;
+ boolean reversed = false;
+
+ if (exponent < 0) {
+ reversed = true;
+ exponent *= -1;
+ }
- while(exponent != 0){
- if((exponent & 1) == 1) res = res * base;
+ while (exponent != 0) {
+ if ((exponent & 1) == 1) res = res * base;
exponent /= 2;
base = base * base;
}
- return res;
+ return reversed ? 1 / res : res;
}
}
diff --git a/src/main/resources/fxml/dd1k_output_screen.fxml b/src/main/resources/fxml/dd1k_output_screen.fxml
index a8a016d..e217d90 100644
--- a/src/main/resources/fxml/dd1k_output_screen.fxml
+++ b/src/main/resources/fxml/dd1k_output_screen.fxml
@@ -1,14 +1,98 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/fxml/main_screen.fxml b/src/main/resources/fxml/main_screen.fxml
index 08b7f04..f8a4157 100644
--- a/src/main/resources/fxml/main_screen.fxml
+++ b/src/main/resources/fxml/main_screen.fxml
@@ -39,7 +39,7 @@
-
+
diff --git a/src/test/java/UnitTest.java b/src/test/java/UnitTest.java
index 7cebd88..4a33d4f 100644
--- a/src/test/java/UnitTest.java
+++ b/src/test/java/UnitTest.java
@@ -1,11 +1,8 @@
import io.reactivex.Observable;
import io.reactivex.observers.DisposableObserver;
-import models.MM1KQueueModel;
-import models.MM1QueueModel;
-import models.PerformanceMetrics;
-import models.QueueSystemInput;
-import org.apache.commons.lang3.builder.ToStringExclude;
+import models.*;
import org.junit.Test;
+import org.junit.runners.JUnit4;
import utils.MathUtils;
/**
@@ -13,7 +10,7 @@
* Date: 17-Dec-17.
*/
-public class UnitTest {
+public class UnitTest{
@Test
public void testSomething() {
try {
@@ -67,4 +64,26 @@ public void onComplete() {
}
});
}
+
+ @Test
+ public void testMMCKQueueModel() {
+ MMCKQueueModel model = new MMCKQueueModel();
+ Observable ob = model.getPerformanceMetrics(new QueueSystemInput(1.0, 1.0 / 6.0,3, 7));
+ ob.subscribeWith(new DisposableObserver() {
+ @Override
+ public void onNext(PerformanceMetrics performanceMetrics) {
+ System.out.println(performanceMetrics);
+ }
+
+ @Override
+ public void onError(Throwable e) {
+ e.printStackTrace();
+ }
+
+ @Override
+ public void onComplete() {
+ System.out.println("done!");
+ }
+ });
+ }
}