Industry rating

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

User avatar
George
Tycoon
Tycoon
Posts: 4364
Joined: 16 Apr 2003 16:09
Skype: george-vb
Location: Varna, Bulgaria
Contact:

Industry rating

Post by George »

How do OTTD calculates the industry rating?
I supposed that
1) if there is 1 station, then the industry rating is equal to station rating
2) if there are 2 stations with rating a and b, where a > b, then the rating is a+(100-a)*b
3) if there are more stations, the game takes 2 stations with the highest rating and uses rule 2.
my test games show that it is not correct, so what is the right rule?
Image Image Image Image
PhilSophus
Chairman
Chairman
Posts: 776
Joined: 20 Jan 2007 12:08
Location: Germany

Re: Industry rating

Post by PhilSophus »

George wrote:How do OTTD calculates the industry rating?
I supposed that
1) if there is 1 station, then the industry rating is equal to station rating
2) if there are 2 stations with rating a and b, where a > b, then the rating is a+(100-a)*b
3) if there are more stations, the game takes 2 stations with the highest rating and uses rule 2.
my test games show that it is not correct, so what is the right rule?
The industry rating is essentially the percentage of goods produced which is actually moved to a station, so the relevant part of the code is the MoveGoodsToStation function which is in line 2735 of station_cmd.cpp. So according to my understanding of the code there:

1) is correct

2) seems a bit more complicated. I assume a, b and rating being in the range 0..1 (so multiply by 100 if you want to have them in percent). I simplified a bit by ignoring the +1s in the calculations so the following result is not totally exact, but should be okay if production and rating is high enough.

Code: Select all

rating = ( a / (a + b/2) ) * (a - b/2) + b/2
I hope I haven't made a mistake. If in doubt, please check the source code yourself.

3) is correct with new rule 2
"The bigger the island of our knowledge, the longer the shore of our ignorance" - John A. Wheeler, Physicist, 1911-2008
Gonozal_VIII
Traffic Manager
Traffic Manager
Posts: 165
Joined: 03 Dec 2007 15:06

Re: Industry rating

Post by Gonozal_VIII »

in my testgame: two stations that pick up oil from oil wells
new and fast trains, both station ratings are 91%, oil wells cargo transported is 83%
trains get older, both stations have rating 86%, oil wells rating decreases to 76%
stopped one of the trains, ratings are 82% and 30%, oil well increased to 78%
bulldozed the stopped station, ratings: 82% for the remaining station and 83% for the oil wells
something is very wrong there
edit: same results with coal mine
User avatar
George
Tycoon
Tycoon
Posts: 4364
Joined: 16 Apr 2003 16:09
Skype: george-vb
Location: Varna, Bulgaria
Contact:

Re: Industry rating

Post by George »

PhilSophus wrote:

Code: Select all

rating = ( a / (a + b/2) ) * (a - b/2) + b/2
if b=a*x then the rating is (if I have not mistaken) = a (4+x)/(4+2*x), that means the rating of the industry is ALWAYS lower than the rating of the best station.
Either the formula is wrong or we need to review the formula, because it is unacceptable (2 stations should always provide a BETTER service to the industry, than a single station)
Image Image Image Image
User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: Industry rating

Post by Bilbo »

Well, problem is with 3 or more stations, if there is waiting train on the third station, the rating would rise to the point that the station possibly gets rating between the top two, snitching out some cargo too. Basically, the rating is changing quite rapidly, while transported goods percentage is updated only once per month, so it is impossible to get some exact equation between these number (though they are surely correlated, higher rating <-> more production)
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)
User avatar
George
Tycoon
Tycoon
Posts: 4364
Joined: 16 Apr 2003 16:09
Skype: george-vb
Location: Varna, Bulgaria
Contact:

Re: Industry rating

Post by George »

Bilbo wrote:Well, problem is with 3 or more stations,
There is no problem. The game should take 2 best stations and calculate the rating on the 1-st day of the month. this value will be the rating, that the industry will use during the current month (stored as last month % transported). Also it is possible to take 3, 4, stations into account, using the formula like a+(100%-a)*b+(100%-a-(100%-a)*b)*c+ (100%-a-(100%-a)*b-(100%-a-(100%-a)*b)*c)*d ...
Bilbo wrote:if there is waiting train on the third station, the rating would rise to the point that the station possibly gets rating between the top two, snitching out some cargo too. Basically, the rating is changing quite rapidly, while transported goods percentage is updated only once per month, so it is impossible to get some exact equation between these number (though they are surely correlated, higher rating <-> more production)
But why not to have it correct on the first day of month? Why not to set it to a+(100%-a)*b for example? Or use some other formula?
The main problem, I see for the current formula, is that it does not fit the simple logical rule:
2 stations should always provide better rating, than one of them, and never worse. (I hope no one will disagree :roll: )
Image Image Image Image
PhilSophus
Chairman
Chairman
Posts: 776
Joined: 20 Jan 2007 12:08
Location: Germany

Re: Industry rating

Post by PhilSophus »

Gonozal_VIII wrote:in my testgame: two stations that pick up oil from oil wells
new and fast trains, both station ratings are 91%, oil wells cargo transported is 83%
That is strange. According to my formula and also if I hand-simulate the code, this should be about 76%.

First let me post the part of the code relevant for two stations:

Code: Select all

uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount)
{
	Station *st1 = NULL;	// Station with best rating
	Station *st2 = NULL;	// Second best station
	uint best_rating1 = 0;	// rating of st1
	uint best_rating2 = 0;	// rating of st2

	[Code for finding stations left out]

	/* several stations around, the best two (highest rating) are in st1 and st2 */
	assert(st1 != NULL);
	assert(st2 != NULL);
	assert(best_rating1 != 0 || best_rating2 != 0);

	/* the 2nd highest one gets a penalty */
	best_rating2 >>= 1;

	/* amount given to station 1 */
	uint t = (best_rating1 * (amount + 1)) / (best_rating1 + best_rating2);

	uint moved = 0;
	if (t != 0) {
		moved = t * best_rating1 / 256 + 1;
		amount -= t;
		UpdateStationWaiting(st1, type, moved);
	}

	if (amount != 0) {
		amount = amount * best_rating2 / 256 + 1;
		moved += amount;
		UpdateStationWaiting(st2, type, amount);
	}

	return moved;
}
First of all the worse rating is cut in half (which is pretty unfair if both are the same). Then the total production is cut into two pieces with the (penalized) rating taken as weight. But the stations do not get their complete piece but again only the part related to their (penalized) rating. At first, this seems reasonable as otherwise 100% would be transported, but I think here the second station gets its penalty a second time, so not the halfed rating but the original one should be taken. What do the others think?
George wrote:if b=a*x then the rating is (if I have not mistaken) = a (4+x)/(4+2*x), that means the rating of the industry is ALWAYS lower than the rating of the best station.
Either the formula is wrong or we need to review the formula, because it is unacceptable (2 stations should always provide a BETTER service to the industry, than a single station)
I get x^2 instead of x in the enumerator but the effect of getting less than with one station is the same. IMHO this comes from the double penalty.
George wrote:The main problem, I see for the current formula, is that it does not fit the simple logical rule:
2 stations should always provide better rating, than one of them, and never worse. (I hope no one will disagree :roll: )
Well not necessarily better, but nevertheless not worse. I would find the following conditions also logical:
1) Industry rating is never better than the maximum of the two station ratings
2) Industry rating is never worse than the minimum of the two station ratings

So essentially industry rating should be some kind of weighted average of the ratings.

No. 2 is violated at the moment. Would taking the non-penalized rating2 in the second step, as I suggested above, fix that?

EDIT: I just checked and now for b=a*x (with x between 0 and 1 as b is the smaller rating by definition) I get rating=a*(2+x^2)/(2+x) which is a if x=1 (reasonable) and less if x<1. On the other hand it is rating=a*x*(2+x^2)/(2*x+x^2) which is always bigger than a*x (=b). So, looks promising.
"The bigger the island of our knowledge, the longer the shore of our ignorance" - John A. Wheeler, Physicist, 1911-2008
User avatar
George
Tycoon
Tycoon
Posts: 4364
Joined: 16 Apr 2003 16:09
Skype: george-vb
Location: Varna, Bulgaria
Contact:

Re: Industry rating

Post by George »

After some thoughts I became confused :oops:
TTD savegame internals specifies industry array this way

Code: Select all

14 	W[2] 	Amounts of cargo produced so far this month
18 	W[2] 	Amounts of cargo transported so far this month
1C 	B[2] 	Fractions of cargo transported last month (FF means 100%)
1E 	W[2] 	Amounts of cargo produced last month
22 	W[2] 	Amounts of cargo transported last month
And I would like to ask: should var 1C = 255 * 1E / 22 and var 1D = 255 * 20 / 24?
If yes, than our discussion about the formula is silly. Every time, when the industry distributes the cargo, amount of produced cargo is added to 14 (16) and amount of cargo distributed (according to the station rating at the moment of distribution) is added to 18 (1A). On the first day of month vars 14, 16, 18, 1A are copied to vars 1E, 20, 22, 24 and vars 1C and 1D are recalculated. Isn't it?
Image Image Image Image
PhilSophus
Chairman
Chairman
Posts: 776
Joined: 20 Jan 2007 12:08
Location: Germany

Re: Industry rating

Post by PhilSophus »

George wrote:After some thoughts I became confused :oops:
TTD savegame internals specifies industry array this way

Code: Select all

14 	W[2] 	Amounts of cargo produced so far this month
18 	W[2] 	Amounts of cargo transported so far this month
1C 	B[2] 	Fractions of cargo transported last month (FF means 100%)
1E 	W[2] 	Amounts of cargo produced last month
22 	W[2] 	Amounts of cargo transported last month
Which directly maps to certain variables in OpenTTD code.
George wrote:And I would like to ask: should var 1C = 255 * 1E / 22 and var 1D = 255 * 20 / 24?
If yes, than our discussion about the formula is silly. Every time, when the industry distributes the cargo, amount of produced cargo is added to 14 (16) and amount of cargo distributed (according to the station rating at the moment of distribution) is added to 18 (1A). On the first day of month vars 14, 16, 18, 1A are copied to vars 1E, 20, 22, 24 and vars 1C and 1D are recalculated. Isn't it?
I think so, but you are now missing the point, I think. The reason why I mentioned MoveGoodsToStation is because this is exactly the place where the fraction of cargo transported is determined. The function is given the amount of cargo, the industry has just produced (which is also added to 14 or 16) and it returns the amount of cargo it has distributed to stations (which is then written to 18 or 20). So essentially at the end of the month you get the weighted average of the fraction MoveGoodsToStation uses for its calculations. So my implicit simplification when deriving the formula from the code, was that ratings stayed the same during the month. I think this is okay for the sake of argument.

I just prepared a patch with my suggestion above (see attachment). Please note that this is only a quick fix following the philosophy of the existing code. This means:
1) If two stations have the same rating the total transported cargo is the same as with one station with exactly this rating and each station gets half of it.
2) If two stations have different rating the total transported cargo is more than that of a single station with the lower rating but less than that of a single station with the higher rating. So having one station and then building a second one with lower rating would decrease transported cargo, which is not that logical. I'm just trying to finding an easy and convincing solution for this. Maybe in an hour or so I can make a suggestion.
Attachments
rating_fix_11984.patch
(740 Bytes) Downloaded 82 times
"The bigger the island of our knowledge, the longer the shore of our ignorance" - John A. Wheeler, Physicist, 1911-2008
User avatar
George
Tycoon
Tycoon
Posts: 4364
Joined: 16 Apr 2003 16:09
Skype: george-vb
Location: Varna, Bulgaria
Contact:

Re: Industry rating

Post by George »

Sorry I'm confused with your answer :oops:
Does it mean that this is wrong in general? And 1C and 1D are calculated with your formula, not with 1E, 20, 22, 24?
George wrote:var 1C = 255 * 1E / 22 and var 1D = 255 * 20 / 24
Image Image Image Image
PhilSophus
Chairman
Chairman
Posts: 776
Joined: 20 Jan 2007 12:08
Location: Germany

Re: Industry rating

Post by PhilSophus »

George wrote:Sorry I'm confused with your answer :oops:
Does it mean that this is wrong in general? And 1C and 1D are calculated with your formula, not with 1E, 20, 22, 24?
George wrote:var 1C = 255 * 1E / 22 and var 1D = 255 * 20 / 24
Sorry for confusing you :wink:

No, of course 1C and 1D are calculated as you said. The fraction of cargo transported is just the amount of cargo transported (delivered to stations) divided by the amount of cargo produced and then normalized to a range of 0..255 (so 255 is 100%). This is logical and should stay.

But where do you think, the amount of cargo transported (18/20) come from? They are the sum of the amounts of cargo which where actually transferred to stations this month. So, how is this done? For each production event MoveGoodsToStation is called with the amount produced. The function distributes a certain fraction of this amount (which is calculated based on the ratings of the stations) to the best two stations and returns how much it distributed. Thus, this return value is added to 18 or 20 during the month. So if we want to know, how the ratio of cargo transported depends on the ratings, we have to look on how the amount of cargo transported was calculated in the first place. And this is done in MoveGoodsToStation, from which I derived my formula.

I hope, this was clearer now.
"The bigger the island of our knowledge, the longer the shore of our ignorance" - John A. Wheeler, Physicist, 1911-2008
User avatar
rbenevid
Traffic Manager
Traffic Manager
Posts: 192
Joined: 14 Oct 2004 20:08
Location: Brazil

Re: Industry rating

Post by rbenevid »

Gonozal_VIII wrote:in my testgame: two stations that pick up oil from oil wells
new and fast trains, both station ratings are 91%, oil wells cargo transported is 83%
trains get older, both stations have rating 86%, oil wells rating decreases to 76%
stopped one of the trains, ratings are 82% and 30%, oil well increased to 78%
bulldozed the stopped station, ratings: 82% for the remaining station and 83% for the oil wells
something is very wrong there
edit: same results with coal mine
Weird, one old train resulted in the same rating than 2 new trains??
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: Industry rating

Post by SirkoZ »

Gonozal_VIII wrote:in my testgame: two stations that pick up oil from oil wells
new and fast trains, both station ratings are 91%, oil wells cargo transported is 83%
trains get older, both stations have rating 86%, oil wells rating decreases to 76%
stopped one of the trains, ratings are 82% and 30%, oil well increased to 78%
bulldozed the stopped station, ratings: 82% for the remaining station and 83% for the oil wells
something is very wrong there
edit: same results with coal mine
Absolutely nothing wrong - industry's % transported is derived from the amount of cargo that is delivered to the station with higher ratings/non-penalised station.

The one thing to take into account with 1% difference between % transported and station ratings with only 1 serviced station being there is that all is being calculated in non-decimal numbers and the decimal part gets cut off.
Gonozal_VIII
Traffic Manager
Traffic Manager
Posts: 165
Joined: 03 Dec 2007 15:06

Re: Industry rating

Post by Gonozal_VIII »

so you can sabotage an opponent by building a station next to his, letting a train pick something up once and then sell the train again?
no matter how high his station rating is, your bad rating will drag the industry rating down and it will decrease production and close down... yay
User avatar
George
Tycoon
Tycoon
Posts: 4364
Joined: 16 Apr 2003 16:09
Skype: george-vb
Location: Varna, Bulgaria
Contact:

Re: Industry rating

Post by George »

Gonozal_VIII wrote:so you can sabotage an opponent by building a station next to his, letting a train pick something up once and then sell the train again?
no matter how high his station rating is, your bad rating will drag the industry rating down and it will decrease production and close down... yay
Totally agree.
That is unacceptable! The station rating should be always higher, than the best station rating! Because the best station should provide the main service, and the other stations provide ADDITIONAL service, that means the industry rating should grow. I vote for reviewing the distributing mechanism.
PhilSophus wrote:Well not necessarily better, but nevertheless not worse. I would find the following conditions also logical:
1) Industry rating is never better than the maximum of the two station ratings
Totally disagree! Gonozal_VIII is right. Such rule would become the way for sabotage X(
Image Image Image Image
LordAzamath
Tycoon
Tycoon
Posts: 1656
Joined: 08 Jun 2007 08:00

Re: Industry rating

Post by LordAzamath »

George wrote:
PhilSophus wrote:Well not necessarily better, but nevertheless not worse. I would find the following conditions also logical:
1) Industry rating is never better than the maximum of the two station ratings
Totally disagree! Gonozal_VIII is right. Such rule would become the way for sabotage X(
Maybe the sum of both stations... so if one has 50% rating and the second 2%, then total max for industry would be 52%..
PS: And I stopped the propaganda to support Dave Worley since he got a nice new red hat now.[/color]
I know I have a BBCode error in my signature but I really cba to fix it.
User avatar
George
Tycoon
Tycoon
Posts: 4364
Joined: 16 Apr 2003 16:09
Skype: george-vb
Location: Varna, Bulgaria
Contact:

Re: Industry rating

Post by George »

lordazamath wrote:
George wrote:
PhilSophus wrote:Well not necessarily better, but nevertheless not worse. I would find the following conditions also logical:
1) Industry rating is never better than the maximum of the two station ratings
Totally disagree! Gonozal_VIII is right. Such rule would become the way for sabotage X(
Maybe the sum of both stations... so if one has 50% rating and the second 2%, then total max for industry would be 52%..
The sum is too much, imho. a + (100-a) * b is enough.
Image Image Image Image
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: Industry rating

Post by SirkoZ »

Gonozal_VIII wrote:so you can sabotage an opponent by building a station next to his, letting a train pick something up once and then sell the train again?
no matter how high his station rating is, your bad rating will drag the industry rating down and it will decrease production and close down... yay
If you can't overcome such a simple challenge, that's really your problem. It's the same way in TTD and is easily manage-able.
User avatar
SirkoZ
Tycoon
Tycoon
Posts: 1518
Joined: 06 Mar 2004 23:51
Location: The sunny side of Alps

Re: Industry rating

Post by SirkoZ »

George wrote:
PhilSophus wrote:Well not necessarily better, but nevertheless not worse. I would find the following conditions also logical:
1) Industry rating is never better than the maximum of the two station ratings
Totally disagree! Gonozal_VIII is right. Such rule would become the way for sabotage X(
Same in TTD - will you change that too? Any settings in TTDPatch yet to overcome that "problem"?
Gonozal_VIII
Traffic Manager
Traffic Manager
Posts: 165
Joined: 03 Dec 2007 15:06

Re: Industry rating

Post by Gonozal_VIII »

it doesn't matter much if the industry rating is low in ttd, it's not worth the effort to sabotage a player that way, you'll only cut some percent of the production of that industry but it matters a lot for georges industries, they close down if the rating is low
edit: and where is the logic in the fact that an industry that's serviced by two stations produces less than it would with only one station? that's clearly a bug and just because it's a bug that has already been there in ttd doesn't mean that it shouldn't be fixed
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 12 guests