tom davies

Ranch Hand

Posts: 168

posted 5 years ago

I am trying to simulate a number of checkout lines.

Each checkout line is a LinkedList which is filled with customers.

The method i am trying to create adds customers to a checkout line (LinkedList) depending on the length of the line and also the amount of shopping the customers on each line have.

In the real world you wouldn't just go for the checkout with the least people, you would see how much shopping they had as well which is what i am trying to replicate.

However when i run this, if i add a few hundred customers they all split evenly among the checkouts i have.

If i add 1000 then there are slight variations between each checkout, only by 3-4 people though.

Does anyone have any ideas why they are splitting so evenly.

checkout1 is the first of my checkouts (LinkedList)

and linkedlists is a LinkedList of my checkouts to allow me to loop through them all.

Each checkout line is a LinkedList which is filled with customers.

The method i am trying to create adds customers to a checkout line (LinkedList) depending on the length of the line and also the amount of shopping the customers on each line have.

In the real world you wouldn't just go for the checkout with the least people, you would see how much shopping they had as well which is what i am trying to replicate.

However when i run this, if i add a few hundred customers they all split evenly among the checkouts i have.

If i add 1000 then there are slight variations between each checkout, only by 3-4 people though.

Does anyone have any ideas why they are splitting so evenly.

checkout1 is the first of my checkouts (LinkedList)

and linkedlists is a LinkedList of my checkouts to allow me to loop through them all.

posted 5 years ago

The problem is that, by using nextInt, you are getting numbers following a uniform distribution.

This means that they all have the same chance of getting picked.

For random discrete numbers up to 100, the average will be 50.

That's why you're getting the same distribution among each line.

Try using a normal distribution instead. Look at the nextGaussian method.

This means that they all have the same chance of getting picked.

For random discrete numbers up to 100, the average will be 50.

That's why you're getting the same distribution among each line.

Try using a normal distribution instead. Look at the nextGaussian method.

[My Blog]
*All roads lead to JavaRanch*

posted 5 years ago

Greetings,

A couple of points......

First while Christophe is correct a normal (actually i would a triangular distribution for shopping cart contents rather than an normal distribution, but..) distribution is more closer to what would be found, it would be even closer (what you think of less random) than a uniform distribution.

Now tom, rather than simply answering you question, please do some research on chi-squared analysis and the write a very simple loop calculating the chi-squared analysis, and then go back to how Random should be used. after you correct that and rerun the chi-squared. You will then know how random the random number generator (and your code) is.

-steve

A couple of points......

First while Christophe is correct a normal (actually i would a triangular distribution for shopping cart contents rather than an normal distribution, but..) distribution is more closer to what would be found, it would be even closer (what you think of less random) than a uniform distribution.

Now tom, rather than simply answering you question, please do some research on chi-squared analysis and the write a very simple loop calculating the chi-squared analysis, and then go back to how Random should be used. after you correct that and rerun the chi-squared. You will then know how random the random number generator (and your code) is.

-steve

tom davies

Ranch Hand

Posts: 168

posted 5 years ago

Umm, a normal distribution? Unless you chose a very large mean value, you could easily get negative values. Not what you want for a shopping cart. Maybe a log-normal distribution?

Sorry, Tom, if this is leading the thread into deep water where you don't need to go. Just tell us to knock it off if that's the case.

Christophe Verré wrote:Try using a normal distribution instead. Look at the nextGaussian method.

Umm, a normal distribution? Unless you chose a very large mean value, you could easily get negative values. Not what you want for a shopping cart. Maybe a log-normal distribution?

Sorry, Tom, if this is leading the thread into deep water where you don't need to go. Just tell us to knock it off if that's the case.

posted 5 years ago

You can tweak the mean and the standard deviation, and check for negative values, like done here.

But I agree that some other type of distribution should be chosen for a shopping cart.

Paul Clapham wrote:Umm, a normal distribution? Unless you chose a very large mean value, you could easily get negative values. Not what you want for a shopping cart. Maybe a log-normal distribution?

You can tweak the mean and the standard deviation, and check for negative values, like done here.

But I agree that some other type of distribution should be chosen for a shopping cart.

[My Blog]
*All roads lead to JavaRanch*

tom davies

Ranch Hand

Posts: 168

posted 5 years ago

Initially all checkouts are set to 0 so customer shopping will not be greater than the initial shopping. The current code does add values to all checkouts uniformly although maybe I should say customersshopping<=initialshopping

As part of this simulation I have to write a report to discuss the model and any enhancements I could make. Learning about how the random numbers are generated and the distributions different methods create will help me think of improvements if nothing else. So it is not a problem Paul

Jayesh A Lalwani wrote:Ok am I reading your code completely wrong? Looks like you'll will never add any customers to first queue, initialShopping will always be 0 for the first iteration. CustomerShopping will never be less than initialShopping

Initially all checkouts are set to 0 so customer shopping will not be greater than the initial shopping. The current code does add values to all checkouts uniformly although maybe I should say customersshopping<=initialshopping

As part of this simulation I have to write a report to discuss the model and any enhancements I could make. Learning about how the random numbers are generated and the distributions different methods create will help me think of improvements if nothing else. So it is not a problem Paul

posted 5 years ago

To be honest, I reckon all this fancy speculation is a bit OTT.

Why not simply sum all the shopping items for each checkout line and choose the one which has the least? You could then introduce some sort of "error factor" (ie, the likelihood of someone making an error in their "item count"), viz something like:There are probably several other ways of doing it though.

Winston

PS: I broke up that very long line of yours because it makes your thread hard to read. Please re-read the UseCodeTags page

- 1

tom davies wrote:In the real world you wouldn't just go for the checkout with the least people, you would see how much shopping they had as well which is what i am trying to replicate.

To be honest, I reckon all this fancy speculation is a bit OTT.

Why not simply sum all the shopping items for each checkout line and choose the one which has the least? You could then introduce some sort of "error factor" (ie, the likelihood of someone making an error in their "item count"), viz something like:There are probably several other ways of doing it though.

Winston

PS: I broke up that very long line of yours because it makes your thread hard to read. Please re-read the UseCodeTags page

*thoroughly*. Thanks.

"Leadership is nature's way of removing morons from the productive flow" - Dogbert

Articles by Winston can be found here

Matthew Brown

Bartender

Posts: 4568

9

posted 5 years ago

- 2

I haven't checked through this code properly - this is gut feeling - so apologies if it isn't relevant...

...But if you're randomly assigning the amounts of shopping to different shoppers, is it really a surprise that the queues will tend to the same length? The variation of the amount of shopping for N shoppers is less than the variation for one shopper, so I'd expect things to even out.

...But if you're randomly assigning the amounts of shopping to different shoppers, is it really a surprise that the queues will tend to the same length? The variation of the amount of shopping for N shoppers is less than the variation for one shopper, so I'd expect things to even out.

It is sorta covered in the JavaRanch Style Guide. |