Latest Posts

Topic: Solution proposals for maritime shipping problems

Nordfriese
Avatar
Joined: 2017-01-17, 17:07
Posts: 1949
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-02-02, 15:33

This is how the current algorithm works:
Each ship has a sorted list of the ports it´s planning to visit next. When new wares are loaded or some port requires a ship, the destinations may be reordered to accommodate for the importance of the several destinations (which depends on distance and number of wares). Ports whose visit is often postponed increase in priority so single wares won´t be sailing around forever if more important orders keep dropping in. Ports that can be visited on-the-fly (only a small detour) between two more important ports are also preferred. Ships may also be called back if a new ware arrives at the port immediately after the ship has left.

When a ship arrives at a port, it unloads wares destinated for this port. Afterwards, the port decides which waiting wares to load on the ship. It will load wares for ports in the ship's destination list, and possibly for other destinations as well which are then added to the ship's list. If the ship is planning to take the detour A-C-B and another ship with route X-A-B is on its way to the port, the port may decid to hold back some items to put them on the next ship.

Nearby idle ships are not taken into account yet, this should be fixed.

Other than that, the issues you reported can be resolved by tweaking the detour estimations in portdock.cc and ship_fleet.cc.


Top Quote
Yo...
Avatar
Joined: 2019-10-28, 13:47
Posts: 26
OS: Win 10
Version: 1.0 + 1.2
Ranking
Pry about Widelands
Location: MiddleEurope
Posted at: 2020-02-02, 20:12

Nordfriese wrote:

This is how the current algorithm works:
[...]

That seems more complex than I thought. Still it doesn't work always very well (it seems). We have to find out, what doesn't work as planned.
How about workers and soldiers? How they are preferred or not? How decides the algorithm which worker/soldier ist more important than others? Sometimes it seems the soldiers have the lowest priority, they are shipped nearly across the map and back with the wares bevor they reach their Isle with the assigned military site. If it is close to an enemy, or is a military site which prefers "strong" soldiers, or is the first military site close to a new port (built by explorer ship): these soldiers should be more important (just my opinion).

(only a small detour)

How is "small" defined? face-wink.png I think on a huge map "small" is something different than on a small map ...

Nearby idle ships are not taken into account yet, this should be fixed.

Yes, this can solve some of the issues. With the already existing list for every ship it should be known if a ship will be idle after unlaoding the wares at the last port in the list. Such "will be idle" ships could be taken in account too for the planning. Then the "planning ahead" maybe is not so tricky as I thought.

Other than that, the issues you reported can be resolved by tweaking the detour estimations in portdock.cc and ship_fleet.cc.

ok, I just say "Bahnhof" face-wink.png No, you don't have to explain it ...


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 17:07
Posts: 1949
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-02-02, 21:07

How about workers and soldiers? How they are preferred or not?

Currently: Not at all. Algorithm considers only number of items shipped for a certain destination. Whether it is just a log or a supersoldier urgently needed somewhere is not taken into account.

How decides the algorithm which worker/soldier ist more important than others? Sometimes it seems the soldiers have the lowest priority, they are shipped nearly across the map and back with the wares bevor they reach their Isle with the assigned military site.

That´s because if you urgently need your soldier, you tend to be a bit impatient and if the soldier is not sent via the shortest possible route it is much more noticable than for ordinary wares.

If it is close to an enemy, or is a military site which prefers "strong" soldiers, or is the first military site close to a new port (built by explorer ship): these soldiers should be more important (just my opinion).

It would be difficult to code. And if we implement it, next someone will demand to also prioritise input wares with high priority in the destination building, and next that wares for military constructionsites close to a hostile border to be prioritiued as well... and nobody would understand the code anymore.

(only a small detour)

How is "small" defined? face-wink.png I think on a huge map "small" is something different than on a small map ...

Very very very short detours are preferred, a bit longer detours drastrically penalized. Exact definition

Yes, this can solve some of the issues. With the already existing list for every ship it should be known if a ship will be idle after unlaoding the wares at the last port in the list. Such "will be idle" ships could be taken in account too for the planning. Then the "planning ahead" maybe is not so tricky as I thought.

Already started a branch to implement this face-smile.png


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 22:16
Posts: 2648
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-02-02, 21:18

Well I have tried the Tasmanian map of Solstice_s_Return. And indeed this made some problems obvious. Especially some ships got cluttered at a far away colony. They were sent with all the build materials and afterwards they were not considered anymore as they were to far away. This lastet really long and might be leading to a solution.
What if when there are more then 1 idle ships at a port they could be sent to a unoccupied port perhaps.


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 17:07
Posts: 1949
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-02-02, 21:48

Good idea, implemented this face-smile.png


Top Quote
JanO
Avatar
Joined: 2015-08-02, 10:56
Posts: 177
Ranking
At home in WL-forums
Posted at: 2020-02-02, 22:00

Good idea. Send it to which port?
- Simple (pick the closest)
- Advanced (pick the closest that will not be reached by another ship sooner)
- Complex (pick one that is outstandingly busy)

Another idea: If a ship with more than one port in queue docks to a port (1) with any idle ship within a small distance, the busy ship should unload all wares for the last port (z) in queue so the idle ship can pick them up. "Small" could be estimated as "idle ship is closer to the port (1) then the distance between port (z) and port (z-1). Or to a fixed value.

Edited: 2020-02-02, 22:02

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 17:07
Posts: 1949
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-02-02, 22:27

I implemented it now so that closer ports are preferred but ports with many ships nearby are penalized. Previously the code checked only for sailing distance, now it checks (sailing_distance * (number_of_ships_near_the_other_port + 1)).
No need to have complex calculations here, especially as we don´t have "busyness" stats for ports available, and as empty ships sailing around long distances are not desirable because at the time when they will be needed they then are quite likely far away from any port.

Another idea: If a ship with more than one port in queue docks to a port (1) with any idle ship within a small distance, the busy ship should unload all wares for the last port (z) in queue so the idle ship can pick them up. "Small" could be estimated as "idle ship is closer to the port (1) then the distance between port (z) and port (z-1). Or to a fixed value.

Regarding loading wares between ships. I don´t like this idea because this is messing up two strictly separated concepts. ShipFleets assign ships to ports, and PortDocks load wares onto ships. PortDocks may also assign the ship currently present there another destination, but only if it´s really necessary. But the PortDock never, ever directly interacts with a ship other than the one asking it for cargo. Such requests are handled through the Fleet, which does not care about individual wares. So this would just result in the wares being unloaded, the idle ship coming or perhaps not, and loading perhaps these wares or completely other wares for a different destination.
Edit: That´s why ships should never unload an item except at its destination port, which the item sets once when it enters the portdock and which changes only in the rare case of the destination port is destroyed.

Edited: 2020-02-02, 22:32

Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 19:48
Posts: 2439
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2020-02-03, 07:23

Just a question: Is shipping wares preferred over shipping workers?

I had a agame where i have to move all wares and workers to another island, and a brewery waits hours to get the brewer because all ships are only transferring wares.


Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 17:07
Posts: 1949
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-02-03, 07:43

Just a question: Is shipping wares preferred over shipping workers?

I had a agame where i have to move all wares and workers to another island, and a brewery waits hours to get the brewer because all ships are only transferring wares.

A brewer doesn´t need a tool so he should be created in the nearest warehouse and not require shipping...

All shippingitems are equal, no matter whether they are a ware or worker. Whether one item is preferred over another is decided by exactly two factors: Their destinations, and how long they are waiting in the portdock already.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 22:16
Posts: 2648
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-02-03, 07:52

Nordfriese wrote:

Just a question: Is shipping wares preferred over shipping workers?

I had a agame where i have to move all wares and workers to another island, and a brewery waits hours to get the brewer because all ships are only transferring wares.

A brewer doesn´t need a tool so he should be created in the nearest warehouse and not require shipping...

Can't say from the code just from experience, if there is a lazy worker available (brewer in this case) he is sent to the new location even if a warehouse much closer could create one easily.

All shippingitems are equal, no matter whether they are a ware or worker. Whether one item is preferred over another is decided by exactly two factors: Their destinations, and how long they are waiting in the portdock already.

Edited: 2020-02-03, 07:53

Top Quote