0% found this document useful (0 votes)
10 views3 pages

App

1) The document defines a Java program that implements the simplex method to solve linear programming problems. 2) It takes in the number of decision variables and constraints as user input, initializes the constraint matrix and vectors, and prints the initial tableau. 3) It then calculates the reduced costs and identifies the leaving variable and entering variable to perform a pivot operation on the constraint matrix. 4) After pivoting, it prints the updated tableau and repeats the process to iteratively solve the linear program.

Uploaded by

Andretorre12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

App

1) The document defines a Java program that implements the simplex method to solve linear programming problems. 2) It takes in the number of decision variables and constraints as user input, initializes the constraint matrix and vectors, and prints the initial tableau. 3) It then calculates the reduced costs and identifies the leaving variable and entering variable to perform a pivot operation on the constraint matrix. 4) After pivoting, it prints the updated tableau and repeats the process to iteratively solve the linear program.

Uploaded by

Andretorre12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

static String cad="";

public static void main(String[]orf){


int n,m;
n= Integer.parseInt(JOptionPane.showInputDialog("Ingrese la cantidad de
variables de decision: "));
m= Integer.parseInt(JOptionPane.showInputDialog("Ingrese la cantidad de
restricciones: "));
double num[][]=new double[m][n+m];
double Bi[] = new double [m];
double Cj[] = new double [n+m];
double Zi[]= new double [n+m];

llenado(n,m,num,Bi,Cj);
imprimir(n,m,num,Bi,Cj,Zi);
calculando(Zi, Cj, Bi, num, n, m);
imprimir(n,m,num,Bi,Cj,Zi);
}
public static void llenado(int n, int m, double num[][],double Bi[],double Cj[])
{

for(int z=0;z<(n+m);z++)
{
Cj[z]=Integer.parseInt(JOptionPane.showInputDialog("Ingrese los
coeficientes de la funcion objetivo(Cj) X"+(z+1)));
cad=cad+"--------------";
}
for(int i=0;i<m;i++){
JOptionPane.showMessageDialog(null,"Ingresando variables de la
ecuacion de restriccion numero "+(i+1));
for(int j=0;j<(n+m);j++)
{

num[i][j] = Integer.parseInt(JOptionPane.showInputDialog("Ingrese el
coeficiente de la variable x"+(j+1)));

Bi[i]=Integer.parseInt(JOptionPane.showInputDialog("Ingrese Bi Resticcion
"+(i+1)));
}
}
public static void imprimir(int n, int m, double num[][],double Bi[],double
Cj[],double Zi[]){
double acum=0;

System.out.println("|-----------------------------------------------"+cad);
System.out.print("\t\t\t\t|\tCJ");
for(int z=0;z<(n+m);z++)
{

System.out.print("\t|\t"+Cj[z]+"");
}
System.out.print("\t|\n");
System.out.println("|-----------------------------------------------"+cad);
System.out.print("|\tCk\t|\tXk\t|\tBi\t|\t");
for(int h=1;h<=(n+m);h++)
{
System.out.print("X" +h+"\t|\t");
}
System.out.println();
System.out.println("|-----------------------------------------------"+cad);
int k=n+1;
for(int i=0;i<m;i++){

System.out.print("|\t0\t|\tx"+(k)+"\t|\t"+Bi[i]+"\t|\t");
for(int j=0;j<(n+m);j++)
{
System.out.print(num[i][j]+"\t|\t");
}
System.out.println();
k++;
}
System.out.println("|-----------------------------------------------"+cad);
System.out.print("|\t\tZi\t\t");
for(int i=0;i<m;i++)
{
System.out.print("|\t"+(Bi[i]*0));
for(int j=0;j<(n+m);j++)
{
Zi[i]=(num[i][j]*0);
acum=acum+Zi[i];
}
System.out.print("\t|\t"+acum+"\t");
}
System.out.println("|");
System.out.println("|-----------------------------------------------"+cad);
System.out.print("|\t\t\tZi-Cj\t\t\t");

}
public static void calculando(double Zi[],double Cj[],double Bi[],double num[]
[],int n,int m)
{
double menor=999999;
double menor2=99999;
double pivot;
double div=0;
for(int i=0;i<m+n;i++)
{
System.out.print("|\t"+(Zi[i]-Cj[i])+"\t");
double c=(Zi[i]-Cj[i]);
if(c<menor)
{
menor=c;
}
}

for(int i=0;i<(m+n);i++)
{
if((Zi[i]-Cj[i])==menor)
{
for(int j=0;j<m;j++){
div=Bi[j]/num[j][i];
if(div<menor2)
{
menor2=div;
}
}
}
}
System.out.println(menor2);
int b=0,a=0;

for(int i=0;i<(m+n);i++)
{
for(int j=0;j<m;j++)
{
if(menor2==((Bi[j])/(num[j][i])))
{
a=j;
b=i;
Bi[j]=(Bi[j]/num[j][i]);
System.out.println(a+" dedeeded "+b);
}

}
}

pivot=num[a][b];
for(int i=0;i<(m+n);i++)
{

num[a][i]=(num[a][i])/(pivot);
System.out.println(num[a][i]);
}

for(int j=0;j<m;j++)
{
if(a!=j)
{
System.out.println(Bi[j]);
Bi[j]=Bi[j]-(num[j][b]*Bi[a]);

}
}
double sempivot;
for(int i=0;i<m;i++)
{
if(a!=i){
for(int j=0;j<(m+n);j++){
sempivot=num[i][b];
num[i][j]=num[i][j]-(num[a][j]*sempivot);
System.out.println(num[i][j]);

}
}
}
}
}

You might also like