nus-cs2030 / 2122-s2

CS2030 repository and wiki for AY 2021/2022 Sem 2
MIT License
0 stars 0 forks source link

Level 8 #546

Open tristky opened 2 years ago

tristky commented 2 years ago

Summary

Hi, i have decided to start working from the back of the project to conquer the hard parts then complete the front, is there any tips for me before i start on level 8?

Noel-Lee commented 2 years ago

What I did was to handle the queuing and dequeuing in shop for selfcheckout servers since the queuing and dequeuing of the customers is only in the k+1 selfcheckout server, but the service will be done at their respective servers. Other than that is mostly overriding your methods to return a new selfcheckout instead of a new server. This worked for me at least. Kind of really depends on ur implementation.

jonyeokj commented 2 years ago

You shouldn't approach the project like that, because it's meant to build up from each level, but I can roughly share with you my thought process, pseudo-code and thought process behind solving Level 8.

Firstly, you need to decide where you want to put the shared queue. The most common methods I've seen on these threads are people updating the queues of ALL self-checkouts when one of them updates (which is what I did, in the Wait and Serve Events), as well as putting the queue in the Simulation itself. However, I don't recommend the latter method as the structure of your code and classes should not rely on the Simulation class.

Further elaborating on my approach, I did not create a new Self-Checkout class like others and instead, created a boolean property in my existing Server class to indicate whether it is a Self-Checkout or not. In the Simulate, I instantiate my Server objects differently depending on whether the Server is a human or self-checkout server. Afterwards, I created a getter to get this boolean, checking it during my different executes in the Events.

Most importantly, make sure you update your Servers properly in all your Events, making sure you update your queues. Also, in your Wait (or Pending class if you have one), make sure that you get the Self-Checkout with the earliest available timing, and allocate the next Event to that Self-Checkout as they all share the same queue.

Lastly, in your Done Event, make sure that you do not account for the rest times.

Hope this helps you, and that you solve it before the deadline!

Alexius0123 commented 2 years ago

Hi @tristky! I share similar sentiments to Jon above. This project is meant to be completed incrementally, and the portions behind builds a lot on the concepts from the front.

Once you have completed Level 7, my implementation logic was to simply add an additional boolean to Servers that were deemed to be Self Check-out servers. The rest of my implementation logic within the Server class then depended on this boolean to give different results.

My Shop class then updated the shared queue for all the Self Check-out servers whenever a Serve, WaitServe or Wait event was executed. This ensured consistency throughout all my Self Check-out servers' customer wait list. I also had a poll method in my Shop that will return the Self Check-out servers with the fastest available time.

Hope this helps!

tristky commented 2 years ago

Thank you all for your inputs, it is heartening to see everyone's kind hearted words and inputs from the bottom of your hearts, i have been going at this assignment and i do not see the end, however i am trying my best as my grades are on the line, please do give yourselves a pat on the back as this is no easy feat. Thank you for being so altruistic. it warms the cockles of my heart to see such kind gestures in the course, hopefully when covid is over, let us all celebrate.

pwintthiri commented 2 years ago

Hi!

I extended SelfCheckout from Server and most of the methods there are the same. I had the shared queue in Simulate8 and did the updating of the queues there as well. Only SelfCheckout k + 1 has a maximum queue length which is the same as the maximum queue length for each human Server while subsequent SelfCheckouts have a maximum queue length of 0. To check if a Server was a SelfCheckout, I had an identify method that would return a String.

For the updating, if it's a Wait event, I checked if the Server was a SelfCheckout and added the Customer to the shared queue. I then updated all the SelfCheckout queues. Also remember to update Shop after updating all the queues because I forgot to and ended up getting the wrong answer!

I think most of the threads recommend removing from the queue in Done event but my implementation was different so I used Serve event instead. If the polled event is a Serve event and the Server was a SelfCheckout, I removed the Customer from all the other SelfCheckouts' queues except for the SelfCheckout that was serving because I would remove that Customer later in Done event. I then updated the Shop again.

I hope this helps and all the best in completing the project!!

aldrichwilliams23 commented 2 years ago

Hi!

Similar to the previous comments, I think you should do your projects incrementally. The implementation of the self check-out object is similar to the implementation of the server object. As mentioned previously, you can make self check-out an extension of server, though, you'd have to find out a way to differentiate between human and self check-out server. You can do this either using boolean (true for server, false for checkout), string (if server, the identity is "server", if selfcheckout, the identity is "checkout"), etc.

Hope this helps!