Package eas.simulation.spatial.standardBrains.marb

Source Code of eas.simulation.spatial.standardBrains.marb.MARBBrain

/*
* File name:        MARBBrain.java (package eas.simulation.spatial.standardBrains.marb)
* Author(s):        Lukas König
* Java version:     6.0
* Generation date:  03.02.2011 (16:30:45)
*
* (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.simulation.spatial.standardBrains.marb;

import java.awt.image.BufferedImage;
import java.util.List;

import eas.math.geometry.Geometry2D;
import eas.simulation.Wink;
import eas.simulation.agent.AbstractAgent;
import eas.simulation.brain.AbstractBrain;
import eas.simulation.spatial.sim2D.marbSimulation.endlAutomat.EndlicherAutomat;
import eas.startSetup.ParCollection;
import eas.startSetup.SingleParameter;
import eas.startSetup.marbBuilder.DargestellterGraph;
import eas.startSetup.marbBuilder.darstellungsModi.DarstModEA;
import eas.startSetup.marbBuilder.graph.Knoten;
import eas.startSetup.marbBuilder.zeichenModi.ArrowMaster;
import eas.startSetup.parameterDatatypes.Datatypes;

/**
* @author Lukas König
*
*/
public class MARBBrain<AgentType extends AbstractAgent<?>> extends AbstractBrain<AgentType> {

    private static final long serialVersionUID = -4089723741265027442L;
    private EndlicherAutomat marb;
    private ParCollection pars;
    private ArrowMaster master;
   
    /**
     * @param brainsBody  The agent that this brain belongs to.
     */
    public MARBBrain(
            final AgentType brainsBody,
            final String sequence,
            final ParCollection params) {
        super(brainsBody);
        marb = new EndlicherAutomat();
        marb.erzeugeAusStdSequenz(sequence);
        this.pars = params;
        this.master = new ArrowMaster(this.pars);
    }

    public MARBBrain(final AgentType brainsBody, final ParCollection params) {
        this(brainsBody, "", params);
    }
   
    @Override
    public BufferedImage generateMRTImage() {
        float nodeCount = this.marb.getKnList().size();
        float sizeConstant = 100;
        float relation = 1;
       
        DargestellterGraph g = new DarstModEA(
                0,
                0,
                (int) (sizeConstant * Math.sqrt(nodeCount)),
                (int) (relation * sizeConstant * Math.sqrt(nodeCount))).erzeuge(marb, marb.getCurrentState());
        List<Object> toPaint = master.graph(g);
        return Geometry2D.erzBuffImgAusObjekten(toPaint);
    }
   
    @Override
    public void decideAndReact(Wink time) {
        int[] sensors = new int[this.getMyBody().getSensors().size()];
        int action = -1;
       
        for (int j = 0; j < sensors.length; j++) {
            sensors[j] = -1;
        }
       
        Knoten node = marb.step(this.getMyBody(), sensors);
       
        try {
            action = node.getInfo().getAktion();
        } catch (Exception e) {
        }
       
        if (action >= 0) {
            try {
                this.getMyBody().actuate((action - 1) % this.getMyBody().getActuators().size());
            } catch (Exception e) {
                throw new RuntimeException("(MARBBrain) No actuators found in agent " + this.getMyBody().id());
            }
        }
    }
   
    /**
     * @return Returns the marb.
     */
    public EndlicherAutomat getMarb() {
        return this.marb;
    }
   
    @Override
    public List<SingleParameter> getParameters() {
        List<SingleParameter> list = super.getParameters();
        list.add(
                new SingleParameter(
                        eas.statistics.ConstantsStatistics.BEZIER_KONST,
                        Datatypes.DOUBLE,
                        eas.startSetup.marbBuilder.zeichenModi.ConstantsZeichenModi.BEZ_NORMAL,
                        "Die Bezier-Konstante (je kleiner, desto feiner).",
                "MARB-BRAIN"));
        list.add(
                new SingleParameter(
                        eas.statistics.ConstantsStatistics.EINFACHE_DARSTELLUNG,
                        Datatypes.BOOLEAN,
                        true,
                        "Ob einfache Darstellung für MARBs ausgewählt ist.",
                "MARB-BRAIN"));
       
        list.add(new SingleParameter(
                "showEALabels?",
                Datatypes.BOOLEAN,
                true,
                "Ob die Labels (Knoten / Kanten) in der grafischen Darstellung eines MARBs angezeigt werden.",
                "MARB-BRAIN"));

        return list;
    }
}
TOP

Related Classes of eas.simulation.spatial.standardBrains.marb.MARBBrain

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.