10/15/2003 10:54:57 PM|||Travis||| Here is a note that I wrote to my TA for CS 170- Computer Operating systems. It is in regard to a lab where I had to simulate an elevator that moved between floors, picked people up, took them to where they wanted to go, and didn't kill to many of them in the process. I call it:
The Simulated Elevator Saga
E1 was easy enough- one global list of people,
a lock, and a condition variable. Block the
person until the elevator has taken them to
their destination. Everyone is happy, and my
sims are all merrily getting to their destination
and then exiting on floor 6 or 9 to their death.
By easy I mean that my addiction to caffine was
completely reinstated, pages of notebooks were
filled with desgin and echos of my curses bounced
off the CSILS walls.
Then came E2.
The initial implementation worked... magically and
barely. I didn't know how people were getting to their
destination, why they were getting there and all
of my print statements were showing that nothing
was working like I expected.
So it was refactored.
And to my horror, it stopped working. People
started to starve, cores started dumping in
unkown threads stuck on floor -34.... it wasn't
pretty. Some people got into elevators never to
see the light of day again.
But I understood it all. The values made sense,
and I could see how to improve it. Four cups of coffee,
two early mornings and ten if statement patches
later- my program worked.
The initial algorithim that was implimented (the
magic one) knew about directions and such, but the
later one (which I understood and handed in) picks people
up and then moves them to the farthest floor away from
floor 5 that someone wants to go to.
This is quite a strange algoritim indeed.
It was an improvement upon a strategy where I had
the elevator simply move to the farthest destination
floor that it could find, but barley. My attempts to
implement a system that picked people up based on "going
up" or "going down" like real elevators never got off the
ground (hehe, no pun intended). For a split second, I
believed that my new elevator algorith could perhaps change
the very nature of elevator engineering everywhere.
This was not the case.|||106628369768590209|||