randomcity.java

来自「This program is using Genetic Algorithm 」· Java 代码 · 共 53 行

JAVA
53
字号
/*
 * 
 *
 * this file is to generate a map of cities with random
 * locations within a square area (BORDER*BORDER)
 * 
 * usage: java RandomCity <number of cities> <output file>
 * 
 * Author:		Liu Yang 
 *
 *  			20/04/2006
 * */

import java.util.Random;

public class RandomCity{	private static int numOfCities = 0;    public static void main(String[] args)
 {
	if (args.length != 2){
		System.out.println("Usage: ");
		System.out.println("java RandomCity <number of cities> <output file>");
		return;
	}	    try {
	   	numOfCities = Integer.parseInt(args[0]);
	    if(numOfCities < 0)
						throw new NumberFormatException();
	}
    catch(NumberFormatException e){
	    System.out.println("Invalid number of cities: "+args[0]);
	    throw e;
	}
		
    CityMap citymap = new CityMap();
    Random m_random = new Random();
    int BODER = 10;
    
    for(int i=0; i<numOfCities; i++){
    	citymap.addCity( m_random.nextDouble() * BODER,m_random.nextDouble() * BODER );
    }		
    try{
		citymap.save(args[1]);
	}catch (Exception e){
		System.out.println(e);
	}
	}//end main
}

⌨️ 快捷键说明

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