Author |
Topic |
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2011-01-11 : 08:51:49
|
I work in the 22nd floor of an office building with 26 floors and 6 elevators and it has been annoying me since the day I started that I always have to stand around seemingly forever to get an elevator. And once I'm in the elevator it takes forever to get either up or down since it seems to stop on every other floor, stealing a good part of my day. Totally annoying!! So I've been thinking...since I'm not doing anything sensible for the time being I wanted to see if I could make an algorithm using t-sql that would always give me the elevator that would get me where I wanted to go in the shortest amount of time. To be honest I haven't even started designing the tables I need, but I thought it would be a cool challenge. So if anyone wants to join in, feel free!Here are some requirements:- 26 floors (basement and 25 storeys)- 6 elevators- max 20 people per elevator- elevator moves 1 floor/second- each elevator stop takes 20 secondsI was thinking about creating this with full simulation of the lifts, running 6 scripts in parallel simulating each elevator picking up and dropping off people and one script that continuously orders lifts randomly, but we'll see how it goes.- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
|
TimSman
Posting Yak Master
127 Posts |
Posted - 2011-01-11 : 09:24:35
|
I think you would also need to know the traffic and times. In other words, you would need to know the number of people at a given point of time, both in the elevators and waiting. Might also want to know the number of people on average that get out on each floor. |
|
|
Kristen
Test
22859 Posts |
Posted - 2011-01-11 : 09:26:29
|
You need to install the Elevators from "The Hitch Hiker's Guide to the Galaxy" - they had extra-sensory-perception and they "arrive on the floor you are on before you know you need one" |
|
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2011-01-11 : 09:40:30
|
quote: Originally posted by Kristen You need to install the Elevators from "The Hitch Hiker's Guide to the Galaxy" - they had extra-sensory-perception and they "arrive on the floor you are on before you know you need one"
Win. not only for knowing it, but for quoting it.Did you think the iPad when it first came out was a basic version of "The Guide". First thing the iPad reminded me of... LOL.Sounds like an interesting problem to mess around with Lumbago, I might have to give it some thought. Poor planning on your part does not constitute an emergency on my part. |
|
|
Kristen
Test
22859 Posts |
Posted - 2011-01-11 : 13:23:19
|
I liked the peril-sensitive-glasses too - the lenses turn back at the first hint of danger so you don't have to see what happens! |
|
|
TimSman
Posting Yak Master
127 Posts |
Posted - 2011-01-11 : 14:41:05
|
quote: Originally posted by Kristen I liked the peril-sensitive-glasses too - the lenses turn back at the first hint of danger so you don't have to see what happens!
I have users that ascribe to this technique. Covering their eyes is the only way they can come up with some of the things I've seen. |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2011-01-11 : 17:23:36
|
quote: Originally posted by TimSman I think you would also need to know the traffic and times. In other words, you would need to know the number of people at a given point of time, both in the elevators and waiting. Might also want to know the number of people on average that get out on each floor.
Traffic and times isn't really necessary but it would be nice to have for statistical purposes. My plan is to create a process that orders lifts randomly and the people coming in to the lift will necessarily go out on the floor they ordered. But this system will of course need to keep track of which people are going where and add new records when people order a "trip" and delete them again when they are delivered at their destination...- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-01-11 : 18:48:06
|
We don't do homework questions N 56°04'39.26"E 12°55'05.63" |
|
|
Kristen
Test
22859 Posts |
Posted - 2011-01-12 : 02:58:02
|
Only time I worked in a tower block the lifts "parked" in non busy periods on ground floor, top floor (where the expensive people were I suppose) and half way up.I worked on the half-way floor, and we always had a lift waiting in the middle of the day! |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2011-01-12 : 09:38:40
|
Ok, this is taking me longer than I expected. I have gotten to a point where I have created a table with 2 lifts, created a lift-queue and now I'm trying to order a lift from the 6th to the 9th floor (in the DECLARE statement in the middle there). My problem is: even though Lift1 has the least amount of work to do (78 seconds of work, compared to 101 seconds for Lift2) Lift2 is both closer (only 2 floors away) and has no stops in between floors 6 and 9 which would make Lift2 the better choice. How can I identify this...? And another thing...if I actually choose Lift2 the people that are already in it will get upset because their ride will be longer than necessary, actually 40 seconds longer (2 stops). Should I then choose Lift1 after all??DECLARE @Lifts table ( LiftID int, CurrentFloor tinyint NULL, LiftStatus varchar(50) NULL --> 'GoingUp', 'GoingDown' or 'Idle' )INSERT INTO @Lifts VALUES (1, 1, 'GoingUp') , (2, 4, 'GoingUp')DECLARE @LiftQueue table ( LiftQueueID int identity(1, 1), LiftID int, FloorNum int )INSERT INTO @LiftQueue (LiftID, FloorNum)VALUES (1, 5), (1, 8), (1, 19), (2, 6), (2, 12), (2, 15), (2, 25)SELECT * FROM @LiftQueueDECLARE @FromFloor int = 6, @ToFloor int = 9, @Direction varchar(50) = 'GoingUp'SELECT LiftID, TravelDurationSeconds = (FloorStops * 20) + (HighestFloor - LowestFloor), CurrentFloor, FloorStops, LowestFloor, HighestFloor, LiftStatusFROM ( SELECT b.LiftID, b.CurrentFloor, b.LiftStatus, FloorStops = COUNT(*), LowestFloor = CASE WHEN CurrentFloor < MIN(FloorNum) THEN CurrentFloor ELSE MIN(FloorNum) END, HighestFloor = CASE WHEN CurrentFloor > MAX(FloorNum) THEN CurrentFloor ELSE MAX(FloorNum) END FROM @LiftQueue a INNER JOIN @Lifts b ON a.LiftID = b.LiftID GROUP BY b.LiftID, b.CurrentFloor, b.LiftStatus ) AS bWHERE LiftStatus IN ('Idle', @Direction)ORDER BY TravelDurationSeconds - LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-01-12 : 15:03:58
|
Do you have weight-sensors in your lifts?Even if Lift2 is closer, it might be full. N 56°04'39.26"E 12°55'05.63" |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2011-01-12 : 15:48:10
|
Well, yes there are weight sensors with a max capacity of 1600kg. There is also a max number of people (20) but I left both out intentionally to make it easier for myself :)- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2011-01-12 : 15:49:11
|
There are other factors to consider.When I was in college, the local pranksters in the dorm used to love to take the furniture from the lobbies and fill the elevators so that no one could use them. That was especially popular at meal times when people on the tenth floor wanted to get to the cafeteria in the basement level.Or just some simple annoyance like pressing the button for every floor right before you get off. Or leaving a chair in the door so it can't close.CODO ERGO SUM |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2011-01-14 : 04:33:30
|
I've heard some elevator pranks before but no one where the entire elevator was filled with furniture. That would actually be hilarious to do in my office building...fill all 6 elevators with furniture :D We did have some good times with the furniture in high school though. We once superglued a chair and a desk with a book on it to the blackborad. It was one of those time where you wish mobile cameraphones and youtube were invented :)- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
|
|
|