/usr/share/mozart/doc/demo/node25.html is in mozart-doc 1.4.0-8ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Root functor: Lift.oz</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="lift.html">- Up -</A></TD></TR></TABLE><DIV class="unnumbered" id="code.lift"><H3><A name="code.lift">Root functor: <CODE>Lift.oz</CODE></A></H3><P class="margin"><A href="Lift.oz">Source File</A></P><P> </P><BLOCKQUOTE><PRE><SPAN class="keyword">functor</SPAN> <BR> <BR><SPAN class="keyword">require</SPAN> <BR> DemoUrls(image)<BR> <BR><SPAN class="keyword">prepare</SPAN> <BR> ImageNames = {Map [upF downF upE downE lift liftUp liftDown]<BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> A}<BR> DemoUrls<SPAN class="keyword">.</SPAN>image<SPAN class="keyword">#</SPAN><SPAN class="string">'lift/'</SPAN><SPAN class="keyword">#</SPAN>A<SPAN class="keyword">#</SPAN><SPAN class="string">'.xbm'</SPAN> <BR> <SPAN class="keyword">end</SPAN>}<BR> <BR><SPAN class="keyword">import</SPAN> <BR> Tk<BR> TkTools<BR> Application<BR> <BR><SPAN class="keyword">define</SPAN> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">Lift Simulation -- Randomised and Interactive Lift Requests<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">The Scheduling Algorithm is taken from the book<BR></SPAN> %% <SPAN class="comment">'Concurrent Programming in Erlang', Chapter 11: Real-Time Control<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">Colors<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> [BGColor FGColor FloorsColor KnobColor NumColor]<BR> = <SPAN class="keyword">if</SPAN> Tk<SPAN class="keyword">.</SPAN>isColor <SPAN class="keyword">then</SPAN> <BR> [steelblue bisque lightsteelblue blue <SPAN class="string">'IndianRed'</SPAN>]<BR> <SPAN class="keyword">else</SPAN> <BR> [grey55 grey55 grey55 black black]<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">Parameters<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> NumFloors = 5 %% <SPAN class="comment">number of floors<BR></SPAN> NumLifts = 3 %% <SPAN class="comment">number of lifts<BR></SPAN> <BR> CallMode = call %% <SPAN class="comment">lift called from floor<BR></SPAN> SendMode = send %% <SPAN class="comment">lift sent from inside<BR></SPAN> DelayLift = 2500 %% <SPAN class="comment">delay between simulated lift calls<BR></SPAN> DelayOpen = 500 %% <SPAN class="comment">delay for opening doors<BR></SPAN> DelayStep = 120 %% <SPAN class="comment">delay for lift speed<BR></SPAN> <BR> %% <SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">Images<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> Images = {TkTools<SPAN class="keyword">.</SPAN>images ImageNames}<BR> <BR> Bold = {New Tk<SPAN class="keyword">.</SPAN>font tkInit(family:courier weight:bold size:<SPAN class="keyword">~</SPAN>24)}<BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">constants and procedures for the graphical representation<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> FloorDelta = 10<BR> FloorSteps = 7<BR> FloorLeft = 10<BR> FloorRight = 220<BR> FloorSize = FloorDelta <SPAN class="keyword">*</SPAN> FloorSteps<BR> Height = FloorSize <SPAN class="keyword">*</SPAN> NumFloors <SPAN class="keyword">-</SPAN> 15<BR> Width = 230<BR> LeftMost = 110<BR> Bound = 3<BR> LiftDelta = 38<BR> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Pos2Floor</SPAN> Y} (Height <SPAN class="keyword">-</SPAN> Y) <SPAN class="keyword">div</SPAN> FloorSize <SPAN class="keyword">+</SPAN> 1 <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Floor2Pos</SPAN> N} Height <SPAN class="keyword">-</SPAN> (N<SPAN class="keyword">-</SPAN>1) <SPAN class="keyword">*</SPAN> FloorSize <SPAN class="keyword">end</SPAN> <BR> <BR> GroundLevel = {Floor2Pos 1} <SPAN class="keyword">-</SPAN> LiftDelta<BR> <BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">Random Number Generator (alternatively, see OS.rand)<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">Randomizer</SPAN> <SPAN class="keyword">from</SPAN><SPAN class="type"> BaseObject</SPAN> <BR> <SPAN class="keyword">prop</SPAN> <BR> final<BR> <BR> <SPAN class="keyword">feat</SPAN> <BR> a: 24298<BR> b: 9991<BR> c: 199017<BR> <BR> <SPAN class="keyword">attr</SPAN> <BR> seed:24676<BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">next</SPAN>(?N)<BR> S=<SPAN class="keyword">@</SPAN>seed<BR> <SPAN class="keyword">in</SPAN> <BR> N={IntToFloat S}<SPAN class="keyword">/</SPAN>{IntToFloat <SPAN class="keyword">self.</SPAN>c}<BR> seed <SPAN class="keyword"><-</SPAN> (<SPAN class="keyword">self.</SPAN>a <SPAN class="keyword">*</SPAN> S <SPAN class="keyword">+</SPAN> <SPAN class="keyword">self.</SPAN>b) <SPAN class="keyword">mod</SPAN> <SPAN class="keyword">self.</SPAN>c<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">uniform</SPAN>(A B ?R)<BR> N <SPAN class="keyword">in</SPAN> Randomizer<SPAN class="keyword">,</SPAN> next(N) R=N<SPAN class="keyword">*</SPAN>(B<SPAN class="keyword">-</SPAN>A)<SPAN class="keyword">+</SPAN>A<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> Random = {New Randomizer noop}<BR> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">RandomChoice</SPAN> N M}<BR> {FloatToInt {Random uniform({IntToFloat N}<BR> {IntToFloat M}<BR> $)}}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">RanChoiceFloor</SPAN>}<BR> {RandomChoice 1 NumFloors}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">RanChoiceBin</SPAN> X Y}<BR> <SPAN class="keyword">if</SPAN> {RandomChoice 0 1}<SPAN class="keyword">==</SPAN>1 <SPAN class="keyword">then</SPAN> X <SPAN class="keyword">else</SPAN> Y <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">Compute the cost of a request from floor Floor with direction <BR></SPAN> %% <SPAN class="comment">Dir for a lift at floor At with current task stack CurrSch,<BR></SPAN> %% <SPAN class="comment">and also return the corresponding new schedule NewSch.<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> CostWait = 5 %% <SPAN class="comment">cost estimate for opening and closing the doors<BR></SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Insert</SPAN> Task At CurrSch}<BR> {Cost Task At CurrSch _} % <SPAN class="comment">ignore cost<BR></SPAN> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Cost</SPAN> Task At CurrSch Offer NewSch}<BR> goto(To _ Dir _) = Task<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">case</SPAN> CurrSch<BR> <SPAN class="keyword">of</SPAN> nil <SPAN class="keyword">then</SPAN> <BR> Offer = {Abs At<SPAN class="keyword">-</SPAN>To}<BR> NewSch = [Task]<BR> <BR> <SPAN class="keyword">[]</SPAN> CurrTask<SPAN class="keyword">|</SPAN>RCurrSch <SPAN class="keyword">then</SPAN> <BR> goto(CurrTo _ _ _) = CurrTask<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">if</SPAN> At<SPAN class="keyword">=<</SPAN>To<BR> <SPAN class="keyword">andthen</SPAN> To<SPAN class="keyword">=<</SPAN>CurrTo<BR> <SPAN class="keyword">andthen</SPAN> Dir<SPAN class="keyword">==</SPAN>up<BR> <SPAN class="keyword">then</SPAN> <BR> Offer = {Abs At<SPAN class="keyword">-</SPAN>To}<BR> NewSch = Task<SPAN class="keyword">|</SPAN>CurrSch<BR> <BR> <SPAN class="keyword">elseif</SPAN> CurrTo<SPAN class="keyword">=<</SPAN>To<BR> <SPAN class="keyword">andthen</SPAN> To<SPAN class="keyword">=<</SPAN>At<BR> <SPAN class="keyword">andthen</SPAN> Dir<SPAN class="keyword">==</SPAN>down<BR> <SPAN class="keyword">then</SPAN> <BR> Offer = {Abs At<SPAN class="keyword">-</SPAN>CurrTo}<BR> NewSch = Task<SPAN class="keyword">|</SPAN>CurrSch<BR> <BR> <SPAN class="keyword">else</SPAN> <BR> ROffer RNewSch<BR> <SPAN class="keyword">in</SPAN> <BR> {Cost Task CurrTo RCurrSch ROffer RNewSch}<BR> Offer = {Abs At<SPAN class="keyword">-</SPAN>CurrTo} <SPAN class="keyword">+</SPAN> CostWait <SPAN class="keyword">+</SPAN> ROffer<BR> NewSch = CurrTask<SPAN class="keyword">|</SPAN>RNewSch<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">Interactively send the lift somewhere<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">Press</SPAN> <SPAN class="keyword">from</SPAN><SPAN class="type"> BaseObject</SPAN> <BR> <BR> <SPAN class="keyword">prop</SPAN> final<BR> <SPAN class="keyword">attr</SPAN> val<BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">init</SPAN>(Choice)<BR> val <SPAN class="keyword"><-</SPAN> Choice<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">press</SPAN>(N)<BR> <SPAN class="keyword">@</SPAN>val = N<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">PopChoice</SPAN> View P ?Choice}<BR> Select = {New Press init(Choice)}<BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Button</SPAN> N}<BR> At = NumFloors <SPAN class="keyword">-</SPAN> N <SPAN class="keyword">+</SPAN> 1<BR> Y = P <SPAN class="keyword">+</SPAN> LiftDelta <SPAN class="keyword">-</SPAN> At <SPAN class="keyword">*</SPAN> 8<BR> Knob = {New Tk<SPAN class="keyword">.</SPAN>canvasTag tkInit(parent:View)}<BR> Num = {New Tk<SPAN class="keyword">.</SPAN>canvasTag tkInit(parent:View)}<BR> <SPAN class="keyword">in</SPAN> <BR> {View tk(crea oval 92 Y 100 Y<SPAN class="keyword">+</SPAN>5 tag:Knob fill:KnobColor)}<BR> {View tk(crea text 85 Y tag:Num text:At fill:NumColor)}<BR> {Knob tkBind(event:<SPAN class="string">'<1>'</SPAN> action: Select <SPAN class="keyword">#</SPAN> press(At))}<BR> <BR> <SPAN class="keyword">thread</SPAN> <BR> {Wait Choice}<BR> {Knob tkClose}<BR> {Num tkClose}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> {For 1 NumFloors 1 Button}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">Individual Lift Object<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">Lift</SPAN> <SPAN class="keyword">from</SPAN><SPAN class="type"> Tk.canvasTag</SPAN> <BR> <BR> <SPAN class="keyword">prop</SPAN> <BR> locking<BR> final<BR> <BR> <SPAN class="keyword">feat</SPAN> <BR> View<BR> PosX<BR> <BR> <SPAN class="keyword">attr</SPAN> <BR> PosY : GroundLevel<BR> CurrFloor: 1<BR> Agenda : nil<BR> State : idle<BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">init</SPAN>(L)<BR> <SPAN class="keyword">self.</SPAN>PosX = {L join(<SPAN class="keyword">self</SPAN> $)}<BR> <SPAN class="keyword">self.</SPAN>View = L<BR> <BR> Tk<SPAN class="keyword">.</SPAN>canvasTag<SPAN class="keyword">,</SPAN> tkInit(parent:L)<BR> Lift<SPAN class="keyword">,</SPAN> drawInit<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">request</SPAN>(Task ?Offer Cont)<BR> <BR> <SPAN class="keyword">lock</SPAN> <BR> ReqCost NewAgenda<BR> <SPAN class="keyword">in</SPAN> <BR> {Cost Task <SPAN class="keyword">@</SPAN>CurrFloor <SPAN class="keyword">@</SPAN>Agenda ReqCost NewAgenda}<BR> <BR> <SPAN class="keyword">case</SPAN> <SPAN class="keyword">@</SPAN>State<BR> <SPAN class="keyword">of</SPAN> openDoor <SPAN class="keyword">then</SPAN> <BR> %% <SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">guess a high delay dependent on current agenda<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> Offer = ({Length <SPAN class="keyword">@</SPAN>Agenda}<SPAN class="keyword">+</SPAN>1)<SPAN class="keyword">*</SPAN>1000<BR> <SPAN class="keyword">else</SPAN> <BR> Offer = ReqCost<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">wait for release (false) or commit (true)<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <SPAN class="keyword">if</SPAN> Cont <SPAN class="keyword">then</SPAN> <BR> Agenda <SPAN class="keyword"><-</SPAN> NewAgenda<BR> <SPAN class="keyword">case</SPAN> <SPAN class="keyword">@</SPAN>Agenda <SPAN class="keyword">of</SPAN> [_] <SPAN class="keyword">then</SPAN> <BR> <SPAN class="keyword">case</SPAN> <SPAN class="keyword">@</SPAN>State <SPAN class="keyword">of</SPAN> openDoor<BR> <SPAN class="keyword">then</SPAN> <SPAN class="keyword">skip</SPAN> <SPAN class="keyword">else</SPAN> Lift<SPAN class="keyword">,</SPAN> proceed<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">else</SPAN> <SPAN class="keyword">skip</SPAN> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">moveBy</SPAN>(Y)<BR> PosY <SPAN class="keyword"><-</SPAN> <SPAN class="keyword">@</SPAN>PosY<SPAN class="keyword">+</SPAN>Y<BR> CurrFloor <SPAN class="keyword"><-</SPAN> {Pos2Floor <SPAN class="keyword">@</SPAN>PosY}<BR> Tk<SPAN class="keyword">.</SPAN>canvasTag<SPAN class="keyword">,</SPAN> tk(move 0 Y)<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">proceed</SPAN> <BR> <BR> <SPAN class="keyword">if</SPAN> <SPAN class="keyword">@</SPAN>Agenda<SPAN class="keyword">==</SPAN>nil <SPAN class="keyword">then</SPAN> <BR> State <SPAN class="keyword"><-</SPAN> idle<BR> Lift<SPAN class="keyword">,</SPAN> draw(lift)<BR> <SPAN class="keyword">else</SPAN> <BR> To = <SPAN class="keyword">@</SPAN>Agenda<SPAN class="keyword">.</SPAN>1<SPAN class="keyword">.</SPAN>1<BR> PosTo = {Floor2Pos To}<BR> CurrPos = <SPAN class="keyword">@</SPAN>PosY<SPAN class="keyword">+</SPAN>LiftDelta<BR> <SPAN class="keyword">in</SPAN> <BR> Lift<SPAN class="keyword">,</SPAN> draw(<SPAN class="keyword">if</SPAN> To<SPAN class="keyword">>@</SPAN>CurrFloor <SPAN class="keyword">then</SPAN> liftUp<BR> <SPAN class="keyword">elseif</SPAN> To<SPAN class="keyword"><@</SPAN>CurrFloor <SPAN class="keyword">then</SPAN> liftDown<BR> <SPAN class="keyword">else</SPAN> lift <SPAN class="keyword">end</SPAN>)<BR> <BR> <SPAN class="keyword">if</SPAN> {Abs CurrPos<SPAN class="keyword">-</SPAN>PosTo}<SPAN class="keyword"><</SPAN>5 <SPAN class="keyword">then</SPAN> <BR> Lift<SPAN class="keyword">,</SPAN> reached<BR> <SPAN class="keyword">elseif</SPAN> CurrPos<SPAN class="keyword">></SPAN>PosTo <SPAN class="keyword">then</SPAN> <BR> Lift<SPAN class="keyword">,</SPAN> moveBy(<SPAN class="keyword">~</SPAN>FloorDelta)<BR> <BR> <SPAN class="keyword">thread</SPAN> <BR> {Delay DelayStep}<BR> {<SPAN class="keyword">self</SPAN> proceed}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">else</SPAN> <BR> Lift<SPAN class="keyword">,</SPAN> moveBy(FloorDelta)<BR> <BR> <SPAN class="keyword">thread</SPAN> <BR> {Delay DelayStep}<BR> {<SPAN class="keyword">self</SPAN> proceed}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">reached</SPAN> <BR> <BR> Mode Who RestAgenda<BR> <SPAN class="keyword">in</SPAN> <BR> <BR> <SPAN class="keyword">lock</SPAN> <BR> goto(_ Mode _ Who)<SPAN class="keyword">|</SPAN>RestAgenda = <SPAN class="keyword">@</SPAN>Agenda<BR> {<SPAN class="keyword">self.</SPAN>View reached(<SPAN class="keyword">@</SPAN>CurrFloor)}<BR> Agenda <SPAN class="keyword"><-</SPAN> RestAgenda<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">if</SPAN> Mode<SPAN class="keyword">==!</SPAN>CallMode <SPAN class="keyword">then</SPAN> <BR> To<BR> CurrY = <SPAN class="keyword">@</SPAN>PosY<BR> Num = <SPAN class="keyword">@</SPAN>CurrFloor<BR> <SPAN class="keyword">in</SPAN> <BR> State <SPAN class="keyword"><-</SPAN> openDoor<BR> <BR> <SPAN class="keyword">thread</SPAN> <BR> To = <SPAN class="keyword">case</SPAN> Who <SPAN class="keyword">of</SPAN> sim <SPAN class="keyword">then</SPAN> <BR> {Delay DelayOpen}<BR> {RanChoiceFloor}<BR> <SPAN class="keyword">elseof</SPAN> press <SPAN class="keyword">then</SPAN> <BR> {PopChoice <SPAN class="keyword">self.</SPAN>View CurrY}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> {Wait To}<BR> <BR> Agenda <SPAN class="keyword"><-</SPAN> {Insert<BR> goto(To<BR> SendMode<BR> <SPAN class="keyword">if</SPAN> To<SPAN class="keyword">></SPAN>Num <SPAN class="keyword">then</SPAN> up <SPAN class="keyword">else</SPAN> down <SPAN class="keyword">end</SPAN> <BR> Who)<BR> <SPAN class="keyword">@</SPAN>CurrFloor<BR> <SPAN class="keyword">@</SPAN>Agenda}<BR> <SPAN class="keyword">end</SPAN> <BR> Lift<SPAN class="keyword">,</SPAN> closeDoor<BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">closeDoor</SPAN> <BR> State <SPAN class="keyword"><-</SPAN> idle<BR> Lift<SPAN class="keyword">,</SPAN> proceed<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">drawInit</SPAN> <BR> {<SPAN class="keyword">self.</SPAN>View<BR> tk(crea image <SPAN class="keyword">self.</SPAN>PosX<SPAN class="keyword">+</SPAN>12 <SPAN class="keyword">@</SPAN>PosY<SPAN class="keyword">+</SPAN>12 image:Images<SPAN class="keyword">.</SPAN>lift tag:<SPAN class="keyword">self</SPAN>)}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">draw</SPAN>(I)<BR> Tk<SPAN class="keyword">.</SPAN>canvasTag<SPAN class="keyword">,</SPAN> tk(itemconf image:Images<SPAN class="keyword">.</SPAN>I)<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">request a lift <BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> <SPAN class="keyword">local</SPAN> <BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">ListMin</SPAN> Xs}<BR> <SPAN class="keyword">case</SPAN> Xs <SPAN class="keyword">of</SPAN> [X] <SPAN class="keyword">then</SPAN> X<BR> <SPAN class="keyword">elseof</SPAN> (X<SPAN class="keyword">#</SPAN>CX)<SPAN class="keyword">|</SPAN>Xr <SPAN class="keyword">then</SPAN> <BR> MXr<SPAN class="keyword">#</SPAN>CXr = {ListMin Xr}<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">if</SPAN> X<SPAN class="keyword"><</SPAN>MXr <SPAN class="keyword">then</SPAN> <BR> CXr = <SPAN class="keyword">false</SPAN> % <SPAN class="comment">release <BR></SPAN> X<SPAN class="keyword">#</SPAN>CX % <SPAN class="comment">current minimal offer<BR></SPAN> <SPAN class="keyword">else</SPAN> <BR> CX = <SPAN class="keyword">false</SPAN> % <SPAN class="comment">release<BR></SPAN> MXr<SPAN class="keyword">#</SPAN>CXr % <SPAN class="comment">current minimal offer<BR></SPAN> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">Request</SPAN> Ls Task}<BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">DoReq</SPAN> L}<BR> O C<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">thread</SPAN> <BR> {L request(Task O C)}<BR> <SPAN class="keyword">end</SPAN> <BR> O<SPAN class="keyword">#</SPAN>C<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">true</SPAN> = {ListMin {Map Ls DoReq}}<SPAN class="keyword">.</SPAN>2 % <SPAN class="comment">commit <BR></SPAN> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">Individual Floor Object<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">Floor</SPAN> <SPAN class="keyword">from</SPAN><SPAN class="type"> BaseObject</SPAN> <BR> <BR> <SPAN class="keyword">prop</SPAN> <BR> final<BR> <BR> <SPAN class="keyword">feat</SPAN> <BR> Num<BR> PosY<BR> View<BR> Up UpTag<BR> Down DownTag<BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">init</SPAN>(L N)<BR> <SPAN class="keyword">self.</SPAN>Num = N<BR> <SPAN class="keyword">self.</SPAN>PosY = {Floor2Pos N}<BR> <SPAN class="keyword">self.</SPAN>View = L<BR> <SPAN class="keyword">self.</SPAN>Down = N<SPAN class="keyword">></SPAN>1<BR> <SPAN class="keyword">self.</SPAN>Up = N<SPAN class="keyword"><</SPAN>NumFloors<BR> <BR> Floor<SPAN class="keyword">,</SPAN> drawText<BR> <BR> <SPAN class="keyword">if</SPAN> <SPAN class="keyword">self.</SPAN>Up <SPAN class="keyword">then</SPAN> <BR> Floor<SPAN class="keyword">,</SPAN> drawButton(<SPAN class="keyword">self.</SPAN>UpTag<BR> 35<BR> <SPAN class="keyword">self.</SPAN>PosY<SPAN class="keyword">-</SPAN>15<BR> upF<BR> doUp(press))<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">if</SPAN> <SPAN class="keyword">self.</SPAN>Down <SPAN class="keyword">then</SPAN> <BR> Floor<SPAN class="keyword">,</SPAN> drawButton(<SPAN class="keyword">self.</SPAN>DownTag<BR> 55<BR> <SPAN class="keyword">self.</SPAN>PosY<SPAN class="keyword">-</SPAN>15<BR> downF<BR> doDown(press))<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> Floor<SPAN class="keyword">,</SPAN> show<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">doUp</SPAN>(Who)<BR> <SPAN class="keyword">if</SPAN> <SPAN class="keyword">self.</SPAN>Up <SPAN class="keyword">then</SPAN> <BR> Ms = {<SPAN class="keyword">self.</SPAN>View members($)}<BR> <SPAN class="keyword">in</SPAN> <BR> Floor<SPAN class="keyword">,</SPAN> draw(<SPAN class="keyword">true</SPAN> <SPAN class="keyword">false</SPAN>) % <SPAN class="comment">up/empty<BR></SPAN> {Request Ms goto(<SPAN class="keyword">self.</SPAN>Num CallMode up Who)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">doDown</SPAN>(Who)<BR> <SPAN class="keyword">if</SPAN> <SPAN class="keyword">self.</SPAN>Down <SPAN class="keyword">then</SPAN> <BR> Ms = {<SPAN class="keyword">self.</SPAN>View members($)}<BR> <SPAN class="keyword">in</SPAN> <BR> Floor<SPAN class="keyword">,</SPAN> draw(<SPAN class="keyword">false</SPAN> <SPAN class="keyword">false</SPAN>) % <SPAN class="comment">down/empty<BR></SPAN> {Request Ms goto(<SPAN class="keyword">self.</SPAN>Num CallMode down Who)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">reached</SPAN> <BR> <SPAN class="keyword">if</SPAN> <SPAN class="keyword">self.</SPAN>Up <SPAN class="keyword">then</SPAN> <BR> Floor<SPAN class="keyword">,</SPAN> draw(<SPAN class="keyword">true</SPAN> <SPAN class="keyword">true</SPAN>) % <SPAN class="comment">up/full<BR></SPAN> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">if</SPAN> <SPAN class="keyword">self.</SPAN>Down <SPAN class="keyword">then</SPAN> <BR> Floor<SPAN class="keyword">,</SPAN> draw(<SPAN class="keyword">false</SPAN> <SPAN class="keyword">true</SPAN>) % <SPAN class="comment">down/full<BR></SPAN> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">show</SPAN> <BR> {<SPAN class="keyword">self.</SPAN>View<BR> tk(crea line FloorLeft <SPAN class="keyword">self.</SPAN>PosY FloorRight <SPAN class="keyword">self.</SPAN>PosY)}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">draw</SPAN>(Up Full)<BR> <SPAN class="keyword">if</SPAN> Up <SPAN class="keyword">then</SPAN> <BR> <SPAN class="keyword">if</SPAN> Full<BR> <SPAN class="keyword">then</SPAN> {<SPAN class="keyword">self.</SPAN>UpTag tk(itemconf image:Images<SPAN class="keyword">.</SPAN><SPAN class="string">'upF'</SPAN>)}<BR> <SPAN class="keyword">else</SPAN> {<SPAN class="keyword">self.</SPAN>UpTag tk(itemconf image:Images<SPAN class="keyword">.</SPAN><SPAN class="string">'upE'</SPAN>)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">else</SPAN> <BR> <SPAN class="keyword">if</SPAN> Full<BR> <SPAN class="keyword">then</SPAN> {<SPAN class="keyword">self.</SPAN>DownTag tk(itemconf image:Images<SPAN class="keyword">.</SPAN><SPAN class="string">'downF'</SPAN>)}<BR> <SPAN class="keyword">else</SPAN> {<SPAN class="keyword">self.</SPAN>DownTag tk(itemconf image:Images<SPAN class="keyword">.</SPAN><SPAN class="string">'downE'</SPAN>)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">drawText</SPAN> <BR> {<SPAN class="keyword">self.</SPAN>View tk(crea text 15 <SPAN class="keyword">self.</SPAN>PosY<SPAN class="keyword">-</SPAN>17<BR> text: <SPAN class="keyword">self.</SPAN>Num<BR> font: Bold<BR> tag : {New Tk<SPAN class="keyword">.</SPAN>canvasTag tkInit(parent:<SPAN class="keyword">self.</SPAN>View)}<BR> fill: blue)}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">drawButton</SPAN>(Tag X Y I Action)<BR> Tag = {New Tk<SPAN class="keyword">.</SPAN>canvasTag tkInit(parent:<SPAN class="keyword">self.</SPAN>View)}<BR> {<SPAN class="keyword">self.</SPAN>View tk(crea image X Y image:Images<SPAN class="keyword">.</SPAN>I tag:Tag)}<BR> {Tag tkBind(event:<SPAN class="string">'<1>'</SPAN> action:<SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN>} {<SPAN class="keyword">self</SPAN> Action} <SPAN class="keyword">end</SPAN>)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">Lift Manager<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">LiftManager</SPAN> <SPAN class="keyword">from</SPAN><SPAN class="type"> Tk.canvas Time.repeat</SPAN> <BR> <BR> <SPAN class="keyword">prop</SPAN> <BR> final<BR> <BR> <SPAN class="keyword">feat</SPAN> <BR> Floors<BR> <BR> <SPAN class="keyword">attr</SPAN> <BR> Members: nil<BR> PosX : LeftMost<BR> Queue : nil<BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">init</SPAN>(parent:W floors:AllFloors)<BR> <SPAN class="keyword">self.</SPAN>Floors = AllFloors<BR> <BR> Tk<SPAN class="keyword">.</SPAN>canvas<SPAN class="keyword">,</SPAN> tkInit(parent: W<BR> width: Width<BR> height: Height<BR> relief: sunken<BR> bd: Bound<BR> background: FloorsColor)<BR> <BR> Time<SPAN class="keyword">.</SPAN>repeat<SPAN class="keyword">,</SPAN> setRepAll(action:press delay:DelayLift)<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">join</SPAN>(L ?X)<BR> X = <SPAN class="keyword">@</SPAN>PosX<BR> PosX <SPAN class="keyword"><-</SPAN> X <SPAN class="keyword">+</SPAN> LiftDelta<BR> Members <SPAN class="keyword"><-</SPAN> L<SPAN class="keyword">|@</SPAN>Members<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">members</SPAN>($)<BR> <SPAN class="keyword">@</SPAN>Members<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">press</SPAN> <BR> R={RanChoiceFloor}<BR> Action = <SPAN class="keyword">if</SPAN> R<SPAN class="keyword">==</SPAN>NumFloors <SPAN class="keyword">then</SPAN> doDown<BR> <SPAN class="keyword">elseif</SPAN> R<SPAN class="keyword">==</SPAN>1 <SPAN class="keyword">then</SPAN> doUp<BR> <SPAN class="keyword">else</SPAN> {RanChoiceBin doUp doDown}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> {{Nth <SPAN class="keyword">self.</SPAN>Floors R} Action(sim)}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">reached</SPAN>(N)<BR> {{Nth <SPAN class="keyword">self.</SPAN>Floors N} reached}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">close</SPAN> <BR> Time<SPAN class="keyword">.</SPAN>repeat<SPAN class="keyword">,</SPAN> stop<BR> Tk<SPAN class="keyword">.</SPAN>canvas<SPAN class="keyword">,</SPAN> tkClose<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">Create Window and Lifts object as manager for group of Lift objects<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> Top = {New Tk<SPAN class="keyword">.</SPAN>toplevel tkInit(title: <SPAN class="string">'Oz Lifts'</SPAN> <BR> delete: Application<SPAN class="keyword">.</SPAN>exit <SPAN class="keyword">#</SPAN> 0)}<BR> <BR> BFrame = {New Tk<SPAN class="keyword">.</SPAN>frame tkInit(parent: Top<BR> width: 20<BR> background: BGColor)}<BR> <BR> L1 = {New Tk<SPAN class="keyword">.</SPAN>label tkInit(parent: BFrame<BR> text: <SPAN class="string">"automatic operation"</SPAN> <BR> background: BGColor)}<BR> <BR> L2 = {New Tk<SPAN class="keyword">.</SPAN>label tkInit(parent: Top<BR> text: <SPAN class="string">"Press arrows for manual operation"</SPAN> <BR> width: 30<BR> background: BGColor)}<BR> <BR> AllFloors = {List<SPAN class="keyword">.</SPAN>make NumFloors}<BR> AllLifts = {List<SPAN class="keyword">.</SPAN>make NumLifts}<BR> <BR> Lifts = {New LiftManager init(parent:Top floors:AllFloors)}<BR> <BR> GoB = {New Tk<SPAN class="keyword">.</SPAN>label tkInit(parent: BFrame<BR> text: <SPAN class="string">" start "</SPAN> <BR> relief: raised<BR> bd: 2<BR> width: 9<BR> background: FGColor)}<BR> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">AutoOn</SPAN>}<BR> {GoB tk(conf text:<SPAN class="string">" stop "</SPAN>)}<BR> {GoB tkBind(action:AutoOff event:<SPAN class="string">'<1>'</SPAN>)}<BR> {Lifts go}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">AutoOff</SPAN>}<BR> {GoB tk(conf text:<SPAN class="string">" start "</SPAN>)}<BR> {GoB tkBind(action:AutoOn event:<SPAN class="string">'<1>'</SPAN>)}<BR> {Lifts stop}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> {GoB tkBind(action:AutoOn event:<SPAN class="string">'<1>'</SPAN>)}<BR> <BR> {Tk<SPAN class="keyword">.</SPAN>batch [pack(Lifts padx:10 pady:20)<BR> pack(BFrame side:top)<BR> pack(GoB L1 side:left padx:2 expand:<SPAN class="keyword">true</SPAN>)<BR> pack(L2 side:top pady:2)<BR> ]}<BR> <BR> <BR> %%<SPAN class="comment"> <BR></SPAN> %% <SPAN class="comment">Create lift and floor objects<BR></SPAN> %%<SPAN class="comment"> <BR></SPAN> <BR> <SPAN class="keyword">if</SPAN> NumFloors<SPAN class="keyword">>=</SPAN>2 <SPAN class="keyword">then</SPAN> <BR> <BR> {List<SPAN class="keyword">.</SPAN>forAllInd AllFloors<BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> N}<BR> {New Floor init(Lifts N)}<BR> <SPAN class="keyword">end</SPAN>}<BR> <BR> {ForAll AllLifts<BR> <SPAN class="keyword">fun</SPAN>{<SPAN class="functionname">$</SPAN>}<BR> {New Lift init(Lifts)}<BR> <SPAN class="keyword">end</SPAN>}<BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <BR><SPAN class="keyword">end</SPAN> <BR> <BR></PRE></BLOCKQUOTE><P></P></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="lift.html">- Up -</A></TD></TR></TABLE><HR><ADDRESS><SPAN class="version">Version 1.4.0 (20110908185330)</SPAN></ADDRESS></BODY></HTML>
|