Knapsack Branch and Bound C Program Error Output -


i have source code knapsack branch , bound in c program :

int fnbound(int icp,int icw,int ik,int imax,int aip[9],int iitem,int aiw[9]) { float iub; if(ik+1) iub=icp+(imax - icw)*(aip[ik+1]/(float)aiw[ik+1]); else iub=icp; return iub; }  void fnbranch_bound(int ik,int icp,int icw,int imax,int aiw[9],int aipr[9],int iitem) { static int ssol[9]; static int sfp,sfw; int ii,ij; if(icw+aiw[ik]<=imax) { ssol[ik]=1; if(ik) fnbranch_bound(ik+1,icp+aipr[ik],icw+aiw[ik],imax,aiw,aipr,iitem); if(ik==iitem && (icp+aipr[ik])>sfp) { printf("\nsolution vectors : "); for(ii=0;ii;) printf(" %d ",ssol[ii]); sfp=icp+aipr[ik]; sfw=icw+aiw[ik-1]; printf("\nprofit : %d",sfp); printf("\nweight : %d",sfw); } } if (fnbound(icp,icw,ik,imax,aipr,iitem,aiw)>sfp) { ssol[ik]=0; if(ik)fnbranch_bound(ik+1,icp,icw,imax,aiw,aipr,iitem); if(ik==iitem && icp>sfp) { sfp=icp; sfw=icw; for(ij=0;ij;) printf(" %d ",ssol[ij]); printf("\nprofit : %d",sfp); printf("\nweight : %d",icw); } } }    void main() { int iitem,aiweight[9],aiprofit[9],ii,ij,imax; void fnbranch_bound(int ik,int icp,int icw,int imax,int aiw[9],int aipr[9],int iitem);  printf("knap sack problem solving using branch , bound method.\n"); printf("how many item want : "); scanf("%d",&iitem); printf("enter weight , profit each item \n"); printf("weight profit\n"); for(ij=0;ij;) scanf("%d%d",&aiweight[ij],&aiprofit[ij]); printf("enter maximum capacity of knapsack : "); scanf("%d",&imax); fnbranch_bound(0,0,0,imax,aiweight,aiprofit,iitem); getch(); } 

when run program, output :

"knap sack problem solving using branch , bound method. how many item want : 8 enter weight , profit each item weight profit

enter maximum capacity of knapsack : "

i cant fill weight , profit.. can please ?

you must increase ij ij++, so:

for (ij=0;ij<9;ij++)   scanf("%d%d",&aiweight[ij],&aiprofit[ij]); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -