Combining liquids/powders results in overall lower QL

The worst monsters in the Hearthlands warp the fabric of space and time...

Re: Combining liquids/powders results in overall lower QL

Postby Granger » Tue Sep 15, 2015 9:35 pm

There are two basic ways to store such things (pile of same type while averaging quality):
You have to store an amount (A) anyway (increment on pit and decrement on get), so we can forget about this.
The other value is the quality (Q), i use only one in this example with Qi as quality of item added/removed:

1) Store average quality (Qa)
Put: Qa=floor((Qa*A+Qi)/(A+1)), A+=1
Get: A-=1, return Qa
Needs memory location to hold Qmax.
Returns possibly less total q than put in, q is same for all items returned, order of insertion matters.
Option is to store more digits after the decimal point to lessen the problem, needing more memory to hold the fractions.

2) Store sum of quality (Qs)
Put: Qs+=Qi, A+=1
Get: q=floor(Qs/A), Qs-=q, A-=1, return q
Needs memory location to hold (Amax*Qmax).
Returns total q put in, items returned might oscillate +/- 1 in q, order of insertion irrelevant.

According to the effects we see we currently have 1).
Given that the extra memory for 2) is one extra byte for piles <2^8 items, or none in case 1) stores fractions, storage is cheap these days, plus the math is cheaper for 2)... I would like to have the second solution.
⁎ Mon Mar 22, 2010 ✝ Thu Jan 23, 2020
User avatar
Granger
 
Posts: 9264
Joined: Mon Mar 22, 2010 2:00 pm

Re: Combining liquids/powders results in overall lower QL

Postby Sever » Tue Sep 15, 2015 11:07 pm

One's a 32 bit integer, the other's a 32 bit float. I don't think storing the variable is the problem, it's constantly doing floating point operations and the weird things that can happen with error.

Of course it's probably not those things because I am not a programmer.
Come back two hours earlier.
User avatar
Sever
 
Posts: 723
Joined: Fri Aug 28, 2009 8:38 pm
Location: Elsewhere

Re: Combining liquids/powders results in overall lower QL

Postby Granger » Wed Sep 16, 2015 11:47 am

Sever wrote:Of course it's probably not those things because I am not a programmer.

One wouldn't want to use floats for stuff like that, you'll run into numeric instabilities.
http://floating-point-gui.de/ could be a starting point in case you're interested why.

Also loftar well might have cut memory useage by using smaller locations for the values.
Why, for example, should you reserve longint when you know a byte will do?
⁎ Mon Mar 22, 2010 ✝ Thu Jan 23, 2020
User avatar
Granger
 
Posts: 9264
Joined: Mon Mar 22, 2010 2:00 pm

Re: Combining liquids/powders results in overall lower QL

Postby g1real » Thu Sep 17, 2015 5:38 am

welp

Image
loftar: The inner chaos of the Jorbian mind is hard to conceal. :)
jorb: It's called creative license. You know, that thing you seem to want to apply to logic, grammar and coherence? :)
User avatar
g1real
 
Posts: 881
Joined: Sun Aug 09, 2009 10:30 am
Location: You are now breathing manually.

Re: Combining liquids/powders results in overall lower QL

Postby loftar » Thu Sep 17, 2015 5:41 am

g1real wrote:welp

I don't understand that screenshot either. What are you mixing, what were the results, and what results were you expecting?
"Object-oriented design is the roman numerals of computing." -- Rob Pike
User avatar
loftar
 
Posts: 9045
Joined: Fri Apr 03, 2009 7:05 am

Re: Combining liquids/powders results in overall lower QL

Postby g1real » Thu Sep 17, 2015 6:07 am

loftar wrote:
g1real wrote:welp

I don't understand that screenshot either. What are you mixing, what were the results, and what results were you expecting?


Well I would think it was rather obvious that I threw all the carrot seeds in that barrel, that seem to be dominantly in the Qa 7-9 range, and I got Qa 4 out. What I would expect is for it to give me a Qa around 8.

Edit: I've noticed that adding 1 seed of similar but slightly lower quality to a stack of 4 doesn't lower quality, hurray, do I have to meticulously add 1 seed every time just to avoid tanking my quality?

Edit2: Nevermind, even adding 1 seed reduces quality, amber's client didn't update displayed quality until I picked it up.
loftar: The inner chaos of the Jorbian mind is hard to conceal. :)
jorb: It's called creative license. You know, that thing you seem to want to apply to logic, grammar and coherence? :)
User avatar
g1real
 
Posts: 881
Joined: Sun Aug 09, 2009 10:30 am
Location: You are now breathing manually.

Previous

Return to Bugs

Who is online

Users browsing this forum: Claude [Bot], Dotbot [Bot] and 4 guests