270
X-Machines for Agent-Based Modeling: FLAME Perspectives
int stock[FIRMSNO];
float price[FIRMSNO];
int consumers[PEOPLENO];
float spending[PEOPLENO];
int firmcount=0;
/* Read goods stock price messages */
xmachine_message_firm_stock_price* current_message =
get_first_firm_stock_price_message(firm_stock_price_messages);
while(current_message)
{
/* If the vacancy message refers to this mall*/
if(agent->id == current_message->mall_id)
{
firms[firmcount]=current_message->firm_id;
stock[firmcount]=current_message->stock;
price[firmcount]=current_message->price;
firmcount=firmcount+1;
}
/* Move onto next message to check */
current_message = get_next_firm_stock_price_message
(current_message,firm_stock_price_messages);
}
/* Sort goods cheapest first */
sort_prices(&firms, &stock, &price, firmcount);
agent->firm_1_goods=firms[0];
agent->firm_1_stock=stock[0];
agent->firm_1_price=price[0];
agent->firm_2_goods=firms[1];
agent->firm_2_stock=stock[1];
agent->firm_2_price=price[1];
agent->firm_3_goods=firms[2];
agent->firm_3_stock=stock[2];
agent->firm_3_price=price[2];
agent->firm_4_goods=firms[3];
agent->firm_4_stock=stock[3];
agent->firm_4_price=price[3];
agent->firm_5_goods=firms[4];
agent->firm_5_stock=stock[4];
agent->firm_5_price=price[4];
return 0;
}
__FLAME_GPU_FUNC__ int Goods_market_b(xmachine_memory_Mall* agent,
xmachine_message_consumer_spending_list* consumer_spending_messages,
xmachine_message_consumer_spent_list* consumer_spent_messages)
{
int consumers[PEOPLENO];
float spending[PEOPLENO];
int i;
int can_buy = 1;
int consumer_count;
int consumercnt=0;
/* Read consumer spending messages */
Précédent

- 299/329

Suivant