Package eas.users.ocScenarios.oclrws1112.antTrail

Source Code of eas.users.ocScenarios.oclrws1112.antTrail.AntScheduler

/*
* File name:        AntScheduler.java (package eas.users.oclrws1112.AntTrail)
* Author(s):        Julien
* Java version:     6.0
* Generation date:  04.01.2012 (15:42:07)
*
* (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.ocScenarios.oclrws1112.antTrail;

import java.util.List;
import java.util.Random;

import eas.math.geometry.Vector2D;
import eas.plugins.masterScheduler.AbstractDefaultMaster;
import eas.simulation.ConstantsSimulation;
import eas.startSetup.ParCollection;
import eas.startSetup.SingleParameter;
import eas.startSetup.parameterDatatypes.Datatypes;

/**
* @author Nico
* @author Julien
*/
public class AntScheduler extends AbstractDefaultMaster<AntEnvironment> {

  /**
     *
     */
    private static final long serialVersionUID = -2059841931197150678L;
    // Der Startwert des Pheromonwertes
  public double pheromonStartWert = 1;
 
  @Override
  public List<SingleParameter> getParameters() {
      List<SingleParameter> list = super.getParameters();
     
      list.add(new SingleParameter(
              "ants.nestKoordinaten",
              Datatypes.VECTOR2D,
              new Vector2D(10, 10)));
      list.add(new SingleParameter(
              "ants.foodKoordinaten",
              Datatypes.VECTOR2D,
              new Vector2D(20, 20)));
      list.add(new SingleParameter(
              "ants.fieldSize",
              Datatypes.INTEGER,
              30));
      list.add(new SingleParameter(
              "ants.numberOfAnts",
              Datatypes.INTEGER,
              10));
     
      return list;
  }
 
  @Override
  public AntEnvironment[] generateRunnables(ParCollection params) {
      int size = params.getParValueInt("ants.fieldSize"); // Groesse des Grids
      AntEnvironment env = new AntEnvironment(0, params, size, size, true, false, 50, -1, null);   
        return new AntEnvironment[] { env };
  }

  @Override
  public String id() {
    return ConstantsSimulation.DEFAULT_MASTER_SCHEDULER_ID + "_oclrws1112.AntTrail";
  }
 
  // Hier drinnen werden die Pheromonwerte initialisiert
  @Override
  public void runBeforeSimulation(AntEnvironment env, ParCollection params) {
      super.runBeforeSimulation(env, params);
      int nestX;
      int nestY;
      int foodX;
      int foodY;
      int amountOfAnts;
   
        amountOfAnts = params.getParValueInt("ants.numberOfAnts");
        foodX = (int) params.getParValueVector2D("ants.foodKoordinaten").x;
        foodY = (int) params.getParValueVector2D("ants.foodKoordinaten").y;
        nestX = (int) params.getParValueVector2D("ants.nestKoordinaten").x;
        nestY = (int) params.getParValueVector2D("ants.nestKoordinaten").y;
     
        Random rand = new Random(params.getSeed());

        // Hinzufuegen des Nests
        env.addGridObject(new Nest(nestX, nestY), nestX, nestY);

        // Hinzufuegen der Ameisen
        for (int i = 0; i < amountOfAnts; i++) {
            env.addAgent(new Ant(i, env, params, nestX, nestY), new Vector2D(
                    nestX, nestY), rand.nextInt(8) * 45);
        }

        // Hinzufuegen des Futters
        env.addGridObject(new Food(), foodX, foodY);

    env.setNest(new Vector2D(nestX, nestY));
   
    for (int i = 0; i < env.getWidth(); i++) {
      for (int j = 0; j < env.getHeight(); j++) {
        Pheromone ph = new Pheromone();
        ph.setPheromone(pheromonStartWert);
        env.addGridObject(ph, i, j);
      }
    }
  }
}
TOP

Related Classes of eas.users.ocScenarios.oclrws1112.antTrail.AntScheduler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.