Newsgroup: it.istruzione.universita.ingegneria
Titolo: garbage can model o modello decisionale a cestino dei rifiuti

Salve a tutti,
Sono uno studente universitario di ingegneria gestionale,
sto studiando il codice sviluppato in turbopascal del modello di scelta
decisionale
del tipo a " cestino dei rifiuti" o anche detto "garbage can model".
La mia domanda è:
Perchè sono state costruite e inizializzate le matrici  JIA, IKA se
dopo non vengono utilizzate in seguito.
Di seguito è riportato il codice
{
THE GARBAGE CAN MODEL
TRANSLATOR:SHIH-KUNG LAI
AFFILIATION:CENTER FOR LAND AND ENVIRONMENTAL PLANNING, NATIONAL TAIPEI
UNIVERSITY
67,SEC 3, MIN SHENG ROAD
TAIPEI, TAIWAN
R.O.C,
FEBRUARY,1994
The program is a direct translation from Cohen et al.'s original code
FORTRAN.
io is 1 for summary statistics only
io is 2 summary statistics plus histories
na is 1 when probs and dmkrs both move
na is 2 when dmkrs only move
na is 3 when probs only move
na is 4 when neither probs nor dmkrs move
il is a factor determining prob energy req
variables
munbers
counters      upper limits      name
i            NCH           choices
j            NPR           problem
k           NDM           decmkrs
lt           NTP            time
1-dimensional arrays
kdc         NDM            dmkr. att. choice
kdcw        NDM            working copy kdc
xee          NCH            energy expended
xerc         NCH            choice en. reqt.
xerp         NPR            prob. En. reqt.
xsc          NTP            solution coefficient
2- dimensional arrays
code           dimension      name
ika            NCH,NDM     decision structure
jia            NPR,NCH      problem-choice access structure
xea           NDM,NTP      energy matrix
summary statistics for each variant
  col 0:kp:total decisions not activated for all time periods
  col 1:kp:total decisions not activated at the end
  col 2:kz:total decisions not made
  col 3:ky:total number active choice periods
  col 4:kx:total number changes by decision makers
  col 5:kw:total problems not solved
  col 6:kv:total number changes by problems
  col 7:ku:total number latent problem periods
  col 8:kt:total number attached problem periods
  col 9:ks:total number periods dmkrs resting
  col 10:xr:total amount of unused energy
  col 11:xs:total amount of wasted energy
}
Program Garbage_Can_Model (input, output);
const NTP=20;
      NCH=10;
      NPR=20;
      NDM=10;
      ZERO=0.0000000001;
type im1= array [1..NCH] of integer;
     im2= array [1..NCH] of real;
     jm1= array [1..NPR] of integer;
     jm2= array [1..NPR] of real;
     km1= array [1..NDM] of integer;
     km2= array [1..NDM] of real;
     lm1= array [1..NTP] of integer;
     lm2= array [1..NTP] of real;
     ik1= array [1..NCH,1..NDM] of integer;
     ji1= array [1..NPR,1..NCH] of integer;
     kl2= array [1..NDM,1..NTP] of real;
     li1= array [1..NTP,1..NCH] of integer;
     lj1= array [1..NTP,1..NPR] of integer;
     lk1= array [1..NTP,1..NDM] of integer;
var ich, ics: im1;
    jet, jf, jff, jps: jm1;
    kdc, kdcw: km1;
    xee, xerc: im2;
    xerp: jm2;
    xsc: lm2;
    ika: ik1;
    jia: ji1;
    xea: kl2;
    kabc: li1;
    kbbc: lk1;
    kcbc: lj1;
    io, na, I, j, k, lt, ltt, il, jab, jdb, jeb, ib, ja, jd, je, kp,
kq, kz, ky, kx, kw, kv, ku, kt, ks, kr: integer;
    xxa, s, xr, xs: real;
    fi, fo: text;
begin
   assign (fi,'garbage.dat');
   assign (fo,'garbage.out');
   reset (fi);
   rewrite (fo);
   for i :=1 to NCH do
      read (fi, ich[i]);
   readln (fi);
   for j :=1 to NPR do
      read(fi, jet[j]);
   readln (fi);
   for lt :=1 to NTP do
      read (fi, xsc[lt]);
   readln (fi);
   readln (fi, na, io);
   for il:=1 to 3 do
   begin
      ib:=il-1;
      for jab:=1 to 3 do
      begin
	 ja:=jab-1;
	 for jeb:=1 to 3 do
	    begin
	       je:=jeb-1;
	       xr:=0.0;
	       xs:=0.0;
	       ks:=0;
	       for i:=1 to NCH do
	       begin
		  xerc[i]:=1.1;
		  xee[i]:=0.0;
		  ics[i]:=0;
	       end;
	       for k:=1 to NDM do
	       begin
		  kdc[k]:=0;
		  kdcw[k]:=kdc[k];
	       end;
	       for j:=1 to NPR do
	       begin
		  xerp[j]:=il*1.1;
		  jf[j]:=0;
		  jff[j]:=0;
		  jps[j]:=0;
	       end;
	       {setting up the problems access to choices.}
	       for i :=1 to NPR do
		  for j :=1 to NCH do
		  begin
		     jia[i,j] :=0;
		     case ja of
		       1 : if i - j <=i/2 then
					jia[i,j] :=1;
		       2 : if i <> 2*j then
				     begin
					jia[i,j] :=1;
					jia[i-1,j] :=1;
				     end;
		     else
			jia[i,j]:=1;
		     end;
		  end;
	       {setting up the decision makers access to choices}
	       for i:=1 to NCH do
		  for j :=1 to NDM do
		  begin
		     ika[j,i] :=1;
		     case jd of
		       1 : if j > i then
			      ika[j,i] :=0;
		       2 : if j <> I then
			      ika[j,i] :=0;
		     end;
		  end;
	       for i :=1 to NDM do
		  for j :=1 to NTP do
		  begin
		     xea[i,j]:=0.55;
		     if je<>1 then
		     begin
			xxa :=i;
			if je <>0 then
			   xea[i,j] := (11.0-xxa)/10.0
			else
			   xea[I,j] :=xxa/10.0;
		     end;
		  end;
	       {finish read initialization}
	       for lt :=1 to NTP do
	       begin
		  {choice activation}
		  for i :=1 to NCH do
		     if ich[i]= lt then
			ics [i] :=1;
		  {prob, activation}
		  for j :=1 to NPR do
		     if jet [j] =lt then
			jps [j] :=1;
		  {find most attractive choice for problem j }
		  for j :=1 to NPR do
		     if jps[j]=1 then
			if (na =2) or (na=4) then
			   if jf [j]<>0 then
			      jff [j] :=jf [j]
			   else
			   begin
			      s :=1000000;
			      for i :=1 to NCH do
				 if ics [i] =1 then
				    if jia [j,i]<>0 then
				       if ( jf [j] =0) or ( jf [j]=i) then
					  if (( xerc [i] - xee [i] <s)
					      and (abs(xerc[i]-xee[i] -s) >ZERO)) then
					  begin
					     s:= xerc[i] - xee[i];
					     jff [j]:=i;
					  end
					  else
					     {else}
					     if ((xerp[j]+ xerc[i] - xee[i]<s)
						 and ( abs (xerp[j] +xerc[i]-s)>ZERO))then
					     begin
						s:= xerp[j] + xerc[i] - xee[i];
						jff[j] :=I;
					     end;
			   end
			   else
			   begin
			      s := 1000000;
			      for i:=1 to NCH do
				 if ics[i]=1 then
				    if jia[j,i]<>0 then
				       if (jf[j] =0) or (jf[j] = i) then
					  if ((xerc[i] -xee[i] <s)
					      and (abs(xerc[i] - xee[i] -s)> ZERO)) THEN
					  begin
					     s :=xerc[i] -xee[i];
					     jff [j]:=i;
					  end
					  else
					     {else}
					     if ((xerp[j] +xerc[i] -xee[i]<s)
						 and (abs (xerp[j]+xerc[i]-xee[i]-s)>ZERO))then
					     begin
						s :=xerp[j]+ xerc[i]- xee[i];
						jff[j] :=I;
					     end;
			   end;
		  for j :=1 to NPR do
		  begin
		     jf[j]:= jff[j];
		     jff[j] :=0;
		  end;
		  ltt :=lt -1;
		  if lt =1 then
		     ltt :=1;
		  {find most attractive choice for dmkr k}
		  for k :=1 to NDM do
		     case na of
		       3,4 : if kdc[k]<>0 then
			  kdcw[k]:= kdc[k]
		       else
		       begin
			  s :=1000000;
			  for i :=1 to NCH do
			     if ics[i] =1 then
				if ika[k,i]<>0 then
				   if (kdc[k]=0) or (kdc[k]=i) then
				      if (xerc[i]-xee[i]<s)
					 and (abs(xerc[i]- xee[i]- s)>ZERO) then
				      begin
					 s := xerc[i]- xee[i];
					 kdcw[k] :=i;
				      end
			  {else}
				      else
					 if ((xerc[i] -xee[i]- xea[k,ltt]* xsc[ltt]) < s)
					    and (abs( xerc[i] -xee[i] -xea[k,ltt]*xsc[ltt] -s)> ZERO) then
					 begin
					    s := xerc[i]-xee[i] -xea[k,ltt]*xsc[ltt];
					 end;
		       end
		       else
		       begin
			  s:=1000000;
			  for i:=1 to NCH do
			     if ics[i] =1 then
				if ika[k,i]<> 0 then
				   if (kdc[k]=0) or ( kdc[k]=i) then
				      if (xerc[i] -xee[i]<s)
					 and (abs( xerc[i]- xee[i] - s)> ZERO) then
				      begin
					 s :=xerc[i] -xee[i];
					 kdcw[k] :=I;
				      end
			  {else}
				      else
					 if(( xerc[i] - xee[i] - xea[k,ltt]*xsc[ltt] <s)
					    and (abs( xerc[i] - xee[i] - xea[k,ltt] -s)>ZERO)) then
					 begin
					    s:= xerc[i] - xee[i] - xea[k,ltt]*xsc[ltt];
					    kdcw[k] :=i;
					 end
		       end;
		     end;
		  for k :=1 to NDM do
		  begin
		     if kdc[k] =0 then
		     begin
			xr := xr +xea[k,lt]*xsc[lt];
			ks := ks +1;
		     end;
		     kdcw[k] :=0;
		  end;
		  {establishing the energy required to make each choice.}
		  for i :=1 to NCH do
		     if ics[i]<> 0 then
		     begin
			xerc[i] :=0.0;
			for j :=1 to NPR do
			   if jps[j]=1 then
			      if jf[j] =I then
				 xerc[i]:=xerc[i]+ xerp[j];
			for k :=1 to NDM do
			   if ika[k,i]<>0 then
			      if kdc[k] =I then
				 xee[i]:= xee[i]+xsc[lt]*xea[k,lt];
		     end;
		  {making decisions}
		  for i :=1 to NCH do
		     if ics[i] =1 then
			if (xee[i] >xerc[i]) or (abs( xee[i]-xerc[i]) <=ZERO){and(
xerc[i]>0)} then
			begin
			   xs := xs +xee[i] - xerc[i];
			   ics[i] :=2;
			   for j:=1 to NPR do
			      if jf[j] = I then
				 jps[j] := 2;
			   if (na =3) or (na =4) then
			      for k :=1 to NDM do
				 if kdc[k] = I then
				    kdcw[k] :=1;
			end;
		  for i:=1 to NCH do
		     kabc[lt,i] := ics[i];
		  for k :=1 to NDM do
		  begin
		     kbbc[lt,j] :=jf[j];
		     if jps[j] =0 then
			kcbc[lt,j]:=-1
		     else
			if jps[j]<>1 then
			   kcbc[lt,j]:=1000;
		  end;
	       end;
	       {finish time period loop. begin accumulation}
	       {of 10 summary statistics.               }
	       kp := 0;
	       kq :=0;
	       kz :=0;
	       ky :=0;
	       kx :=0;
	       kw :=0;
	       kv :=0;
	       ku :=0;
	       kt :=0;
	       for I :=1 to NTP do
		  for j :=1 to NCH do
		     if kabc[I,j] =1 then
		     begin
			ky:=ky+1;
			if i=NTP then
			   kz:=kz+1;
		     end
		     else
			if kabc[I,j]=0 then
			begin
			   kp :=kp+1;
			   if i =NTP then
			      kq :=kq+1;
			end;
	       for I :=2 to NTP do
		  for j:=1 to NDM do
		     if kbbc[I,j]<>kbbc[i-1,j] then
			kx:=kx+1;
	       for I :=1 to NTP do
		  for j :=1 to NPR do
		     case kcbc[I,j] of
		       0   : ku :=ku+1;
		       -1  : ;
		       1000: if i =NTP then
				kw:=kw+1;
		     else
			kt :=kt+1;
		     end;
	       kw := NPR-kw;
	       for I :=2 to NTP do
		  for j :=1 to NPR do
		     if kcbc[i,j] <>kcbc[i-1,j] then
			kv:=kv+1;
	       {begin write out of materials for this reganizational variant.}
	       writeln(fo, ib,' ',ja,' ',jd,' ', je,' ',kp ,' ',kq,' ', kz,'
',ky,' ',kx,' ', kw,' ',kv,' ',ku,' ',
		       kt,' ',ks,' ',xr,' ',xs);
	       writeln(fo);
	       if io =2 then
		  for lt :=1 to NTP do
		  begin
		     writeln(fo,lt);
		     for I :=1 to NCH do
			write(fo,kabc[lt,i],' ');
		     writeln(fo);
		     for k:=1 to NDM do
			write(fo,kbbc[lt,k],' ');
		     writeln(fo);
		     for j:=1 to NPR do
		     begin
			write(fo,kcbc[lt,j],' ');
			if j =NPR/2 then
			   writeln(fo);
		     end;
		     writeln(fo);
		  end;
	       writeln(fo);
	       writeln(fo);
	       writeln(fo);
	    end;
      end;
   end;
   close(fi);
   close(fo);
end.

Di seguito č riportato il codice
(Tanto ovviamente nessuno si mettera` a leggere 400 righe di codice
procedurale)
Fai debugging, no? Prova a non definire le matrici, e vedi che succede.
Forza, un po` di problem-solving.