Discussion:
[Freecol-developers] enhanced trade routes
Michael T. Pope
2015-10-27 09:23:56 UTC
Permalink
A while back I mentioned that I was working on improvements to trade
routes. This work has just been committed. All new functionality is
gated by the new "Enhanced Trade Routes" option which is marked as
experimental. Nevertheless, it is reasonably well tested in a quite
complex game and has held up well so far, so I have taken the opportunity
to commit it now at this early point in the release cycle. Of course, I
have probably forgotten something, so beware of trade route strangeness.

The new functionality has two parts. The first part attempts to maximize
the amount of goods transferred and prevent warehouse overflows, by taking
account of the production at the point of delivery and the expected time
to make the delivery. The second part adds an Import Level setting to
the WarehouseDialog, such that trade route units will never unload more
than this amount --- I set this to "40 tools" in the late game, where you
want to make sure a bunch of colonies get regularly supplied with what
they need to keep building artillery.

Cheers,
Mike Pope
w***@genial.ms
2015-10-30 15:51:44 UTC
Permalink
Hi,

I can't say much about traderoutes, as I somehow tend to micromanage that
myself if I'm playing FreeCol, which is kinda weird as I was extensively
using traderoutes in Patrician 2/3.
Anyway, I just loaded an old savegame from an old BR (I'm sure you kept it
as 3a6413be_Espanyol_1774_1_PrimaveraSendToSF.fsg was the largest game I
ever saw). It contains very many traderoutes and I tried to end the turn.
It started processing these and moved some wagons around, but then stopped
and I had to hit enter and accept the end-turn-dialog again and again and ...
Could that be a regression from these changes?

NB, I guess you are working on many of your own changes you delayed until
the release, but did you have a look at the commandline and AI changes
on my fork meanwhile? I based my other changes on the aicleanup branch,
but they are not pushed yet and only like 30% done.


Greetings,

wintertime



> Gesendet: Dienstag, 27. Oktober 2015 um 10:23 Uhr
> Von: "Michael T. Pope" <***@computer.org>
>
> A while back I mentioned that I was working on improvements to trade
> routes. This work has just been committed. All new functionality is
> gated by the new "Enhanced Trade Routes" option which is marked as
> experimental. Nevertheless, it is reasonably well tested in a quite
> complex game and has held up well so far, so I have taken the opportunity
> to commit it now at this early point in the release cycle. Of course, I
> have probably forgotten something, so beware of trade route strangeness.
>
> The new functionality has two parts. The first part attempts to maximize
> the amount of goods transferred and prevent warehouse overflows, by taking
> account of the production at the point of delivery and the expected time
> to make the delivery. The second part adds an Import Level setting to
> the WarehouseDialog, such that trade route units will never unload more
> than this amount --- I set this to "40 tools" in the late game, where you
> want to make sure a bunch of colonies get regularly supplied with what
> they need to keep building artillery.
>
> Cheers,
> Mike Pope

------------------------------------------------------------------------------
Michael T. Pope
2015-11-03 07:40:20 UTC
Permalink
On Sat, 31 Oct 2015 23:21:07 +0100
***@genial.ms wrote:
>[enhanced trade routes patch causes fail]

Its looking better with the trade route unit selection simplification in
git.3592f3f. I did find one stupid NPE along the way too.

> What I found strange in AIColony was mostly how the worker wishes get created
> when less than 6 experts are there while most buildings have just 3 spots,

I do not understand where the 6 experts effect is coming from.

> how
> colonies with the least need as they have most experts already get higher
> priority,

Yes, that favours the stronger colonies. IIRC there were problems with
too many experts being sent out to the low population colonies before
optimizing the really productive ones. However that was a long time ago
when the AI was much more prone to found lots of small colonies, and can
probably be revisited.

> how workerwishes never get deleted,

WishRealizatioMission calls completeWish which deletes wishes. Is this not
happening?

Cheers,
Mike Pope
w***@genial.ms
2015-11-04 20:37:50 UTC
Permalink
Hi,

I had written that from memory and reread the code in AIColony now.

> Gesendet: Dienstag, 03. November 2015 um 08:40 Uhr
> Von: "Michael T. Pope" <***@computer.org>
>
> On Sat, 31 Oct 2015 23:21:07 +0100
> ***@genial.ms wrote:
> > What I found strange in AIColony was mostly how the worker wishes get created
> > when less than 6 experts are there while most buildings have just 3 spots,
>
> I do not understand where the 6 experts effect is coming from.

I slightly misremembered, it increases the request priority for up to 6
experts, but I found no check which could stop requesting more when all work
locations in buildings or tiles are filled.

> > how
> > colonies with the least need as they have most experts already get higher
> > priority,
>
> Yes, that favours the stronger colonies. IIRC there were problems with
> too many experts being sent out to the low population colonies before
> optimizing the really productive ones. However that was a long time ago
> when the AI was much more prone to found lots of small colonies, and can
> probably be revisited.

Together with what I wrote above I assume a single colony could suck up all
experts of one type leaving none for other colonies.
I think it should prioritize based on higherlevel buildings standing in the
colony, and as a tie breaker on input material production.

> > how workerwishes never get deleted,
>
> WishRealizatioMission calls completeWish which deletes wishes. Is this not
> happening?

Sorry, when writing this I did not think of distinguishing deletion of
outdated wishes which for some reason the colony does not need anymore
(for example the forests got cut down and no more trappers or woodcutters
needed or higher level materials stopped being produced there for some reason),
which I was writing about, from cleaning up fulfilled wishes.
updateGoodsWishes deletes outdated wishes, updateWorkerWishes does not
(sometimes when the loop checking if expers are needed finds none,
the fallback pop increase loop might accidentally downgrade an old wish
to non-expert though other old wishes from former turns are never removed).


Greetings,

wintertime

------------------------------------------------------------------------------
Michael T. Pope
2015-11-05 21:19:37 UTC
Permalink
On Wed, 4 Nov 2015 21:37:50 +0100
***@genial.ms wrote:
> I slightly misremembered, it increases the request priority for up to 6
> experts, but I found no check which could stop requesting more when all work
> locations in buildings or tiles are filled.

OK, that makes sense. I think its 5 experts though (multipleMax). You
are right though that there should be a brake on this to stop requesting
when there are plenty of experts, and it should also be suppressed when
the bonus would be reduced. In practice though, colonies change their
production priorities moderately often, so many wishes (should:-) get
dropped.

> Together with what I wrote above I assume a single colony could suck up all
> experts of one type leaving none for other colonies.
> I think it should prioritize based on higherlevel buildings standing in the
> colony, and as a tie breaker on input material production.

IMHO the expert should go where it can have most effect. When the big
AIColony rewrite was done, that was very hard to work out. The production
code has since been improved, and it should be easier.

> > > how workerwishes never get deleted,
> >
> > WishRealizatioMission calls completeWish which deletes wishes. Is this not
> > happening?
>
> Sorry, when writing this I did not think of distinguishing deletion of
> outdated wishes which for some reason the colony does not need anymore
> (for example the forests got cut down and no more trappers or woodcutters
> needed or higher level materials stopped being produced there for some reason),
> which I was writing about, from cleaning up fulfilled wishes.
> updateGoodsWishes deletes outdated wishes, updateWorkerWishes does not

Goods do not have missions (although a bunch of code would be nicer if
they did), so they need special handling in updateGoodsWishes.
WishRealizationMission cleans up completed worker wishes because it is in
control when the wish is completed.

Anyway, my reservations aside, there is certainly enough substance here
that this area could do with a revisit. I have got as far as grabbing and
reading your aicleanup patch, and expect to start merging it soon. BTW,
why in an abstract class like AIPlayer do you want to have methods with
empty implementations (i.e. "{}"). Surely declaring them abstract
is clearer?

Cheers,
Mike Pope
w***@genial.ms
2015-11-06 07:46:22 UTC
Permalink
Hi,

> Gesendet: Donnerstag, 05. November 2015 um 22:19 Uhr
> Von: "Michael T. Pope" <***@computer.org>
>
> On Wed, 4 Nov 2015 21:37:50 +0100
> ***@genial.ms wrote:
> OK, that makes sense. I think its 5 experts though (multipleMax). You
> are right though that there should be a brake on this to stop requesting
> when there are plenty of experts, and it should also be suppressed when
> the bonus would be reduced. In practice though, colonies change their
> production priorities moderately often, so many wishes (should:-) get
> dropped.

There is a -1 to the number of experts before the maximum is taken, so
the result can increase for up to 6.
I think reducing that 6 to 3 is better.

> > Together with what I wrote above I assume a single colony could suck up all
> > experts of one type leaving none for other colonies.
> > I think it should prioritize based on higherlevel buildings standing in the
> > colony, and as a tie breaker on input material production.
>
> IMHO the expert should go where it can have most effect. When the big
> AIColony rewrite was done, that was very hard to work out. The production
> code has since been improved, and it should be easier.

Yeah, when I play my thinking is "find colony/workplace where this expert
produces most stuff and arrange for raw materials" not "look at each colony
what it could use then calculate some priorities". This is one of the things
I hope can be improved someday.

> > > > how workerwishes never get deleted,
> > >
> > > WishRealizatioMission calls completeWish which deletes wishes. Is this not
> > > happening?
> >
> > Sorry, when writing this I did not think of distinguishing deletion of
> > outdated wishes which for some reason the colony does not need anymore
> > (for example the forests got cut down and no more trappers or woodcutters
> > needed or higher level materials stopped being produced there for some reason),
> > which I was writing about, from cleaning up fulfilled wishes.
> > updateGoodsWishes deletes outdated wishes, updateWorkerWishes does not
>
> Goods do not have missions (although a bunch of code would be nicer if
> they did), so they need special handling in updateGoodsWishes.
> WishRealizationMission cleans up completed worker wishes because it is in
> control when the wish is completed.

Goods have transport missions, but thats besides the point. I was writing
of Wishes which can not be easiliy fulfilled, never get assigned to a mission
and then should be deleted by the AIColony when the conditions change.

> Anyway, my reservations aside, there is certainly enough substance here
> that this area could do with a revisit. I have got as far as grabbing and
> reading your aicleanup patch, and expect to start merging it soon. BTW,
> why in an abstract class like AIPlayer do you want to have methods with
> empty implementations (i.e. "{}"). Surely declaring them abstract
> is clearer?

Normally yes, but I decided it would be cleaner that way:
- removeAIColony and removeAIUnit are optional hooks for when an AIPlayer
is creating more data structures. Both get overwritten only once and I
think in that case its better to provide a sensible default than force
duplicated dummy implementations.
- getNeededWagons, scoutsNeeded and completeWish are necessary to avoid
type testing for EuropeanAIPlayer (and resulting crashes in alternative
AI-implementations), mainly in AIColony, AIUnit and some Missions.
Some tests sadly do that, too, and I still need to figure out a solution
for these.
As native players are not using AIColony and have that ai-settlement code
inline (and its problematic as multiple inheritance would not work, but
adding an interface would clutter the code more and require type testing
for the hypothetical weird EuropeanAIColonyCallbacks interface in AIColony),
its currently better to provide dummy methods in the AIPlayer base class
(until other code can be reorganized, if even possible).


Greetings,

wintertime

------------------------------------------------------------------------------
Loading...