Currently Online

Latest Posts

Topic: Measuring working time of productionsites

Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2019-05-19, 17:46

Hi, I would like to improve the measurement of utilization time of productionsites - as used by AI. I found a function ProductionSite::program_end() - that is fine, but I would like to have also something that starts the program itself.

Or can we say that the productionsite is always executing some program? So measuring end to end is fine...


Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 15:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2019-05-19, 18:29

I am interested in working on the production program code in the tribes. This would also allow us to show the time measurements in the encyclopedia without having to calculate anything manually.


Busy indexing nil values

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2019-05-19, 20:20

The productionsite now has "crude_statistics_" variable that is used only by AI, now I am just trying to code something and see if it will work reasonably....


Top Quote
einstein13
Avatar
Joined: 2013-07-29, 00:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2019-05-20, 09:34

Do you consider also production time which depends on land (forester, woodcutter, stonemason, farms, vineyard, ...)?

I did some experiments long time ago:
http://wuatek.no-ip.org/~rak/widelands/docs/ForestersWoodcutters/ForestersAndWoodcutters1.3.pdf
There you can find on page 3-4 some calculations about mean distance from building to target place. On flat, empty land. If you add coast or impassable territory, everything can change.

That is why I wanted to check every building manually and see how many resources it can produce, but it is tones of work. I don't think that it is worth it, but if it worth - there are some methods currently available to help this.


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 15:56
Posts: 3324
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2019-05-20, 09:43

I think an average value according to work area size would work just fine. A formula to capture that would be perfect.


Busy indexing nil values

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2019-05-20, 09:50

einstein13 wrote:

Do you consider also production time which depends on land (forester, woodcutter, stonemason, farms, vineyard, ...)?

The beauty of my approach is that measures actual time. From program end to program end. Usually it matches LUA conf as it should of course...

I just want to add that it is still aproximate as it does not keep the history for x minutes, just do some crude average of previous average with current result...

But this is indeed used only by AI and is not visible to player


Top Quote
einstein13
Avatar
Joined: 2013-07-29, 00:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2019-05-20, 14:50

Tibor wrote:

just do some crude average of previous average with current result...

Can I suggest one small change?

As I understand, for given values:

v_1, v_2, v_3, v_4, v_5, v_6, ...

You are trying to calculate averages:

a_1, a_2, a_3, a_4, a_5, ...

Where:

a1 = v1
a_N = (a_N-1 + v_N)/2

Right?

I have prepared short excel file: https://files.fm/u/85djxzg6 (hopefully you can download)

Columns:

  • Just numbers (1...N)
  • Raw, random data (range 0...20)
  • Modified average of above definition
  • Full-time average
  • N-terms average

I expect that we want to know what is average of last N terms in working building, because the environment can change (borders, stone cut, trees, etc.). Average described above is working well, but it can work even better.

Let's change the equation from:

a_N = (a_N-1 + v_N)/2

To:

a_N = mu*a_N-1 + (1-mu)*v_N

If mu=1/2=0.5, you will get the first equation.
But if you place another value of mu, you will get better fit value.

For example using mu=0.8 is almost like 7 terms average (for uniform distribution).

That change is almost nothing to the code & memory, but the value is much closer to the target one.


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2019-05-20, 15:16

@Einstain

we dont have fixed mu, but

total_duration = 5 * 60 * 1000 seconds

curent_result_weight = duration / total_duration

previous_average_weight = (total_duration - duration) / total duration.

So weight of current result vs previous average depends on duration of just finished program....

If "something" took few seconds it will have lesser impact and so on...


Top Quote
einstein13
Avatar
Joined: 2013-07-29, 00:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2019-05-20, 21:18

Tibor wrote:

total_duration = 5 * 60 * 1000 seconds

I guess that it is 560 seconds or 560*1000 miliseconds, but that is minor thing (rather a bit funny to me face-smile.png )

curent_result_weight (...) If "something" took few seconds it will have lesser impact and so on...

I don't understand everything (total duration is a constant here?), but as I know you, I believe that this formulas are good. So I will have no objections for your work any more! face-smile.png Go for it and merge to make the AI even better!


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2019-05-20, 22:31

einstein13 wrote:

Tibor wrote:

total_duration = 5 * 60 * 1000 seconds

I guess that it is 560 seconds or 560*1000 miliseconds, but that is minor thing (rather a bit funny to me face-smile.png )

No it is 5 minutes, but value is arbitrary...

curent_result_weight (...) If "something" took few seconds it will have lesser impact and so on...

I don't understand everything (total duration is a constant here?), but as I know you, I believe that this formulas are good. So I will have no objections for your work any more! face-smile.png Go for it and merge to make the AI even better!

What I dont like (too) about current main statistics, that it covers varying range of time. From 20x skipped to 20x producing, this can be from 1 minute to more then 20 minutes...


Top Quote