metodo simplex por maximizacion necesito ayuda no me sale las veces que se tiene que repetir
Publicado por MIGUEL (1 intervención) el 06/10/2020 06:33:49
necesito ayuda en este programa solo me sale una matriz y necesito que la matriz se repite hasta que sea sea menor o mayor a 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>
#include <conio.h>
using namespace std;
void ingreso(float [][100],int[],int [],int,int );
void mostrar(float [][100],int,int);
void maximizacion(float [][100],int[],int [],int,int);
void solucion(float [][100],int,int);
int main(){
int f,c,z[100],t[100];
float matriz3[100][100],temp[100][100];
cout<<"programa del metodo simplex (maximizacion)"<<endl;
cout<<"ingrese la cantidad de filas: ";
cin>>f;
cout<<"ingrese la cantidad de columnas:";
cin>>c;
ingreso(matriz3,z,t,f,c);
maximizacion(matriz3,z,t,f,c);
mostrar(matriz3,f,c);
solucion(matriz3,f,c);
mostrar(matriz3,f,c);
};
void ingreso(float matriz3[][100],int z[], int t[],int f,int c ){
float matriz[100][100];
for(int i=0;i<f+1;i++){
for(int j=0;j<c+c+1;j++){
matriz3[i][j]=0;
}
}
for(int i=0;i<f;i++){
cout<<"ingrese x"<<i+1<<": ";
cin>>z[i];
}
cout<<"\n";
for(int i=0;i<f;i++){
for(int j=0;j<c;j++){
cout<<"ingrese x"<<j+1<<": ";
cin>>matriz[i][j];
}
cout<<"ingrese el total: ";
cin>>t[i];
}
for(int i=0;i<f;i++){
for(int j=0;j<c;j++){
matriz3[i][j]=matriz[i][j];
}
}
}
void maximizacion(float matriz3[][100],int z[], int t[],int f,int c){
int a,h,xd;
float div;
a=c;
for(int i=0;i<c;i++){
matriz3[i][a]=1;
a++;
}
//maximizacion
h=c+c;
for(int i=0;i<f;i++){
matriz3[i][h]=t[i];
}
xd=c;
for(int i=0;i<c;i++){
div=z[i]*-1;
matriz3[xd][i]=div;
}
}
void mostrar(float matriz3[][100],int f,int c){
for(int i=0;i<f+1;i++){
cout<<"\n";
for(int j=0;j<c+c+1;j++){
cout<<matriz3[i][j];
cout<<"\t";
}
}
}
void solucion(float matriz3[][100],int f,int c){
int pivote,pos,t1,pos2,enc,v;
pivote=9999*9999,enc=9999*9999;
for(int i=0;i<c+c;i++){
if(matriz3[f][i]<pivote){
pivote=matriz3[f][i];
pos=i;
}
}
cout<<endl;
for(int i=0;i<f;i++){
t1=matriz3[i][c+c]/matriz3[i][pos];
if(t1<enc){
enc=t1;
pos2=i;
}
}
cout<<endl;
v=matriz3[pos2][pos];
for(int j=0;j<c+c+1;j++){
matriz3[pos2][j]=matriz3[pos2][j]/v;
}
int s20;
for(int i=0;i<f+1;i++){
if(i!=pos2){
s20=matriz3[i][pos];
for(int j=0;j<c+c+1;j++){
matriz3[i][j]=((matriz3[pos2][j]*(-s20)+matriz3[i][j]));
}
}
}
}
Valora esta pregunta
0