/* * * A modified version of the standard EZBin analysis tool of Swarm. * (The original tool displays barcharts of data sets.) * * It was modified: * - to show percentages instead of the actual numbers. * - to use fix scaleat the Y-axis (instead dynamically rescaling it * according to the current maximum value) * - to allow for dynamically changing the window's title * * This code has been developed as part of the following project: * */ /* * * EDGECITY v1.5 -- Modified EZBin to show Percentages * * '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 * */ // This agent inherites from the Swarm Agent (object) called 'EZBin' @agent EZPercentages : EZBin { @uses ; // We need to use the original definition // to be able to inherit from it. // The agent's internal variables @var: [] double percentages; // Percentages to be displayed. @var: int titleChanged; // Refresh of the frame needed or not. @var: int outliersCounted; // Determines whether to count // outliers (values outside the // range on the x-axis) in the 'sum' // (Note, this option is irrelevant // for the EdgeCity model, as there // are no such values.) // 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 { // Call the parent of this class to initialize the // inherited parts. [super createEnd]; // Set the y-axis' scale to constant values. [globalTkInterp eval: "%s yaxis configure -min 0.0 -max 100.0;", [aHisto getWidgetName] ]; // Creates the percentage buffer. @create [binNum] double percentages; // Initializes the internal variables. titleChanged = 0; outliersCounted = 1; return self; // This method must always end by this. // (This originates in Obj-C & Swarm.) } // Updates the content of the percentage buffer. @sub: (void) update { int i; // Local (loop) variable int usedCount; // Local variable to store the // number of values counted. // Calls the parent to do the 'hard stuff' // (Such as pulling the values storing them, etc.) [super update]; // Determines the number of values counted. usedCount = (outliersCounted == 1) ? count : count-outliers; // Determines the percentages. for (i=0; i < binNum; i++) percentages[i] = (double) distribution[i] / (double)usedCount * (double) 100; } // Outputs (displays) the percentages on the barchart. @sub: (void) output { int i ; // If in graphical mode, if (graphics) { // Updates the outlier marker on the display. [globalTkInterp eval: "%s marker configure active_outlier_marker \ -text \"outliers: %d (%g)\" ", [aHisto getWidgetName], outliers, ((double)outliers) / (((double)outliers) + ((double)count)) ]; // And the window title, if needed. if (titleChanged) [aHisto title: theTitle]; // Finally updates the barchart. [aHisto drawHistoWithDouble: percentages atLocations: locations] ; } // If in store-to-file mode, if (fileOutput) { // Dumps out the values into a text file. [anOutFile putDouble: percentages[0]] ; for (i=1 ; i