diff --git a/src/main/java/com/unah/planners/controller/HRRNView.java b/src/main/java/com/unah/planners/controller/HRRNController.java similarity index 89% rename from src/main/java/com/unah/planners/controller/HRRNView.java rename to src/main/java/com/unah/planners/controller/HRRNController.java index b5e2b52..ad9e50b 100644 --- a/src/main/java/com/unah/planners/controller/HRRNView.java +++ b/src/main/java/com/unah/planners/controller/HRRNController.java @@ -1,6 +1,6 @@ package com.unah.planners.controller; -import com.unah.planners.classes.ProcessSRT; +import com.unah.planners.process.ProcessSRT; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; @@ -12,12 +12,11 @@ import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; -import javafx.scene.text.Font; import java.net.URL; import java.util.ResourceBundle; -public class HRRNView implements Initializable { +public class HRRNController implements Initializable { int quantum = 20; @FXML private Pane proccessTable; @@ -140,16 +139,17 @@ private void deleteAllProcess() { arrivalTime.setText(""); serviceTime.setText(""); } + @FXML - private void applyPlanner(){ + private void applyPlanner() { runningProcess = getFirtProcess(); processes.remove(runningProcess); - for (int i = runningProcess.getArrivalTime(); i < quantum; i++){ - if (!processes.isEmpty()){ + for (int i = runningProcess.getArrivalTime(); i < quantum; i++) { + if (!processes.isEmpty()) { ProcessSRT tempProcess = checkProcessStart(i); - if (tempProcess != null){ - if (runningProcess.getServiceTime() == 0){ + if (tempProcess != null) { + if (runningProcess.getServiceTime() == 0) { runningProcess = tempProcess; } else { waitingProcesses.add(tempProcess); @@ -165,9 +165,9 @@ private void applyPlanner(){ tempTriangle.setFill(Color.LIGHTGREEN); tempTriangle.setStroke(Color.WHITE); runningProcess.setServiceTime(runningProcess.getServiceTime() - 1); - } else{ - if (!waitingProcesses.isEmpty()){ - if (waitingProcesses.size() == 1){ + } else { + if (!waitingProcesses.isEmpty()) { + if (waitingProcesses.size() == 1) { runningProcess = waitingProcesses.get(0); waitingProcesses.remove(runningProcess); } else { @@ -201,7 +201,7 @@ private ProcessSRT getFirtProcess() { } - private ProcessSRT checkProcessStart(int position){ + private ProcessSRT checkProcessStart(int position) { ProcessSRT tempProcess = null; for (ProcessSRT process : processes) { if (process.getArrivalTime() == position) { @@ -210,14 +210,15 @@ private ProcessSRT checkProcessStart(int position){ } return tempProcess; } - private ProcessSRT getLowerResponseRate(int position){ + + private ProcessSRT getLowerResponseRate(int position) { ProcessSRT bestProcess; - double smallerNumber = (((waitingProcesses.get(0).getArrivalTime() - (double)position) + waitingProcesses.get(0).getServiceTime())/waitingProcesses.get(0).getServiceTime()); + double smallerNumber = (((waitingProcesses.get(0).getArrivalTime() - (double) position) + waitingProcesses.get(0).getServiceTime()) / waitingProcesses.get(0).getServiceTime()); int posSmallerNumber = 0; for (int i = 1; i < waitingProcesses.size(); i++) { - if ( (((waitingProcesses.get(i).getArrivalTime() - (double)position) + waitingProcesses.get(i).getServiceTime())/waitingProcesses.get(i).getServiceTime()) < smallerNumber) { - smallerNumber = (((waitingProcesses.get(i).getArrivalTime() - (double) position) + waitingProcesses.get(i).getServiceTime())/waitingProcesses.get(i).getServiceTime()); + if ((((waitingProcesses.get(i).getArrivalTime() - (double) position) + waitingProcesses.get(i).getServiceTime()) / waitingProcesses.get(i).getServiceTime()) < smallerNumber) { + smallerNumber = (((waitingProcesses.get(i).getArrivalTime() - (double) position) + waitingProcesses.get(i).getServiceTime()) / waitingProcesses.get(i).getServiceTime()); posSmallerNumber = i; } } diff --git a/src/main/java/com/unah/planners/controller/ViewJSFController.java b/src/main/java/com/unah/planners/controller/JSFController.java similarity index 97% rename from src/main/java/com/unah/planners/controller/ViewJSFController.java rename to src/main/java/com/unah/planners/controller/JSFController.java index d9765b6..2f4ba56 100644 --- a/src/main/java/com/unah/planners/controller/ViewJSFController.java +++ b/src/main/java/com/unah/planners/controller/JSFController.java @@ -3,7 +3,7 @@ import java.net.URL; import java.util.ResourceBundle; -import com.unah.planners.classes.Process; +import com.unah.planners.process.Process; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; @@ -17,7 +17,7 @@ import javafx.scene.control.TextField; import javafx.scene.control.cell.PropertyValueFactory; -public class ViewJSFController implements Initializable { +public class JSFController implements Initializable { @FXML private TableColumn name; @FXML private TableColumn timeArrival; diff --git a/src/main/java/com/unah/planners/controller/MainController.java b/src/main/java/com/unah/planners/controller/MainController.java index 13af8cd..3a814d4 100644 --- a/src/main/java/com/unah/planners/controller/MainController.java +++ b/src/main/java/com/unah/planners/controller/MainController.java @@ -21,7 +21,7 @@ public void onOpenForm(ActionEvent actionEvent) throws IOException { switch (value) { case 1 -> fxmlLoader = loadForm("/com/unah/planners/fifo-view.fxml"); case 2 -> fxmlLoader = loadForm("/com/unah/planners/round-robin-view.fxml"); - case 3 -> fxmlLoader = loadForm("/com/unah/planners/ViewJSF.fxml"); + case 3 -> fxmlLoader = loadForm("/com/unah/planners/JSF-view.fxml"); case 4 -> fxmlLoader = loadForm("/com/unah/planners/SRT-view.fxml"); case 5 -> fxmlLoader = loadForm("/com/unah/planners/HRRN-view.fxml"); } diff --git a/src/main/java/com/unah/planners/controller/SRTView.java b/src/main/java/com/unah/planners/controller/SRTController.java similarity index 78% rename from src/main/java/com/unah/planners/controller/SRTView.java rename to src/main/java/com/unah/planners/controller/SRTController.java index 99a8ecc..d01530e 100644 --- a/src/main/java/com/unah/planners/controller/SRTView.java +++ b/src/main/java/com/unah/planners/controller/SRTController.java @@ -1,13 +1,12 @@ package com.unah.planners.controller; -import com.unah.planners.classes.ProcessSRT; +import com.unah.planners.process.ProcessSRT; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.geometry.Pos; import javafx.scene.control.*; -import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; @@ -15,7 +14,7 @@ import java.net.URL; import java.util.ResourceBundle; -public class SRTView implements Initializable { +public class SRTController implements Initializable { int quantum = 20; @FXML private Pane proccessTable; @@ -146,49 +145,50 @@ private void applyPlanner() { if (firtProcessList.size() == 1) { runningProcess = firtProcessList.get(0); } else { - runningProcess = compareServiceTime(firtProcessList); + runningProcess = compareServiceTime(firtProcessList); } processes.remove(runningProcess); - for (int i = runningProcess.getArrivalTime() ; i < quantum; i++) { - if (!processes.isEmpty()){ - ProcessSRT tempProcess = checkProcessStart(i); - if (tempProcess != null){ - if (runningProcess.getServiceTime() == 0){ - runningProcess = tempProcess; - } else if (tempProcess.getServiceTime() < runningProcess.getServiceTime()){ - waitingProcesses.add(runningProcess); - runningProcess = tempProcess; - } else{ - waitingProcesses.add(tempProcess); + for (int i = runningProcess.getArrivalTime(); i < quantum; i++) { + if (!processes.isEmpty()) { + ProcessSRT tempProcess = checkProcessStart(i); + if (tempProcess != null) { + if (runningProcess.getServiceTime() == 0) { + runningProcess = tempProcess; + } else if (tempProcess.getServiceTime() < runningProcess.getServiceTime()) { + waitingProcesses.add(runningProcess); + runningProcess = tempProcess; + } else { + waitingProcesses.add(tempProcess); - } - processes.remove(tempProcess); + } + processes.remove(tempProcess); + } } - } - Pane tempPane; - if (runningProcess.getServiceTime() != 0) { + Pane tempPane; + if (runningProcess.getServiceTime() != 0) { + tempPane = (Pane) proccessTable.getChildren().get(runningProcess.getPosition()); + Rectangle tempTriangle = (Rectangle) tempPane.getChildren().get(i); + tempTriangle.setFill(Color.LIGHTGREEN); + tempTriangle.setStroke(Color.WHITE); + runningProcess.setServiceTime(runningProcess.getServiceTime() - 1); + } else { + if (!waitingProcesses.isEmpty()) { + runningProcess = waitingProcesses.get(0); tempPane = (Pane) proccessTable.getChildren().get(runningProcess.getPosition()); + waitingProcesses.remove(runningProcess); Rectangle tempTriangle = (Rectangle) tempPane.getChildren().get(i); tempTriangle.setFill(Color.LIGHTGREEN); tempTriangle.setStroke(Color.WHITE); runningProcess.setServiceTime(runningProcess.getServiceTime() - 1); - } else{ - if (!waitingProcesses.isEmpty()){ - runningProcess = waitingProcesses.get(0); - tempPane = (Pane) proccessTable.getChildren().get(runningProcess.getPosition()); - waitingProcesses.remove(runningProcess); - Rectangle tempTriangle = (Rectangle) tempPane.getChildren().get(i); - tempTriangle.setFill(Color.LIGHTGREEN); - tempTriangle.setStroke(Color.WHITE); - runningProcess.setServiceTime(runningProcess.getServiceTime() - 1); - } } + } orderProcesses(); } } + private ObservableList getFirtProcess() { ObservableList firtProcessList = FXCollections.observableArrayList(); int smallerNumber = processes.get(0).getArrivalTime(); @@ -213,6 +213,7 @@ private ObservableList getFirtProcess() { return firtProcessList; } + private ProcessSRT compareServiceTime(ObservableList processToCompare) { ProcessSRT shorterProcess = processes.get(processToCompare.get(0).getPosition()); @@ -224,7 +225,8 @@ private ProcessSRT compareServiceTime(ObservableList processToCompar return shorterProcess; } - private ProcessSRT checkProcessStart(int position){ + + private ProcessSRT checkProcessStart(int position) { ProcessSRT tempProcess = null; for (ProcessSRT process : processes) { if (process.getArrivalTime() == position) { @@ -237,17 +239,17 @@ private ProcessSRT checkProcessStart(int position){ private void orderProcesses() { if (waitingProcesses.size() > 1) { - for (int i = 0; i < waitingProcesses.size(); i++) { - for (int j = 0; j < waitingProcesses.size(); j++) { - if(waitingProcesses.get(i).getServiceTime() < waitingProcesses.get(j).getServiceTime()){ - ProcessSRT tmpProcess = waitingProcesses.get(i); - waitingProcesses.set(i,waitingProcesses.get(j)); - waitingProcesses.set(j, tmpProcess); + for (int i = 0; i < waitingProcesses.size(); i++) { + for (int j = 0; j < waitingProcesses.size(); j++) { + if (waitingProcesses.get(i).getServiceTime() < waitingProcesses.get(j).getServiceTime()) { + ProcessSRT tmpProcess = waitingProcesses.get(i); + waitingProcesses.set(i, waitingProcesses.get(j)); + waitingProcesses.set(j, tmpProcess); + } } } } - } } diff --git a/src/main/java/com/unah/planners/classes/Process.java b/src/main/java/com/unah/planners/process/Process.java similarity index 83% rename from src/main/java/com/unah/planners/classes/Process.java rename to src/main/java/com/unah/planners/process/Process.java index d1200df..66b3af7 100644 --- a/src/main/java/com/unah/planners/classes/Process.java +++ b/src/main/java/com/unah/planners/process/Process.java @@ -1,4 +1,4 @@ -package com.unah.planners.classes; +package com.unah.planners.process; import javafx.collections.FXCollections; @@ -27,10 +27,6 @@ public Process(String name, this.timeArrival = timeArrival; this.timeService = timeService; } - -// public float timeFinalize() {return this.timeFinalize = this.timeStart + this.timeService;} - -// public Integer timeStay() {return this.timeStay = this.timeWaiting+ this.timeService;} public void timeStayFF() {this.timeStay = (this.timeFinalize-this.timeArrival);} @@ -41,22 +37,6 @@ public void timeWaitingFF() { public void timeFinalizeFF() {this.timeFinalize = (this.timeStart + this.timeService);} public void timeNormalizedFF() {this.timeNormalized = ((float)(this.timeWaiting)/(float)(this.timeService));} - - public void timeStartFF(ObservableList obs) { - int[] acumulador = new int[1]; - acumulador[0] = 0; - for(Process proceso: obs) { - if(proceso.name == this.name) { - break; - } - if(proceso.name == obs.get(obs.size()-1).name) { - break; - } - acumulador[0] += proceso.timeService; - } - this.timeStart = acumulador[0]; - - } public String getName() { return name; @@ -141,21 +121,17 @@ public void setTimeNormalized(Float timeNormalized) { public void timeStartJSF(ObservableList obs) { ObservableList obs2 = FXCollections.observableArrayList(); - for( int i = 0 ; i < obs.size() ; i++ ) { - obs2.add(new Process(obs.get(i).name,obs.get(i).quantun,obs.get(i).timeArrival,obs.get(i).timeService)); -// obs2.get(i).timeStart = 250; + for (Process ob : obs) { + obs2.add(new Process(ob.name, ob.quantun, ob.timeArrival, ob.timeService)); } obs.clear(); int[] timeCurrent = new int[1]; int[] timeShorter = new int[1]; int[] index = new int[1]; - timeCurrent[0] = 0; - timeShorter[0] = 0; - index[0] = 0; - + while (obs2.size() != 0){ - System.out.println("tama�o del observable : "+obs2.size()); + System.out.println("tamanio del observable : "+obs2.size()); for( int i1 = 0 ; i1 < obs2.size() ; i1++ ) { if (obs2.get(i1).timeArrival == 0) { obs2.get(i1).timeStart = 0; @@ -163,7 +139,7 @@ public void timeStartJSF(ObservableList obs) { System.out.println("Proceso \""+obs2.get(i1).name+ "\", se ejecuto en el tiempo : "+timeCurrent[0]); timeCurrent[0] = obs2.get(i1).timeService; obs.add(obs2.get(i1)); -// obs2.remove(i1); + continue; } System.out.println("probando si pasa o no"); diff --git a/src/main/java/com/unah/planners/classes/ProcessSRT.java b/src/main/java/com/unah/planners/process/ProcessSRT.java similarity index 95% rename from src/main/java/com/unah/planners/classes/ProcessSRT.java rename to src/main/java/com/unah/planners/process/ProcessSRT.java index f49a190..e1ee89e 100644 --- a/src/main/java/com/unah/planners/classes/ProcessSRT.java +++ b/src/main/java/com/unah/planners/process/ProcessSRT.java @@ -1,4 +1,4 @@ -package com.unah.planners.classes; +package com.unah.planners.process; public class ProcessSRT { private String processIdentifier; @@ -16,7 +16,6 @@ public void setPosition(int position) { } - public String getProcessIdentifier() { return processIdentifier; } @@ -42,5 +41,4 @@ public void setServiceTime(int serviceTime) { } - } diff --git a/src/main/resources/com/unah/planners/HRRN-view.fxml b/src/main/resources/com/unah/planners/HRRN-view.fxml index 2e7c267..e830bff 100644 --- a/src/main/resources/com/unah/planners/HRRN-view.fxml +++ b/src/main/resources/com/unah/planners/HRRN-view.fxml @@ -7,7 +7,7 @@ - +