Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

Saikrishnan Srivatsan

Ranch Hand
+ Follow
since Sep 20, 2013
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Saikrishnan Srivatsan

Stephan van Hulst wrote:The strategy would be used by the controller like this:



Could you please clarify who is likely to be the consumer of the events "StopScheduledEventHandler" and "ArrivalEventHandler"? Let us say that the strategy schedules a stop and raises this event. Why would we need the elevator to react to this(assuming this is why we have the delegate?) the stop has already been scheduled, isn't it?
1 year ago

Maybe it's just me but in an interview setting, say with a time limit of a couple of hours, I wouldn't be looking for that much as an evaluator. In fact, if you came to me with that much "design," I'd be scared. I'd have to ask myself what kind of complex monstrosities would everybody have to deal with if we hired someone who could come up with all that in just a couple of hours? But again, it's just me. To others, having all that might be impressive but for me, simple is better.



I totally hear you Junilu, and I agree with you that it is way more than what you can typically come up with for a real world project in 2 hours. But the recent trend in some of the interviews I've had is to gauge how wide and deep the candidate could go - a lot of people do feel that that isn't the right way to go about it, but I was actually rejected recently for picking up one part of a big problem similar to this and starting simple. It was a 40 min interview and the feedback I was given was I did not go into the wider aspects of the problem. And like I had mentioned earlier, my aim is to be very good at this stuff and learn it the right way, but unfortunately the interviewing style of some companies now does not necessarily align with that line of thinking. So for short term gains, I'm having to go down this path. But I promise, when I actually sit down to do this for my pleasure/understanding/learning I will adopt the approach that you have mentioned.
1 year ago

For a first iteration, I would go with this design:



Thanks, that looks great

The strategy would be used by the controller like this:



Could you please help me understand why we need the stopIndex and why it is returned by the strategy? Is this to determine which index in the current list of stops the next stop needs to be inserted?

On a related note, I see that the type of the ScheduledStops is a readonly list, how could we insert stops in this case?

Could you also please help me understand why we need the two Events and and their corresponding EventArgs?

1 year ago

Here is a Floor class you could use:



Thank you so much for this and for helping out overall.

I would use a strong type to represent a floor. It will make your code much nicer to read, and you can also use it to represent levels that aren't associated with a number. Just this morning I stepped in an elevator that had the levels -1, E, L, 1, 2, 3, ...

I think the RequestDirection enum is useless. Instead of telling an elevator to move in a specified direction, just let it move closer to the next scheduled stop.

Why does ElevatorRequest have private setters? If the properties are intended to be read-only, remove the setters completely. Same goes for all your other classes.

The RequestTime parameter of the ElevatorRequest doesn't follow naming conventions. Start it with a lower-case letter.

What is the purpose of a Button? It looks like a useless wrapper around a floor ID. And what is the purpose of a ButtonPanel? Why not just call the ElevatorRequest constructor directly?

Why does an elevator need an ID?

The name 'capacity' does not clearly indicate whether it concerns weight or volume.

Property names should start with a capital letter.

I wouldn't use a PriorityQueue to hold your scheduled stops, because you will never be able to schedule stops in the opposite direction until the queue is completely empty. A simple List will do. Besides, I don't think PriorityQueue is a standard class in the .NET API.

Don't let a class react to events that it raises itself. Just call a method directly from the place where the event is raised.

SetElevatorRequest is a really poor name. Name it something like RequestRide instead.



I promise I have made these changes, but before posting it here again, I would really like to get the logic behind the scheduling strategy right since that is the core of the problem and would really appreciate some pointers on how I could make it self-sufficient.



I have added the list of elevators as a parameter(returning an elevator instead of void) and will be determining the state of each of them and choosing the most optimal one to serve the request at hand. Is this sufficient information for the strategy to work? If not, I would like to clarify if I am even thinking along the right lines as to what is required for it to be self-sufficient? Does it need the activeRequests of the controller itself as opposed to having just the requests currently served by each of the elevators? I am a little lost for ideas.

My assumption is that the SchedulingStrategy is the one that determines the rules that govern which elevator the request should go to.
1 year ago

Or is it that the strategy is used to decide whether or not to add a floor to an elevator's queue?


Yes. Strategy determines which elevator the request goes to. PriorityQueue in the elevator will have its own comparer to sort the stops and the top(min/max) will be the next stop it stops at.
1 year ago
The SchedulingStrategy is only to determine which of the four elevators the current request goes to. The PriorityQueue<int> of activeStops within each elevator is only for that elevator. The top will always have the next floor it needs to make a stop at. I cam unable to think of a more efficient way to insert stops to the list of stops an elevator has.
1 year ago
Thanks for the detailed feedback. I apologize for the ambiguity and the inconsistency in my code. My immediate goal is to figure out if I have the right set of classes for the given specifications and then move on to the scheduling solution. That being said, I also intend to do a fully implemented solution eventually - hence the additional implementation detail skeleton code.

The capacity is central to both the scheduling strategies. My idea of the EnergyEfficientStrategy is:

  • Check if an elevator is within 3 floors and already moving in the direction of the request.
  • If yes, choose this elevator for the request even if there is an idle elevator closer.
  • If the capacity exceeds the limit by the time it gets to the request floor, return the request to the controller to be assigned to another elevator.


  • My idea of the ShortestWaitTimeStrategy is:

  • Check the closest elevator from the request floor(idle or moving).
  • If there is a tie between two idle elevators choose the one with the lower total weight.


  • C# has properties. Why aren't you using them? Why aren't there event declarations in your API? Most importantly, why aren't there constructors, so I can see what dependencies a class relies on?


    Fixed this.

    You're using inappropriate types. A long is a poor representation for an instant of time. Why do you have int to represent floors in some cases and char to represent them in other cases? Be consistent.


    And this.

    If you're using a Queue for stops, how are you going to insert a stop when it turns out that inserting a stop is more efficient than adding the stop at the end of the queue?


    Added a comment and changed the type to a PriorityQueue. Will this work?

    How is a scheduling strategy going to be effective when the only information it has is the request? Why doesn't a strategy have access to the available elevators or their current schedules?


    The idea is to query the controller for the available elevators, employ some custom comparison mechanism that determines the best elevator and chooses it from the list.

    What does it mean to "Set a request" in your ElevatorController?


    Added a comment to clarify this.

    1 year ago
    Sorry, I am not sure why my classes show up in a small white box in my original post. Add this post to make it more readable.

    1 year ago
    My friend was asked to design an elevator system for a building with 50 floors and 4 elevators in a recent interview. This seems like a very open-ended question and I wanted to try my hand at it. I have come up with a few classes that I think will suit the use cases and is also extensible.
    I would clarify this with an interviewer in a real interview, but I have made the following assumptions:

  • The elevators are all capable of serving all 50 floors. They are not divided into serving a specific set of floors.
  • There are no special or express elevators.
  • There will be peak and off-peak usage patterns.
  • The button panel on floors will be able to take the actual destination floor as input rather than just the direction. There is no special reason for this assumption, just that this was how it was in the last high-rise hotel I was staying at.
  • The elevators themselves have no buttons apart from close door, alarm, open door(I have not accounted for these in my classes since I felt they are not central to the design).


  • Please point out the bad/negative aspects of the design/assumptions and my overall idea. Please let me know putting yourself in the shoes of an interview the aspects you liked.

    P.S. I am a C# developer by trade, so the declarations and casing adhere to standard C# conventions. I apologize for any convenience due to this. But given the syntactical similarity between the languages, the code is hopefully clear enough from a readability standpoint.

    1 year ago
    SQL server is the only application running on that host name. The database client I use to connect also connects to that host. That is probably why.

    On an independent note, I have managed to get this working using Connection pool but still would be interested to know why the regular jdbc connection wouldn't work.
    Hello all,

    I am trying to make a jdbc connection to MS SQL server 2014 using sqljdbc4 from an Eclipse Web project,
    without any luck whatsoever.

    Here is what I have tried so far:
  • 1. Create a test class outside of the Web project, add jar to classpath and try to make a connection - success
  • 2. Place jar under project's WEB-INF/lib, add jar to classpath with and without adding a Web App Library
    for the project and try to make a connection - failure
  • 3. Place jar under the central Tomcat lib and try to make a connection - failure


  • Most of the forums have users who have succeeded by doing number 2. I am just starting out with JDBC and it took a
    while to figure out to get to this stage.
    But unfortunately, couldn't get any further. I am stuck at this point for close to 5 hours now and the frustrating thing is
    it works every time from a regular java project.
    Why is that so, when any kind of project in an IDE requires the jar to be in its classpath?

    Not sure how much help this will be of, but here is the code that I had come up with that tries to establish the connection.
    And it always leads to an SQLException : No suitable driver found for jdbc:sqlserver on the first line after 'try'.


    Kindly review and help.
    Thanks, Jeanne. What if I don't have shared or joint accounts? Could you kindly give me other examples where having an account number will not be appropriate?

    If I were to have customer IDs for customers, should I have something like this:

    HashMap <customerID, customer>

    and then have some means to link account number and customer ID?
    6 years ago
    Hello all,

    I recently had to work on a very simple banking application. Since customers provide their account numbers when they go to the teller to perform a transaction, I chose account number as the key to uniquely identify a customer. To address the fact that a customer can have multiple accounts, I decided to have an entry for every account the customer had, as part of my Teller class, so that he can identify himself with any of his active account numbers. When I was discussing this design with my friend, he felt it was bad and that I had to have a CustomerID field to uniquely identify a customer. I can't seem to understand why we can't do that with account numbers belonging to the customer? Could someone please give an example of where this might not work to help me understand this better?

    Thanks.
    6 years ago
    Thank you! I wanted to ask you in general as well if you have ever had to create your own data structure? What things do you consider when you do? I'd like to know if you've ever had to do so.

    For example, in this case, if there were a dual key map, I could have used that. Should I try to create one or just use 2 maps?
    6 years ago

    Campbell Ritchie wrote:

    Thank you Would you create a new data structure (dual key hash map?) that takes 2 keys and a value? Or would you just use 2 hash maps in the address book class?
    6 years ago