Latest Posts

Topic: main roads becoming normal again

ypopezios
Avatar
Joined: 2018-04-20, 00:22
Posts: 220
Ranking
Widelands-Forum-Junkie
Posted at: 2018-04-20, 15:11

No need to repeat the almost self-evident over and over, especially since this thread has already been a perfect example of an idea which never reached implementation. And since this time there is improvement in the distance (now shorter) between the new idea and its implementation, we can be optimistic of producing some improved code at last. After all, the same way that a great idea needs actual code to get implemented, actual code needs an idea to justify its writing. Let's not discourage something as cheap as ideas. Having said that, I have more ideas for sharing, so I hope of not getting too discouraged with the treatment of the first one.


Top Quote
Tibor

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

We are short of developers so If you deliver reasonable code, chances are high that it will be accepted.....


Top Quote
ypopezios
Avatar
Joined: 2018-04-20, 00:22
Posts: 220
Ranking
Widelands-Forum-Junkie
Posted at: 2018-04-20, 16:02

If the idea gets accepted, chances are high that I will deliver reasonable code...


Top Quote
teppo

Joined: 2012-01-30, 09:42
Posts: 423
Ranking
Tribe Member
Posted at: 2018-04-20, 17:37

Tibor wrote:

We are short of developers so If you deliver reasonable code, chances are high that it will be accepted.....

It is not fun to first implement a change and then learn that is is not wanted or even accepted.


Top Quote
teppo

Joined: 2012-01-30, 09:42
Posts: 423
Ranking
Tribe Member
Posted at: 2018-04-20, 17:44

king_of_nowhere wrote:

IF m-business greater than 350, upgrade road. IF m-business lower than 350, demote road.

No hysteresis?


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

ypopezios wrote:

Calculating busyness is not the best model, not to mention it's hard for simple users to understand. I believe that the following algorithm is superior:

  • Every human carrier starts with a hypothetical wallet empty of coins (zero value of a single simple integer variable, very friendly both to calculations and to savegame).
  • Every time a carrier loads a ware, his wallet gets increased by an amount of coins equal to the number of wares awaiting in the respective queue of the flag (no wallet is permitted to go above the maximum amount of coins gainable in a specific length of time). If we also want to help long roads, the said amount could be increased by the length of the road.
  • Periodically (only a single system-wide timer) the system removes a fair amount of coins (say maintenance costs) from the wallet of every carrier (no wallet is permitted to go below zero), except of those in congested roads (since they cannot increase their coins). Removes double that amount from the wallets of those who have animals. If one of those has not enough coins for the payment (thus wallet goes to zero), his road gets demoted and his animal becomes available for reassignment.
  • Same period second step (applicable only when there are animals available), the system checks the amount of coins of every carrier in unpromoted roads. If any of those carriers has accumulated enough coins (say to buy an animal), his road gets promoted and the proper amount of coins is removed from his wallet, while an animal is assigned to his road. If there are not enough animals available, they get preferably assigned to the carriers with the most coins.

No, this is an AWFUL idea, just like all previous ideas for demoting roads. And the reason is always the same: it penalizes a road for working properly.

On a 2-steps road, a carrier needs 7.2 seconds to make a full trip. If the road has one ware every 5 second, then you NEED an animal. But with this algorithm, you only see that every ware gets transported immediately, so you demote it. The purpose of the discussion was to AVOID the demoting of roads when the traffic is enough that it can only be sorted with an animal.

So no, No, NO demoting roads just on the base that wares do not wait on the flag. Wares not waiting on the flag should be the normal state of business, not a reason to demote roads.

it could work with the following change: whenever both carriers on the road are busy, increase the value of the road. That way the algorithm can keep track of the fact that the road actually needs two workers to be effective.

And I would also add the clause "if the economy does not need pack animal, do not demote roads ever."


Top Quote
ypopezios
Avatar
Joined: 2018-04-20, 00:22
Posts: 220
Ranking
Widelands-Forum-Junkie
Posted at: 2018-04-20, 18:46

Could we all get a little less passionate and focus more on the solution than on the problems please? Thanks in advance.

king_of_nowhere wrote:

it penalizes a road for working properly

Maybe you thought that the queue is considered after removing the ware. This is not the case. A carrier who takes a ware, always takes a minimum of 1 coin for it, plus some for the length of his road. Let me describe again the basic idea in isolation: As time passes, all carriers lose coins. But carriers who are not idle, get rewarded with coins for their work. Therefore, if the calculations for increasing and decreasing the wallet are chosen fairly, a properly working road will receive plenty of coins to avoid demoting indefinitely. Only underutilized roads will get bankrupt and demoted.

king_of_nowhere wrote:

if the economy does not need pack animal, do not demote roads ever

It has already been explained somewhere else that it is a feature of the game to not use animals unless they are really needed. This is the reason they all stay in HQ in the beginning of the game.


Top Quote
ypopezios
Avatar
Joined: 2018-04-20, 00:22
Posts: 220
Ranking
Widelands-Forum-Junkie
Posted at: 2018-04-20, 18:49

Tibor wrote:

If you deliver reasonable code, chances are high that it will be accepted.....

Well, I decided to bite the bullet. For those who want to understand basic C++, here is the form of current implementation:

file economy/road.cc

// line 545
handle ware

if carrier is available for the ware, then
  // line 558
  busyness_last_update = gametime
  if busyness > 0, then
    decrease busyness by 1
    if busyness < 350, then demote the road
else
  // line 592
  busyness_last_update = gametime
  increase busyness by 10
  if busyness > 500, then promote the road

And here is what should be done:

  • The variable busyness should everywhere change name to wallet.
  • The variable busyness_last_update should everywhere change name to e.g. last_wallet_check.
  • The variable tdelta should probably get removed.
  • The handling of the ware should change to this form:
if carrier is available for the ware, then
  decrease wallet by (nof_carriers() * (gametime - last_wallet_check))
  last_wallet_check = gametime
  increase wallet by (some_factor * (nof_wares_in_queue() + path.get_nsteps()))
  if wallet < 0, then
    wallet = 0
    if type_ == RoadType::kBusy, then demote the road
  else
    if type_ == RoadType::kNormal
      if wallet > (1.5 * animal_price), then
        decrease wallet by animal_price
        promote the road
    if wallet > max_wallet, then wallet = max_wallet

Missing things (not hard for anyone who understands the codebase):

  • Handling of congested roads.
  • Dummy functions nof_carriers and nof_wares_in_queue.
  • Constants some_factor, animal_price and max_wallet.
Edited: 2018-04-21, 04:44

Top Quote
Tibor

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

Ypopezios,

good to see something real. I (or anybody) can create new branch, update the road.cc with your changes and have have the binary built so everybody (windows users mainly) can test it. You too of course

Can you update directly the function Road::notify_ware() here on forum or elsewhere so that I can just copy&paste it to code? Ignore formatting now, we can have it formatted automatically later on. Also use comments wherever you have some questions or doubts....

As for missing functions - let them undefined, somebody will look at them.

Also explain please what you mean with "Handling of congested roads"

Endnote: For this kind of work it is very useful to be able to compile yourself and see immediately effect of the changes in code... But unless you are a linux user this can be a problem..


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

Concerning congested roads, probably all that is needed is a statement:

last_wallet_check = gametime

...to be placed at the point they finally resume operations, so as to not get bankrupt from all the time of forced idleness. But I cannot know that, since I haven't read the respective code.

I'm on windows myself and not willing to install a virtual box for C++, nor to write actual code without debugging it. Therefore I'm afraid that I cannot do much more without seeing any progress. If someone makes the changes and points me to the new file, I can inspect it and detect any errors on the algorithm's implementation. Any other errors should be debugged by someone who has C++ installed. Tweaking the constants to finetune the algorithm needs again access to an easy cycle of compile-test-startover. The ball is no more on my field, sorry. By the way, if such a small change is too much for the active developers of Widelands, we may as well abandon all hope for any changes whatsoever.


Top Quote