Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

…lines 1–341 unchanged (341 lines)
342/************************************************************************//**
343 Create a new cm_result.
344****************************************************************************/
345struct cm_result *cm_result_new(struct city *pcity)
346{
347 struct cm_result *result;
348
349 /* initialise all values */
350 result = fc_calloc(1, sizeof(*result));
351 result->city_radius_sq = pcity ? city_map_radius_sq_get(pcity)
352 : CITY_MAP_MAX_RADIUS_SQ;
353 result->worker_positions
354 = fc_calloc(city_map_tiles(result->city_radius_sq),
355 sizeof(*result->worker_positions));
356
357 /* test if the city pointer is valid; the cm_result struct can be
358 * returned as it uses the maximal possible value for the size of
359 * 'worker_positions' (= city_map_tiles(CITY_MAP_MAX_RADIUS_SQ))*/
360 fc_assert_ret_val(pcity != NULL, result);
361
362 return result;
363}
364
365/************************************************************************//**
366 Destroy a cm_result.
367****************************************************************************/
368void cm_result_destroy(struct cm_result *result)
369{
370 if (result != NULL) {
371 if (result->worker_positions != NULL) {
372 FC_FREE(result->worker_positions);
373 }
374 FC_FREE(result);
375 }
376}
377
…lines 378–551 unchanged (174 lines)
552 as a lookup.
553****************************************************************************/
554static const struct cm_tile_type *tile_type_get(const struct cm_state *state,
555 int type)
556{
557 /* Sanity check the index. */
558 fc_assert_ret_val(0 <= type, NULL);
559 fc_assert_ret_val(state->lattice.size > type, NULL);
560
561 return state->lattice.p[type];
562}
563
564/************************************************************************//**
565 Retrieve a tile of a particular type by index. For a given tile type
566 there are a certain number of tiles (1 or more), which may be iterated
567 over using this function for index. Don't call this for is_specialist
568 types. See also tile_type_num_tiles().
569****************************************************************************/
570static const struct cm_tile *tile_get(const struct cm_tile_type *ptype, int j)
571{
572 fc_assert_ret_val(!ptype->is_specialist, NULL);
573 fc_assert_ret_val(0 <= j, NULL);
574 fc_assert_ret_val(j < ptype->tiles.size, NULL);
575
576 return &ptype->tiles.p[j];
577}
578
579
580/****************************************************************************
…lines 581–2019 unchanged (1439 lines)
2020 timer_stop(performance.current->wall_timer);
2021
2022#ifdef PRINT_TIME_STATS_EVERY_QUERY
2023 print_performance(performance.current);
2024#endif /* PRINT_TIME_STATS_EVERY_QUERY */
2025
2026 performance.current = NULL;
2027#endif /* GATHER_TIME_STATS */
2028}
2029
2030/************************************************************************//**
2031 Release all the memory allocated by the state.
2032****************************************************************************/
…lines 2033–2125 unchanged (93 lines)
2126 struct cm_state *state = cm_state_init(pcity, negative_ok);
2127 const struct civ_map *nmap = &(wld.map);
2128
2129 /* Refresh the city. Otherwise the CM can give wrong results or just be
2130 * slower than necessary. Note that cities are often passed in in an
2131 * unrefreshed state (which should probably be fixed). */
2132 city_refresh_from_main_map(nmap, pcity, NULL);
2133
2134 cm_find_best_solution(state, param, result, negative_ok);
2135 cm_state_free(state);
2136}
2137
2138/************************************************************************//**
…lines 2139–2257 unchanged (119 lines)
2258 Copy the city's current setup into the cm result structure. Wrapper for
2259 cm_result_main().
2260****************************************************************************/
2261void cm_result_from_main_map(struct cm_result *result,
2262 const struct city *pcity)
2263{
2264 cm_result_copy(result, pcity, NULL);
2265}
2266
2267/************************************************************************//**
2268 Copy the city's current setup into the cm result structure. 'workers_map'
2269 is a bool array with the size city_map_tiles_from_city(pcity). It is TRUE
2270 for tiles worked by the city.
…lines 2271–2277 unchanged (7 lines)
2278 /* Clear worker positions */
2279 memset(result->worker_positions, 0,
2280 sizeof(*result->worker_positions)
2281 * city_map_tiles(result->city_radius_sq));
2282
2283 city_tile_iterate_index(nmap, result->city_radius_sq, pcenter, ptile, ctindex) {
2284 if (workers_map == NULL) {
2285 /* Use the main map */
2286 struct city *pwork = tile_worked(ptile);
2287
2288 result->worker_positions[ctindex] = (NULL != pwork && pwork == pcity);
2289 } else {
2290 result->worker_positions[ctindex] = workers_map[ctindex];
2291 }
2292 } city_tile_iterate_index_end;
2293
2294 /* Copy the specialist counts */
…lines 2295–2438 unchanged (144 lines)
2439
2440 log_test(" workers at:");
2441 city_tile_iterate_index(nmap, city_map_radius_sq_get(pcity), pcenter, ptile,
2442 cindex) {
2443 struct city *pwork = tile_worked(ptile);
2444
2445 if (NULL != pwork && pwork == pcity) {
2446 int cx, cy;
2447
2448 city_tile_index_to_xy(&cx, &cy, cindex,
2449 city_map_radius_sq_get(pcity));
2450 log_test(" {%2d,%2d} (%4d,%4d)", cx, cy, TILE_XY(ptile));
2451 }
2452 } city_tile_iterate_index_end;
2453
2454 log_test(" food = %3d (%+3d)",
2455 pcity->prod[O_FOOD], pcity->surplus[O_FOOD]);
2456 log_test(" shield = %3d (%+3d)",
2457 pcity->prod[O_SHIELD], pcity->surplus[O_SHIELD]);
…lines 2458–2498 unchanged (41 lines)

After

…lines 1–341 unchanged (341 lines)
342/************************************************************************//**
343 Create a new cm_result.
344****************************************************************************/
345struct cm_result *cm_result_new(struct city *pcity)
346{
347 struct cm_result *result;
348
349 /* Initialise all values */
350 result = fc_calloc(1, sizeof(*result));
351 result->city_radius_sq = pcity ? city_map_radius_sq_get(pcity)
352 : CITY_MAP_MAX_RADIUS_SQ;
353 result->worker_positions
354 = fc_calloc(city_map_tiles(result->city_radius_sq),
355 sizeof(*result->worker_positions));
356
357 /* Test if the city pointer is valid; the cm_result struct can be
358 * returned as it uses the maximal possible value for the size of
359 * 'worker_positions' (= city_map_tiles(CITY_MAP_MAX_RADIUS_SQ))*/
360 fc_assert_ret_val(pcity != nullptr, result);
361
362 return result;
363}
364
365/************************************************************************//**
366 Destroy a cm_result.
367****************************************************************************/
368void cm_result_destroy(struct cm_result *result)
369{
370 if (result != nullptr) {
371 if (result->worker_positions != nullptr) {
372 FC_FREE(result->worker_positions);
373 }
374 FC_FREE(result);
375 }
376}
377
…lines 378–551 unchanged (174 lines)
552 as a lookup.
553****************************************************************************/
554static const struct cm_tile_type *tile_type_get(const struct cm_state *state,
555 int type)
556{
557 /* Sanity check the index. */
558 fc_assert_ret_val(0 <= type, nullptr);
559 fc_assert_ret_val(state->lattice.size > type, nullptr);
560
561 return state->lattice.p[type];
562}
563
564/************************************************************************//**
565 Retrieve a tile of a particular type by index. For a given tile type
566 there are a certain number of tiles (1 or more), which may be iterated
567 over using this function for index. Don't call this for is_specialist
568 types.
569 See also tile_type_num_tiles().
570****************************************************************************/
571static const struct cm_tile *tile_get(const struct cm_tile_type *ptype, int j)
572{
573 fc_assert_ret_val(!ptype->is_specialist, nullptr);
574 fc_assert_ret_val(0 <= j, nullptr);
575 fc_assert_ret_val(j < ptype->tiles.size, nullptr);
576
577 return &ptype->tiles.p[j];
578}
579
580
581/****************************************************************************
…lines 582–2020 unchanged (1439 lines)
2021 timer_stop(performance.current->wall_timer);
2022
2023#ifdef PRINT_TIME_STATS_EVERY_QUERY
2024 print_performance(performance.current);
2025#endif /* PRINT_TIME_STATS_EVERY_QUERY */
2026
2027 performance.current = nullptr;
2028#endif /* GATHER_TIME_STATS */
2029}
2030
2031/************************************************************************//**
2032 Release all the memory allocated by the state.
2033****************************************************************************/
…lines 2034–2126 unchanged (93 lines)
2127 struct cm_state *state = cm_state_init(pcity, negative_ok);
2128 const struct civ_map *nmap = &(wld.map);
2129
2130 /* Refresh the city. Otherwise the CM can give wrong results or just be
2131 * slower than necessary. Note that cities are often passed in in an
2132 * unrefreshed state (which should probably be fixed). */
2133 city_refresh_from_main_map(nmap, pcity, nullptr);
2134
2135 cm_find_best_solution(state, param, result, negative_ok);
2136 cm_state_free(state);
2137}
2138
2139/************************************************************************//**
…lines 2140–2258 unchanged (119 lines)
2259 Copy the city's current setup into the cm result structure. Wrapper for
2260 cm_result_main().
2261****************************************************************************/
2262void cm_result_from_main_map(struct cm_result *result,
2263 const struct city *pcity)
2264{
2265 cm_result_copy(result, pcity, nullptr);
2266}
2267
2268/************************************************************************//**
2269 Copy the city's current setup into the cm result structure. 'workers_map'
2270 is a bool array with the size city_map_tiles_from_city(pcity). It is TRUE
2271 for tiles worked by the city.
…lines 2272–2278 unchanged (7 lines)
2279 /* Clear worker positions */
2280 memset(result->worker_positions, 0,
2281 sizeof(*result->worker_positions)
2282 * city_map_tiles(result->city_radius_sq));
2283
2284 city_tile_iterate_index(nmap, result->city_radius_sq, pcenter, ptile, ctindex) {
2285 if (workers_map == nullptr) {
2286 /* Use the main map */
2287 struct city *pwork = tile_worked(ptile);
2288
2289 result->worker_positions[ctindex] = (pwork != nullptr && pwork == pcity);
2290 } else {
2291 result->worker_positions[ctindex] = workers_map[ctindex];
2292 }
2293 } city_tile_iterate_index_end;
2294
2295 /* Copy the specialist counts */
…lines 2296–2439 unchanged (144 lines)
2440
2441 log_test(" workers at:");
2442 city_tile_iterate_index(nmap, city_map_radius_sq_get(pcity), pcenter, ptile,
2443 cindex) {
2444 struct city *pwork = tile_worked(ptile);
2445
2446 if (pwork != nullptr && pwork == pcity) {
2447 int cx, cy;
2448
2449 city_tile_index_to_xy(&cx, &cy, cindex,
2450 city_map_radius_sq_get(pcity));
2451 log_test(" {%2d,%2d} (%4d,%4d)", cx, cy, TILE_XY(ptile));
2452 }
2453 } city_tile_iterate_index_end;
2454
2455 log_test(" food = %3d (%+3d)",
2456 pcity->prod[O_FOOD], pcity->surplus[O_FOOD]);
2457 log_test(" shield = %3d (%+3d)",
2458 pcity->prod[O_SHIELD], pcity->surplus[O_SHIELD]);
…lines 2459–2499 unchanged (41 lines)

Before

translation_unit
comment "/***********************************************************"...
preproc_ifdef
#ifdef "#ifdef"
identifier "HAVE_CONFIG_H"
preproc_include
#include "#include"
system_lib_string "<fc_config.h>"
#endif "#endif"
preproc_include
#include "#include"
system_lib_string "<stdlib.h>"
preproc_include
#include "#include"
system_lib_string "<string.h>"
comment "/* utility */"
preproc_include
#include "#include"
string_literal
" "\""
string_content "fcintl.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "log.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "mem.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "shared.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "support.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "timing.h"
" "\""
comment "/* common */"
preproc_include
#include "#include"
string_literal
" "\""
string_content "city.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "game.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "government.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "map.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "specialist.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "cm.h"
" "\""
comment "/*\n * Terms used\n * ==========\n *\n * Stats: food, shields, t"...
comment "/***********************************************************"...
comment "/* If this is uncommented, research loop runs without limit "...
comment "/* #define CM_LOOP_NO_LIMIT */"
comment "/* Maximal iterations before the search loop is stopped, or "...
preproc_def
#define "#define"
identifier "CM_MAX_LOOP"
preproc_arg "27500"
preproc_def
#define "#define"
identifier "CPUHOG_CM_MAX_LOOP"
preproc_arg "(CM_MAX_LOOP * 4)"
preproc_ifdef
#ifdef "#ifdef"
identifier "DEBUG_TIMERS"
preproc_def
#define "#define"
identifier "GATHER_TIME_STATS"
#endif "#endif"
preproc_ifdef
#ifdef "#ifdef"
identifier "FREECIV_DEBUG"
preproc_def
#define "#define"
identifier "CM_DEBUG"
#endif "#endif"
comment "/* Whether to print every query, or just at cm_free ; matter"...
preproc_def
#define "#define"
identifier "PRINT_TIME_STATS_EVERY_QUERY"
preproc_def
#define "#define"
identifier "LOG_TIME_STATS"
preproc_arg "LOG_DEBUG"
preproc_def
#define "#define"
identifier "LOG_CM_STATE"
preproc_arg "LOG_DEBUG"
preproc_def
#define "#define"
identifier "LOG_LATTICE"
preproc_arg "LOG_DEBUG"
preproc_def
#define "#define"
identifier "LOG_REACHED_LEAF"
preproc_arg "LOG_DEBUG"
preproc_def
#define "#define"
identifier "LOG_BETTER_LEAF"
preproc_arg "LOG_DEBUG"
preproc_def
#define "#define"
identifier "LOG_PRUNE_BRANCH"
preproc_arg "LOG_DEBUG"
preproc_ifdef (+74 nodes collapsed)
comment "/* GATHER_TIME_STATS */"
comment "/* Fitness of a solution. */"
struct_specifier
struct "struct"
type_identifier "cm_fitness"
field_declaration_list
{ "{"
field_declaration
primitive_type "int"
field_identifier "weighted"
; ";"
comment "/* weighted sum */"
field_declaration
primitive_type "bool"
field_identifier "sufficient"
; ";"
comment "/* false => doesn't meet constraints */"
} "}"
; ";"
comment "/*\n * We have a cyclic structure here, so we need to forward"...
struct_specifier
struct "struct"
type_identifier "cm_tile_type"
; ";"
struct_specifier
struct "struct"
type_identifier "cm_tile"
; ";"
comment "/*\n * A tile. Has a pointer to the type, and the x/y coords"...
struct_specifier (+21 nodes collapsed)
; ";"
comment "/* define the tile_vector as array<cm_tile> */"
preproc_def
#define "#define"
identifier "SPECVEC_TAG"
preproc_arg "tile"
preproc_def
#define "#define"
identifier "SPECVEC_TYPE"
preproc_arg "struct cm_tile"
preproc_include
#include "#include"
string_literal
" "\""
string_content "specvec.h"
" "\""
comment "/* define the tile_type_vector as array <cm_tile_type*> */"
preproc_def
#define "#define"
identifier "SPECVEC_TAG"
preproc_arg "tile_type"
preproc_def
#define "#define"
identifier "SPECVEC_TYPE"
preproc_arg "struct cm_tile_type *"
preproc_include
#include "#include"
string_literal
" "\""
string_content "specvec.h"
" "\""
preproc_function_def
#define "#define"
identifier "tile_type_vector_iterate"
preproc_params
( "("
identifier "vector"
, ","
identifier "var"
) ")"
preproc_arg "{ \\\n struct cm_tile_type *var; \\\n TYPED_VECTOR_ITERATE"...
preproc_def
#define "#define"
identifier "tile_type_vector_iterate_end"
preproc_arg "}} VECTOR_ITERATE_END; }"
comment "/*\n * A tile type.\n * Holds the production (a hill produces "...
struct_specifier (+57 nodes collapsed)
; ";"
comment "/*\n * A partial solution.\n * Has the count of workers assign"...
struct_specifier (+35 nodes collapsed)
; ";"
comment "/*\n * State of the search.\n * This holds all the information"...
struct_specifier (+99 nodes collapsed)
; ";"
comment "/* return #fields + specialist types */"
declaration
storage_class_specifier
static "static"
primitive_type "int"
function_declarator
identifier "num_types"
parameter_list
( "("
parameter_declaration
type_qualifier
const "const"
struct_specifier
struct "struct"
type_identifier "cm_state"
pointer_declarator
* "*"
identifier "state"
) ")"
; ";"
comment "/* debugging functions */"
preproc_ifdef (+224 nodes collapsed)
comment "/* CM_DEBUG */"
declaration (+33 nodes collapsed)
declaration (+28 nodes collapsed)
declaration (+25 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Initialize the CM data at the start of each game. Not"...
function_definition (+115 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Initialize the CM citymap data. This function is call"...
function_definition
primitive_type "void"
function_declarator
identifier "cm_init_citymap"
parameter_list
( "("
parameter_declaration
primitive_type "void"
) ")"
compound_statement
{ "{"
comment "/* In the B&B algorithm there's not really anything to initi"...
} "}"
comment "/***********************************************************"...
comment "/**\n Clear the cache for a city.\n**************************"...
function_definition
primitive_type "void"
function_declarator
identifier "cm_clear_cache"
parameter_list
( "("
parameter_declaration
struct_specifier
struct "struct"
type_identifier "city"
pointer_declarator
* "*"
identifier "pcity"
) ")"
compound_statement
{ "{"
comment "/* The B&B algorithm doesn't have city caches so there's not"...
} "}"
comment "/***********************************************************"...
comment "/**\n Called at the end of a game to free any CM data.\n*****"...
function_definition (+90 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Create a new cm_result.\n******************************"...
function_definition
struct_specifier
struct "struct"
type_identifier "cm_result"
pointer_declarator
* "*"
function_declarator
identifier "cm_result_new"
parameter_list
( "("
parameter_declaration
struct_specifier
struct "struct"
type_identifier "city"
pointer_declarator
* "*"
identifier "pcity"
) ")"
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "cm_result"
pointer_declarator
* "*"
identifier "result"
; ";"
comment "/* initialise all values */"
expression_statement
assignment_expression
identifier "result"
= "="
call_expression
identifier "fc_calloc"
argument_list
( "("
number_literal "1"
, ","
sizeof_expression
sizeof "sizeof"
parenthesized_expression
( "("
pointer_expression
* "*"
identifier "result"
) ")"
) ")"
; ";"
expression_statement
assignment_expression
field_expression
identifier "result"
-> "->"
field_identifier "city_radius_sq"
= "="
conditional_expression
identifier "pcity"
? "?"
call_expression
identifier "city_map_radius_sq_get"
argument_list
( "("
identifier "pcity"
) ")"
: ":"
identifier "CITY_MAP_MAX_RADIUS_SQ"
; ";"
expression_statement (+34 nodes collapsed)
comment "/* test if the city pointer is valid; the cm_result struct c"...
expression_statement
call_expression
identifier "fc_assert_ret_val"
argument_list
( "("
binary_expression
identifier "pcity"
!= "!="
null
NULL "NULL"
, ","
identifier "result"
) ")"
; ";"
return_statement
return "return"
identifier "result"
; ";"
} "}"
comment "/***********************************************************"...
comment "/**\n Destroy a cm_result.\n*********************************"...
function_definition
primitive_type "void"
function_declarator
identifier "cm_result_destroy"
parameter_list
( "("
parameter_declaration
struct_specifier
struct "struct"
type_identifier "cm_result"
pointer_declarator
* "*"
identifier "result"
) ")"
compound_statement
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "result"
!= "!="
null
NULL "NULL"
) ")"
compound_statement
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
field_expression
identifier "result"
-> "->"
field_identifier "worker_positions"
!= "!="
null
NULL "NULL"
) ")"
compound_statement
{ "{"
expression_statement
call_expression
identifier "FC_FREE"
argument_list
( "("
field_expression
identifier "result"
-> "->"
field_identifier "worker_positions"
) ")"
; ";"
} "}"
expression_statement
call_expression
identifier "FC_FREE"
argument_list
( "("
identifier "result"
) ")"
; ";"
} "}"
} "}"
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n Set all production to zero and initialize the vectors "...
function_definition (+77 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Duplicate a tile type, except for the vectors - the ve"...
function_definition (+110 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Free all the storage in the tile type (but don't free "...
function_definition (+59 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Destroy and free all types in the vector, and the vect"...
function_definition (+60 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return TRUE iff all categories of the two types are eq"...
function_definition (+99 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return positive value if tile a is better or equal to "...
function_definition (+236 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n If there is a tile type in the vector that is equivale"...
function_definition (+89 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return the number of tiles of this type that can be wo"...
function_definition (+56 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return the number of tile types that are better than t"...
function_definition (+31 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Retrieve a tile type by index. For a given state there"...
function_definition
storage_class_specifier
static "static"
type_qualifier
const "const"
struct_specifier
struct "struct"
type_identifier "cm_tile_type"
pointer_declarator
* "*"
function_declarator
identifier "tile_type_get"
parameter_list
( "("
parameter_declaration
type_qualifier
const "const"
struct_specifier
struct "struct"
type_identifier "cm_state"
pointer_declarator
* "*"
identifier "state"
, ","
parameter_declaration
primitive_type "int"
identifier "type"
) ")"
compound_statement
{ "{"
comment "/* Sanity check the index. */"
expression_statement
call_expression
identifier "fc_assert_ret_val"
argument_list
( "("
binary_expression
number_literal "0"
<= "<="
identifier "type"
, ","
null
NULL "NULL"
) ")"
; ";"
expression_statement
call_expression
identifier "fc_assert_ret_val"
argument_list
( "("
binary_expression
field_expression
field_expression
identifier "state"
-> "->"
field_identifier "lattice"
. "."
field_identifier "size"
> ">"
identifier "type"
, ","
null
NULL "NULL"
) ")"
; ";"
return_statement
return "return"
subscript_expression
field_expression
field_expression
identifier "state"
-> "->"
field_identifier "lattice"
. "."
field_identifier "p"
[ "["
identifier "type"
] "]"
; ";"
} "}"
comment "/***********************************************************"...
comment "/**\n Retrieve a tile of a particular type by index. For a g"...
function_definition
storage_class_specifier
static "static"
type_qualifier
const "const"
struct_specifier
struct "struct"
type_identifier "cm_tile"
pointer_declarator
* "*"
function_declarator
identifier "tile_get"
parameter_list
( "("
parameter_declaration
type_qualifier
const "const"
struct_specifier
struct "struct"
type_identifier "cm_tile_type"
pointer_declarator
* "*"
identifier "ptype"
, ","
parameter_declaration
primitive_type "int"
identifier "j"
) ")"
compound_statement
{ "{"
expression_statement
call_expression
identifier "fc_assert_ret_val"
argument_list
( "("
unary_expression
! "!"
field_expression
identifier "ptype"
-> "->"
field_identifier "is_specialist"
, ","
null
NULL "NULL"
) ")"
; ";"
expression_statement
call_expression
identifier "fc_assert_ret_val"
argument_list
( "("
binary_expression
number_literal "0"
<= "<="
identifier "j"
, ","
null
NULL "NULL"
) ")"
; ";"
expression_statement
call_expression
identifier "fc_assert_ret_val"
argument_list
( "("
binary_expression
identifier "j"
< "<"
field_expression
field_expression
identifier "ptype"
-> "->"
field_identifier "tiles"
. "."
field_identifier "size"
, ","
null
NULL "NULL"
) ")"
; ";"
return_statement
return "return"
pointer_expression
& "&"
subscript_expression
field_expression
field_expression
identifier "ptype"
-> "->"
field_identifier "tiles"
. "."
field_identifier "p"
[ "["
identifier "j"
] "]"
; ";"
} "}"
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n Return TRUE iff fitness A is strictly better than fitn"...
function_definition (+61 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return a fitness struct that is the worst possible res"...
function_definition (+46 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Compute the fitness of the given surplus (and disorder"...
function_definition (+205 nodes collapsed)
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n Allocate and initialize an empty solution.\n***********"...
function_definition (+156 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Free all storage associated with the solution. This is"...
function_definition (+41 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Copy the source solution into the destination one (the"...
function_definition (+149 nodes collapsed)
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n Apply the solution to state->workers_map.\n************"...
function_definition (+425 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Convert the city's surplus numbers into an array. Get "...
function_definition (+95 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Compute the fitness of the solution. This is a fairly "...
function_definition (+186 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Convert the solution into a cm_result. This is a fairl"...
function_definition (+144 nodes collapsed)
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n All the sorting in this code needs to respect the part"...
function_definition (+152 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Sort by fitness. Since fitness is monotone in the prod"...
function_definition (+155 nodes collapsed)
declaration
storage_class_specifier
static "static"
type_identifier "Output_type_id"
identifier "compare_key"
; ";"
declaration
storage_class_specifier
static "static"
primitive_type "double"
identifier "compare_key_trade_bonus"
; ";"
comment "/***********************************************************"...
comment "/**\n Compare by the production of type compare_key.\n If a "...
function_definition (+189 nodes collapsed)
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n Compute the production of tile [x,y] and stuff it into"...
function_definition (+87 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Add the tile [x,y], with production indicated by type,"...
function_definition (+295 nodes collapsed)
comment "/*\n * Add the specialist types to the lattice.\n */"
comment "/***********************************************************"...
comment "/**\n Create lattice nodes for each type of specialist. This"...
function_definition (+140 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Topologically sort the lattice.\n Sets the lattice_dep"...
function_definition (+553 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Remove unreachable lattice nodes to speed up processin"...
function_definition (+356 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Determine the estimated_fitness fields, and sort by th"...
function_definition (+163 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Create the lattice.\n**********************************"...
function_definition (+217 nodes collapsed)
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n Return TRUE iff the stack is empty.\n******************"...
function_definition (+32 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return the last choice in the stack.\n*****************"...
function_definition (+59 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return the number of different tile types. There is o"...
function_definition (+35 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Update the solution to assign 'number' more workers on"...
function_definition (+436 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Add just one worker to the solution.\n*****************"...
function_definition (+47 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Remove just one worker from the solution.\n************"...
function_definition (+47 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Remove a worker from the current solution, and pop onc"...
function_definition (+67 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n True if all tiles better than this type have been used"...
function_definition (+81 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return the next choice to make after oldchoice.\n A ch"...
function_definition (+252 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Pick a sibling choice to the last choice. This works "...
function_definition (+163 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Go down from the current branch, if we can.\n Thanks t"...
function_definition (+187 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Complete the solution by choosing tiles in order off t"...
function_definition (+284 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return number of specialists used in partial solution\n"...
function_definition (+116 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n The heuristic:\n A partial solution cannot produce mor"...
function_definition (+457 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n A choice is unpromising if isn't better than the best "...
function_definition (+360 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Initialize minimal production needed to be sufficient\n"...
function_definition (+79 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Get the tax rates, see city.c\n************************"...
function_definition (+222 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Estimate the fitness of a tile. Tiles are put into th"...
function_definition (+314 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n The high-level algorithm is:\n\n for each idle worker,\n"...
function_definition (+226 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Initialize the state for the branch-and-bound algorith"...
function_definition (+586 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Find the minimum food surplus needed to grow in the fe"...
function_definition (+397 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Set the parameter for the state. This is the first st"...
function_definition (+206 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Clean up after a search.\n Currently, does nothing exc"...
function_definition
storage_class_specifier
static "static"
primitive_type "void"
function_declarator
identifier "end_search"
parameter_list
( "("
parameter_declaration
struct_specifier
struct "struct"
type_identifier "cm_state"
pointer_declarator
* "*"
identifier "state"
) ")"
compound_statement
{ "{"
preproc_ifdef
#ifdef "#ifdef"
identifier "GATHER_TIME_STATS"
expression_statement
call_expression
identifier "timer_stop"
argument_list
( "("
field_expression
field_expression
identifier "performance"
. "."
field_identifier "current"
-> "->"
field_identifier "wall_timer"
) ")"
; ";"
preproc_ifdef
#ifdef "#ifdef"
identifier "PRINT_TIME_STATS_EVERY_QUERY"
expression_statement
call_expression
identifier "print_performance"
argument_list
( "("
field_expression
identifier "performance"
. "."
field_identifier "current"
) ")"
; ";"
#endif "#endif"
comment "/* PRINT_TIME_STATS_EVERY_QUERY */"
expression_statement
assignment_expression
field_expression
identifier "performance"
. "."
field_identifier "current"
= "="
null
NULL "NULL"
; ";"
#endif "#endif"
comment "/* GATHER_TIME_STATS */"
} "}"
comment "/***********************************************************"...
comment "/**\n Release all the memory allocated by the state.\n*******"...
function_definition (+120 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Run B&B until we find the best solution.\n*************"...
function_definition (+327 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Wrapper that actually runs the branch & bound, and ret"...
function_definition
primitive_type "void"
function_declarator (+34 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "cm_state"
init_declarator
pointer_declarator
* "*"
identifier "state"
= "="
call_expression
identifier "cm_state_init"
argument_list
( "("
identifier "pcity"
, ","
identifier "negative_ok"
) ")"
; ";"
declaration (+21 nodes collapsed)
comment "/* Refresh the city. Otherwise the CM can give wrong results"...
expression_statement
call_expression
identifier "city_refresh_from_main_map"
argument_list
( "("
identifier "nmap"
, ","
identifier "pcity"
, ","
null
NULL "NULL"
) ")"
; ";"
expression_statement
call_expression
identifier "cm_find_best_solution"
argument_list
( "("
identifier "state"
, ","
identifier "param"
, ","
identifier "result"
, ","
identifier "negative_ok"
) ")"
; ";"
expression_statement
call_expression
identifier "cm_state_free"
argument_list
( "("
identifier "state"
) ")"
; ";"
} "}"
comment "/***********************************************************"...
comment "/**\n Returns true if the two cm_parameters are equal.\n*****"...
function_definition (+219 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Copy the parameter from the source to the destination "...
function_definition (+48 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Initialize the parameter to sane default values.\n*****"...
function_definition (+100 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Initialize the parameter to sane default values that w"...
function_definition (+102 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Count the total number of workers in the result.\n*****"...
function_definition (+91 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Count the total number of specialists in the result.\n*"...
function_definition (+55 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Count the total number of citizens in the result.\n****"...
function_definition (+36 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Copy the city's current setup into the cm result struc"...
function_definition
primitive_type "void"
function_declarator (+22 nodes collapsed)
compound_statement
{ "{"
expression_statement
call_expression
identifier "cm_result_copy"
argument_list
( "("
identifier "result"
, ","
identifier "pcity"
, ","
null
NULL "NULL"
) ")"
; ";"
} "}"
comment "/***********************************************************"...
comment "/**\n Copy the city's current setup into the cm result struc"...
function_definition
storage_class_specifier
static "static"
primitive_type "void"
function_declarator (+28 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "tile"
init_declarator
pointer_declarator
* "*"
identifier "pcenter"
= "="
call_expression
identifier "city_tile"
argument_list
( "("
identifier "pcity"
) ")"
; ";"
declaration (+21 nodes collapsed)
comment "/* Clear worker positions */"
expression_statement (+36 nodes collapsed)
expression_statement
call_expression
identifier "city_tile_iterate_index"
argument_list
( "("
identifier "nmap"
, ","
field_expression
identifier "result"
-> "->"
field_identifier "city_radius_sq"
, ","
identifier "pcenter"
, ","
identifier "ptile"
, ","
identifier "ctindex"
) ")"
; ""
compound_statement
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "workers_map"
== "=="
null
NULL "NULL"
) ")"
compound_statement
{ "{"
comment "/* Use the main map */"
declaration
struct_specifier
struct "struct"
type_identifier "city"
init_declarator
pointer_declarator
* "*"
identifier "pwork"
= "="
call_expression
identifier "tile_worked"
argument_list
( "("
identifier "ptile"
) ")"
; ";"
expression_statement
assignment_expression
subscript_expression
field_expression
identifier "result"
-> "->"
field_identifier "worker_positions"
[ "["
identifier "ctindex"
] "]"
= "="
parenthesized_expression
( "("
binary_expression
binary_expression
null
NULL "NULL"
!= "!="
identifier "pwork"
&& "&&"
binary_expression
identifier "pwork"
== "=="
identifier "pcity"
) ")"
; ";"
} "}"
else_clause (+22 nodes collapsed)
} "}"
expression_statement
identifier "city_tile_iterate_index_end"
; ";"
comment "/* Copy the specialist counts */"
function_definition (+29 nodes collapsed)
expression_statement
identifier "specialist_type_iterate_end"
; ";"
comment "/* Find the surplus production numbers */"
expression_statement (+27 nodes collapsed)
comment "/* This is a valid result, in a sense */"
expression_statement
assignment_expression
field_expression
identifier "result"
-> "->"
field_identifier "found_a_valid"
= "="
true "TRUE"
; ";"
} "}"
comment "/***********************************************************"...
comment "/**\n Debugging routines.\n**********************************"...
preproc_ifdef (+828 nodes collapsed)
comment "/* CM_DEBUG */"
preproc_ifdef (+117 nodes collapsed)
comment "/* GATHER_TIME_STATS */"
comment "/***********************************************************"...
comment "/**\n Print debugging information about one city.\n**********"...
function_definition
primitive_type "void"
function_declarator
identifier "cm_print_city"
parameter_list
( "("
parameter_declaration
type_qualifier
const "const"
struct_specifier
struct "struct"
type_identifier "city"
pointer_declarator
* "*"
identifier "pcity"
) ")"
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "tile"
init_declarator
pointer_declarator
* "*"
identifier "pcenter"
= "="
call_expression
identifier "city_tile"
argument_list
( "("
identifier "pcity"
) ")"
; ";"
declaration (+21 nodes collapsed)
expression_statement (+27 nodes collapsed)
expression_statement (+28 nodes collapsed)
expression_statement
call_expression
identifier "log_test"
argument_list
( "("
string_literal
" "\""
string_content " workers at:"
" "\""
) ")"
; ";"
expression_statement (+21 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "city"
init_declarator
pointer_declarator
* "*"
identifier "pwork"
= "="
call_expression
identifier "tile_worked"
argument_list
( "("
identifier "ptile"
) ")"
; ";"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
binary_expression
null
NULL "NULL"
!= "!="
identifier "pwork"
&& "&&"
binary_expression
identifier "pwork"
== "=="
identifier "pcity"
) ")"
compound_statement (+54 nodes collapsed)
} "}"
expression_statement
identifier "city_tile_iterate_index_end"
; ";"
expression_statement (+29 nodes collapsed)
expression_statement (+29 nodes collapsed)
expression_statement
call_expression
identifier "log_test"
argument_list
( "("
string_literal
" "\""
string_content " trade = %3d"
" "\""
, ","
subscript_expression
field_expression
identifier "pcity"
-> "->"
field_identifier "surplus"
[ "["
identifier "O_TRADE"
] "]"
) ")"
; ";"
expression_statement (+29 nodes collapsed)
expression_statement
call_expression
identifier "log_test"
argument_list
( "("
string_literal
" "\""
string_content " luxury = %3d"
" "\""
, ","
subscript_expression
field_expression
identifier "pcity"
-> "->"
field_identifier "prod"
[ "["
identifier "O_LUXURY"
] "]"
) ")"
; ";"
expression_statement
call_expression
identifier "log_test"
argument_list
( "("
string_literal
" "\""
string_content " science = %3d"
" "\""
, ","
subscript_expression
field_expression
identifier "pcity"
-> "->"
field_identifier "prod"
[ "["
identifier "O_SCIENCE"
] "]"
) ")"
; ";"
} "}"
comment "/***********************************************************"...
comment "/**\n Print debugging information about a full CM result.\n**"...
function_definition (+287 nodes collapsed)

After

translation_unit
comment "/***********************************************************"...
preproc_ifdef
#ifdef "#ifdef"
identifier "HAVE_CONFIG_H"
preproc_include
#include "#include"
system_lib_string "<fc_config.h>"
#endif "#endif"
preproc_include
#include "#include"
system_lib_string "<stdlib.h>"
preproc_include
#include "#include"
system_lib_string "<string.h>"
comment "/* utility */"
preproc_include
#include "#include"
string_literal
" "\""
string_content "fcintl.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "log.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "mem.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "shared.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "support.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "timing.h"
" "\""
comment "/* common */"
preproc_include
#include "#include"
string_literal
" "\""
string_content "city.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "game.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "government.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "map.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "specialist.h"
" "\""
preproc_include
#include "#include"
string_literal
" "\""
string_content "cm.h"
" "\""
comment "/*\n * Terms used\n * ==========\n *\n * Stats: food, shields, t"...
comment "/***********************************************************"...
comment "/* If this is uncommented, research loop runs without limit "...
comment "/* #define CM_LOOP_NO_LIMIT */"
comment "/* Maximal iterations before the search loop is stopped, or "...
preproc_def
#define "#define"
identifier "CM_MAX_LOOP"
preproc_arg "27500"
preproc_def
#define "#define"
identifier "CPUHOG_CM_MAX_LOOP"
preproc_arg "(CM_MAX_LOOP * 4)"
preproc_ifdef
#ifdef "#ifdef"
identifier "DEBUG_TIMERS"
preproc_def
#define "#define"
identifier "GATHER_TIME_STATS"
#endif "#endif"
preproc_ifdef
#ifdef "#ifdef"
identifier "FREECIV_DEBUG"
preproc_def
#define "#define"
identifier "CM_DEBUG"
#endif "#endif"
comment "/* Whether to print every query, or just at cm_free ; matter"...
preproc_def
#define "#define"
identifier "PRINT_TIME_STATS_EVERY_QUERY"
preproc_def
#define "#define"
identifier "LOG_TIME_STATS"
preproc_arg "LOG_DEBUG"
preproc_def
#define "#define"
identifier "LOG_CM_STATE"
preproc_arg "LOG_DEBUG"
preproc_def
#define "#define"
identifier "LOG_LATTICE"
preproc_arg "LOG_DEBUG"
preproc_def
#define "#define"
identifier "LOG_REACHED_LEAF"
preproc_arg "LOG_DEBUG"
preproc_def
#define "#define"
identifier "LOG_BETTER_LEAF"
preproc_arg "LOG_DEBUG"
preproc_def
#define "#define"
identifier "LOG_PRUNE_BRANCH"
preproc_arg "LOG_DEBUG"
preproc_ifdef (+74 nodes collapsed)
comment "/* GATHER_TIME_STATS */"
comment "/* Fitness of a solution. */"
struct_specifier
struct "struct"
type_identifier "cm_fitness"
field_declaration_list
{ "{"
field_declaration
primitive_type "int"
field_identifier "weighted"
; ";"
comment "/* weighted sum */"
field_declaration
primitive_type "bool"
field_identifier "sufficient"
; ";"
comment "/* false => doesn't meet constraints */"
} "}"
; ";"
comment "/*\n * We have a cyclic structure here, so we need to forward"...
struct_specifier
struct "struct"
type_identifier "cm_tile_type"
; ";"
struct_specifier
struct "struct"
type_identifier "cm_tile"
; ";"
comment "/*\n * A tile. Has a pointer to the type, and the x/y coords"...
struct_specifier (+21 nodes collapsed)
; ";"
comment "/* define the tile_vector as array<cm_tile> */"
preproc_def
#define "#define"
identifier "SPECVEC_TAG"
preproc_arg "tile"
preproc_def
#define "#define"
identifier "SPECVEC_TYPE"
preproc_arg "struct cm_tile"
preproc_include
#include "#include"
string_literal
" "\""
string_content "specvec.h"
" "\""
comment "/* define the tile_type_vector as array <cm_tile_type*> */"
preproc_def
#define "#define"
identifier "SPECVEC_TAG"
preproc_arg "tile_type"
preproc_def
#define "#define"
identifier "SPECVEC_TYPE"
preproc_arg "struct cm_tile_type *"
preproc_include
#include "#include"
string_literal
" "\""
string_content "specvec.h"
" "\""
preproc_function_def
#define "#define"
identifier "tile_type_vector_iterate"
preproc_params
( "("
identifier "vector"
, ","
identifier "var"
) ")"
preproc_arg "{ \\\n struct cm_tile_type *var; \\\n TYPED_VECTOR_ITERATE"...
preproc_def
#define "#define"
identifier "tile_type_vector_iterate_end"
preproc_arg "}} VECTOR_ITERATE_END; }"
comment "/*\n * A tile type.\n * Holds the production (a hill produces "...
struct_specifier (+57 nodes collapsed)
; ";"
comment "/*\n * A partial solution.\n * Has the count of workers assign"...
struct_specifier (+35 nodes collapsed)
; ";"
comment "/*\n * State of the search.\n * This holds all the information"...
struct_specifier (+99 nodes collapsed)
; ";"
comment "/* return #fields + specialist types */"
declaration
storage_class_specifier
static "static"
primitive_type "int"
function_declarator
identifier "num_types"
parameter_list
( "("
parameter_declaration
type_qualifier
const "const"
struct_specifier
struct "struct"
type_identifier "cm_state"
pointer_declarator
* "*"
identifier "state"
) ")"
; ";"
comment "/* debugging functions */"
preproc_ifdef (+224 nodes collapsed)
comment "/* CM_DEBUG */"
declaration (+33 nodes collapsed)
declaration (+28 nodes collapsed)
declaration (+25 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Initialize the CM data at the start of each game. Not"...
function_definition (+115 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Initialize the CM citymap data. This function is call"...
function_definition
primitive_type "void"
function_declarator
identifier "cm_init_citymap"
parameter_list
( "("
parameter_declaration
primitive_type "void"
) ")"
compound_statement
{ "{"
comment "/* In the B&B algorithm there's not really anything to initi"...
} "}"
comment "/***********************************************************"...
comment "/**\n Clear the cache for a city.\n**************************"...
function_definition
primitive_type "void"
function_declarator
identifier "cm_clear_cache"
parameter_list
( "("
parameter_declaration
struct_specifier
struct "struct"
type_identifier "city"
pointer_declarator
* "*"
identifier "pcity"
) ")"
compound_statement
{ "{"
comment "/* The B&B algorithm doesn't have city caches so there's not"...
} "}"
comment "/***********************************************************"...
comment "/**\n Called at the end of a game to free any CM data.\n*****"...
function_definition (+90 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Create a new cm_result.\n******************************"...
function_definition
struct_specifier
struct "struct"
type_identifier "cm_result"
pointer_declarator
* "*"
function_declarator
identifier "cm_result_new"
parameter_list
( "("
parameter_declaration
struct_specifier
struct "struct"
type_identifier "city"
pointer_declarator
* "*"
identifier "pcity"
) ")"
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "cm_result"
pointer_declarator
* "*"
identifier "result"
; ";"
comment "/* Initialise all values */"
expression_statement
assignment_expression
identifier "result"
= "="
call_expression
identifier "fc_calloc"
argument_list
( "("
number_literal "1"
, ","
sizeof_expression
sizeof "sizeof"
parenthesized_expression
( "("
pointer_expression
* "*"
identifier "result"
) ")"
) ")"
; ";"
expression_statement
assignment_expression
field_expression
identifier "result"
-> "->"
field_identifier "city_radius_sq"
= "="
conditional_expression
identifier "pcity"
? "?"
call_expression
identifier "city_map_radius_sq_get"
argument_list
( "("
identifier "pcity"
) ")"
: ":"
identifier "CITY_MAP_MAX_RADIUS_SQ"
; ";"
expression_statement (+34 nodes collapsed)
comment "/* Test if the city pointer is valid; the cm_result struct c"...
expression_statement
call_expression
identifier "fc_assert_ret_val"
argument_list
( "("
binary_expression
identifier "pcity"
!= "!="
null
nullptr "nullptr"
, ","
identifier "result"
) ")"
; ";"
return_statement
return "return"
identifier "result"
; ";"
} "}"
comment "/***********************************************************"...
comment "/**\n Destroy a cm_result.\n*********************************"...
function_definition
primitive_type "void"
function_declarator
identifier "cm_result_destroy"
parameter_list
( "("
parameter_declaration
struct_specifier
struct "struct"
type_identifier "cm_result"
pointer_declarator
* "*"
identifier "result"
) ")"
compound_statement
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "result"
!= "!="
null
nullptr "nullptr"
) ")"
compound_statement
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
field_expression
identifier "result"
-> "->"
field_identifier "worker_positions"
!= "!="
null
nullptr "nullptr"
) ")"
compound_statement
{ "{"
expression_statement
call_expression
identifier "FC_FREE"
argument_list
( "("
field_expression
identifier "result"
-> "->"
field_identifier "worker_positions"
) ")"
; ";"
} "}"
expression_statement
call_expression
identifier "FC_FREE"
argument_list
( "("
identifier "result"
) ")"
; ";"
} "}"
} "}"
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n Set all production to zero and initialize the vectors "...
function_definition (+77 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Duplicate a tile type, except for the vectors - the ve"...
function_definition (+110 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Free all the storage in the tile type (but don't free "...
function_definition (+59 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Destroy and free all types in the vector, and the vect"...
function_definition (+60 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return TRUE iff all categories of the two types are eq"...
function_definition (+99 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return positive value if tile a is better or equal to "...
function_definition (+236 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n If there is a tile type in the vector that is equivale"...
function_definition (+89 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return the number of tiles of this type that can be wo"...
function_definition (+56 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return the number of tile types that are better than t"...
function_definition (+31 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Retrieve a tile type by index. For a given state there"...
function_definition
storage_class_specifier
static "static"
type_qualifier
const "const"
struct_specifier
struct "struct"
type_identifier "cm_tile_type"
pointer_declarator
* "*"
function_declarator
identifier "tile_type_get"
parameter_list
( "("
parameter_declaration
type_qualifier
const "const"
struct_specifier
struct "struct"
type_identifier "cm_state"
pointer_declarator
* "*"
identifier "state"
, ","
parameter_declaration
primitive_type "int"
identifier "type"
) ")"
compound_statement
{ "{"
comment "/* Sanity check the index. */"
expression_statement
call_expression
identifier "fc_assert_ret_val"
argument_list
( "("
binary_expression
number_literal "0"
<= "<="
identifier "type"
, ","
null
nullptr "nullptr"
) ")"
; ";"
expression_statement
call_expression
identifier "fc_assert_ret_val"
argument_list
( "("
binary_expression
field_expression
field_expression
identifier "state"
-> "->"
field_identifier "lattice"
. "."
field_identifier "size"
> ">"
identifier "type"
, ","
null
nullptr "nullptr"
) ")"
; ";"
return_statement
return "return"
subscript_expression
field_expression
field_expression
identifier "state"
-> "->"
field_identifier "lattice"
. "."
field_identifier "p"
[ "["
identifier "type"
] "]"
; ";"
} "}"
comment "/***********************************************************"...
comment "/**\n Retrieve a tile of a particular type by index. For a g"...
function_definition
storage_class_specifier
static "static"
type_qualifier
const "const"
struct_specifier
struct "struct"
type_identifier "cm_tile"
pointer_declarator
* "*"
function_declarator
identifier "tile_get"
parameter_list
( "("
parameter_declaration
type_qualifier
const "const"
struct_specifier
struct "struct"
type_identifier "cm_tile_type"
pointer_declarator
* "*"
identifier "ptype"
, ","
parameter_declaration
primitive_type "int"
identifier "j"
) ")"
compound_statement
{ "{"
expression_statement
call_expression
identifier "fc_assert_ret_val"
argument_list
( "("
unary_expression
! "!"
field_expression
identifier "ptype"
-> "->"
field_identifier "is_specialist"
, ","
null
nullptr "nullptr"
) ")"
; ";"
expression_statement
call_expression
identifier "fc_assert_ret_val"
argument_list
( "("
binary_expression
number_literal "0"
<= "<="
identifier "j"
, ","
null
nullptr "nullptr"
) ")"
; ";"
expression_statement
call_expression
identifier "fc_assert_ret_val"
argument_list
( "("
binary_expression
identifier "j"
< "<"
field_expression
field_expression
identifier "ptype"
-> "->"
field_identifier "tiles"
. "."
field_identifier "size"
, ","
null
nullptr "nullptr"
) ")"
; ";"
return_statement
return "return"
pointer_expression
& "&"
subscript_expression
field_expression
field_expression
identifier "ptype"
-> "->"
field_identifier "tiles"
. "."
field_identifier "p"
[ "["
identifier "j"
] "]"
; ";"
} "}"
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n Return TRUE iff fitness A is strictly better than fitn"...
function_definition (+61 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return a fitness struct that is the worst possible res"...
function_definition (+46 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Compute the fitness of the given surplus (and disorder"...
function_definition (+205 nodes collapsed)
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n Allocate and initialize an empty solution.\n***********"...
function_definition (+156 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Free all storage associated with the solution. This is"...
function_definition (+41 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Copy the source solution into the destination one (the"...
function_definition (+149 nodes collapsed)
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n Apply the solution to state->workers_map.\n************"...
function_definition (+425 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Convert the city's surplus numbers into an array. Get "...
function_definition (+95 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Compute the fitness of the solution. This is a fairly "...
function_definition (+186 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Convert the solution into a cm_result. This is a fairl"...
function_definition (+144 nodes collapsed)
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n All the sorting in this code needs to respect the part"...
function_definition (+152 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Sort by fitness. Since fitness is monotone in the prod"...
function_definition (+155 nodes collapsed)
declaration
storage_class_specifier
static "static"
type_identifier "Output_type_id"
identifier "compare_key"
; ";"
declaration
storage_class_specifier
static "static"
primitive_type "double"
identifier "compare_key_trade_bonus"
; ";"
comment "/***********************************************************"...
comment "/**\n Compare by the production of type compare_key.\n If a "...
function_definition (+189 nodes collapsed)
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n Compute the production of tile [x,y] and stuff it into"...
function_definition (+87 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Add the tile [x,y], with production indicated by type,"...
function_definition (+295 nodes collapsed)
comment "/*\n * Add the specialist types to the lattice.\n */"
comment "/***********************************************************"...
comment "/**\n Create lattice nodes for each type of specialist. This"...
function_definition (+140 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Topologically sort the lattice.\n Sets the lattice_dep"...
function_definition (+553 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Remove unreachable lattice nodes to speed up processin"...
function_definition (+356 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Determine the estimated_fitness fields, and sort by th"...
function_definition (+163 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Create the lattice.\n**********************************"...
function_definition (+217 nodes collapsed)
comment "/***********************************************************"...
comment "/***********************************************************"...
comment "/**\n Return TRUE iff the stack is empty.\n******************"...
function_definition (+32 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return the last choice in the stack.\n*****************"...
function_definition (+59 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return the number of different tile types. There is o"...
function_definition (+35 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Update the solution to assign 'number' more workers on"...
function_definition (+436 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Add just one worker to the solution.\n*****************"...
function_definition (+47 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Remove just one worker from the solution.\n************"...
function_definition (+47 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Remove a worker from the current solution, and pop onc"...
function_definition (+67 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n True if all tiles better than this type have been used"...
function_definition (+81 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return the next choice to make after oldchoice.\n A ch"...
function_definition (+252 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Pick a sibling choice to the last choice. This works "...
function_definition (+163 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Go down from the current branch, if we can.\n Thanks t"...
function_definition (+187 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Complete the solution by choosing tiles in order off t"...
function_definition (+284 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Return number of specialists used in partial solution\n"...
function_definition (+116 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n The heuristic:\n A partial solution cannot produce mor"...
function_definition (+457 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n A choice is unpromising if isn't better than the best "...
function_definition (+360 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Initialize minimal production needed to be sufficient\n"...
function_definition (+79 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Get the tax rates, see city.c\n************************"...
function_definition (+222 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Estimate the fitness of a tile. Tiles are put into th"...
function_definition (+314 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n The high-level algorithm is:\n\n for each idle worker,\n"...
function_definition (+226 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Initialize the state for the branch-and-bound algorith"...
function_definition (+586 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Find the minimum food surplus needed to grow in the fe"...
function_definition (+397 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Set the parameter for the state. This is the first st"...
function_definition (+206 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Clean up after a search.\n Currently, does nothing exc"...
function_definition
storage_class_specifier
static "static"
primitive_type "void"
function_declarator
identifier "end_search"
parameter_list
( "("
parameter_declaration
struct_specifier
struct "struct"
type_identifier "cm_state"
pointer_declarator
* "*"
identifier "state"
) ")"
compound_statement
{ "{"
preproc_ifdef
#ifdef "#ifdef"
identifier "GATHER_TIME_STATS"
expression_statement
call_expression
identifier "timer_stop"
argument_list
( "("
field_expression
field_expression
identifier "performance"
. "."
field_identifier "current"
-> "->"
field_identifier "wall_timer"
) ")"
; ";"
preproc_ifdef
#ifdef "#ifdef"
identifier "PRINT_TIME_STATS_EVERY_QUERY"
expression_statement
call_expression
identifier "print_performance"
argument_list
( "("
field_expression
identifier "performance"
. "."
field_identifier "current"
) ")"
; ";"
#endif "#endif"
comment "/* PRINT_TIME_STATS_EVERY_QUERY */"
expression_statement
assignment_expression
field_expression
identifier "performance"
. "."
field_identifier "current"
= "="
null
nullptr "nullptr"
; ";"
#endif "#endif"
comment "/* GATHER_TIME_STATS */"
} "}"
comment "/***********************************************************"...
comment "/**\n Release all the memory allocated by the state.\n*******"...
function_definition (+120 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Run B&B until we find the best solution.\n*************"...
function_definition (+327 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Wrapper that actually runs the branch & bound, and ret"...
function_definition
primitive_type "void"
function_declarator (+34 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "cm_state"
init_declarator
pointer_declarator
* "*"
identifier "state"
= "="
call_expression
identifier "cm_state_init"
argument_list
( "("
identifier "pcity"
, ","
identifier "negative_ok"
) ")"
; ";"
declaration (+21 nodes collapsed)
comment "/* Refresh the city. Otherwise the CM can give wrong results"...
expression_statement
call_expression
identifier "city_refresh_from_main_map"
argument_list
( "("
identifier "nmap"
, ","
identifier "pcity"
, ","
null
nullptr "nullptr"
) ")"
; ";"
expression_statement
call_expression
identifier "cm_find_best_solution"
argument_list
( "("
identifier "state"
, ","
identifier "param"
, ","
identifier "result"
, ","
identifier "negative_ok"
) ")"
; ";"
expression_statement
call_expression
identifier "cm_state_free"
argument_list
( "("
identifier "state"
) ")"
; ";"
} "}"
comment "/***********************************************************"...
comment "/**\n Returns true if the two cm_parameters are equal.\n*****"...
function_definition (+219 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Copy the parameter from the source to the destination "...
function_definition (+48 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Initialize the parameter to sane default values.\n*****"...
function_definition (+100 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Initialize the parameter to sane default values that w"...
function_definition (+102 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Count the total number of workers in the result.\n*****"...
function_definition (+91 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Count the total number of specialists in the result.\n*"...
function_definition (+55 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Count the total number of citizens in the result.\n****"...
function_definition (+36 nodes collapsed)
comment "/***********************************************************"...
comment "/**\n Copy the city's current setup into the cm result struc"...
function_definition
primitive_type "void"
function_declarator (+22 nodes collapsed)
compound_statement
{ "{"
expression_statement
call_expression
identifier "cm_result_copy"
argument_list
( "("
identifier "result"
, ","
identifier "pcity"
, ","
null
nullptr "nullptr"
) ")"
; ";"
} "}"
comment "/***********************************************************"...
comment "/**\n Copy the city's current setup into the cm result struc"...
function_definition
storage_class_specifier
static "static"
primitive_type "void"
function_declarator (+28 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "tile"
init_declarator
pointer_declarator
* "*"
identifier "pcenter"
= "="
call_expression
identifier "city_tile"
argument_list
( "("
identifier "pcity"
) ")"
; ";"
declaration (+21 nodes collapsed)
comment "/* Clear worker positions */"
expression_statement (+36 nodes collapsed)
expression_statement
call_expression
identifier "city_tile_iterate_index"
argument_list
( "("
identifier "nmap"
, ","
field_expression
identifier "result"
-> "->"
field_identifier "city_radius_sq"
, ","
identifier "pcenter"
, ","
identifier "ptile"
, ","
identifier "ctindex"
) ")"
; ""
compound_statement
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "workers_map"
== "=="
null
nullptr "nullptr"
) ")"
compound_statement
{ "{"
comment "/* Use the main map */"
declaration
struct_specifier
struct "struct"
type_identifier "city"
init_declarator
pointer_declarator
* "*"
identifier "pwork"
= "="
call_expression
identifier "tile_worked"
argument_list
( "("
identifier "ptile"
) ")"
; ";"
expression_statement
assignment_expression
subscript_expression
field_expression
identifier "result"
-> "->"
field_identifier "worker_positions"
[ "["
identifier "ctindex"
] "]"
= "="
parenthesized_expression
( "("
binary_expression
binary_expression
identifier "pwork"
!= "!="
null
nullptr "nullptr"
&& "&&"
binary_expression
identifier "pwork"
== "=="
identifier "pcity"
) ")"
; ";"
} "}"
else_clause (+22 nodes collapsed)
} "}"
expression_statement
identifier "city_tile_iterate_index_end"
; ";"
comment "/* Copy the specialist counts */"
function_definition (+29 nodes collapsed)
expression_statement
identifier "specialist_type_iterate_end"
; ";"
comment "/* Find the surplus production numbers */"
expression_statement (+27 nodes collapsed)
comment "/* This is a valid result, in a sense */"
expression_statement
assignment_expression
field_expression
identifier "result"
-> "->"
field_identifier "found_a_valid"
= "="
true "TRUE"
; ";"
} "}"
comment "/***********************************************************"...
comment "/**\n Debugging routines.\n**********************************"...
preproc_ifdef (+828 nodes collapsed)
comment "/* CM_DEBUG */"
preproc_ifdef (+117 nodes collapsed)
comment "/* GATHER_TIME_STATS */"
comment "/***********************************************************"...
comment "/**\n Print debugging information about one city.\n**********"...
function_definition
primitive_type "void"
function_declarator
identifier "cm_print_city"
parameter_list
( "("
parameter_declaration
type_qualifier
const "const"
struct_specifier
struct "struct"
type_identifier "city"
pointer_declarator
* "*"
identifier "pcity"
) ")"
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "tile"
init_declarator
pointer_declarator
* "*"
identifier "pcenter"
= "="
call_expression
identifier "city_tile"
argument_list
( "("
identifier "pcity"
) ")"
; ";"
declaration (+21 nodes collapsed)
expression_statement (+27 nodes collapsed)
expression_statement (+28 nodes collapsed)
expression_statement
call_expression
identifier "log_test"
argument_list
( "("
string_literal
" "\""
string_content " workers at:"
" "\""
) ")"
; ";"
expression_statement (+21 nodes collapsed)
compound_statement
{ "{"
declaration
struct_specifier
struct "struct"
type_identifier "city"
init_declarator
pointer_declarator
* "*"
identifier "pwork"
= "="
call_expression
identifier "tile_worked"
argument_list
( "("
identifier "ptile"
) ")"
; ";"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
binary_expression
identifier "pwork"
!= "!="
null
nullptr "nullptr"
&& "&&"
binary_expression
identifier "pwork"
== "=="
identifier "pcity"
) ")"
compound_statement (+54 nodes collapsed)
} "}"
expression_statement
identifier "city_tile_iterate_index_end"
; ";"
expression_statement (+29 nodes collapsed)
expression_statement (+29 nodes collapsed)
expression_statement
call_expression
identifier "log_test"
argument_list
( "("
string_literal
" "\""
string_content " trade = %3d"
" "\""
, ","
subscript_expression
field_expression
identifier "pcity"
-> "->"
field_identifier "surplus"
[ "["
identifier "O_TRADE"
] "]"
) ")"
; ";"
expression_statement (+29 nodes collapsed)
expression_statement
call_expression
identifier "log_test"
argument_list
( "("
string_literal
" "\""
string_content " luxury = %3d"
" "\""
, ","
subscript_expression
field_expression
identifier "pcity"
-> "->"
field_identifier "prod"
[ "["
identifier "O_LUXURY"
] "]"
) ")"
; ";"
expression_statement
call_expression
identifier "log_test"
argument_list
( "("
string_literal
" "\""
string_content " science = %3d"
" "\""
, ","
subscript_expression
field_expression
identifier "pcity"
-> "->"
field_identifier "prod"
[ "["
identifier "O_SCIENCE"
] "]"
) ")"
; ";"
} "}"
comment "/***********************************************************"...
comment "/**\n Print debugging information about a full CM result.\n**"...
function_definition (+287 nodes collapsed)