Latest Posts

Topic: Ships optimization - project

einstein13
Avatar
Topic Opener
Joined: 2013-07-28, 23:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-08-14, 22:48
Last update 08-31-15

Hi!

After reading this thread, especially this post and next posts, I've decided to make special project where any ideas can be tested and compared in a proper way.

Few words about project

My project is written in python 2.7, for newer versions I have to test it first.

How to run your own experiment? Very simple:

git clone https://github.com/einstein13/wl_ship_optimization.git
cd wl_ship_optimization
python execute_one.py

The goal for now is to make efficient and math-like algorithm for work of ships and ports in Widelands before build 20.

What is included now?

  1. Ships:
    • Simple ship algorithm (old Widelands)
    • Tibor's ship algorithm (based on his python project)
    • Tibor's ship algorithm (his branch, currently here, almost identical to python one)
    • Einstein's ship algorithm (for example here)
    • Einstein's ship algorithm, change: next destination can be the one after next while calculating new route
    • Einstein's ship algorithm, change: calculating k factor based on wares on the ship
  2. Ports:
    • Simple port algorithm (old Widelands)
    • Einstein's patch for port based on this
  3. Test cases:
    • Line test (ports in line: A---B---C, one ship, 200 wares to transport)
    • Triangle test (ports in regular triangle, one ship, 300 wares)
    • Hexagon test (6 ports, 2 ships, 300 wares)
    • Rectangular test (4 ports: 2 pairs with long distance between, 2 ships, 300 wares)
    • Nonsymmetrical situation, more likely to be in game, huge amount of wares (6 ports, 2 ships, 1200 wares)
  4. Test difficulties:
    • "1" - Slow mode - long time between appearing wares, mostly to see if algorithms aren't working in very strange way
    • "2" - Standard mode - middle time between appearing wares, middle distances, mostly to see if everything is working fine with more complex problems, plus if the algorithm is just wrong (much worse than basic one)
    • "3" - Stressed mode - lots of wares at once, long distances, mostly to see the difference in very complex situations
  5. Statistics:
    • Total simulation time (taken to fulfill test cases)
    • mean/max utilization of ships
    • mean/max wares waiting in ports
    • min/mean/max journey distance for ware
    • min/mean/max existence time for ware (waiting at port + travelling)
    • max/mean/min efficiency of journey for ware
    • min/mean/max time waiting for ware in port (to be taken by a ship)
  6. Statistics display:
    • Statistics every each experiment (test case)
    • Statistics in markdown tables after all experiments for each set of tests
    • Optimization through given value with markdown table of results for each set of tests

Do you want to suggest something?

Feel free to write it down here, on this thread. Now I am developing the code. It needs lots of work. Then you will be able to add any algorithm you want to test.


I will edit this post to keep it up-to-date

Edited: 2015-08-31, 19:58

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

Top Quote
einstein13
Avatar
Topic Opener
Joined: 2013-07-28, 23:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-08-14, 22:54

My current state of the project is more like simple test, plus some statistics. All are available in "full description mode":

$ python execute_one.py
"general: total simulation time"/"Total time: " : Game time when last ware reach destination
"ships: mean utilization"/"Mean utilization: " : Mean ship utilization (how many wares are onboard)
"ships: max utilization"/"Max utilization: " : Maximum ship utilization (how many wares are onboard)
"ports: mean wares waiting"/"Mean wares waiting: " : Mean number of wares waiting in ports
"ports: max wares waiting"/"Max wares waiting: " : Maximum number of wares waiting in ports
"wares: min distance of journey"/"Min journey distance: " : Minimum length of journey for any ware
"wares: mean distance of journey"/"Mean journey distance: " : Mean length of journey for any ware
"wares: max distance of journey"/"Max journey distance: " : Maximum length of journey for any ware
"wares: min time of existence"/"Min existence time: " : Minimum time of existence for any ware (start at port, end at destination)
"wares: mean time of existence"/"Mean existence time: " : Mean time of existence for any ware (start at port, end at destination)
"wares: max time of existence"/"Max existence time: " : Maximum time of existence for any ware  (start at port, end at destination)
"wares: max journey efficiency"/"Max journey efficiency: " : Maximum value of length_journey/minimum_possible_length for any ware
"wares: mean journey efficiency"/"Mean journey efficiency: " : Mean value of length_journey/minimum_possible_length for any ware
"wares: min journey efficiency"/"Min journey efficiency: " : Minimum value of length_journey/minimum_possible_length for any ware

PORTS:
Very basic port class.
SHIPS:
Very basic ship class.
------
Total time: 9226.8
Mean utilization: 1.75757575758
Max utilization: 5
Mean wares waiting: 0.71979451164
Max wares waiting: 4
Min journey distance: 25
Mean journey distance: 43.5
Max journey distance: 75
Min existence time: 48.6
Mean existence time: 178.47
Max existence time: 401.4
Max journey efficiency: 1.0
Mean journey efficiency: 1.43
Min journey efficiency: 3.0

First row is the command, second part is explanation of every statistic written in the bottom part. Middle part (PORTS & SHIPS) is explanation what ship and port algorithm is used for the test.

If something is not understandable enough, please report it. Also If you want some other statistics, please write it down too. I will see if it is possible to implement in current model.


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

Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-08-17, 19:09

Mean existence time: 178.47 Max existence time: 401.4

I think this is what we are after - these should correspond to seafaring delivery time - I mean time from delivery a ware to starting port till delivery to destination port....

Have you implemented also another algorithms for ship movements?


Top Quote
einstein13
Avatar
Topic Opener
Joined: 2013-07-28, 23:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-08-17, 23:10

Tibor wrote:

Mean existence time: 178.47 Max existence time: 401.4

I think this is what we are after - these should correspond to seafaring delivery time - I mean time from delivery a ware to starting port till delivery to destination port....

Yes and no. For me better should be another statistics: "difference between existence time and traveling time => waiting time (ware at first port)" (can be done, because we know the ship speed). But all these times are test-dependent. For close ports everything is smaller. We can compare different methods with one test case, but not different results from different test cases. For me slightly better is travel efficiency. It is dependent on port placement (max value), but for more complex problems it is great factor. For example factor equal to 10 means that the ware was traveling 10 times longer than it was needed. I will improve the statistics in the future, but I hope current version is enough for the first sight face-wink.png

Have you implemented also another algorithms for ship movements?

Not yet. Working currently. I've fixed few bugs to do that correctly. Now it is very, very easy face-wink.png Create new file in ships folder, create there a Ship class and override methods you want to change. After all in settings register your model (give the name of file) in correct list. Creating new file can be just copying the file ship_copy.py and rename it as you want face-smile.png

I will start with your method for ships. Hope in one or two hours time I will have first results face-grin.png

And to answer your old question: this project was easy-tested with python 3.x and it was working fine. Only different results were given. Don't know why. Maybe because random class has different implementation for python 3.x? (different test case -> different results). When I will finish unit tests, I will have the answer face-wink.png


RESULTS FOR TIBOR's ALGORITHM

General results for test cases 1-3 are the same as for older algorithm. For test 4 (>>Rectangular test (4 ports: 2 pairs with long distance between, 2 ships, 300 wares)<<) are better! Congratulations Tibor! Mean journey efficiency is much better, mean journey distance is sligtly better. Utilization is lower - for me it is better efficiency (less wares need to transport). And no "ERRORS". It means that all your ships were going to the ports for reason. In older algorithm that happened twice.

======
TEST CASE 4
======
ERROR: ship: nothing to land and empty port
ERROR: ship: nothing to land and empty port

PORTS:
Very basic port class.
SHIPS:
Very basic ship class.
------
Total time: 5790.6
Mean utilization: 4.77564102564
Mean journey distance: 99.3333333333
Mean journey efficiency: 4.22534313725
Min journey efficiency: 18.0


PORTS:
Very basic port class.
SHIPS:
Tibor's algorithm for ship
------
Total time: 5742.0
Mean utilization: 4.07055961071
Mean journey distance: 83.65
Mean journey efficiency: 2.94966911765
Min journey efficiency: 18.5

EDIT one more time

I've added my patch for port (https://wl.widelands.org/forum/topic/1762/?page=5#post-14225) and run tests. There are slightly different results for last test case. The best are when mixing port patch and Tibor's algorithm. I can't answer one question: why the results are different? Probably there is at least one hidden bug... face-confused.png

Edited: 2015-08-18, 01:19

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

Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-08-18, 20:52

You know, also small differences in algorithm can matter. Also number and layout of ports, number of ships and so on..


Top Quote
einstein13
Avatar
Topic Opener
Joined: 2013-07-28, 23:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-08-22, 00:40

Today I was adding my algorithm to the project.

Also I've added more complicated test case (not symmetrical one) and I've noticed that there are some bugs inside. The project is not stable. I will try to fix it, but not today. I don't know when face-confused.png Sorry


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

Top Quote
einstein13
Avatar
Topic Opener
Joined: 2013-07-28, 23:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-08-24, 00:08

Finally I've found the problem: Tibor's algorithm for finding new path. The problem was with finding best solution for next destination. When the distances were very long (you can think as a very big and complicated map), sometimes carrying the wares to distant ports is very inefficient. That produce "count" value beneath the zero and no maximum is found (Tibor assumed that the minimum is above zero).

When I run the tests again, another issue was found. Here is an output (slightly modified):

======
TEST CASE 5
======

PORTS:
Very basic port class.
SHIPS:
Tibor's algorithm for ship
------
END OF SIMULATION: time interrupt
150/1200 (12.5%) delivered
------
Total time: 40001.4
Mean utilization: 29.8092946171
Mean journey distance: 1092.15
Mean journey efficiency: 9.55608305016
Min journey efficiency: 273.455696203

PORTS:
First einstein's patch
SHIPS:
Tibor's algorithm for ship
------
END OF SIMULATION: time interrupt
86/1200 (7%) delivered
------
Total time: 40001.4
Mean utilization: 29.8099504514
Mean journey distance: 1095.425
Mean journey efficiency: 10.6925650075
Min journey efficiency: 274.544303797

PORTS:
Very basic port class.
SHIPS:
Very basic ship class.
------
Total time: 20334.6
Mean utilization: 17.5978586335
Mean journey distance: 323.243333333
Mean journey efficiency: 1.84243832456
Min journey efficiency: 10.6582278481

PORTS:
Very basic port class.
SHIPS:
Einstein's ships algorithm
------
Total time: 19864.8
Mean utilization: 17.9751887314
Mean journey distance: 325.410833333
Mean journey efficiency: 1.75600830263
Min journey efficiency: 6.7731092437

PORTS:
First einstein's patch
SHIPS:
Very basic ship class.
------
Total time: 18684.0
Mean utilization: 17.1782591415
Mean journey distance: 288.136666667
Mean journey efficiency: 1.57103443669
Min journey efficiency: 10.6582278481

PORTS:
First einstein's patch
SHIPS:
Einstein's ships algorithm
------
Total time: 19994.4
Mean utilization: 19.0557622525
Mean journey distance: 345.719166667
Mean journey efficiency: 1.92729432396
Min journey efficiency: 12.8571428571

First two outputs are about Tibor's ship algorithm with two algorithms for ports. In both cases simulation was interruped by time limits. My idea is that: full ship (30 wares) is going to the port where are many wares, AND all the wares are to other ports. Then the ship can go to other port where are many wares too and the situation is the same as before. The ship is going around two ports and nothing happens.

I am not sure if it happens now, but I will try to fix it in some time in the future.

So my conclusion is that Tibor's algorithm for ships needs some revision. I don't know if it is only python version, but C++ needs to be checked too.

Another conclusion is that my simpliest patch to port algorithm (here is the link) is making some mess. For example mixing it with algorithm for ships is not a good idea (worse results!), but mixing it with basic ships algorithm is making very good results! In this test even better than my algorithm for ships! Mixing this algorithm with new algorithm for ships is not a good idea- it makes lots of problems and efficiency is lower. Maybe in the future I will find another, better algorithm, more suited for ships?


EDIT:

I've provided simple patch: if there is more than 80% of capacity for a ship, it doesn't go to other ports than those that are in ship's wares list.

And to be more specific: plain Tibor's algorithm (without any other patch) is not the best approach for extreme cases (lots of wares at once + large distances). As I can imagine, most of cases where people are not happy with ships are those ones.

Simple tests modifications shows that for most of cases current approach (very simple port & ship algorithms) are good enough. For more complicated and extreme cases modifications can be helpful.

Edited: 2015-08-24, 22:30

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

Top Quote
einstein13
Avatar
Topic Opener
Joined: 2013-07-28, 23:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2015-08-26, 16:07

I've added few fixes, plus some statistic display possibility: markdown tables for statistics (when executing all experiments!). First row, first column is "P\S" what stands for "Port \ Ship": rows are for port algorithms, columns- ship algorithms. If someone has better idea for this abbreviation, I am open to it face-wink.png . The names for algorithms are supposed to be short:

  • Port classes:
    • Base - standard port algorithm in Build-18
    • einst1 - port algorithm introduced by me (einstein13, here)
  • Ship classes:
    • Base - standard ship algorithm in Build-18
    • Tibor1 - ship algorithm introduced by Tibor in his branch (with small fixes)
    • einst1 - ship algorithm introduced by me on this forum (einstein13, here and here)

I think that the results are quite clear. If not- please tell me.

Results for last test case in the project:

Game time when last ware reach destination

P\S Base Tibor1 einst1
Base 20330.0 24690.0 19860.0
einst1 18680.0 18670.0 19990.0

Mean ship utilization (how many wares are onboard)

P\S Base Tibor1 einst1
Base 17.6 22.13 17.98
einst1 17.18 19.83 19.06

Mean number of wares waiting in ports

P\S Base Tibor1 einst1
Base 69.84 64.06 67.06
einst1 64.93 64.38 69.81

Maximum number of wares waiting in ports

P\S Base Tibor1 einst1
Base 449 438 415
einst1 433 436 414

Mean length of journey for any ware

P\S Base Tibor1 einst1
Base 323.2 495.4 325.4
einst1 288.1 336.9 345.7

Mean value of efficiency (length_journey/minimum_possible_length) for any ware

P\S Base Tibor1 einst1
Base 1.842 2.728 1.756
einst1 1.571 1.922 1.927

Minimum value of efficiency (length_journey/minimum_possible_length) for any ware

P\S Base Tibor1 einst1
Base 10.66 29.7 6.773
einst1 10.66 73.63 12.86

Maximum time waiting for ware in port to take by a ship

P\S Base Tibor1 einst1
Base 18250.0 22530.0 17780.0
einst1 16600.0 16890.0 17910.0

Mean time waiting for ware in port to take by a ship

P\S Base Tibor1 einst1
Base 8869.0 10120.0 8359.0
einst1 7597.0 7619.0 8767.0

Minimum time waiting for ware in port to take by a ship

P\S Base Tibor1 einst1
Base 455.4 406.8 520.2
einst1 455.4 406.8 491.4

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

Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-08-28, 20:36

Hey, I was away for couple of days, I could read (on a mobile) but had no comfort way to respond :)

I think you stress your ships too much. Mean number of wares waiting in ports above 60 and Maximum number of wares waiting in ports above 400???? But this is totaly unrealistic! Please recalibrate your test so that average number of wares in port is in range 10-20 and maximum wares in port about 50. That reasonably mimics games conditions.

in regard to your einst1 port algorighm (picking specific wares from a port when loading a ship) - It for sure has huge effect when ports are overloaded by wares, but in more normal conditions - like I indicated above - its effect will be probably lesser.


Top Quote
Tibor

Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2015-08-28, 20:50

And yes, I got approval to merge my branch, but due to this discussion I will wait a bit with merging.....


Top Quote