使用Java解决算法问题的简易模板

public class Problem {
    //创建问题的构造方法 private Problem
    private Problem(String filename) {
    }

    //懒汉模式构造对象
    public static Problem get() {
        if (problem == null) {
            problem = new Problem(fileName);
        }
        return problem;
    }

    //读文件数据,传递Scanner对象
    private void readData(Scanner scan) throws Exception {
    }


    public double getBestTourLength() {
    }

    public static String getFileName() {
    }

    //重写一个toString方法,表达这个问题
    @Override
    public String toString() {
    }
    
    //主函数   
    public static void main(String[] args) {
        String fileName = (new File("")).getAbsolutePath() + "/src/datas/TSPLIB6small/01eil51.txt";
        Problem problem = new Problem(fileName);
    }


//----------------------------变量区--------------------------------

    //1、单例模式
    private static Problem problem = null;


    //2、与问题对象直接有关系的:private 类型
    private int[] bestTour;
    private double bestTourLength;
    private int[][] nearCityList = null;

    
    //3、整个问题类规定的量:private static 类型
    private static int nearCityNumber = 20; //城市近邻列表长度
    private static String fileName = null;
    
    //4、常量:public static final 类型
    public static final boolean USE_INTEGER_EDGE = true;
    public static final int SYMMETRIC = 1;
    public static final int ASYMMETRIC = 2;
    public static final int SYMMETRIC_GEO = 3;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容