Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#10290) rfc: city production circuit
Home

[Freeciv-Dev] (PR#10290) rfc: city production circuit

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#10290) rfc: city production circuit
From: "Benoit Hudson" <bh@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 23 Sep 2004 15:09:03 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10290 >

The city update code that computes the production surpluses given the
buildings, workers, specialists, etc is slow at the moment.  The CM code is
very good at avoiding calling that code, but could still be sped up
enormously were that code faster.  Also, it would be simplified a lot if
generic_city_refresh were sufficiently fast.  The same goes for other
what-if scenarios, other than just CM.

First of all, I can't find the gen-effects patch anywhere on RT.  Maybe
that's because I don't know what to search for, but if someone could point
me the right direction, that'd be appreciated.  I don't know how much I'm
repeating.


The idea is that the CM code and other what-if scenarios change only a
small part of the computation of the city refresh.  Therefore, recomputing
should only touch that small part.  The mechanism will be to have a file
that produces a graph.  For instance, I'll write out the part of the file
relating to shields production:
        factory_factor  = .5 * exists(factory);
        power_factor    = .5 * exists(factory) * exists(power);
        mfg_factor      = .5 * exists(factory) * exists(mfg_factor);
        industry_factor = factory_factor + power_factor + mfg_factor;
        industry        = input(shields) * industry_factor;
        indsurplus      = industry - input(unitupkeep);
        /* assume disorder has already been computed */
        output(shields-produced) = industry;
        output(shields-surplus)  = conditional_clip_max(indsurplus, 0, 
disorder);       
A what-if scenario that just wanted to check the new production if it built
a mfg plant could just call a function to add the mfg plant, then ask to
recompute the shields.  Given the graph, we can know when adding the mfg
plant that only mfg_factor, industry_factor and so on change, and we can
clear them.  Then, when asked to recompute the shields surplus, we know
that only depends on indsurplus and disorder, and work our way back until
all the values are initialized. 

Similarly, if the CM decides to change the allocation of workers, all it
would have to do is tell the city what the new food, shields, etc 
production was, and then ask for what the CM cares about.  Given that about
three quarters of the current city-update time is computing the production
and discovering what buildings and effects and so on exist, this idea
should greatly reduce the time to evaluate one solution from the CM.

Another effect of building the graph is that we could then easily invert
it and solve for the minimum inputs to achieve a certain output.  For
instance, how much food do we need to produce from tiles to be able to feed
the whole population and the settlers and still grow?  The CM can use this
to decide whether to ignore a whole class of possible solutions, and thus
reduce the number of city updates it needs.

Probably the coolest effect of the graph is that we can easily change the
rules quite drastically, perhaps even have this be in the ruleset.  With
all our what-if codes operating on the graph, we should be able to get them
all to use all sorts of assumptions (for speed) and yet still be correct
when we change the way city update computation works.


So the question now is: do people think this is worth implementing at the
moment? Or is the city code too variable still for another big patch to be
floating around?

        -- Benoît


[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#10290) rfc: city production circuit, Benoit Hudson <=