MASON-INTEREST-L Archives

May 2006

MASON-INTEREST-L@LISTSERV.GMU.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Mike Little <[log in to unmask]>
Reply To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Date:
Thu, 4 May 2006 13:23:18 -0400
Content-Type:
multipart/mixed
Parts/Attachments:
text/plain (4090 bytes) , StatChartImage.png (32 kB)
Mike,
   Hmm, while I did not get around to actually setting up JFreeChart
for an earlier version of Mason, I had no problem following the
tutorial suggestions and getting a chart up and going for version 11.
While I would describe my code as well functioning, clean it is not
as it contains lots of non-chart functionality. I have extracted the
following in hopes it helps you:

public class SimulatorWithUI extends GUIState {

   public JFrame			chartFrame;
   public ChartGenerator		statisticsChart;

   public void start() {
	super.start();
	.
	.
	.
	// Set up statistics to display via JCharts
	statisticsChart.removeAllSeries();
         final XYSeries detectedSeries =
		new XYSeries("Detected Attacks", false);
         final XYSeries attacksSeries =
		new XYSeries("Attacks Launched", false);
         final XYSeries missedSeries =
		new XYSeries("Attacks Not Detected", false);
         final XYSeries delaySeries =
		new XYSeries("Recognition Delay (Mean)", false);
         final XYSeries sensorSeries =
		new XYSeries("Sensor Events", false);
         final XYSeries eventSeries =
		new XYSeries("Event Packets Generated", false);
         statisticsChart.addSeries(detectedSeries, null);
         statisticsChart.addSeries(attacksSeries, null);
         statisticsChart.addSeries(missedSeries, null);
         statisticsChart.addSeries(delaySeries, null);
         statisticsChart.addSeries(sensorSeries, null);
         statisticsChart.addSeries(eventSeries, null);
         chartFrame.pack();
         chartFrame.setVisible(false);

         // Set up chart refresh rate with the simulator
         scheduleImmediateRepeat(true, new Steppable() {
           public void step(SimState state) {
              StatLogger logger = ((Simulator)state).stats;
        	     AttackSummary attacks =
			((Simulator)state).getAttackSummary();
	     double currentTime = state.schedule.time();
        	     // Update statistics chart
	     sensorSeries.add(currentTime,
		logger.get(Stats.SENSOR_PACKET_STAT), true);
	     eventSeries.add(currentTime,
		logger.get(Stats.EVENT_PACKET_STAT), true);
	     detectedSeries.add(currentTime,
		attacks.attacksDetected, true);
	     attacksSeries.add(currentTime,
		attacks.attacksRegistered, true);
	     missedSeries.add(currentTime,
		attacks.attacksMissed, true);
	     delaySeries.add(currentTime,
		attacks.meanRecognitionDelay, true);
            }
          });
   }

   public void init(Controller c) {
	super.init(c);
	// Your display frame declaration might be like this:
	displayFrame = display.createFrame();
	.
	.
	.
	// Create the chart frame
	chartFrame = createChartFrame();
		
	// register the frame so it appears in the "Display" list
	c.registerFrame(displayFrame);
	c.registerFrame(chartFrame);
   }

   public JFrame createChartFrame() {
	// Use JFreeChart to display statistics
	statisticsChart = new sim.util.media.ChartGenerator();
	statisticsChart.setTitle("Performance Summary Statistics");
	statisticsChart.setRangeAxisLabel("Peformance Metric Value");
	statisticsChart.setDomainAxisLabel("Time (Simulated)");
	JFrame frame = statisticsChart.createFrame(this);
	frame.setTitle("Statistics Chart");
	return frame;
   }
}

Of course your statistics, and number thereof, and how you acquire
them from your simulation code will differ from mine.

I hope the fact I show the use of six helps, rather than hinders, this
example. For me, this generates a chart like the image attached. It
uses the defaults, with the exception of the title and labels shown
above in the sample code. You can see multiple items show in different
colors by default.

					-Mike

Michael Makowsky wrote:

> Version 11 seems to allow for a slightly different incorporation of JFree
> Charts, and in turn a different set up for the GUI subclass of whatever
> model you are creating. Does anyone have some clean, well functioning code
> of a GUIclass that creates charts. It would be great if the charts plotted
> multiple items in different colors. 
> 
> mike
> 
> Michael Makowsky
> Graduate Student
> Department of Economics
> George Mason University
> 703.608.1366
> [log in to unmask]
> website: http://mason.gmu.edu/~mmakowsk
> ******************************
> 


ATOM RSS1 RSS2