Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
90s Cringe Rock
Nov 29, 2006
:gay:
Man:
Man units

Adbot
ADBOT LOVES YOU

cinci zoo sniper
Mar 15, 2013




90s Cringe Rock posted:

Man:
Man units

The worst man page.

mandatory lesbian
Dec 18, 2012

Yo this was a pretty good read, thanks for posting :-)

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Carbon dioxide posted:

Not a graph but I still feel it should belong here.



It's not even a particularly difficult optimization problem. The solution follows almost immediately from the principle of optimality.

klafbang
Nov 18, 2009
Clapping Larry

ultrafilter posted:

It's not even a particularly difficult optimization problem. The solution follows almost immediately from the principle of optimality.

I am admittedly too lazy to check, but I think you're wrong. The price is not linear so this has more of a feeling of a knapsack problem. Which is hard.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



klafbang posted:

I am admittedly too lazy to check, but I think you're wrong. The price is not linear so this has more of a feeling of a knapsack problem. Which is hard.

Yeah you want to combine the cheapest combination of sub-orders. Feels knapsacky to me as well

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
It seems like pretty straightforward dynamic programming to me -- it has optimal substructure. Let's call C(q) the cost of a single batch of q wings, so C(4) = 4.55.

Define OPT(j) as the optimal (minimum) price for ordering j wings. The last decision you make here is "how big is the final batch of wings in your order?" You can then refer to the optimal solution for the rest of the wings.

You're constrained by the set of quantities Q = {4, 5, ..., 200}, giving this recurrence:

quote:

OPT(j) = minqQ, q < j { OPT(j - q) + C(q) }

You'll need base cases of OPT(0) = 0 and C(0) = 0, and it'll probably be necessary to define C(q) = ∞ if qQ.

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

Lysidas posted:

It seems like pretty straightforward dynamic programming to me -- it has optimal substructure. Let's call C(q) the cost of a single batch of q wings, so C(4) = 4.55.

Define OPT(j) as the optimal (minimum) price for ordering j wings. The last decision you make here is "how big is the final batch of wings in your order?" You can then refer to the optimal solution for the rest of the wings.

You're constrained by the set of quantities Q = {4, 5, ..., 200}, giving this recurrence:


You'll need base cases of OPT(0) = 0 and C(0) = 0, and it'll probably be necessary to define C(q) = ∞ if qQ.

note that you're trying to order wings so loving lol @ "pretty straightforward"

Armacham
Mar 3, 2007

Then brothers in war, to the skirmish must we hence! Shall we hence?

Captain Foo posted:

note that you're trying to order wings so loving lol @ "pretty straightforward"

Hey you only have to write the program once

Vavrek
Mar 2, 2013

I like your style hombre, but this is no laughing matter. Assault on a police officer. Theft of police property. Illegal possession of a firearm. FIVE counts of attempted murder. That comes to... 29 dollars and 40 cents. Cash, cheque, or credit card?
I really enjoy how two divergent conversations in this thread (wings, wikipedia math pages being incomprehensible) managed to unify on this page.

klafbang
Nov 18, 2009
Clapping Larry

Lysidas posted:

It seems like pretty straightforward dynamic programming to me -- it has optimal substructure. Let's call C(q) the cost of a single batch of q wings, so C(4) = 4.55.

Define OPT(j) as the optimal (minimum) price for ordering j wings. The last decision you make here is "how big is the final batch of wings in your order?" You can then refer to the optimal solution for the rest of the wings.

You're constrained by the set of quantities Q = {4, 5, ..., 200}, giving this recurrence:


You'll need base cases of OPT(0) = 0 and C(0) = 0, and it'll probably be necessary to define C(q) = ∞ if qQ.

Good news, I think we're both right. I think your algorithm is good and it does indeed solve the knapsack problem.

It's not "simple" though. The formulation is simple, but computationally it is still in NP (the complexity depends on the number of wings, not just on the number of possible orders).

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


The wing ordering problem can be solved with dynamic programming. To order n wings, you need to know the cheapest combination of n - k wings and k wings for all k in [0, n/2], so the solution should scale polynomially in n.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug

klafbang posted:

Good news, I think we're both right. I think your algorithm is good and it does indeed solve the knapsack problem.

It's not "simple" though. The formulation is simple, but computationally it is still in NP (the complexity depends on the number of wings, not just on the number of possible orders).

No, it's quadratic in the number of wings, as ultrafilter described. You need to store O(n) costs, each of which has O(n) possible values.

I wrote a Python program that calculates optimal orders. Full output is here.

Subset of the output:

quote:

4 wings: $4.55: [4]
5 wings: $5.70: [5]
6 wings: $6.80: [6]
13 wings: $14.75: [13]
14 wings: $15.90: [10, 4]
15 wings: $17.00: [15]
16 wings: $18.15: [16]
17 wings: $19.30: [9, 8]
18 wings: $20.40: [18]
19 wings: $21.55: [10, 9]
20 wings: $22.70: [20]
21 wings: $23.80: [12, 9]
22 wings: $24.95: [22]
23 wings: $26.10: [18, 5]
24 wings: $27.20: [18, 6]
25 wings: $27.80: [25]
30 wings: $33.50: [30]
40 wings: $44.80: [40]
44 wings: $49.35: [40, 4]
45 wings: $50.50: [6, 35, 4]
50 wings: $55.60: [50]
60 wings: $66.95: [50, 10]
70 wings: $78.30: [70]
75 wings: $83.40: [50, 25]
99 wings: $110.60: [50, 6, 6, 28, 9]
100 wings: $111.20: [50, 50]
125 wings: $139.00: [125]
126 wings: $140.15: [50, 50, 26]
150 wings: $166.80: [125, 25]
174 wings: $194.00: [50, 40, 50, 28, 6]
175 wings: $194.60: [125, 50]
176 wings: $195.75: [125, 26, 25]
199 wings: $221.80: [50, 9, 9, 28, 50, 28, 25]
200 wings: $222.40: [125, 50, 25]
201 wings: $223.55: [50, 125, 26]
233 wings: $259.30: [80, 125, 28]
248 wings: $276.30: [125, 80, 6, 28, 9]
249 wings: $277.40: [25, 28, 28, 28, 9, 28, 50, 28, 25]

e: also by "in NP", I assume you mean "NP-hard" -- this is an optimization problem, but the decision version ("can you order n wings for less than $k?") is in P and therefore isn't NP-hard.

Lysidas has a new favorite as of 20:16 on Oct 26, 2018

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

How many wings can I order for $420.69

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
378, and you'll have 29 cents left over

zakharov
Nov 30, 2002

:kimchi: Tater Love :kimchi:
Wings aren't actually very good and make a huge mess. Facts.

Platystemon
Feb 13, 2012

BREADS

Lysidas posted:

378, and you'll have 29 cents left over

Now find all possible orders that spend precisely $420.69

Hurt Whitey Maybe
Jun 26, 2008

I mean maybe not. Or maybe. Definitely don't kill anyone.

Platystemon posted:

Now find all possible orders that spend precisely $420.69

There are none unless you’re going to order 4/5 or 9/10 of a chicken wing.

Barry Bluejeans
Feb 2, 2017

ATTENTHUN THITIZENTH

zakharov posted:

Wings aren't actually very good and make a huge mess. Facts.

:hai:

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

eating wings is a social experience

Platystemon
Feb 13, 2012

BREADS

Hurt Whitey Maybe posted:

There are none unless you’re going to order 4/5 or 9/10 of a chicken wing.

I leave four pence in the “take a penny/leave a penny” dish.

Raldikuk
Apr 7, 2006

I'm bad with money and I want that meatball!

zakharov posted:

Wings aren't actually very good and make a huge mess. Facts.

:wrong:

Control Volume
Dec 31, 2008

I love the kind of goon who doesnt understand whats going on so they interrupt with the worst possible opinion

frankenfreak
Feb 16, 2007

I SCORED 85% ON A QUIZ ABOUT MONDAY NIGHT RAW AND ALL I GOT WAS THIS LOUSY TEXT

#bastionboogerbrigade
I love that the "vision" boils down to "Have the best everything and be the best at everything, duh!"

Goon Danton
May 24, 2012

Don't forget to show my shitposts to the people. They're well worth seeing.

Lysidas posted:

No, it's quadratic in the number of wings, as ultrafilter described. You need to store O(n) costs, each of which has O(n) possible values.

I wrote a Python program that calculates optimal orders. Full output is here.

Subset of the output:


e: also by "in NP", I assume you mean "NP-hard" -- this is an optimization problem, but the decision version ("can you order n wings for less than $k?") is in P and therefore isn't NP-hard.

Wait, why would you buy two sets of nine wings when buying 199, if a single order of 18 is more efficient earlier in the script?

Edit: checked, both ways of getting 18 are the same price

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Lysidas posted:

e: also by "in NP", I assume you mean "NP-hard" -- this is an optimization problem, but the decision version ("can you order n wings for less than $k?") is in P and therefore isn't NP-hard.

We think.

Angepain
Jul 13, 2012

what keeps happening to my clothes
Hi can we get 25 wings, and also 28 wings, and 28 more wings, and 28 wings on top of that, and 9 wings, and another 28 wings, and 50 wings, and 28 wings again, and uh 25 wings, thanks. Actually you know what I'm trying to keep to a diet right now, just give us 125 wings, 80 wings, 6 wings, and then 28 wings and 9 wings, cheers

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug

Angepain posted:

Hi can we get 25 wings, and also 28 wings, and 28 more wings, and 28 wings on top of that, and 9 wings, and another 28 wings, and 50 wings, and 28 wings again, and uh 25 wings, thanks. Actually you know what I'm trying to keep to a diet right now, just give us 125 wings, 80 wings, 6 wings, and then 28 wings and 9 wings, cheers

listen buddy if you want to throw away those 25 cents you can save by using an optimal wing combination instead of a greedy solution, then thats your business, some of us cant afford to throw away that amount of money when buying 497 wings

Space Kablooey
May 6, 2009


Lysidas posted:

No, it's quadratic in the number of wings, as ultrafilter described. You need to store O(n) costs, each of which has O(n) possible values.

I wrote a Python program that calculates optimal orders. Full output is here.

Subset of the output:


e: also by "in NP", I assume you mean "NP-hard" -- this is an optimization problem, but the decision version ("can you order n wings for less than $k?") is in P and therefore isn't NP-hard.

I'm going to be honest here, and say that the thing that is bothering me the most is that the output lists aren't ordered.

Also, how bothersome would making a non pandas version of this be? I don't know pandas at all so I can't really follow this code. :shobon:

Hierophant
Oct 21, 2007

HardDiskD posted:

I'm going to be honest here, and say that the thing that is bothering me the most is that the output lists aren't ordered.

Also, how bothersome would making a non pandas version of this be? I don't know pandas at all so I can't really follow this code. :shobon:

This is a memoized recursive implementation, but it's basically the same algorithm: https://repl.it/repls/MemorableOrangeredMatter.
My results table is slightly different in terms of the actual orders (but not costs) because it breaks ties in favor of shorter orders.

Space Kablooey
May 6, 2009


Thanks!

My Lovely Horse
Aug 21, 2010

Control Volume posted:

I love the kind of goon who doesnt understand whats going on so they interrupt with the worst possible opinion
aww, thank you <3

zakharov
Nov 30, 2002

:kimchi: Tater Love :kimchi:

Control Volume posted:

I love the kind of goon who doesnt understand whats going on so they interrupt with the worst possible opinion

;)

Away all Goats
Jul 5, 2005

Goose's rebellion

System Metternich
Feb 28, 2010

But what did he mean by that?


If the percentage of homeless people in Germany and the US is roughly equal, then why are they so much more visible in the latter? Is it because of less social housing, or maybe simply because the weather is better? Also what's up with the high numbers for Australia and New Zealand?

(This would actually fit better in the dedicated maps thread over in D&D :ssh:)

The Cheshire Cat
Jun 10, 2008

Fun Shoe

System Metternich posted:

If the percentage of homeless people in Germany and the US is roughly equal, then why are they so much more visible in the latter? Is it because of less social housing, or maybe simply because the weather is better? Also what's up with the high numbers for Australia and New Zealand?

(This would actually fit better in the dedicated maps thread over in D&D :ssh:)

It's not like homeless people are evenly distributed across the country; they're concentrated in cities. So if you live in a city, a larger proportional percentage of the population is homeless than the average for the country as a whole. The US has a large rural population which would probably drive the average way down - if you looked solely at urban populations you'd probably get a pretty different looking map.

Unrelated: Kind of weird they didn't colour in Alaska.

Don Gato
Apr 28, 2013

Actually a bipedal cat.
Grimey Drawer

The Cheshire Cat posted:


Unrelated: Kind of weird they didn't colour in Alaska.

Alaska homeless are a species of superhumans from what I understand.

cinci zoo sniper
Mar 15, 2013




System Metternich posted:

If the percentage of homeless people in Germany and the US is roughly equal, then why are they so much more visible in the latter? Is it because of less social housing
Yes it's just this, social housing and other social welfare programs for the homeless. I'm from the poorest Latvian region with -30C winters, and no one gives a poo poo about weather there. The drastic change was when we began to fund welfare for the homeless - shelters, special trade skills education, food, and similar.

Jaguars!
Jul 31, 2012


NZ is the same as usual - wider definition of homeless encompassing motel dwellers, people staying in a garage or relatives shed, etc. There's been quite a bit of focus on it in the last year or two.

Adbot
ADBOT LOVES YOU

Hippie Hedgehog
Feb 19, 2007

Ever cuddled a hedgehog?

I presume that the awful part of this is the choice of colors?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply