/* * (c) 1998-2000 The Brookings Institution, All Rights Reserved * * Permission to use this software and its documentation for non-commercial * purposes and without fee is hereby granted, provided this copyright statement * is included. Please contact us for permission for redistribution and other uses. *  * BROOKINGS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,  * OR NON-INFRINGEMENT. BROOKINGS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY * LICENSEE AS A RESULT OF USING THIS SOFTWARE OR ITS DERIVATIVES. * * _Sugarscape_ * See _Growing Artificial Societies: Social Science from the Ground Up_ * Brookings Institution Press, The MIT Press * Joshua Epstein * jepstein@brook.edu * Robert Axtell * raxtell@brook.edu * * Miles Parker * mparker@brook.edu * http://www.brook.edu/es/dynamics/models/ascape * The Brookings Institution * Washington, D.C. */package edu.brook.sugarscape;import java.lang.*;import java.awt.Color;import edu.brook.ascape.model.*;import edu.brook.ascape.rule.*;import edu.brook.ascape.util.*;class PollutionDiffusion extends Diffusion {    public float getDiffusionValue(Agent agent) {        return ((PollutableSugarCell) agent).getPollution();    }    public void setDiffusionValue(Agent agent, float value) {        ((PollutableSugarCell) agent).setPollution(value);    }}public class PollutableSugarCell extends SugarCell implements Diffusable {        public static float maxPollution = 1;        /**     * Factor for pollution from gathering.     */    private static int sigma = 8;        private float pollution;        public void initialize() {        super.initialize();        pollution = 0;        maxPollution = 1;    }    	public void scapeCreated() {	    scape.addRule(new PollutionDiffusion());	}	    public float takeSugar() {        addPollution(sigma * sugar.getQuantity());        return super.takeSugar();    }        public float getPerceivedValue() {        return sugar.getQuantity() / (1 + pollution);    }        public float getPollution() {        return pollution;    }        public float getMaxPollution() {        return maxPollution;    }        public void setPollution(float pollution) {        this.pollution = pollution;        if (pollution > maxPollution) {            maxPollution = pollution;        }        requestUpdate();    }        public void addPollution(float pollution) {        setPollution(this.pollution + pollution);    }        private float diffusionTemp;        public float getDiffusionTemp() {        return diffusionTemp;    }        public void setDiffusionTemp(float diffusionTemp) {        this.diffusionTemp = diffusionTemp;    }        public double getValue(Object object) {        return (1.0F - (float) (float) ((PollutableSugarCell) object).getPollution() / (float) ((PollutableSugarCell) object).getMaxPollution());    }}
