Skip to content
This repository has been archived by the owner on Sep 11, 2022. It is now read-only.

Commit

Permalink
style(view): JSF, SRT
Browse files Browse the repository at this point in the history
  • Loading branch information
galexbh committed Mar 15, 2022
1 parent 3d26a37 commit cd72b37
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Process, String> name;
@FXML private TableColumn<Process, Number> timeArrival;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
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;

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;
Expand Down Expand Up @@ -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<ProcessSRT> getFirtProcess() {
ObservableList<ProcessSRT> firtProcessList = FXCollections.observableArrayList();
int smallerNumber = processes.get(0).getArrivalTime();
Expand All @@ -213,6 +213,7 @@ private ObservableList<ProcessSRT> getFirtProcess() {
return firtProcessList;

}

private ProcessSRT compareServiceTime(ObservableList<ProcessSRT> processToCompare) {

ProcessSRT shorterProcess = processes.get(processToCompare.get(0).getPosition());
Expand All @@ -224,7 +225,8 @@ private ProcessSRT compareServiceTime(ObservableList<ProcessSRT> processToCompar
return shorterProcess;

}
private ProcessSRT checkProcessStart(int position){

private ProcessSRT checkProcessStart(int position) {
ProcessSRT tempProcess = null;
for (ProcessSRT process : processes) {
if (process.getArrivalTime() == position) {
Expand All @@ -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);

}
}
}
}
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.unah.planners.classes;
package com.unah.planners.process;


import javafx.collections.FXCollections;
Expand Down Expand Up @@ -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);}

Expand All @@ -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<Process> 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;
Expand Down Expand Up @@ -141,29 +121,25 @@ public void setTimeNormalized(Float timeNormalized) {
public void timeStartJSF(ObservableList<Process> obs) {

ObservableList<Process> 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;
System.out.println("primer if entro");
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");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.unah.planners.classes;
package com.unah.planners.process;

public class ProcessSRT {
private String processIdentifier;
Expand All @@ -16,7 +16,6 @@ public void setPosition(int position) {
}



public String getProcessIdentifier() {
return processIdentifier;
}
Expand All @@ -42,5 +41,4 @@ public void setServiceTime(int serviceTime) {
}



}
2 changes: 1 addition & 1 deletion src/main/resources/com/unah/planners/HRRN-view.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>

<AnchorPane prefHeight="700.0" prefWidth="1000.0" style="-fx-background-color: #bfdbf7;" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.unah.planners.controller.HRRNView">
<AnchorPane prefHeight="700.0" prefWidth="1000.0" style="-fx-background-color: #bfdbf7;" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.unah.planners.controller.HRRNController">
<children>
<Label alignment="CENTER" layoutX="255.0" layoutY="33.0" prefHeight="35.0" prefWidth="449.0" text="Hightest response ratio next (HRRN)">
<font>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/com/unah/planners/SRT-view.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>

<AnchorPane prefHeight="700.0" prefWidth="1000.0" style="-fx-background-color: #bfdbf7;" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.unah.planners.controller.SRTView">
<AnchorPane prefHeight="700.0" prefWidth="1000.0" style="-fx-background-color: #bfdbf7;" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.unah.planners.controller.SRTController">
<children>
<Label alignment="CENTER" layoutX="310.0" layoutY="29.0" prefHeight="28.0" prefWidth="381.0" text="Shortest remaining time (SRT)">
<font>
Expand Down

0 comments on commit cd72b37

Please sign in to comment.