Package eas.users.students.dominikColling.rocket

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

/*
* File name:        DomPhysPopulation.java (package eas.simulation.users.students.dominikColling.rocket)
* Author(s):        Dominik
* Java version:     6.0
* Generation date:  11.05.2011 (10:23:46)
*
* (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.util.ArrayList;
import java.util.List;
import java.util.Random;

import eas.users.students.dominikColling.rocket.brain.DomPhysSparseNet;

/**
* @author Dominik
*
*/
public class DomPhysNetPopulation {
 
  int maxSize;
  int size;
  Random rand;
 
  List<DomPhysSparseNet> nets;
  List<Integer> fitnessWerte;
  List<Double> minAbstaende;
  List<Double> maxAbstaende;
  List<Integer> geburten;

  public DomPhysNetPopulation(int maxSize, Random random ) {
    this.maxSize = maxSize;
    this.size = 0;
    this.rand = random;
    this.nets = new ArrayList<DomPhysSparseNet>();
    this.fitnessWerte = new ArrayList<Integer>();
    this.minAbstaende = new ArrayList<Double>();
    this.maxAbstaende = new ArrayList<Double>();
    this.geburten = new ArrayList<Integer>();
  }
 
  public void add(DomPhysSparseNet net, int fitness, double minAbstand, double maxAbstand, int geburt) {
   
    if(size < maxSize) {
    nets.add(net);   
    fitnessWerte.add(fitness);
    //System.out.println ("JETZT Fitness: " + fitnessWerte.size());
    //System.out.println("MIN: " + abstaende[0] + " Max: " + abstaende[1]);
    this.minAbstaende.add(minAbstand);
    this.maxAbstaende.add(maxAbstand);
    this.geburten.add(geburt);
    this.size++;
    // System.out.println ("JETZT NET: " + nets.size() +" " +size);
    }
   
    if (size == maxSize) {
      int minFitness = Integer.MAX_VALUE;
      int anStelle = 0;
          
           for (int k = 0; k < size; k++) {
             if (this.fitnessWerte.get(k) <  minFitness) {
               minFitness = this.fitnessWerte.get(k);
               anStelle = k;
               //System.out.println("MIN: " +minFitness + "Stelle: " + k);
             }                          
          
           //int anStelle = this.fitnessWerte.lastIndexOf(minFitness);
          
           // System.out.println(anStelle + "F: " +fitness + " GROESSE: " + size + "GROESSE2 " + nets.size());
           nets.set(anStelle, net);
           fitnessWerte.set(anStelle, fitness);
           this.minAbstaende.set(anStelle, minAbstand);
        this.maxAbstaende.set(anStelle, maxAbstand);
        this.geburten.set(anStelle, geburt);
           }
    }
  }
 
  //Fügt nur hinzu, falls Netz nicht schlechter als alle bisher vorhandenen
  public void addZwischen(DomPhysSparseNet net, int fitness, double minAbstand, double maxAbstand, int geburt) {

    if(size < maxSize) {
      nets.add(net);     
      fitnessWerte.add(fitness);
      //System.out.println ("JETZT Zw Fitness: " + fitnessWerte.size());
      this.minAbstaende.add(minAbstand);
      this.maxAbstaende.add(maxAbstand);
      this.geburten.add(geburt);
      this.size++;
      // System.out.println ("JETZT Zw NET: " + nets.size() +" " +size);
    }

    if (size == maxSize) {
      int anStelle = 0;
      int minFitness = Integer.MAX_VALUE;

      for (int k = 0; k < size; k++) {
        if (this.fitnessWerte.get(k) <  minFitness) {
          minFitness = this.fitnessWerte.get(k);
          anStelle = k;
        }
        //anStelle = this.fitnessWerte.lastIndexOf(minFitness);
      }
      if(minFitness < fitness) {
        //System.out.println("MINFIT: " +  minFitness+ " NETFIT: " + net.getFitness());
        nets.set(anStelle, net);
        fitnessWerte.set(anStelle, fitness);
        this.minAbstaende.set(anStelle, minAbstand);
         this.maxAbstaende.set(anStelle, maxAbstand);
         this.geburten.set(anStelle, geburt);
      }
    }
  }
 
  public DomPhysSparseNet getBestesNetz() {
     int maxFitness = 0;
        
         for (int k = 0; k < size; k++) {
           if (this.fitnessWerte.get(k) >  maxFitness) {
             maxFitness = this.fitnessWerte.get(k);
           }                          
         }
        
         int anStelle =this.fitnessWerte.lastIndexOf(maxFitness);
        
         DomPhysSparseNet net = nets.get(anStelle);
   
     return net;
  }
 
  public int getIndexBestesNetz() {
    int maxFitness = 0;

    for (int k = 0; k < size; k++) {
      if (this.fitnessWerte.get(k) >  maxFitness) {
        maxFitness = this.fitnessWerte.get(k);
      }                          
    }

    int anStelle =this.fitnessWerte.lastIndexOf(maxFitness);

    return anStelle;
  }
 
  /*public List<DomPhysSparseNet> getBesteNetze(int anzahl) {
    List<DomPhysSparseNet> liste = new ArrayList<DomPhysSparseNet>();
    List<DomPhysSparseNet> liste2 = this.nets;
    int anStelle = 0;
    //System.out.println("A: " + anzahl + " S: " + this.size);

    if (anzahl < this.size) {
      for (int i = 0; i < anzahl; i++) {
        Double maxFitness = new Double(0);

        for (int k = 0; k < liste2.size(); k++) {
          if (this.fitnessWerte.get(k) >  maxFitness) {
            maxFitness = this.fitnessWerte.get(k);
            anStelle = k;
          }                          
        }

        DomPhysSparseNet net = liste2.get(anStelle);
        liste.add(net);
        liste2.remove(anStelle);
      }
    }
    return liste;
  } */
 
  public DomPhysSparseNet getSchlechtestesNetz() {
   
    int minFitness = Integer.MAX_VALUE;
    int zaehler = 0;
        
         for (int k = 0; k < size; k++) {
           if (this.fitnessWerte.get(k) <  minFitness) {
             minFitness = this.fitnessWerte.get(k);
             zaehler = k;
           }                          
         }
        
         int anStelle =zaehler;
        
         DomPhysSparseNet net = nets.get(anStelle);
   
     return net;
   
  }
 
 
  public DomPhysSparseNet getNet (int i) {
    return nets.get(i);
  }
 
  public int getSize() {
    return size;
  }
 
  public int getMaxSize() {
    return maxSize;
  }
 
  public List<DomPhysSparseNet> getNetze() {
    return this.nets;
  }
  /*
  public DomPhysSparseNet turnier (int turnierSize) {
    int maxFitness = 0;
    int zaehler = 0;
   
    for (int k = 0; k < turnierSize; k++) {
            int stelle = rand.nextInt(maxSize);
                       
            if(this.fitnessWerte.get(stelle) > maxFitness) {
              maxFitness = this.fitnessWerte.get(stelle);
              zaehler = k;
            }
           
        }      

        int indexSieger = zaehler;
        DomPhysSparseNet net = nets.get(indexSieger);
   
        return net;
   
  }
 
  public DomPhysSparseNet roulette () {
    double zufall = rand.nextDouble();   
   
    double summeFitness = 0;
    for (int k = 0; k < size; k++) {
            summeFitness = summeFitness + fitnessWerte.get(k);
            }
   
    double f = fitnessWerte.get(0);
    double fGes = zufall * summeFitness;
    int stelle = 0;
   
    while (f < fGes) {
      stelle++;
            f = f + fitnessWerte.get(stelle);
            }
    return nets.get(stelle);
        }
        */
 
  public List<Integer> getFitnesswerte() {
    return this.fitnessWerte;
  }
 
  public int getFitness(int i) {
    return fitnessWerte.get(i);
  }
 
  public List<Double> minAbstaende() {
    return this.minAbstaende;
  }
 
  public double getMinAbstand(int i) {
    return minAbstaende.get(i);
  }
 
  public List<Double> maxAbstaende() {
    return this.maxAbstaende;
  }
 
  public double getMaxAbstand(int i) {
    return maxAbstaende.get(i);
  }
 
  public List<Integer> getGeburten() {
    return this.geburten;
  }
 
  public int getGeburt(int i) {
    return geburten.get(i);
  }
 
 
}
TOP

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

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.