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

📄 citymap.java

📁 This program is using Genetic Algorithm to solve the Travlling Salesman Problem. It gives the bes
💻 JAVA
字号:
// DO NOT MODIFY THIS FILE.

import java.io.*;
import java.util.ArrayList;
public class CityMap
{
    private ArrayList map = new ArrayList();
 
    public int getNumCities(){
				return map.size();
    }

    public double getLocationX(int index) {
        return ((double[])(map.get(index)))[0];
    }

    public double getLocationY(int index) {
        return ((double[])(map.get(index)))[1];
    }

    public void addCity(double x, double y){
				double[] temp = {x,y};
				map.add(temp);
    }

    public void save(String filename) throws IOException{
				BufferedWriter writer = new BufferedWriter(new FileWriter(new File(filename)));
				for(int i=0;i<map.size();i++) {
	    		double[] city = (double[])map.get(i);
	    		writer.write(city[0]+" "+city[1]+"\r\n");
				}
				writer.close();
    }        public void load(File file) throws IOException{
			map = new ArrayList();
			BufferedReader reader = new BufferedReader(new FileReader(file));
			String line = reader.readLine();
			while(line != null) {
	    		String[] result = line.split(" ");	//cities is seperated by space	    		double[] city = {Double.parseDouble(result[0]),Double.parseDouble(result[1])};
	    		map.add(city);
	    		line = reader.readLine();
			}
    }
}

⌨️ 快捷键说明

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