-
Notifications
You must be signed in to change notification settings - Fork 0
/
426280026.html
93 lines (80 loc) · 19.8 KB
/
426280026.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
<head>
<title>Di Luo : Di Luo's CS231 Project 5: Decision-making Simulation: Checkout Lines</title>
<link rel="stylesheet" href="styles/site.css" type="text/css" />
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body class="theme-default aui-theme-default">
<div id="page">
<div id="main" class="aui-page-panel">
<div id="main-header">
<div id="breadcrumb-section">
<ol id="breadcrumbs">
<li class="first">
<span><a href="index.html">Di Luo</a></span>
</li>
<li>
<span><a href="413631037.html">Di Luo’s Home</a></span>
</li>
<li>
<span><a href="474513827.html">Di Luo's CS231</a></span>
</li>
</ol>
</div>
<h1 id="title-heading" class="pagetitle">
<span id="title-text">
Di Luo : Di Luo's CS231 Project 5: Decision-making Simulation: Checkout Lines
</span>
</h1>
</div>
<div id="content" class="view">
<div class="page-metadata">
Created by <span class='author'> Di Luo</span>, last modified on Mar 26, 2019
</div>
<div id="main-content" class="wiki-content group">
<p><u><strong>Description</strong></u></p><p>In Project 5 I worked on <span style="color: rgb(34,51,68);">using my Queue implementation from lab to simulate shoppers picking which check-out line to use. <span style="color: rgb(34,34,34);">The q</span>ueue<span style="color: rgb(34,34,34);"> is used to insert elements at the end of the </span>queue<strong> </strong><span style="color: rgb(34,34,34);">and removes from the beginning of the </span>queue, which is like a check-out line in supermarkets<span style="color: rgb(34,34,34);">. I also <span style="color: rgb(34,51,68);">implemented and investigated the effectiveness of three strategies for choosing a queue</span></span><span style="color: rgb(34,51,68);">. The first strategy is to randomly choose a queue; the second one is to check each of the queues and choose the one with the least customers; the third one is to randomly choose two queues, compare them, and choose the one with fewer customers. By showing the simulation of each strategy using LandscapeDisplay, I created a simulation of the process and it enabled me to analyze the performance of each strategy.</span></span></p><p> </p><p><u><strong>Solution</strong></u></p><p>Firstly I created the Customer class, which represent the customer with items that need to be paid and a counter recording <span style="color: rgb(34,51,68);">how many time-steps it takes for them to choose a line and paid for all of the items, and CheckoutAgent class, which <span style="color: rgb(34,51,68);">maintains a queue of Customers and conducts the money collection process. <span style="color: rgb(34,51,68);">The CheckoutAgent is displayed graphically as a tall rectangle and its height represents the number of customers in the queue.</span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><br/></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);">Then I created the Landscape class to show the scene of the checkout lines, in which I created <span style="color: rgb(34,51,68);">an ArrayList<CheckoutAgent> to hold the list of checkout agents, and a LinkedList<Customer> that I created in the last project to hold the Customers who have left the queues. It also has a function that computes and prints the average and standard deviation of the time-to-leave for all of the Customers in the finished customer list, which is shown below:</span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="300" src="attachments/426280026/426214392.png" data-image-src="attachments/426280026/426214392.png" data-unresolved-comment-count="0" data-linked-resource-id="426214392" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image2019-3-22 21:11:18.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="426280026" data-linked-resource-container-version="3"></span>.</span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);">After that, I used the LandscapeDisplay file to display the scene of the check-out line, which is shown below:</span></span></span></p><p><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="300" src="attachments/426280026/426214393.png" data-image-src="attachments/426280026/426214393.png" data-unresolved-comment-count="0" data-linked-resource-id="426214393" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image2019-3-22 21:13:8.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="426280026" data-linked-resource-container-version="3"></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><br/></span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);">Next, I created <span style="color: rgb(34,51,68);">RandomCustomer, <span style="color: rgb(34,51,68);">Pick2Customer, and <span style="color: rgb(34,51,68);">PickyCustomer, which are respectively the customer with a different strategy. </span></span></span></span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"> </span></span></span></span></span></span></span></p><ul><li>RandomCustomer extends the Customer class and implements the random line-choosing strategy.</li><li>Pick2Customer also extends the Customer class and implements the strategy in which the customer randomly chooses two lines, then joins the shorter of those two.</li><li>PickyCustomer also extends the Customer class and implements the strategy in which the customer chooses to join the shortest queue.<br/><br/></li></ul><p><span style="color: rgb(34,51,68);"><span><span>Then I created <span style="color: rgb(34,51,68);">RandomCustomerSimulation, Pick2CustomerSimulation, PickyCustomerSimulation, which are the main programs that run simulations with the given type of Customer</span>. <span style="color: rgb(34,51,68);">An animated gif of the RandomCustomerSimulation is shown below:</span></span></span></span></p><p><span style="color: rgb(34,51,68);"><span><span><span style="color: rgb(34,51,68);"><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="300" src="attachments/426280026/426214406.gif" data-image-src="attachments/426280026/426214406.gif" data-unresolved-comment-count="0" data-linked-resource-id="426214406" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="ezgif.com-optimize.gif" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/gif" data-linked-resource-container-id="426280026" data-linked-resource-container-version="3"></span></span></span></span></span></p><p><span style="color: rgb(34,51,68);">The test codes in each simulation that I adapted for my simulation from TestRandomCustomer.java give each Customer 1 to 10 items. </span></p><p><span style="color: rgb(34,51,68);"><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="300" src="attachments/426280026/426214410.png" data-image-src="attachments/426280026/426214410.png" data-unresolved-comment-count="0" data-linked-resource-id="426214410" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image2019-3-22 21:26:50.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="426280026" data-linked-resource-container-version="3"></span></span></p><p><span style="color: rgb(34,51,68);">The lines grow over time so that each line becomes long as the number of simulation increases, meaning that 1 to 10 items is too many. Then I adjust the maximum number of items to find a situation in which the queues don't grow over time. Firstly I changed it to 1 to 50 items and</span> the lines grow too long with too many items per Customer:</p><p><strong><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="300" src="attachments/426280026/426214411.png" data-image-src="attachments/426280026/426214411.png" data-unresolved-comment-count="0" data-linked-resource-id="426214411" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image2019-3-22 21:29:3.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="426280026" data-linked-resource-container-version="3"></span></strong>(100 times simulation)</p><p>Then I changed it to 1 to 6 items and then it shows short lines with this new manageable number of items per Customer:<span style="color: rgb(34,51,68);"> </span></p><p><span style="color: rgb(34,51,68);"><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="300" src="attachments/426280026/426214412.png" data-image-src="attachments/426280026/426214412.png" data-unresolved-comment-count="0" data-linked-resource-id="426214412" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image2019-3-22 21:30:50.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="426280026" data-linked-resource-container-version="3"></span>(100 times simulation)</span></p><p><span style="color: rgb(34,51,68);">Then I continue doing my project with the new, smaller number from 1 to 6. Finally by running each simulation the printFinishedCustomerStatistics() function in Landscape class prints out the <span style="color: rgb(34,51,68);">the average and standard deviation of the time-to-leave for all of the Customers in the finished customer list. <span style="color: rgb(34,51,68);"> Each simulation runs with lots of customers, which is 1000 in my case, and print out the statistics once every 100 time steps.</span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);">RandomCustomerSimulation:</span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="300" src="attachments/426280026/426214416.png" data-image-src="attachments/426280026/426214416.png" data-unresolved-comment-count="0" data-linked-resource-id="426214416" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image2019-3-22 21:34:43.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="426280026" data-linked-resource-container-version="3"></span></span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><br/></span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);">Pick2CustomerSimulation:</span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="300" src="attachments/426280026/426214418.png" data-image-src="attachments/426280026/426214418.png" data-unresolved-comment-count="0" data-linked-resource-id="426214418" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image2019-3-22 21:35:19.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="426280026" data-linked-resource-container-version="3"></span></span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><br/></span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span>PickyCustomerSimulation:</span></span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" width="300" src="attachments/426280026/426214417.png" data-image-src="attachments/426280026/426214417.png" data-unresolved-comment-count="0" data-linked-resource-id="426214417" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image2019-3-22 21:35:5.png" data-base-url="https://wiki.colby.edu" data-linked-resource-content-type="image/png" data-linked-resource-container-id="426280026" data-linked-resource-container-version="3"></span></span></span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><br/></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);">As we can see from the results, regarding average time to finish, <span style="color: rgb(34,51,68);">Pick2Customer is the fastest; </span><span style="color: rgb(34,51,68);">RandomCustomer and <span style="color: rgb(34,51,68);">PickyCustomer spend the same average time. Regarding standard deviation, <span style="color: rgb(34,51,68);">PickyCustomer has the lowest standard deviation, meaning that each customer spends almost the same time. <span style="color: rgb(34,51,68);">Pick2Customer's standard deviation is a little higher, and RandomCustomer has a high standard deviation, meaning that the time each customer spends varies greatly. In conclusion, <span style="color: rgb(34,51,68);">Pick2Customer stands out to be the best strategy since it costs the least time with a good standard deviation.</span></span></span></span></span></span></span></p><p><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><span style="color: rgb(34,51,68);"><br/></span></span></span></span></span></span></span></p><p><strong><u>Reflection</u></strong></p><p>In this project, I learned how to implement a queue to represent a check-out line in real life. I also learned how to be the most efficient customer in the supermarket, which is to randomly choose two lines and go for the shorter one. This is the first time I find that Computer Science can be really useful to analyze the real-life situation and to make our life more efficient.</p><p> </p><p><strong><u>Source</u></strong></p><p>Prof. Aaron</p>
</div>
<div class="pageSection group">
<div class="pageSectionHeader">
<h2 id="attachments" class="pageSectionTitle">Attachments:</h2>
</div>
<div class="greybox" align="left">
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/426280026/426214392.png">image2019-3-22 21:11:18.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/426280026/426214393.png">image2019-3-22 21:13:8.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/426280026/426214406.gif">ezgif.com-optimize.gif</a> (image/gif)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/426280026/426214410.png">image2019-3-22 21:26:50.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/426280026/426214411.png">image2019-3-22 21:29:3.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/426280026/426214412.png">image2019-3-22 21:30:50.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/426280026/426214416.png">image2019-3-22 21:34:43.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/426280026/426214417.png">image2019-3-22 21:35:5.png</a> (image/png)
<br/>
<img src="images/icons/bullet_blue.gif" height="8" width="8" alt=""/>
<a href="attachments/426280026/426214418.png">image2019-3-22 21:35:19.png</a> (image/png)
<br/>
</div>
</div>
</div> </div>
<div id="footer" role="contentinfo">
<section class="footer-body">
<p>Document generated by Confluence on Aug 29, 2022 09:29</p>
<div id="footer-logo"><a href="http://www.atlassian.com/">Atlassian</a></div>
</section>
</div>
</div> </body>
</html>