⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 location.java

📁 使用java编写的关于通讯及串口编程所必需的类库
💻 JAVA
字号:
/* * Location.java * * This is a required part of the com.adaptiveview.ospso package. * * Copyright (C) 2003 AdaptiveView.com *  * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * General Public License for more details. *  * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *  * You may contact AdaptiveView.com via email at: comments.pso@adaptiveview.com  * */package com.adaptiveview.ospso;/**Location is an aggregate holding a reference to a LocationChange instance and a fitness value  * (a measure of how close this location, as applied to the problem, is to an optimal * solution of the problem). * A Location instance simply holds and presents data. The data is set by the <b>Particle</b>'s  * <code>moveAlgorithm</code> and the <b>Swarm</b>'s <code>fitnessAlgorithm</code>. * * @author AdaptiveView.com */public final class Location implements com.adaptiveview.ospso.dmi.DMI_GPL_License {        private double fitness;    private boolean haveFitness = false;        private LocationChange locationChange;        /** Creates a new instance of Location     * @param coordinates Locations along each dimension of the solution     * space.     * @param velocities The +/- movement along dimension leading to this     * coordinate. There is a 1-to-1 mapping between velocities and coordinates.     * @param fitness How fit the solution at these coordinates is.     */    public Location(double[] coordinates, double[] velocities, double fitness) {        setFitness(fitness);        locationChange = new LocationChange(coordinates, velocities);    }        /** Creates a new instance of Location     * @param coordinates Locations along each dimension of the solution     * space.     * @param velocities The +/- movement along dimension leading to this     * coordinate. There is a 1-to-1 mapping between velocities and coordinates.     */    public Location(double[] coordinates, double[] velocities) {        locationChange = new LocationChange(coordinates, velocities);    }        /** Returns the fitness value.     * @throws IllegalStateException if fitness has not been set yet.     * @return the fitness value.     */        public double getFitness() throws IllegalStateException {        if (!haveFitness)            throw new IllegalStateException("Fitness has not been set.");        return fitness;    }        /** Returns a copy of this Location.     * @return a copy of this Location.     */        public Location getCopyOfLocation() {        return new Location(locationChange.getCopyOfCoordinates(),                            locationChange.getCopyOfVelocities(),                             fitness);    }        /** Sets the fitness value for the location coordinates.     * @param newFitness The new fitness value.     */        protected void setFitness(double newFitness) {        this.fitness = newFitness;        haveFitness = true;    }        /** Gets a reference to the location's LocationChange instance which     * contains the coordinates and velocities arrays.     * @return a reference to the location's LocationChange instance.     */        protected LocationChange getLocationChange() {        return locationChange;    }        /** Overrides toString and returns a formatted listing of the     * fitness value and (via <code>Move&#46toString</code>) the coordinates and     * velocities for this location.     * @return formatted fitness, coordinates and velocities for this location.     */        public String toString() {        StringBuffer s = new StringBuffer();        s.append("Fitness:     ");        if (haveFitness)          s.append(fitness);        else          s.append("not set");          s.append("\n");        s.append(locationChange.toString());        return s.toString();    }/*    public static void main(String[] args) {        double[] ml = {1.0/3.0,2.0/3.1,3.0/3.2,4.0/3.3,5.0/3.4};        double[] mv = {1.0/5.0,2.0/4.1,3.0/3.2,4.0/2.3,5.0/1.4};        Location l = new Location(ml,mv);        l.setFitness(3.0);        System.out.println(l.toString());    }*/}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -