int co[];
int p[];
int vuelta[];
int q;
int procesos_originales[];
int tamar;
int c = 0;
int temp = 0;
int total = 0;
float tiempo_espera, tiempo_ida;
public void roundrobin() {
tamar=Integer.parseInt(nprocesos.getText());
int p[] = new int[tamar];
int co[] = new int[tamar];
int es[] = new int[tamar];
int vuelta[] = new int[tamar];
for (int i = 0; i < tamar; i++) {
co[i] = p[i] = Integer.parseInt(JOptionPane.showInputDialog("introduza el tamanio "
+ "del proceso [" + (i + 1) + "]"));
}
q = Integer.parseInt(quantum.getText());
for (int j = 0; j <tamar; j++) {
while (p[j] >= 0) {
for (int i = 0; i < p.length; i++) {
if (p[i] >= 0) {
txtoriginales.append("\nP[" + (i + 1) + "] : " + p[i] + "\t");
if (p[i] > 0) {
vuelta[i]++;
}
}
p[i] -= q;
}
c++;
}
}
for (int i = 0; i < p.length; i++) {
es[i] = vuelta[i] + co[i];
tiempo_espera += vuelta[i];
tiempo_ida += es[i];
}
txtesta.append("\nProceso\ttamanio\tespera\tida");
for (int i = 0; i < tamar; i++) {
txtesta.append("\np[" + (i + 1) + "] \t " + co[i] + "\t " + vuelta[i] + "\t" + es[i]);
}
promedioespera.setText(""+ (tiempo_espera / tamar));
promedioida.setText(""+ (tiempo_ida / tamar));
}
public void fcfs(){
tamar=Integer.parseInt(nprocesos.getText());
int p[] = new int[tamar];
int co[] = new int[tamar];
int es[] = new int[tamar];
int vuelta[] = new int[tamar];
for (int i = 0; i < tamar; i++) {
co[i] = p[i] = Integer.parseInt(JOptionPane.showInputDialog("introduza el tamanio "
+ "del proceso [" + (i + 1) + "]"));
}
q = 1;
for (int i = 0; i < p.length; i++) {
txtoriginales.append("\nP[" + (i + 1) + "] : " + p[i] + "\t");
}
vuelta[0] = 0;
for (int i = 1; i < tamar; i++) {
vuelta[i] = vuelta[i - 1] + co[i - 1];
total = total + vuelta[i];
}
for (int i = 0; i < p.length; i++) {
es[i] = vuelta[i] + co[i];
tiempo_espera += vuelta[i];
tiempo_ida += es[i];
}
txtesta.append("\nProceso\ttamanio\tespera\tida" );
for (int i = 0; i < p.length; i++) {
txtesta.append("\np[" + (i + 1) + "] \t " + co[i] + "\t " + vuelta[i] + "\t" + es[i]);
}
promedioespera.setText(""+ (tiempo_espera / tamar));
promedioida.setText(""+ (tiempo_ida / tamar));
}
public void sjf(){
tamar=Integer.parseInt(nprocesos.getText());
int p[] = new int[tamar];
int co[] = new int[tamar];
int es[] = new int[tamar];
int vuelta[] = new int[tamar];
int procesos_originales[] = new int[tamar];
for (int i = 0; i < tamar; i++) {
procesos_originales[i] = co[i] = p[i] = Integer.parseInt(JOptionPane.showInputDialog("introduza el tamanio "
+ "del proceso [" + (i + 1) + "]"));
}
for (int i = 0; i < tamar - 1; i++) {
for (int j = i + 1; j < tamar; j++) {
if (p[i] > p[j]) {
temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
}
for (int i = 0; i < p.length; i++) {
txtoriginales.append("\nP[" + (i + 1) + "] : " + p[i] + "\t");
}
for (int i = 0; i < tamar - 1; i++) {
for (int j = i + 1; j < tamar; j++) {
if (co[i] > co[j]) {
temp = co[i];
co[i] = co[j];
co[j] = temp;
}
}
}
vuelta[0] = 0;
for (int i = 1; i < tamar; i++) {
vuelta[i] = vuelta[i - 1] + co[i - 1];
total = total + vuelta[i];
}
for (int i = 0; i < p.length; i++) {
es[i] = vuelta[i] + co[i];
tiempo_espera += vuelta[i];
tiempo_ida += es[i];
txtordenados.append("\nP[" + (i + 1) + "] : " + procesos_originales[i] + "\t");
}
txtesta.append("\nProceso\ttamanio\tespera\tida");
for (int i = 0; i < p.length; i++) {
txtesta.append("\np[" + (i + 1) + "] \t " + co[i] + "\t " + vuelta[i] + "\t" + es[i]);
}
promedioespera.setText(""+(tiempo_espera / tamar));
promedioida.setText("" + (tiempo_ida / tamar));
}