001 package ifs.example.jobshop;
002
003 import ifs.model.*;
004 import ifs.solver.*;
005 import ifs.solution.*;
006 import ifs.util.*;
007 import java.io.*;
008 import java.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 * @author <a href="mailto:muller@ktiml.mff.cuni.cz">Tomáš Müller</a>
022 * @version 1.0
023 */
024 public class Test {
025 private static java.text.DecimalFormat sDoubleFormat = new java.text.DecimalFormat("0.00",new java.text.DecimalFormatSymbols(Locale.US));
026 private static java.text.SimpleDateFormat sDateFormat = new java.text.SimpleDateFormat("dd-MMM-yy_HHmmss",java.util.Locale.US);
027 private static org.apache.log4j.Logger sLogger = org.apache.log4j.Logger.getLogger(Test.class);
028
029 public static void test(DataProperties properties) {
030 try {
031 String inputFile = properties.getProperty("General.Input");
032 JobShopModel model = JobShopModel.loadModel(inputFile);
033 Solver s = new Solver(properties);
034 s.setInitalSolution(model);
035 s.start();
036 s.getSolverThread().join();
037 Solution best = s.currentSolution();
038 best.restoreBest();
039 sLogger.info("Best solution info:"+best.getInfo());
040 sLogger.info("Best solution:"+model.toString());
041 model.save(properties.getProperty("General.Output")+File.separator+"solution.txt");
042 } catch (Exception e) {
043 e.printStackTrace();
044 }
045 }
046
047 public static void main(String[] args) {
048 try {
049 Progress.getInstance().addProgressListener(new ProgressWriter(System.out));
050
051 File inputCfg = new File(args[0]);
052 DataProperties properties = ToolBox.loadProperties(inputCfg);
053 String outDir = properties.getProperty("General.Output",".")+File.separator + inputCfg.getName().substring(0,inputCfg.getName().lastIndexOf('.'))+File.separator+sDateFormat.format(new Date());
054 (new File(outDir)).mkdirs();
055 properties.setProperty("General.Output", outDir.toString());
056 ToolBox.configureLogging(outDir, null);
057 test(properties);
058 } catch (Exception e) {
059 e.printStackTrace();
060 }
061 }
062 }