001 package net.sf.cpsolver.ifs.example.jobshop; 002 003 import java.io.*; 004 import java.util.*; 005 006 import net.sf.cpsolver.ifs.solution.*; 007 import net.sf.cpsolver.ifs.solver.*; 008 import net.sf.cpsolver.ifs.util.*; 009 010 /** 011 * Test of Job Shop problem. It takes one argument -- property file with all the parameters. 012 * <br><br> 013 * Test's parameters: 014 * <br> 015 * <table border='1'><tr><th>Parameter</th><th>Type</th><th>Comment</th></tr> 016 * <tr><td>General.Input</td><td>{@link String}</td><td>Input file describing the job shop problem</td></tr> 017 * <tr><td>General.Output</td><td>{@link String}</td><td>Output folder where a log file and a solution (solution.txt) will be placed</td></tr> 018 * </table> 019 * <br> 020 * 021 * @version 022 * IFS 1.1 (Iterative Forward Search)<br> 023 * Copyright (C) 2006 Tomáš Müller<br> 024 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 025 * Lazenska 391, 76314 Zlin, Czech Republic<br> 026 * <br> 027 * This library is free software; you can redistribute it and/or 028 * modify it under the terms of the GNU Lesser General Public 029 * License as published by the Free Software Foundation; either 030 * version 2.1 of the License, or (at your option) any later version. 031 * <br><br> 032 * This library is distributed in the hope that it will be useful, 033 * but WITHOUT ANY WARRANTY; without even the implied warranty of 034 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 035 * Lesser General Public License for more details. 036 * <br><br> 037 * You should have received a copy of the GNU Lesser General Public 038 * License along with this library; if not, write to the Free Software 039 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 040 */ 041 public class Test { 042 private static java.text.SimpleDateFormat sDateFormat = new java.text.SimpleDateFormat("dd-MMM-yy_HHmmss",java.util.Locale.US); 043 private static org.apache.log4j.Logger sLogger = org.apache.log4j.Logger.getLogger(Test.class); 044 045 public static void test(DataProperties properties) { 046 try { 047 String inputFile = properties.getProperty("General.Input"); 048 JobShopModel model = JobShopModel.loadModel(inputFile); 049 Solver s = new Solver(properties); 050 s.setInitalSolution(model); 051 s.start(); 052 s.getSolverThread().join(); 053 Solution best = s.currentSolution(); 054 best.restoreBest(); 055 sLogger.info("Best solution info:"+best.getInfo()); 056 sLogger.info("Best solution:"+model.toString()); 057 model.save(properties.getProperty("General.Output")+File.separator+"solution.txt"); 058 } catch (Exception e) { 059 e.printStackTrace(); 060 } 061 } 062 063 public static void main(String[] args) { 064 try { 065 Progress.getInstance().addProgressListener(new ProgressWriter(System.out)); 066 067 File inputCfg = new File(args[0]); 068 DataProperties properties = ToolBox.loadProperties(inputCfg); 069 String outDir = properties.getProperty("General.Output",".")+File.separator + inputCfg.getName().substring(0,inputCfg.getName().lastIndexOf('.'))+File.separator+sDateFormat.format(new Date()); 070 (new File(outDir)).mkdirs(); 071 properties.setProperty("General.Output", outDir.toString()); 072 ToolBox.configureLogging(outDir, null); 073 test(properties); 074 } catch (Exception e) { 075 e.printStackTrace(); 076 } 077 } 078 }