146
X-Machines for Agent-Based Modeling: FLAME Perspectives
int i, j=0;
double total=0.0;
for(i=0;i
{
j=LENGTH-i-1;
total=total+ (pow(2,j)*CURRENT_STRATEGY.output[i]);
}
QUANTITY=total;
add_current_strategy_message(ID,total);
return 0;
}
int Firm_calculate_profit()
{
double price=0.0;
double total_fitness=0.0;
int i;
//get profits from the Demand Price agent
priceP_message=get_first_priceP_message();
while(priceP_message)
{
price=priceP_message->mprice;
priceP_message=NULL; //Stop the message loop once value found
}
PROFIT=(price-COST)*QUANTITY;
CURRENT_STRATEGY.score=PROFIT;
add_current_profit_message(ID,CURRENT_STRATEGY);
//add score to current strategy database
for(i=0;i
{
if(compare_arrays(&FIRM_STRATEGY_MAP[i].output,
&CURRENT_STRATEGY.output)==0)
{
FIRM_STRATEGY_MAP[i].score=CURRENT_STRATEGY.score;
}
}
for(i=0;i
{
total_fitness+=FIRM_STRATEGY_MAP[i].score;
}
AVG_FITNESS=total_fitness/FirmBoardSize;
return 0;
}
// Performs crossover and mutation
int Firm_optimise()
{
int i=0;
double total_fitness=0.0;
strategy parent;
init_strategy(&parent);
strategy_array temp_good_strategies;
init_strategy_array(&temp_good_strategies);
X-Machines for Agent-Based Modeling: FLAME Perspectives
int i, j=0;
double total=0.0;
for(i=0;i
j=LENGTH-i-1;
total=total+ (pow(2,j)*CURRENT_STRATEGY.output[i]);
}
QUANTITY=total;
add_current_strategy_message(ID,total);
return 0;
}
int Firm_calculate_profit()
{
double price=0.0;
double total_fitness=0.0;
int i;
//get profits from the Demand Price agent
priceP_message=get_first_priceP_message();
while(priceP_message)
{
price=priceP_message->mprice;
priceP_message=NULL; //Stop the message loop once value found
}
PROFIT=(price-COST)*QUANTITY;
CURRENT_STRATEGY.score=PROFIT;
add_current_profit_message(ID,CURRENT_STRATEGY);
//add score to current strategy database
for(i=0;i
if(compare_arrays(&FIRM_STRATEGY_MAP[i].output,
&CURRENT_STRATEGY.output)==0)
{
FIRM_STRATEGY_MAP[i].score=CURRENT_STRATEGY.score;
}
}
for(i=0;i
total_fitness+=FIRM_STRATEGY_MAP[i].score;
}
AVG_FITNESS=total_fitness/FirmBoardSize;
return 0;
}
// Performs crossover and mutation
int Firm_optimise()
{
int i=0;
double total_fitness=0.0;
strategy parent;
init_strategy(&parent);
strategy_array temp_good_strategies;
init_strategy_array(&temp_good_strategies);
