/*
* File name: TestEnvironment.java (package eas.users.fredy)
* Author(s): Lukas König
* Java version: 8.0 (at generation time)
* Generation date: 23.05.2014 (15:28:57)
*
* (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 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.fredy.grid;
import java.util.Random;
import eas.simulation.Wink;
import eas.simulation.standardEnvironments.AbstractEnvironment;
import eas.startSetup.ParCollection;
import eas.users.fredy.grid.mgm.ManagerAgent;
import eas.users.fredy.grid.prosumer.ProsumerAgent;
/**
* @author Lukas König
*/
public class FredyEnvironment extends AbstractEnvironment<AbstractFredyAgent> {
private ManagerAgent managerAgent;
private Random rand;
private static final long serialVersionUID = 8986870984458745033L;
public ManagerAgent getManagerAgent() {
return this.managerAgent;
}
public FredyEnvironment(int id, ParCollection params, Random rand) {
super(id, params);
this.rand = rand;
ParameterClass.resetRequested = true;
}
public int getMyIntegerParameter() {
return ParameterClass.getNumberOfProsumers();
}
@Override
public boolean addAgent(AbstractFredyAgent agent) {
if (ManagerAgent.class.isInstance(agent)) {
this.managerAgent = (ManagerAgent) agent;
}
return super.addAgent(agent);
}
@Override
public void step(Wink simTime) {
System.out.println("\n\nHere is environment " + this.id());
if (ParameterClass.resetRequested) {
this.reset();
}
}
public void reset() {
this.removeAllAgents();
if (this.managerAgent == null) {
this.managerAgent = new ManagerAgent(0, this, this.getPars());
}
this.addAgent(this.managerAgent);
for (int i = 0; i < ParameterClass.getNumberOfProsumers(); i++) {
this.addAgent(new ProsumerAgent(i + 1, this, this.getPars(), rand));
}
ParameterClass.resetRequested = false;
}
}