/*
* File name: CleaningPlugin.java (package eas.users.lukas.demos.cleaningPacmen)
* Author(s): Lukas König
* Java version: 6.0
* Generation date: 02.10.2011 (23:28:34)
*
* (c) This file and the EAS (Easy Agent Simulation) framework containing it
* is protected by Creative Commons by-nc-sa license. Any altered or
* further developed versions of this file have to meet the agreements
* stated by the license conditions.
*
* In a nutshell
* -------------
* You are free:
* - to Share -- to copy, distribute and transmit the work
* - to Remix -- to adapt the work
*
* Under the following conditions:
* - Attribution -- You must attribute the work in the manner specified by the
* author or licensor (but not in any way that suggests that they endorse
* you or your use of the work).
* - Noncommercial -- You may not use this work for commercial purposes.
* - Share Alike -- If you alter, transform, or build upon this work, you may
* distribute the resulting work only under the same or a similar license to
* this one.
*
* + Detailed license conditions (Germany):
* http://creativecommons.org/licenses/by-nc-sa/3.0/de/
* + Detailed license conditions (unported):
* http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
*
* This header must be placed in the beginning of any version of this file.
*/
package eas.users.demos.cleaningPacmen;
import java.util.List;
import org.jfree.data.category.DefaultCategoryDataset;
import eas.plugins.AbstractDefaultPlugin;
import eas.simulation.Wink;
import eas.simulation.event.EASEvent;
import eas.startSetup.ParCollection;
import eas.startSetup.SingleParameter;
/**
* @author Lukas König
*
*/
public class CleaningPlugin extends AbstractDefaultPlugin<StandardCleaningEnvironment> {
/**
*
*/
private static final long serialVersionUID = -6569936502701268789L;
@Override
public List<String> getRequiredPlugins() {
return null;
}
@Override
public List<SingleParameter> getParameters() {
return null;
}
// private JFreeChart chart;
private DefaultCategoryDataset dataset;
// private StaticWindow window;
@Override
public String id() {
return "CleaningChart";
}
@Override
public void runBeforeSimulation(StandardCleaningEnvironment env,
ParCollection params) {
dataset = new DefaultCategoryDataset();
// chart = ChartFactory.createLineChart(
// "Dirt count",
// "Simulation time",
// "Avg. amount of dirt on every grid field",
// dataset,
// PlotOrientation.VERTICAL,
// false,
// false,
// false);
// window = StaticMethods.showImage(chart.createBufferedImage(500, 500), "Line chart");
}
@Override
public void runDuringSimulation(StandardCleaningEnvironment env,
Wink currentSimTime, ParCollection params) {
double avgDirt = 0;
for (int i = 0; i < env.getGridWidth(); i++) {
for (int j = 0; j < env.getGridHeight(); j++) {
try {
avgDirt += ((StandardDirt) env.getFieldPosition(i, j).get(0)).getSchmutzWert();
} catch (Exception e) {}
}
}
avgDirt /= env.getGridHeight() * env.getGridHeight();
dataset.addValue((Number) avgDirt, "1", currentSimTime.getLastTick());
// window.getPanel().setImg(chart.createBufferedImage(500, 500));
// window.getPanel().repaint();
}
@Override
public void runAfterSimulation(StandardCleaningEnvironment env,
ParCollection params) {
}
@Override
public void handleEvent(EASEvent e, StandardCleaningEnvironment env,
Wink lastSimTime, ParCollection params) {
}
/* (non-Javadoc)
* @see eas.plugins.Plugin#getSupportedPlugins()
*/
@Override
public List<String> getSupportedPlugins() {
// TODO Auto-generated method stub
return null;
}
@Override
public void onSimulationResumed(StandardCleaningEnvironment env, Wink resumeTime,
ParCollection params) {
}
}