1, 2, 3, 4 take the elevator

This is a discussion on 1, 2, 3, 4 take the elevator within the A Brief History of Cprogramming.com forums, part of the Community Boards category; an interesting problem to try and model: a 20 storey building with two elevators, each can move independantly and at ...

  1. #1
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385

    1, 2, 3, 4 take the elevator

    an interesting problem to try and model:

    a 20 storey building with two elevators, each can move independantly and at the same time in different directions, all features must be present (doors open close etc) and each elevator must be able to be called or sent to different floor at the same time.

    i tried to solve this while bored one day and after several weeks i gave up , i dont think real time systems prgramming is for me.
    have a try
    Monday - what a way to spend a seventh of your life

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    *cough* spam posts *cough*

  3. #3
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    hmm.....think i could do it...

    supposed to do it graphically i am guessing?

    yeah you just have booleans saying whether each elevator is moving, then call the movement functions...you also gotta have a couple vars to keep track of their floor numbers

    I am guessing they are in different elevator shafts also, b/c you dont want them to crash against each other...

    seems possible..
    My Website

    "Circular logic is good because it is."

  4. #4
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    well i had this problem is my ASM(TASM) class....... It is quite easy.....

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> each can move independantly and at the same time in different directions,

    Semantics I'm sure, but to me, that implies that an individual elevator can be moving up and down at the same time. That adds some interest to the model.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    well this can be easily be implementd in JAVA by giving both the elevators thread equal priority..(Multi threading...) this can also be implemented in pure C by having a timer and changing between the two really fast.. or using multi threading.. Believe me it isnt tuff... these kinds of problems are normally given in assembly language classes..

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    559
    This problem is used in Deitel's C++ book, primarily as an example of UML modeling but it walks through all the code.
    Truth is a malleable commodity - Dick Cheney

  8. #8
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    you dont even need multithreading for this, so why even mention it.

    it is pretty simple:

    Code:
    bool elevator1switch;
    bool elevator2switch;
    int floorcur1, floorcur2, floor1, floor2;
    
    while(1)
    {
    MoveElevator ( Elevator1, floorcur1, floor1, elevator1switch );
    MoveElevator ( Elevator2, floorcur2, floor2, elevator2switch );
    
    switch ( command )
    {
        case whatever:
              floor1 = whatever;
              floor2 = whatever;
              break;
    }
    
    }
    My Website

    "Circular logic is good because it is."

  9. #9
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    well u r talkin in terms of program.. In terms of writing code for circuits to be embeded in the real elevator... you cannot always execpt the first input to be for the 1st elevator... and it needs to work in real time...

  10. #10
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Originally posted by DavidP
    you dont even need multithreading for this, so why even mention it.

    it is pretty simple:

    Code:
    bool elevator1switch;
    bool elevator2switch;
    int floorcur1, floorcur2, floor1, floor2;
    
    while(1)
    {
    MoveElevator ( Elevator1, floorcur1, floor1, elevator1switch );
    MoveElevator ( Elevator2, floorcur2, floor2, elevator2switch );
    
    switch ( command )
    {
        case whatever:
              floor1 = whatever;
              floor2 = whatever;
              break;
    }
    
    }
    Without multithreading, how can they be moving at the same time? In your model, the first one would move, then the second, then the first, then the second...etc.

  11. #11
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Originally posted by -KEN-
    Without multithreading, how can they be moving at the same time? In your model, the first one would move, then the second, then the first, then the second...etc.
    You need two CPUs are they still won't be able to move at the same time. Anyway a system like this would undoubtably have one program for each elevator (they could still be run on one CPU due to the wonders of multitasking)

  12. #12
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    umm...put each elevator into its own thread, and do it that way...

  13. #13
    Much older and wiser Fountain's Avatar
    Join Date
    Dec 2001
    Location
    Engeeeerland
    Posts
    1,158
    I take it you lot dont design elevators(now reffered to as lifts). Lots of lifts at UNI. Just concerned thats all. Heh...

    Oh yes there are lots of lifts, each independant......help me here, this is soooooooooo boring.
    Such is life.

  14. #14
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Well not every where they are independent... the controll unit for these lifts are expensive.. So many companys request for one single unit which can controll all the lifts...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem - 2 elevators, when do they meet ?
    By apacz in forum Contests Board
    Replies: 1
    Last Post: 12-03-2005, 10:48 AM
  2. Elevator shaft help me out
    By Ralphiecdn in forum C Programming
    Replies: 3
    Last Post: 06-20-2005, 03:52 PM
  3. Elevator Function confusion
    By applescruff in forum C++ Programming
    Replies: 5
    Last Post: 12-16-2004, 09:14 AM
  4. Idea: Elevator Prog
    By gamer4life687 in forum Contests Board
    Replies: 0
    Last Post: 11-15-2002, 09:01 PM
  5. Elevator program
    By brianptodd in forum C++ Programming
    Replies: 14
    Last Post: 11-01-2002, 10:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21