% philoso_snec10.gpss % 5 dining philosophers problem % (according to SNE Comparison 10, see: % www.argesim.org/uploads/tx_compdb/c10_definition.pdf) % Usage: % >>prepare('philoso_snec10.gpss'), schedule(1,0), printstat init n=5; % number of philosophers & sticks stick= [1:n,1]; % ring of sticks left = 0; % number of used left sticks phil=0; % philosopher counter model generate(0,0,0,n,0) % 5 philosophers phil=phil+1; P(1,phil); % Thinking loop queue(P(1),1) % advance(1,0) advance(duniformd(P(1),1,10),0) % thinking time depart(P(1),1) % Waiting queue(P(1)+10,1) % begin waiting seize(stick(P(1))); % get left stick left=left+1; if left==n, T, error('Deadlock.'); end priority(-1) seize(stick(P(1)+1)) % get right stick depart(P(1)+10,1) % end waiting priority(0) % Eating queue(P(1)+20,1) % advance(1,0) advance(duniformd(P(1)+5,1,10),0) % eating time depart(P(1)+20,1) release(stick(P(1)+1)) % put down right stick release(stick(P(1))); % put down left stick left=left-1; transfer(loop) % Time control generate(1000,0,1000,0,0) terminate(1) %################################################################################ % model execution at Matlab prompt and simulation results %################################################################################ %>>prepare('philoso_snec10.gpss'), schedule(1,0), printstat % ... % T = 1000.00 %Simulation beendet %>> printstat %-------------------------------------------------------------------------------- %QUEUE-STATISTIK, T = 1000.00 %Nr. max. mittl. Eintritte zeitlose mittl. Verweilzeit aktuelle Name % Laenge Laenge insges. Eintritte Verweilzeit WZ~=0 Laenge #### % 1 1 0.27 48 0 5.60 5.60 0 % 2 1 0.25 50 0 4.92 4.92 1 % 3 1 0.24 51 0 4.69 4.69 1 % 4 1 0.30 50 0 6.08 6.08 1 % 5 1 0.32 50 0 6.38 6.38 0 %11 1 0.51 48 3 10.69 11.40 0 %12 1 0.47 49 4 9.65 10.51 0 %13 1 0.46 50 6 9.26 10.52 0 %14 1 0.43 49 7 8.84 10.31 0 %15 1 0.41 50 8 8.14 9.69 1 %21 1 0.22 48 0 4.54 4.54 1 %22 1 0.28 49 0 5.73 5.73 0 %23 1 0.30 50 0 5.96 5.96 0 %24 1 0.26 49 0 5.37 5.37 0 %25 1 0.27 49 0 5.59 5.59 0 %-------------------------------------------------------------------------------- %FACILITY-STATISTIK, T = 1000.00 %Nr. belegende mittl. Anzahl mittl. Name % Transakt. Auslastung Eintritte Verweilzeit #### % 1 1 0.91 97 9.34 % 2 1 0.90 97 9.23 % 3 0 0.93 99 9.38 % 4 0 0.89 99 9.01 % 5 6 0.90 99 9.05 %-------------------------------------------------------------------------------- %kein STORAGE betreten %-------------------------------------------------------------------------------- %keine USER-CHAIN betreten %-------------------------------------------------------------------------------- %BLOCK-STATISTIK, T = 1000.00 % 4 generate(0,0,0,n,0) % 5 phil=phil+1; P(1,phil); % 249 queue(P(1),1) % 249 advance(duniformd(P(1),1,10),0) % 246 depart(P(1),1) % 246 queue(P(1)+10,1) % 246 seize(stick(P(1))); % 246 left=left+1; % 246 if left==n, T, error('Deadlock.'); end % 246 priority(-1) % 245 seize(stick(P(1)+1)) % 245 depart(P(1)+10,1) % 245 priority(0) % 245 queue(P(1)+20,1) % 245 advance(duniformd(P(1)+5,1,10),0) % 244 depart(P(1)+20,1) % 244 release(stick(P(1)+1)) % 244 release(stick(P(1))); % 244 left=left-1; % 244 transfer(loop) % 1 generate(1000,0,1000,0,0) % 1 terminate(1) %-------------------------------------------------------------------------------- %>>