Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2001:
[Freeciv-Dev] [Patch] City management agent
Home

[Freeciv-Dev] [Patch] City management agent

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] [Patch] City management agent
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 6 Feb 2001 20:53:56 +0100
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxxxx

Hi,

Attached is the first version of the city management agent (CMA). It
includes:
 - the algorithmic core (client/agents/city_management)
 - a frontend for the GTK client (client/agents/city_management_frontend_gtk)
 - a method to wait for the final note (this allows it to serialize
   the communication)

The name my be choosen to broad. CMA only manages to people of a city.

event driven vs. serialized: At first I tried using an event driven
approach. I came up with a call chain of length 4 and constructs like
the following all over the place:

  typedef void (*fill_out_callback_function_t) (int city_id,
                                                struct cma_result * result,
                                                int user_data);

  struct fill_out_callback_data
  {
      int city_id;
      struct cma_result *result;
      fill_out_callback_function_t user_function;
      int user_data;
  };

  static void fill_out_result_arrived(int packet_type, int data_)
  {
    struct fill_out_callback_data *data=(struct fill_out_callback_data *)data_;

    ...

    data->user_function(data->city_id, data->result, data->user_data);
    free(data);
  }

This was really ugly. I switch to a serialized approach and the code
became much nicer. It is now possible to see the execution paths. The
call chain in the current version is:

  frontend caller -> cma_query_result -> optimize_final ->
  optimize_people -> maximize_trade -> test_extra_trade ->
  fill_out_result -> real_fill_out_result -> apply_result

So the call chain has a depth of nine. If this is implemented in an
event driven way each of these method will have to save and restore
their state.

performance: (all with a local server) with a city of size 8 and cold
caches:
  2: cma_query_result: overall=2.784365s waiting at network=2.614204s
  2: cma_query_result: requests=72 time per request=36.308000ms

So the agent waits 72 times for the server. This are 94% of the total
time. If the agent waits for each packet individually the time per
request is constant 20ms+-1ms. So there may be some constant overhead
in the network stac of the OS or in the freeciv client/server.

The goal is to minize network usage. Currently the server is used to
determine if a field can be used for a worker and to get the real
production and other stats (disorder) of the city. To speed the agent
up if may be possible to calculate these things in the agent. However
I don't want massiv code duplication. Nevertheless the uses are well
encapsulated in real_can_field_be_used_for_worker() and
fill_out_result().

Another approach to speed up the agent is to remove the serialization
and to manage cities in parallel. However I won't do this. See
callbacks above.

luxury: I would like to enable the agent to show the extra luxury
production which isn't needed to make the city peaceful. I have no
clue in which way the happiness of a city is calculated. It would also
be nice to show the luxury surplus in terms of a celebrating city. So
this could end up with a string like this: "luxury: 15(+10)(-2)" which
means a total production of 15. 15-10 are needed to make to city
peaceful and if the production would be 15+2 the city would celebrate.

TODO:
 - remove CACHE1 (it is obsolete by CACHE3)
 - it my possible to implement real_can_field_be_used_for_worker() in
   the agent; think about it
 - wait for feedback

I would especially like to get feedback on the algorithmic part. So if
the agent doesn't find the ideal solution please let me know. Please
consider that the minial surplus for every choice it set to 0 except
by the "w/o gold limit" options.

technical stuff: the patch has to be applied on top of the current
attribute and note patch. A merged patch of these two is attached.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
  Tank: So what do you need? Besides a miracle.
  Neo: Guns. Lots of guns.
    -- From The Matrix

Attachment: attribute_client_and_server-1_merged_with_note-6.diff.gz
Description: GNU Zip compressed data

Attachment: cma-1.diff.gz
Description: GNU Zip compressed data


[Prev in Thread] Current Thread [Next in Thread]