Package eas.users.students.dominikColling.rocket

Source Code of eas.users.students.dominikColling.rocket.DomPhysEnv

/*
* File name:        DomPhysEnv.java (package eas.simulation.users.Dominik.rocket)
* Author(s):        Dominik
* Java version:     6.0
* Generation date:  12.04.2011 (12:19:17)
*
* (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.students.dominikColling.rocket;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.Random;

import eas.math.geometry.Vector2D;
import eas.simulation.Wink;
import eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.AgentList;
import eas.simulation.spatial.sim2D.physicalSimulation.physicsEngine.net.phys2d.math.Vector2f;
import eas.simulation.spatial.sim2D.physicalSimulation.standardAgents.PhysicsAgent2D;
import eas.simulation.spatial.sim2D.physicalSimulation.standardEnvironments.PhysicsEnvironment2D;
import eas.startSetup.ParCollection;
import eas.startSetup.SingleParameter;
import eas.startSetup.parameterDatatypes.Datatypes;

/**
* @author Dominik Colling
*
*/
public class DomPhysEnv extends PhysicsEnvironment2D<PhysicsAgent2D<?>> {
  /**
     *
     */
    private static final long serialVersionUID = 996078798327786175L;

    private Random rand;
 
  private DomPhysNetPopulation netPop;
  /** Abstand zwischen Raketen und Mond beim Start der Rakete*/
  private double abstand;
  //private String tabelleNetze;
  private String durchschnittFitness;
  private String letztePop;
  private String verzeichnis;
  private String zahl;
 
  private int saveLoad; // 0 nichts 1 Speichern 2 Lesen
 
  /** Staerke der Gravitation*/
  final double gravitationsKonstante; 
 
  /**
   * @param ident
   * @param params
   * @param gravity
   * @param iterations
   */
  public DomPhysEnv(int ident, ParCollection params, Vector2f gravity,
      int iterations) {
    super(ident, params, gravity, iterations);

    /*Hinzufuegen des Mondes */
    DomPhysMond mond = new DomPhysMond(0,this, params);
    this.addAgent(mond, new Vector2D(0, 0), 0)
    this.gravitationsKonstante = params.getParValueDouble("GravitationsKonstante");
   
    this.rand = new Random(params.getSeed());
    //this.popSize = params.getParWertInt("Populationsgroesse");
    this.netPop = new DomPhysNetPopulation(params.getParValueInt("NetPopulationsgroesse"), rand);
    this.saveLoad = params.getParValueInt("Speichern/Laden");
    this.abstand = params.getParValueDouble("Abstand");
    //this.tabelleNetze = params.getParWertString ("TabelleNetze");
    this.durchschnittFitness = params.getParValueString ("DurchschnittFitness");
    this.letztePop = params.getParValueString ("LetztePop");
    this.verzeichnis = params.getParValueString ("Verzeichnis");
    this.zahl = (params.getParValueString ("Zahl"));
    //this.anzahlZufaelligeHirne = params.getParWertInt("AnzahlZufaelligeHirne");
  }
 
  @Override
  public List<SingleParameter> getParameters() {
      List<SingleParameter> list = super.getParameters();
     
      list.add(new SingleParameter("GravitationsKonstante", Datatypes.DOUBLE, 10.0, "Staerke der Anziehungskraft", this.getEnvironmentName().toUpperCase()));
      list.add(new SingleParameter("NetPopulationsgroesse", Datatypes.INTEGER, 100, "Maximale Anzahl der NeuronalenNetze in der Population", this.getEnvironmentName().toUpperCase()));
      list.add(new SingleParameter("Speichern/Laden", Datatypes.INTEGER, 0, "0 = nichts, 1 = Speichern der Population, 2 = Laden einer Population", this.getEnvironmentName().toUpperCase()));
      list.add(new SingleParameter("Abstand", Datatypes.DOUBLE, 0.5, "Abstand", this.getEnvironmentName().toUpperCase()));
      //list.add(new SingleParameter("TabelleNetze", Datatypes.STRING, "TabelleNetzte", "Dateiname für Tabelle der Netzte (ohne .txt)", this.id().toUpperCase()));
      list.add(new SingleParameter("DurchschnittFitness", Datatypes.STRING, "DurchschnittFitness", "Dateiname für Liste der Durchschnittsfitness (ohne .txt)", this.getEnvironmentName().toUpperCase()));
      list.add(new SingleParameter("LetztePop", Datatypes.STRING, "lastPop", "Dateiname für Speichern der letzten Generation (ohne .txt)", this.getEnvironmentName().toUpperCase()));
      list.add(new SingleParameter("Verzeichnis", Datatypes.STRING, "./", "Verzeichnisname für Speichern", this.getEnvironmentName().toUpperCase()));
      list.add(new SingleParameter("Zahl", Datatypes.STRING, "1", "Anhang an Dateiname", this.getEnvironmentName().toUpperCase()));
     
     
      return list;
  }
 
    @Override
  public void step(Wink simTime) {
    super.step(simTime);
 
    AgentList<PhysicsAgent2D<?>> agenten = this.getBodies();
 
      for (int i = 0; i < agenten.size(); i++) {
        PhysicsAgent2D<?> agent = agenten.get(i);
   
        Vector2D posMond = this.getAgentPosition(0);
        Vector2D pos = this.getAgentPosition(agent.getID());
   
        /* Berechnung des Abstands zwischen Körper und Mond, Berechnung der Gravitationsbeschleunigung mit
         * g = Konstante * Masse des Körpers / Abstand^2 und anschließender Beschleunigung des Körpers */
      
        double xAbstand = posMond.x- pos.x;
        double yAbstand = posMond.y- pos.y;
        double abstand =  java.lang.Math.sqrt(xAbstand*xAbstand + yAbstand*yAbstand);
        double anziehungskraft = (gravitationsKonstante * agent.getMass()) / (abstand*abstand);
        float anziehungX = (float)(anziehungskraft * xAbstand);
        float anziehungY = (float)(anziehungskraft * yAbstand);
       
        Vector2f anziehung = new Vector2f(anziehungX,anziehungY);
        agent.adjustVelocity(anziehung);
      }
    
  }
 
  public double getGravitationskonstante() {
    return gravitationsKonstante;
  }
 
  public DomPhysNetPopulation getNetPop() {
    return netPop;
  }
 
  public Random getRand() {
    return rand;
  }
 
  public int getSaveLoad() {
    return saveLoad;
  }
 
  public double getAbstand() {
    return abstand;
  }
 
  public void setNetPop(DomPhysNetPopulation netPop2) {
    this.netPop = netPop2;
  }
 
  /*public String getTabelleNetze() {
    return tabelleNetze;
  }*/
 
  public String getDurchschnittFitness() {
    return durchschnittFitness;
  }
 
  public String getLetztePop() {
    return letztePop;
  }
  public String getVerzeichnis() {
    return verzeichnis;
  }
 
  public String getZahl() {
    return zahl;
  }
 
  /** zeigt den maximalen Abstand, den eine Rakete haben darf, um nicht zu sterben, im Environment */
  @Override
  public synchronized BufferedImage getOutsideView() {
      BufferedImage img = super.getOutsideView();
      Vector2D middle = this.getPositionInVisualization(0);
      double radius = DomPhysAgent.MAX_ORBIT_ABSTAND + DomPhysMond.RADIUS;
      double imgAbstand = radius * this.globalScale();
      Graphics2D g = img.createGraphics();
      g.setColor(Color.red);
      g.drawOval(
              (int) (middle.x - imgAbstand),
              (int) (middle.y - imgAbstand),
              (int) (imgAbstand * 2),
              (int) (imgAbstand * 2));
     
      return img;
  }
}
TOP

Related Classes of eas.users.students.dominikColling.rocket.DomPhysEnv

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.