- Back to Home »
- soal , Tugas Kuliah , Universitas 17 Agustus 1945 Surabaya »
- UAS Riset Operasional 2018 Semester Ganjil || Dosen Geri Kusnanto, S.Kom.,MM
Posted by : Arifah Nur Ainia
Program Transportasi Biaya Terkecil dengan C++
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
main(){
int baris,kolom,baris2,kolom2,cs1,cs2,min,total=0;
int a,b,a2,b2,cost[20][20],gudang[20],pabrik[20],temp[20],temp2[20];
gotoxy(20,1);cout<<"PROGRAM TRANSPORTASI BIAYA TERKECIL";
cout<<"\nBerapa Baris ? ";cin>>baris;
cout<<"Berapa Kolom ? ";cin>>kolom;
cout<<"\n\nMasukkan Biaya !!! \n";
for(a=1; a<=baris; a++){
for(b=1; b<=kolom; b++){
cout<<"Biaya ["<<a<<"]["<<b<<"] = ";cin>>cost[a][b];
}
}
cout<<"\n\nMasukkan Kebutuhan Gudang !!! \n";
for(b=1; b<=kolom; b++){
cout<<"Biaya ["<<a<<"] = ";cin>>gudang[b];
}
cout<<"\n\nMasukkan Kapasitas Pabrik !!! \n";
for(a=1; a<=baris; a++){
cout<<"Biaya ["<<a<<"] = ";cin>>pabrik[a];
}
cout<<"\n--------Matrik--------\n";
cout<<"\n\t\t\t Pabrik\n";
for(a=1; a<=baris; a++){
for(b=1; b<=kolom; b++)
cout<<"\t"<<cost[a][b];
cout<<"\t"<<pabrik[a];
cout<<endl;
}
cout<<"\nGudang ";
for(b=1; b<=kolom; b++)
cout<<gudang[b]<<"\t";
for(a=1; a<=baris; a++)
temp[a]=0;
for(a=1; a<=kolom; a++)
temp2[a]=0;
baris2=baris; kolom2=kolom;
while(baris2>0 && kolom2>0){
min=1000;
for(a=1;a<=baris;a++){
if(temp[a]!=1){
for(b=1;b<=kolom;b++){
if(temp2[b]!=1){
if(min>cost[a][b]){
min=cost[a][b];
a2=a;
b2=b;
}
}
}
}
}
if(pabrik[a2]<gudang[b2])
cs1=pabrik[a2];
else
cs1=gudang[b2];
for(a=1;a<=baris;a++){
if(temp[a]!=1){
for(b=1;b<=kolom;b++){
if(temp2[b]!=1){
if(min==cost[a][b]){
if(pabrik[a]<gudang[b])
cs2=pabrik[a];
else
cs2=gudang[b];
if(cs2>cs1){
cs1=cs2;
a2=a;
b2=b;
}
}
}
}
}
}
cout<<"\n\nBiaya Terkecil || Baris || Kolom";
cout<<"\n\t"<<min<<"\t "<<a2<<"\t "<<b2;
if(pabrik[a2]<gudang[b2]){
cout<<"\n\n Total + Biaya * Pabrik/Gudang";
cout<<"\n "<<total<<" + "<<cost[a2][b2]<<" * "<<pabrik[a2];
total=total+cost[a2][b2]*pabrik[a2];
gudang[b2]=gudang[b2]-pabrik[a2];
temp[a2]=1;
baris2--;
}
else
if(pabrik[a2]>gudang[b2]){
cout<<"\n\n Total + Biaya * Pabrik/Gudang";
cout<<"\n "<<total<<" + "<<cost[a2][b2]<<" * "<<gudang[b2];
total=total+cost[a2][b2]*gudang[b2];
pabrik[a2]-=gudang[b2];
temp2[b2]=1;
kolom2--;
}
else if(pabrik[a2]==gudang[b2]){
cout<<"\n\n Total + Biaya * Pabrik/Gudang";
cout<<"\n "<<total<<" + "<<cost[a2][b2]<<" * "<<pabrik[a2];
total=total+cost[a2][b2]*pabrik[a2];
temp[a2]=1;
temp2[b2]=1;
baris2--;
kolom2--;
}
cout<<"\n\nTotal : "<<total;
}
cout<<"\n\nTotal Akhir : "<<total;
getch();
}