/* * * EDGECITY v1.5 -- Code of the Central Information Broker Agent * * This agent stores the common information available for the agents * (note: every agent could calculate it itself through intensive * communication, however technically this is a much more elegant * version). * * * 'Evolution of Central Places' a model by Paul Krugman * * This simulation is based on the demo model published by P. Krugman, which was * reformulated as an agent-based model by László Gulyás. * It was implemented in MAML v0.03 as an example application. * * (c) 1998, CEU Systems Laboratory * */ // Definition of a shorthand for 'model->NumOfPlaces' $define MAX: "model->NumOfPlaces"; @agent InfoBank { @uses ; // We need some mathematical routines // (namely exp) to calculate the values // in the model's equations. // The agent's internal variables @var: [] double percs; // Market share (in %) of the ith location @var: [] double pots; // Potential of the ith location @var: double avg; // Average potential // The following two tables are technical helpers // to improve the efficiency of the simulation. @var: [] int offset; // Reference table to determine the // (circular) distance of two locations. @var: [] double weight; // Table storing the constant part of // the equations for each possible // distance value // End of create phase. This subroutine is automatically // called at the end of the creation of the agent. // It initializes the internal variables. @sub: (id) createEnd { // First create the informational arrays. @create [MAX] double pots, percs; // Then, create the two technical helper arrays // Note, that the size of this array is only MAX/2 as this // is the MAXIMUM circular distance! @create [MAX/2:i] double weight { weight[i] = (model->A) * exp( (model->r1) * (double)i ) - (model->B) * exp( (model->r2) * (double)i ); } // Note, that the initialization highly depends on the // index of the given array element! @create [MAX*2:i] int offset { if ((iMAX) && (i=0) && (iNumOfPlaces) ) // Check if the location is // correct. return pots[i]; else return 0; // Returns 0, if it isn't. } // Reports back the market share at the given location. // (The value is given as percentage, represented by a // value between 0 and 1.) @sub: (double) getPercentage: (int) i { if ( (i>=0) && (iNumOfPlaces) ) // Check it the location is // correct. return percs[i]; else return 0; // Returns 0, if it isn't. } // Updates the information stored, according to the current changes. @sub: (void) updateInformation { int i, j; // Local (loop) variables. // Calculating percentages for (i=0; iplaces[i]) / (double)model->NumOfFirms; // Calculating potentials for (i=0; i