Currently Online

Latest Posts

Topic: main roads becoming normal again

king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 17:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2018-04-24, 15:40

ypopezios wrote:

king_of_nowhere wrote:

I would think that promoting a road with 1000 coins and demoting it it it goes below 900 should be a good idea, with a maximum value of 2000 should be reasonable. a road with a full 8 wares at a flag would earn 114 coins per trip and level up in a minute, and once it goes to maximum it needs 20 minutes idle to go back to simple road.

If you instead want to stick with your "increase cost per number of carriers"... It's harder to make the numbers work. We absolutely cannot demote a road that gets more than a ware every 7.2 seconds

Could you share how you got to those numbers? Best would be through a sheet, but this is up to you.

No need for a sheet.

Let's call the basic distance unit a "step". Then the shorter road is 2 steps long. A worker (carrier or otherwise) takes 1.8 seconds to take a step, that's somewhere in the lua files. A carrier can transport 1 ware every 7.2 seconds (2 steps to bring ware to next flag, 2 steps to go back, 1.8 seconds times 4). So every road carrying more than one ware every 7.2 seconds does need a pack animal.

As for the 1000 and 900, those numbers I just eyeballed. I figured that if a road is too busy for a single carrier, it will accumulate wares at the flag. At worst it can accumulate 8 wares, so if a single ware per flag is worth 7 * the lenght of the road, then with 8 wares there will be 7 * 2 * 8 = 112 (the 114 was a miscalculation). as the worker moves a new ware every 7.2 seconds, the road will gain a value of 112 every 7.2 seconds, so it will get promoted in about a minute (64 seconds to be exact), which seems about right.

Demotion at 900 is just to avoid a road getting promoted and then demoted immediately after if it remains idle for 10 seconds.

Maximum value at 2000 is because then a road becoming idle, losing 1 coin per second, would take 1000 seconds (16 and a half minutes) to go back to normal. And those values seem right.

RE: increased maintenance of the second carrier.

The problem is not when you have two carriers being busy all the time. Of course such a road will keep getting value - and incidentally, such a road is already at its limit and you should already be trying to divert traffic way from it. the problem is when the secondary carrier is only busy 10% of the time. Say that at your flag arrive 1 ware every 6.5 seconds. Your carrier can only carry one every 7.2 seconds, so he needs a donkey. But the donkey will be idle 90% of the time. Still, it is needed. you remove it, the road will get jammed until a new donkey is sent. And it causes a very small loss of efficnency, but it is very ugly to see. And it makes the algorithm look really bad.

So, you have to fix the numbers so that a road that uses the donkey only 10% of the time is still gaining value. Even on a road that would be effectively serviced by a single carrier you may want a second one, just on the offchance that you get a random fluctuation in traffic; but let's skip that for simplicity.

But if you plan your algorithm to keep increasing the value of a road getting 110% the ware capacity of a single worker, then it means when there is a single worker the road willl gain value when it is at 55% occupation. And when the worker is only working 55% of the time, a second carrier is not needed.

If I may surmise, the problem arise because you're trying to fit a transportation algorithm used in real life to a different situation. Such an alogirthm would work fine if you have a lot of vehicles, and it works because there is some flexibility in the carrying capacity of a single vehicle (say, you can load the truck a bit more, or you can push a bit more people on the same train). In the passage between 1 and 2 carriers you suffer of excessive granularity. You also suffer for inelastic carrying capacity; your carrier can't move just a bit faster.


Top Quote
king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 17:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2018-04-24, 15:53

Actually, since there are a lot of borderline cases where a donkey wuld be useful but not really needed, I have an idea that could help there (t the cost of adding more CPU): have the maintenance cost be dependant upon the amount of donkeys and corn (grain/barley/whatever) available. Say, if economy_does_not_need_donkey, and economy_does_not_need_corn, then this could lower the maintenance value of all roads, encouraging more donkeys to be sent around.


Top Quote
teppo

Joined: 2012-01-30, 08:42
Posts: 423
Ranking
Tribe Member
Posted at: 2018-04-24, 19:26

king_of_nowhere wrote:

Let's call the basic distance unit a "step". Then the shorter road is 2 steps long. A worker (carrier or otherwise) takes 1.8 seconds to take a step, that's somewhere in the lua files. A carrier can transport 1 ware every 7.2 seconds (2 steps to bring ware to next flag, 2 steps to go back, 1.8 seconds times 4). So every road carrying more than one ware every 7.2 seconds does need a pack animal.

As for the 1000 and 900, those numbers I just eyeballed. I figured that if a road is too busy for a single carrier, it will accumulate wares at the flag. At worst it can accumulate 8 wares, so if a single ware per flag is worth 7 * the lenght of the road, then with 8 wares there will be 7 * 2 * 8 = 112 (the 114 was a miscalculation). as the worker moves a new ware every 7.2 seconds, the road will gain a value of 112 every 7.2 seconds, so it will get promoted in about a minute (64 seconds to be exact), which seems about right.

After this about minute, the one segment is promoted and the leading pile of stuff moves to next flag. Promoting an entire (long) road takes about 18 minutes. Was that right?

Demotion at 900 is just to avoid a road getting promoted and then demoted immediately after if it remains idle for 10 seconds.

+1

So, you have to fix the numbers so that a road that uses the donkey only 10% of the time is still gaining value. Even on a road that would be effectively serviced by a single carrier you may want a second one, just on the offchance that you get a random fluctuation in traffic; but let's skip that for simplicity.

Donkey is (marginally) useful even before the average flow of wares reaches the limit of the single carrier. Example: The road capacity is close to (single carrier) limit. Player places a construction cite of a castle somewhere. Traffic jam is guaranteed, when the peak competes with the base load. Yet the player might be in need the building badly (first to build castle gets gold mine or so). Having carrier animals to handle the rush hour would have been nice.

=====

Is there a reason to use integer maths? Add constant, remove constant/time leads in static cases the purse to be either empty or full, but not in-between. If the "toll" would be, say one permille of current value instead of a minus-one, then an old road that does not quite meet the requirements would be quickly promoted after a traffic increase: old roads with some traffic would already have acquired coinage.


Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2018-04-24, 20:53

OK, good news - it compiled and windows binaries should be available here: https://code.launchpad.net/~widelands-dev/widelands/road_promotions/+merge/344182

However when testing I saw no road promotions during 3 hours of game, probably matter of finetuning...


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 22:16
Posts: 2649
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2018-04-24, 21:48

What is the unit of Gametime? In lua it is Milliseconds if it is milliseconds in C++ as well, this might be the problem as instead of 1 coin per second it is 1000 per second.


Top Quote
king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 17:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2018-04-25, 00:05

teppo wrote:

After this about minute, the one segment is promoted and the leading pile of stuff moves to next flag. Promoting an entire (long) road takes about 18 minutes. Was that right?

that's a problem. of course you want to promote all the road at once. If the road has no intersections, then you can teach the code to treat it as a single road. But if there are intersections? I have no idea how to deal with a case like that.

Maybe a value of 500 to promote the road would be better in such a circumstance? but too much chance to accidentally promote a road just because you made some buildings and there was a temporary influx of building materials.

Edited: 2018-04-25, 00:06

Top Quote
ypopezios
Avatar
Joined: 2018-04-19, 23:22
Posts: 220
Ranking
Widelands-Forum-Junkie
Posted at: 2018-04-25, 04:29

Tibor wrote:

OK, good news - it compiled

This still says busyness:

molog("busyness_: %i\n", wallet_);

Finetune the algorithm like this:

// delete some_factor
// set constants
animal_price = 600
max_wallet = 2.5 * animal_price

//update income formula
wallet += 2 * (nof_carriers + 1) * (4 * (nof_wares_in_queue - 1) + nof_steps);

Don't bother with binaries and hours of gaming before having it print some numbers to see if we got the code right. Testing can wait for later.

You guys have increased the requirements since the last time I checked them. I made some effort to incorporate in the income formula as many of them as possible, but we should take a break from that and focus on getting something workable and better than what we already have. Later we can let testing guide us to further improvements (instead of making hypotheses all the time). So, if the improved formula looks too complicated, it is your fault... Below is some explanation of its performance, based on king_of_nowhere's scenario:

In a central road, a carrier transfers wares in both directions, so his maximum income would be double of what you tried to calculate so far. But let's take the case of one direction. For a 2-step road with full queue and one carrier, the formula gives an income of 2 * (1 + 1) * (4 * (8 - 1) + 2) = 120 coins per ware. If we want this to get promoted after carrying 8 wares in about one minute, this would be 8 * 120 = 960 coins. The maintenance cost during that time would be about 60 coins, so a previously empty wallet would be left with 960 - 60 = 900 coins. From those coins we can calculate the animal_price as 900 / 1.5 = 600 coins. So after the promotion the wallet will have 900 - 600 = 300 coins. Thus, if the road gets immediately fully-idle and remains like that, losing 1 coin per carrier per second will lead to minimum time for demotion equal to 300 / 2 = 150 seconds = 2.5 minutes. Therefore, under extreme conditions (full one-direction traffic followed by full idleness), demotion needs 150% more time than promotion. Real conditions would increase the needed time for both. In the same scenario, the promoted road has a positive balance if the second carrier's average utilization doesn't drop below 20%. If both flags operate similarly, that percentage goes down to half, which is king_of_nowhere's desired number.


Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2018-04-25, 06:48

ypopezios wrote:

Tibor wrote:

OK, good news - it compiled

This still says busyness: ~~~~ molog("busyness_: %i\n", wallet_); ~~~~

Cosmetic issue, we are far from merging into trunk ... but I will fix this face-smile.png

Finetune the algorithm like this: ~~~~ // delete some_factor // set constants animal_price = 600 max_wallet = 2.5 * animal_price

//update income formula wallet += 2 * (nof_carriers + 1) * (4 * (nof_wares_in_queue - 1) + nof_steps); ~~~~

Don't bother with binaries and hours of gaming before having it print some numbers to see if we got the code right. Testing can wait for later.

It was AI-only game - no wasted time for me... Also binaries are built automatically, no effort needed. And I presume you (as you are not able to built the game by yourselves) will want to test it and see how it works....


Top Quote
king_of_nowhere
Avatar
Topic Opener
Joined: 2014-09-15, 17:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2018-04-25, 10:49

ypopezios wrote:

In a central road, a carrier transfers wares in both directions, so his maximum income would be double of what you tried to calculate so far.

Damn, I hadn't considered that. And it means that in order to promote a road that only get traffic in one direction (say, a road connecting a bunch of farms and wells to the rest of the land) you'd also promote a read that was idle half th etime.

From an efficiency point of view, traffic in both directions is completely irrelevant. The varrier needs to go back to the previous flag to pick another ware regardless of whether it is carrrying something back. It doesn't affect it in the slightest. Ideally, we should consider traffic in both directions separately and then pick the highest value, but that alone would double CPU consumption.

ypopezios wrote:

You guys have increased the requirements since the last time I checked them.

There's a reason this issue was never takled in the thrree years since I raised the issue: once you start checking the requirements, it opens a can of worms.

If it was for me, I'd skip road demotion entirely. It is a damn mess to code, it is a real CPU problem on large maps, and I don't see it adding much to the game.


Top Quote
ypopezios
Avatar
Joined: 2018-04-19, 23:22
Posts: 220
Ranking
Widelands-Forum-Junkie
Posted at: 2018-04-25, 11:45

Tibor wrote:

It was AI-only game - no wasted time for me... Also binaries are built automatically, no effort needed. And I presume you (as you are not able to built the game by yourselves) will want to test it and see how it works....

I understand. Still what is needed next is printing of numbers.

king_of_nowhere wrote:

There's a reason this issue was never takled in the thrree years since I raised the issue: once you start checking the requirements, it opens a can of worms.

Apart from lack of developers, the only other reason was the bad model. Incorporating advanced requirements in it, is simply impossible. And incorporating everything at once is even more impossible. But strong models (and determined programmers) are not afraid of worms. And they have proven their effectiveness in critical software for real-life environments, which are much much harder to deal with than the limited predictable environment of a game.

king_of_nowhere wrote:

If it was for me, I'd skip road demotion entirely. It is a damn mess to code, it is a real CPU problem on large maps, and I don't see it adding much to the game.

Things are not that dark. Have some faith and you'll get a reasonable and CPU-friendly version soon. For sure it won't add much to the game, but it will be a welcome improvement and a step towards the right direction. Some special cans contain goodies instead. Let's try opening one of them.


Top Quote