Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: Multi-Threaded Elevator Simulator

by samtregar (Abbot)
on Aug 07, 2002 at 14:31 UTC ( [id://188326]=note: print w/replies, xml ) Need Help??


in reply to Re: Multi-Threaded Elevator Simulator
in thread Multi-Threaded Elevator Simulator

Your version is shorter but it's not right! My code computes max_ride and max_wait across all people. Yours finds the max_ride and max_wait for each person and only keeps the last one.

As far as making the simulation more accurate, there are many ways I could go. For one thing I could limit the number of people in a single elevator. And I could have the elevators communicate so they don't all rush off to the same floor at once. But ultimately this would be counter-productive as a teaching example since it would only make the code longer and thicker.

Thanks,
-sam

  • Comment on Re: Re: Multi-Threaded Elevator Simulator

Replies are listed 'Best First'.
Re: Re: Re: Multi-Threaded Elevator Simulator
by dimmesdale (Friar) on Aug 08, 2002 at 14:41 UTC
    As far as making the simulation more accurate, there are many ways I could go.

    I suggest you go to a near-by university and observe people's habbits getting on and off elevators (as well as finding out how the elevators operate), calculating how long people usually wait for an elevator to come down before leaving ... etc.

    (Or if that doesn't strike you as fun, or you don't have several weeks ... :), you could always check out Knuth's The Art of Computer Programming. I don't have the books here as a reference, but I believe it is either the first or second one. Knuth does just what I described above--memory permitting, of course. Its pretty informative if you have the books or can get them at a library--of course, I make no guarentees that he talks about threading, either in Perl 5.8.0 or otherwise :)

      At my university (NYU) they actually had security guards posted at all the ground floor elevator doors to tell people how to get on and off the elevators. No joke.

      But ultimately, this exercise isn't about building the best possible elevator simulator. It's about showing people how to use Perl's threading support. In fact, if anyone could show me how to build a dumber, simpler simulator that still works I'd probably use that. The elevator algorithm is really just a distraction here.

      -sam

Re: Re: Re: Multi-Threaded Elevator Simulator
by Anonymous Monk on Aug 07, 2002 at 22:45 UTC
    man...I hate when people point out the obvious when its not even related to the point. The point was to test the new and improved 5.8 threading...which I think was a good idea....besides...
    $max_wait = $wait1 > $wait2 ? $wait1 : $wait2;

    does not equal
    $max_wait = $wait1 if $wait1 > $max_wait;

    because $max_wait is an aggregate value and is not in the same scope....you would lose your max value at every iteration....instead...
    $max_wait = ($wait1 > $wait2) ? ($wait1 > $max_wait) ? $wait1 : $max +_wait : ($wait2 > $max_wait) ? $wait2 : $max_wait;

    would work....
    -insomnia
      $max_wait = ($wait1 > $wait2) ? ($wait1 > $max_wait) ? $wait1 : $max +_wait : ($wait2 > $max_wait) ? $wait2 : $max_wait;
      If I was your teacher, I'd rap you on the knuckles with a ruler for writing that! Gah!

      Please, consider this much clearer alternative:

      $max_wait < $_ and $max_wait = $_ for $wait1, $wait2;
      Or, if you don't like the "and" there...
      for ($wait1, $wait2) { $max_wait = $_ if $max_wait < $_; }

      -- Randal L. Schwartz, Perl hacker

        Personally, I've always been fond of (sort {$a<=>$b} ($wait1, $wait2))[-1]...

        =cut
        --Brent Dax
        There is no sig.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://188326]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-20 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found