Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elevators should not ignore passengers that want to travel in the wrong direction if they have already entered the elevator. #10

Open
alexanderpas opened this issue Jan 18, 2016 · 5 comments

Comments

@alexanderpas
Copy link

When a passenger is already inside the elevator, and wants to travel in the wrong direction, the elevator should not ignore that passenger completely, but only ignore the passenger until it's done travelling in the current direction.

The current situation means that when you press the button for a lower floor inside the elevator, the button for that floor doesn't light up, causing confusion from the rider, who doesn't expect the elevator to not continue to his floor but stay put at a different floor.

@nocarryr
Copy link

@alexanderpas is this the section describing the logic you're referring to?

https://github.com/mshang/python-elevator-challenge/blame/master/README.md#L159-L179

In fact, if a passenger tries to select a floor that contradicts the current direction of the elevator, that selection is ignored entirely. You've probably seen this before. You call the elevator to go down. The elevator shows up, and you board, not realizing that it's still going up. You select a lower floor. The elevator ignores you.

    >>> e = Elevator(ElevatorLogic())
    1...
    >>> e.select_floor(3)
    >>> e.select_floor(5)
    >>> e.run_until_stopped()
    2... 3...
    >>> e.select_floor(2)

At this point the elevator is at the third floor. It's not finished going up because it's wanted at the fifth floor. Therefore, selecting the second floor goes against the current direction, so that request is ignored.

    >>> e.run_until_stopped()
    4... 5...
    >>> e.run_until_stopped()  # nothing happens, because e.select_floor(2) was ignored

Now it's done going up, so you can select the second floor.

    >>> e.select_floor(2)
    >>> e.run_until_stopped()
    4... 3... 2...

I agree. The request should be serviced (or "queued"), but obviously not acted upon immediately. The expected behavior, at least in elevators I've used, should be:

>>> e = Elevator(ElevatorLogic())
    1...
    >>> e.select_floor(3)
    >>> e.select_floor(5)
    >>> e.run_until_stopped()
    2... 3...
    >>> e.select_floor(2)

At this point the elevator is at the third floor. It's not finished going up because it's wanted at the fifth floor. Therefore, selecting the second floor goes against the current direction, so that request is serviced after it's reached reached the fifth floor.

    >>> e.run_until_stopped()
    4... 5...
    >>> e.run_until_stopped()  # now it services the request for e.select_floor(2)
    4... 3... 2...

But that's my opinion

@alexanderpas
Copy link
Author

Yes.

A second instance of this problem is seen in this section

If the elevator is called in both directions at that floor, it must wait once for each direction. You may have seen this too. Some elevators will close their doors and reopen them to indicate that they have changed direction.

    >>> e = Elevator(ElevatorLogic())
    1...
    >>> e.select_floor(5)
    >>> e.call(5, UP)
    >>> e.call(5, DOWN)
    >>> e.run_until_stopped()
    2... 3... 4... 5...

Here, the elevator considers itself to be going up, as it favors continuing in the direction it came from.

    >>> e.select_floor(4)  # ignored
    >>> e.run_until_stopped()

Since nothing caused the elevator to move further up, it now waits for requests that cause it to move down.

    >>> e.select_floor(6)  # ignored
    >>> e.run_until_stopped()

Since nothing caused the elevator to move down, the elevator now considers itself idle. It can move in either direction.

    >>> e.select_floor(6)
    >>> e.run_until_stopped()
    6...

Which causes the rider that wanted to go to the 4th floor, which was already in the elevator to not being serviced, despite having entered before the rider that wanted to go to the 6th floor, which had to enter the destination twice.).

Additionally, This case shows the doors opening and closing 3 times on the same floor, despite having riders already in the elevator, and having selected a destination.

@nocarryr
Copy link

@alexanderpas I hadn't noticed that one. I didn't even get as far as the section your issue refers to. What got me was the section above (directly beneath "Directionality"). Have a look at my comment on it

It seems this has become an interesting exercise in defining elevator logic rather than implementing it.

@mshang
Copy link
Owner

mshang commented Jan 21, 2016

The behavior in this challenge is based on the elevator in my building, which actually is that dumb...

@nocarryr
Copy link

Hahaha... I understand. This has actually been an interesting process, but for me it's been more interesting in terms of the logic itself rather than programming for it.

Thinking about how to make an elevator do things efficiently was a nice break from my typical coding routines, so thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants