2 мustaqil ta’lim ish hisoboti Fan “ Algoritmlarni loyihalash” Fan o’qituvchisi: Bobonazarov A. Talaba: Erbo’tayev F



Yüklə 293,97 Kb.
səhifə6/6
tarix22.05.2023
ölçüsü293,97 Kb.
#119500
1   2   3   4   5   6
algoritmlarni loyihalash 2- amaliy ish

4-Amali mashg’ulot topshiriqlari
4-masala. Firma bosh og‘rig‘ini qoldiruvchi va o‘lchamdagi tabletkalarni ishlab chiqaradi. o‘lcham 2 dona asprin, 5 dona bikarbonat va 1 dona kodeinlardan tashkil topadi. o‘lcham 1 dona asprin, 8 dona bikarbonat va 6 dona kodeinlardan tashkil topgan. Iste’molchilar darhol samara berishi uchun kamida 12 dona aspirin, 74 dona bikarbonat va 24 dona kodein talab qilinishini aniqlashdi. Iste’molchilar darhol ta’sir qilishi uchun qabul qilishi mumkin bo‘lgan eng kam tabletkalar sonini aniqlash zarur. Ushbu masalani standart chiziqli dasturlash masalasi sifatida rasmiylashtiring
#include
#include
using namespace std;

int main() {


//Input Data


cout<<"\n\nUzgaruvchilar sonini kiriting..";


int n;
cin>>n;
double x[n];
int ER;
int c;
cout<<"\n\nTenglamalar sonini kiriting..";
cin>>c;

//total elements


int t=n+c;

double C[c][t+1]; //={0};


cout<<"\n\nSimplex jadval koeffitsentlarini kiriting"<for (int i=0; ifor(int j=0; jcin>>C[i][j];
}
}

double Zc[t]; //={0};


cout<<"\n\nMaqsad funksiya koeffitsenlarini kiriting..";
for(int i = 0; icin>>Zc[i];
}
//Verification of the input data

cout<<"\n\nThe Objective Function is Z = ";


for (int i=0; i
cout<}

for (int i=n; i
cout<if (i

}
//Contition for iteration


double Zsol[t+1]; //Zj array


double ratio[c]; //Ratio array
double Bv[c]; //basic values array
for (int i=0; iBv[i]=0;
}

double Zfin[t];


double Zfin_max;
Zfin_max = 1;
int Ce;

double ratio_min;


int Re;
int iter;
iter = 1;
//compute Zj

cout<<"\n\nZj = ";


for(int j=0; j<=t; j++){
for(int i=0; iZsol[j] += Bv[i]*C[i][j];
}
cout<}
//compute Cj-Zj

cout<<"\n\nCj - Zj = ";


for(int i=0; iZfin[i] = Zc[i] - Zsol[i];
//cout<}
//Compute (Cj - Zj)max == Zfin_max

Zfin_max = Zfin[0];


Ce = 0;
for(int i=1; iif( Zfin_max < Zfin[i]) {
Zfin_max = Zfin[i] ;
Ce=i;
}

else {
cout<<"\n\nChosing nex Cj-Zj";


}
}

cout<<"\n\n\nMaximum value of Cj - Zj = "<

//compute Ratio


cout<<"\n\n\nRatio array is R = ";


for(int i=0; iratio[i] = C[i][t]/C[i][Ce];
cout<}
//Compute min Ratio

cout<<"\n\n\nMinimum value f ratio is ";


ratio_min = 2500;
Re = 0;

for (int i=0; i
if(ratio_min > fabs(ratio[i]) ){
ratio_min = fabs(ratio[i]) ;
Re = i;
}
}

cout<
double Iter_C[c][t+1];

while(Zfin_max>0){


cout<<"\n\n\nIteration "<

//Entering column and exiting row


cout<<"\n\nEntering column is "<cout<<"\n\nKeyElement is "<Bv[Re] = Zc[Ce];
//Calculation for rows
// cout<<"\n\nEntering row coeff are ";
cout<<"\n\nFor entering row, old values and new values are ";

for(int j=0; j
cout<<"\t"<Iter_C[Re][j] = C[Re][j] / C[Re][Ce];
cout<<"\t"<}

// cout<<"\n\nOther columns coeff are ";


cout<<"\n\nFor other rows, old values and new values are ";
for(int i=0; iif (i != Re){
for(int j=0; j<=t; j++){
cout<<"\t"<double a = C[i][Ce] * C[Re][j] / C[Re][Ce];
Iter_C[i][j] = C[i][j] - a;
cout<<"\t"<}
cout<<"\n";
}
}

//compute Zj


cout<<"\n\n\nZj = ";


//re-assigning Zj to 0


for(int i=0; i<=t; i++){
Zsol[i] = 0;
}

for(int j=0; j<=t; j++){


for(int i=0; iZsol[j] += Bv[i]*Iter_C[i][j];
}
cout<}
//compute Cj-Zj

cout<<"\n\n\nCj - Zj = ";


for(int i=0; iZfin[i] = Zc[i] - Zsol[i];
//cout<}
//Compute (Cj - Zj)max == Zfin_max

Zfin_max = Zfin[0];


Ce = 0;
for(int i=1; iif(Zfin_maxZfin_max=Zfin[i];
Ce=i;
}

else {
// cout<<"\n\nChosing nex Cj-Zj";


}
}

cout<<"\n\n\nMaximum value of Cj - Zj = "<

if(Zfin_max<0) {


goto end;
}

//compute Ratio


cout<<"\n\n\nRatio array is R = ";


for(int i=0; iratio[i] = Iter_C[i][t]/Iter_C[i][Ce];
cout<}
//Compute min Ratio

cout<<"\n\n\nMinimum value f ratio is ";


ratio_min =2500;
Re = 0;

for (int i=0; i
if(ratio_min > fabs(ratio[i]) ){
ratio_min = fabs(ratio[i]);
Re = i;
}
}

cout<
for(int i=0; ifor(int j=0; j<=t; j++){
C[i][j] = Iter_C[i][j];
}
}

iter++;

end:cout<<"\n\nPlease check ";
}

cout<<"\n\n\n";


for(int i=0; i
for(int j=0; j<=t; j++){
cout<}
cout<<"\n";
}

cout<
return 0;
}




5 Amaliy mashg’ulot topshiriqlari
Berilgan masalalarni simpleks usulda yechish algoritmini tuzing. Masalalarni matematik hisoblashlarni o’zingiz (qo’lda) bajaring va har bir qadamdagi simpleks jadvallarni keltiring



#include
#include
using namespace std;

int main() {


//Input Data


cout<<"\n\nUzgaruvchilar sonini kiriting..";


int n;
cin>>n;
double x[n];
int ER;
int c;
cout<<"\n\nTenglamalar sonini kiriting..";
cin>>c;

//total elements


int t=n+c;

double C[c][t+1]; //={0};


cout<<"\n\nSimplex jadval koeffitsentlarini kiriting"<for (int i=0; ifor(int j=0; jcin>>C[i][j];
}
}

double Zc[t]; //={0};


cout<<"\n\nMaqsad funksiya koeffitsenlarini kiriting..";
for(int i = 0; icin>>Zc[i];
}
//Verification of the input data

cout<<"\n\nThe Objective Function is Z = ";


for (int i=0; i
cout<}

for (int i=n; i
cout<if (i

}
//Contition for iteration


double Zsol[t+1]; //Zj array


double ratio[c]; //Ratio array
double Bv[c]; //basic values array
for (int i=0; iBv[i]=0;
}

double Zfin[t];


double Zfin_max;
Zfin_max = 1;
int Ce;

double ratio_min;


int Re;
int iter;
iter = 1;
//compute Zj

cout<<"\n\nZj = ";


for(int j=0; j<=t; j++){
for(int i=0; iZsol[j] += Bv[i]*C[i][j];
}
cout<}
//compute Cj-Zj

cout<<"\n\nCj - Zj = ";


for(int i=0; iZfin[i] = Zc[i] - Zsol[i];
//cout<}
//Compute (Cj - Zj)max == Zfin_max

Zfin_max = Zfin[0];


Ce = 0;
for(int i=1; iif( Zfin_max < Zfin[i]) {
Zfin_max = Zfin[i] ;
Ce=i;
}

else {
cout<<"\n\nChosing nex Cj-Zj";


}
}

cout<<"\n\n\nMaximum value of Cj - Zj = "<

//compute Ratio


cout<<"\n\n\nRatio array is R = ";


for(int i=0; iratio[i] = C[i][t]/C[i][Ce];
cout<}
//Compute min Ratio

cout<<"\n\n\nMinimum value f ratio is ";


ratio_min = 2500;
Re = 0;

for (int i=0; i
if(ratio_min > fabs(ratio[i]) ){
ratio_min = fabs(ratio[i]) ;
Re = i;
}
}

cout<
double Iter_C[c][t+1];

while(Zfin_max>0){


cout<<"\n\n\nIteration "<

//Entering column and exiting row


cout<<"\n\nEntering column is "<cout<<"\n\nKeyElement is "<Bv[Re] = Zc[Ce];
//Calculation for rows
// cout<<"\n\nEntering row coeff are ";
cout<<"\n\nFor entering row, old values and new values are ";

for(int j=0; j
cout<<"\t"<Iter_C[Re][j] = C[Re][j] / C[Re][Ce];
cout<<"\t"<}

// cout<<"\n\nOther columns coeff are ";


cout<<"\n\nFor other rows, old values and new values are ";
for(int i=0; iif (i != Re){
for(int j=0; j<=t; j++){
cout<<"\t"<double a = C[i][Ce] * C[Re][j] / C[Re][Ce];
Iter_C[i][j] = C[i][j] - a;
cout<<"\t"<}
cout<<"\n";
}
}

//compute Zj


cout<<"\n\n\nZj = ";


//re-assigning Zj to 0


for(int i=0; i<=t; i++){
Zsol[i] = 0;
}

for(int j=0; j<=t; j++){


for(int i=0; iZsol[j] += Bv[i]*Iter_C[i][j];
}
cout<}
//compute Cj-Zj

cout<<"\n\n\nCj - Zj = ";


for(int i=0; iZfin[i] = Zc[i] - Zsol[i];
//cout<}
//Compute (Cj - Zj)max == Zfin_max

Zfin_max = Zfin[0];


Ce = 0;
for(int i=1; iif(Zfin_maxZfin_max=Zfin[i];
Ce=i;
}

else {
// cout<<"\n\nChosing nex Cj-Zj";


}
}

cout<<"\n\n\nMaximum value of Cj - Zj = "<

if(Zfin_max<0) {


goto end;
}

//compute Ratio


cout<<"\n\n\nRatio array is R = ";


for(int i=0; iratio[i] = Iter_C[i][t]/Iter_C[i][Ce];
cout<}
//Compute min Ratio

cout<<"\n\n\nMinimum value f ratio is ";


ratio_min =2500;
Re = 0;

for (int i=0; i
if(ratio_min > fabs(ratio[i]) ){
ratio_min = fabs(ratio[i]);
Re = i;
}
}

cout<
for(int i=0; ifor(int j=0; j<=t; j++){
C[i][j] = Iter_C[i][j];
}
}

iter++;

end:cout<<"\n\nPlease check ";
}

cout<<"\n\n\n";


for(int i=0; i
for(int j=0; j<=t; j++){
cout<}
cout<<"\n";
}

cout<
return 0;
}

Yüklə 293,97 Kb.

Dostları ilə paylaş:
1   2   3   4   5   6




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin