Postingan

Menampilkan postingan dari Mei, 2014

Program Algoritma Prim

#include <cstdlib> #include <iostream> using namespace std; class prims { private: int n; //no of nodes =>tidak ada node int graph_edge[250][4]; //edges in the graph =>tepi dalam grafik int g; //no of edges in the graph => tidak ada dari tepi dalam grafik int tree_edge[250][4]; //edges in the tree =>  tepi di pohon int t; //no of edges in the tree => tidak ada tepi di pohon int s; //source node =>node sumber //Partition the graph in to two sets => Partisi grafik ke dua set int T1[50],t1; // Set 1 int T2[50],t2; // Set 2 public: void input(); int findset(int); void algorithm(); void output(); }; void prims::input() { cout<<"*************************************************\n" <<" program implements the prims algorithm \n" <<"*************************************************\n"; cout<<"Enter the no. of nodes in the undirected weighted graph/"<<endl; cout<<"Masukkan no tersebu...

Program Fractional Knapsack

#include <cstdlib> #include <iostream> using namespace std; void SolveFract(int p[], int w[], float W, int n, int x[], float &TotalUntung){      int i;      float kapasitas;      bool MasihMuatUtuh;           for(i=0;i<n;i++){                       x[i];                       }      kapasitas = W;      TotalUntung = 0;      i = 0;      MasihMuatUtuh = true;      while ((i < n) && (MasihMuatUtuh)){            if (w[i] <= kapasitas){             ...

Fractional Knapsack 2 (struct)

#include <cstdlib> #include <iostream> using namespace std; struct knapsack{ float p,w,pw,x; //profit,berat,nilai dari p/w,nilai probabilita barang yang masuk char barang; } void swap(T *c,int i,int j){ T temp; temp=c[j]; c[j]=c[i]; c[i]=temp; return;} void Pengurutan(knapsack c[], int n){ for(int i=0;i<=n;i++){ for(int j=0;i<=n;i++){ if(c[i].pw tukar(c[i],c[j]; } } } void SolveFractorialKnapsack(knapsack c[], float w, int n,float  &TotalUntung){ int i; float kapasitas; bool MasihMuatUtuh; for (i=0;i<=n;i++){ c[i].x=0; } kapaitas=W; TotalUntung=0; i=1; MasihMuatUtuh=true; while ((i<=n) && (MasihMuatUtuh)){ if(c[i].w<=kapasitas){ c[i].x=1; totalUntung = totalUntung + c[i].p; kapasitas = kapaitas - c[i].w; i++ } else{ MasihMuatUtuh=false; } } if(i<=n){ c[i].x=kapaitas/c[i].w; totalUntung = totalUntung+c[i].x*c[i].p; } } int main(int argc, char *argv[]) { float c[100]; int n,W; //kapaistas char j=0; cout<<"Jumlah barang: "; cin>...

Fractional Knapsack 1

#include <cstdlib> #include <iostream> using namespace std; void SolveFractionalKnapsack(int p[], int w[], float W, int n, int x[], float TotalUntung){      int i;      float kapasitas;      bool MasihMuatUtuh;           for(i=1;i>n;i++){                       x[i];                       }      kapasitas = W;      TotalUntung = 0;      i = 1;      MasihMuatUtuh = true;      while ((i <= n) && (MasihMuatUtuh)){            if (w[i] <= kapasitas){           ...