The International Simutrans Forum

 

Author Topic: [patch] new goods ai using the network to pass on goods (incomplete)  (Read 5884 times)

0 Members and 1 Guest are viewing this topic.

Offline TimWintle

  • *
  • Posts: 16
This suffers from one major flaw, but since I probably won't find any time to improve it for quite a while I thought I would post it and see if anyone else could find a work-around.

This patch adds a new goods ai (and adds it to the makefile, player menu etc.), heavily based on the existing one, but with the following changes:

 * Looks at the time it will take to make an ROI when deciding to use rail or road
 * changed calculation of ships required to be slightly lower
 * When deciding on a route, it looks to see if there is a factory nearby that is already transporting that type of good to the target. If there is then it will attempt to connect to that factory instead so that the original connection can be used to transport goods for part of the route. This can significantly reduce the cost of building a new route, and reduce congestion etc.

The issue is that it assumes that when it connects to the factory in between, it will end up building a station that is part of the one where goods are transported to the final destination from. I assume this should be easy enough to fix by ensuring that the station is built next to the existing one, or by building some form of station tiles in between before building the final station.

It does work correctly roughly 1/3 of the time, but the other 2/3 need to be ironed out.

I will attach some screenshots to show what I mean.


Offline TimWintle

  • *
  • Posts: 16
Re: [patch] new goods ai using the network to pass on goods (incomplete)
« Reply #1 on: February 22, 2009, 11:50:09 PM »
The attached screenshots show two examples of the problem.


(1) Screenshot.jpg
the stations on the left were already there (except the one with the right arrow on it) when the ai decided to build the one with the arrow on the right.

The left arrow shows a connection from boxed goods from a windmill to a market.

On the right there is a brewery, and the ai decided to ship boxed goods from there to the market, via the windmill. Unfortunately it build the target station (on the left of the right arrow) next to the incorrect station, and so the connection was incomplete.


(2) Screenshot-1.jpg
The road connection on the right was already built (shipping bulk goods to the iron foundary from the ore mine).
Instead of shipping goods from the coal mine to the iron factory directly, it decided to ship them to the ore mine, so that the trucks could take them the rest of the way. Unfortunately the station that it built did not connect with the existing station.

As I said, I am sure that it should be quite fixable, and I am not likely to get any more time to spend on this for a few weeks, so I thought someone else might like to have a go at finishing it.

Tim

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4877
  • Languages: EN, DE, AT
Re: [patch] new goods ai using the network to pass on goods (incomplete)
« Reply #2 on: February 23, 2009, 06:22:28 AM »
At least, someone is working on AI :)

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10663
  • Languages: De,EN,JP
Re: [patch] new goods ai using the network to pass on goods (incomplete)
« Reply #3 on: February 23, 2009, 01:33:18 PM »
Checking for connection should be not too difficult anyway. Great to see somebody is working on a new AI!

Offline TimWintle

  • *
  • Posts: 16
Re: [patch] new goods ai using the network to pass on goods (incomplete)
« Reply #4 on: February 23, 2009, 02:55:21 PM »
It currently checks for a connection from the factory - the issue is that it has to choose the end-point for the station to be next to the station that serves the factory and has that connection.

I'm still only just getting to know the code, so I wasn't sure how to do that, but I think it should be fairly easy for someone who knows the code.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10663
  • Languages: De,EN,JP
Re: [patch] new goods ai using the network to pass on goods (incomplete)
« Reply #5 on: February 23, 2009, 04:01:22 PM »
halt->suche_route() [with a good package that has the correct destination] will give you an answer. You can find a similar way in simfabrik.cc, where the goods are actually put en route.

Offline TimWintle

  • *
  • Posts: 16
Re: [patch] new goods ai using the network to pass on goods (incomplete)
« Reply #6 on: February 24, 2009, 09:57:55 PM »
Right I've found an hour or two and I'm almost done (I hope),

But I'm getting the error

Code: [Select]
player/ai_goods_tim.cc:1314: error: no matching function for call to ‘haltestelle_t::suche_route(const ware_besch_t*&, koord*)’
player/../simhalt.h:355: note: candidates are: void haltestelle_t::suche_route(ware_t&, koord*)

when calling "welt->lookup_kartenboden(platz)->get_halt()->suche_route(freight,&target)". Haven't really used C++ much, but I'm assuming that's because I need a ware_t object. How can I get that from "freight" (which is a ware_besch_t) ?

Thanks

(edit - switched around ware_t and ware_besch_t in my question)

Offline TimWintle

  • *
  • Posts: 16
Re: [patch] new goods ai using the network to pass on goods (incomplete)
« Reply #7 on: February 24, 2009, 10:22:58 PM »
Ah, I found it

Code: [Select]
ware_t ware(freight);


Offline TimWintle

  • *
  • Posts: 16
Re: [patch] new goods ai using the network to pass on goods (incomplete)
« Reply #8 on: February 25, 2009, 12:44:05 AM »
(Sorry for the tripple post)
I think I just realised something  when I was testing it (now I've got it compiling and kind of working),

Does suche_route() only work if the good I look with is one there is already a line for?

i.e. if I have

       iron ore
A<---------->B                       C

and C produces coal then I am testing the connection between A and B for coal. Will suche_route() only find a route between A and B for iron ore, not for other bulk goods?

If so, is there an easy way to iterate through all the bulk goods so I can check them one by one?

Thanks.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4877
  • Languages: EN, DE, AT
Re: [patch] new goods ai using the network to pass on goods (incomplete)
« Reply #9 on: February 25, 2009, 06:17:43 AM »
imho suche_route() only looks for the ware categories (ie bulk) and not for a certain good. All vehicles, convois etc are made to transport _all_ goods from a certain category.