! 5.1.js ! 2014-10-26 ! $Id: 5.1.f90 1.1 2024/11/02 11:42:49 s Exp $ implicit none ! initialization integer ol(5) integer pw(5) integer npv(5) integer x(32,6) integer scost(32) integer snpv(32) integer snpvmax integer i,j,k,l,m,ns character*10 comment(32) character*60 fmt1 ! input ol(1:5)=[100,300,200,150,150] pw(1:5)=[200,500,300,200,250] comment(1:32)='-' ! calculation npv(1:5)=pw(1:5)-ol(1:5) ns=1 snpvmax=0 do i=0,1 do j=0,1 do k=0,1 do l=0,1 do m=0,1 x(ns,1) = i x(ns,2) = j x(ns,3) = k x(ns,4) = l x(ns,5) = m scost(ns) = dot_product( ol(1:5),x(ns,1:5)) snpv(ns) = dot_product(npv(1:5),x(ns,1:5)) if(scost(ns)>600) then comment(ns)='cost>600' else if(snpv(ns) > snpvmax) then snpvmax = snpv(ns) end if ns=ns+1 end do end do end do end do end do do i=1,32 if(scost(i)<=600 .and. snpv(i)==snpvmax) then comment(i) = 'optimal' end if end do ! output print *,'5.1.f90' print '(8a5,a8)','ns','x1','x2','x3','x4','x5','cost','npv','comment' print *,repeat('-',48) fmt1='(i5,i5,i5,i5,i5,i5,i5,i5,1x,a8)' print fmt1,(i,(x(i,j),j=1,5),scost(i),snpv(i), comment(i),i=1,32) print *,repeat('-',48) end ! end