Package eas.users.other.marc.smartCity

Source Code of eas.users.other.marc.smartCity.AgentSmartCar

/*
* Datei:            AgentSmartCar.java
* Autor(en):        Lukas König, Marc Mültin
* Java-Version:     6.0
* Erstellt:         ??.06.2010
*
* (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.other.marc.smartCity;

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

import eas.simulation.Wink;
import eas.simulation.agent.AbstractAgent;
import eas.simulation.agent.GenericActuator;
import eas.simulation.agent.GenericSensor;
import eas.simulation.event.EASEvent;
import eas.simulation.standardEnvironments.AbstractEnvironment;
import eas.startSetup.ParCollection;
import eas.startSetup.SingleParameter;

/**
* @author aifb
*
*/
public class AgentSmartCar extends AbstractAgent<AbstractEnvironment<?>> {

    /**
     *
     */
    private static final long serialVersionUID = -3813507048013748619L;
    private boolean loading;
   
    /**
     * @param id
     * @param env
     */
    public AgentSmartCar(int id, AbstractEnvironment<AbstractAgent<?>> env, ParCollection params) {
        super(id, env, params);
       
        this.addSensor(new GenericSensor<Double, EnvSmartCity, AgentSmartCar>() {

            /**
             *
             */
            private static final long serialVersionUID = -8859849131321932582L;

            @Override
            public String id() {
                return "GetPriceSignal";
            }

            @Override
            public Double sense(EnvSmartCity env, AgentSmartCar agent) {
                return env.getPriceSignal();
            }
           
        });
       
        this.addSensor(new GenericSensor<Double, EnvSmartCity, AgentSmartCar>() {
            /**
             *
             */
            private static final long serialVersionUID = -4881746506556280157L;

            @Override
            public String id() {
                return "GetPVValueGeneral";
            }

            @Override
            public Double sense(EnvSmartCity env, AgentSmartCar agent) {
                return env.getPVValueGeneral();
            }
        });

        this.addSensor(new GenericSensor<Boolean, EnvSmartCity, AgentSmartCar>() {

            /**
             *
             */
            private static final long serialVersionUID = -8467639743507798746L;

            @Override
            public String id() {
                return "IsLoading";
            }

            @Override
            public Boolean sense(EnvSmartCity env, AgentSmartCar agent) {
                return AgentSmartCar.this.loading;
            }
           
        });

        this.addActuator(new GenericActuator<EnvSmartCity, AgentSmartCar>() {
          /**
             *
             */
            private static final long serialVersionUID = -272002735770333086L;

            @Override
            public String id() {
                return "LoadIfCheap";
            }
         
            @Override
            public void actuate(EnvSmartCity env, AgentSmartCar agent) {
                double signal = (Double) AgentSmartCar.this.sense("GetPriceSignal");
                if (signal <= 10) {
                    AgentSmartCar.this.loading = true;
                } else {
                    AgentSmartCar.this.loading = false;
                }
            }           
        });
    }

    /* (non-Javadoc)
     * @see eas.simulation.AbstractAgent#step(double)
     */
    @Override
    public void step(final Wink simZyk) {
        this.actuate("LoadIfCheap");
    }

    /* (non-Javadoc)
     * @see eas.simulation.AbstractAgent#getControllerView()
     */
    @Override
    public BufferedImage getInsideView() {
        BufferedImage img = super.getInsideView();
        if (img == null) {
            return null;
        }
        Graphics2D g = img.createGraphics();

        if (this.loading) {
            g.setColor(Color.green);
        } else {
            g.setColor(Color.red);
        }
       
        g.fillOval(img.getWidth() - 25, 50, 20, 20);
        g.setColor(Color.black);
        g.drawOval(img.getWidth() - 25, 50, 20, 20);
       
        return img;
    }

    @Override
    public void handleEvent(EASEvent e, Wink lastActionTime) {
       
    }

    @Override
    public List<SingleParameter> getParameters() {
        return null;
    }
}
TOP

Related Classes of eas.users.other.marc.smartCity.AgentSmartCar

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.