Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.drools.planner.benchmark;
 
 import java.io.File;
 import java.io.Reader;
 import java.io.Writer;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import  org.jfree.chart.ChartFactory;
 import  org.jfree.chart.JFreeChart;
 import  org.jfree.chart.axis.CategoryAxis;
 import  org.jfree.chart.axis.NumberAxis;
 import  org.jfree.chart.labels.CategoryItemLabelGenerator;
 import  org.jfree.chart.labels.ItemLabelAnchor;
 import  org.jfree.chart.labels.ItemLabelPosition;
 import  org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
 import  org.jfree.chart.labels.StandardCategoryToolTipGenerator;
 import  org.jfree.chart.labels.StandardXYItemLabelGenerator;
 import  org.jfree.chart.labels.XYItemLabelGenerator;
 import  org.jfree.chart.plot.CategoryPlot;
 import  org.jfree.chart.plot.PlotOrientation;
 import  org.jfree.chart.plot.XYPlot;
 import  org.jfree.chart.renderer.category.BarRenderer;
 import  org.jfree.chart.renderer.category.CategoryItemRenderer;
 import  org.jfree.chart.renderer.xy.StandardXYItemRenderer;
 import  org.jfree.chart.renderer.xy.XYItemRenderer;
 import  org.jfree.chart.renderer.xy.XYStepRenderer;
 import  org.jfree.data.category.DefaultCategoryDataset;
 import  org.jfree.data.xy.XYSeries;
 import  org.jfree.data.xy.XYSeriesCollection;
 import  org.jfree.ui.TextAnchor;
 
 @XStreamAlias("solverBenchmarkSuite")
 public class SolverBenchmarkSuite {
 
     private static final NumberFormat TIME_FORMAT = NumberFormat.getIntegerInstance(.);
 
     protected final transient Logger logger = LoggerFactory.getLogger(getClass());
 
     private File benchmarkDirectory = null;
    private File benchmarkInstanceDirectory = null;
    private File solvedSolutionFilesDirectory = null;
    private File solverStatisticFilesDirectory = null;
    @XStreamImplicit(itemFieldName = "solverStatisticType")
    private Long warmUpTimeMillisSpend = null;
    private Long warmUpSecondsSpend = null;
    private Long warmUpMinutesSpend = null;
    private Long warmUpHoursSpend = null;
    private SolverBenchmark inheritedSolverBenchmark = null;
    @XStreamImplicit(itemFieldName = "solverBenchmark")
    private List<SolverBenchmarksolverBenchmarkList = null;
//    @XStreamImplicit(itemFieldName = "solverBenchmarkSuiteResult")
//    private List<SolverBenchmarkSuiteResult> solverBenchmarkSuiteResultList;
    public File getBenchmarkDirectory() {
        return ;
    }
    public void setBenchmarkDirectory(File benchmarkDirectory) {
        this. = benchmarkDirectory;
    }
        return ;
    }
    public void setBenchmarkInstanceDirectory(File benchmarkInstanceDirectory) {
        this. = benchmarkInstanceDirectory;
    }
        return ;
    }
    public void setSolvedSolutionFilesDirectory(File solvedSolutionFilesDirectory) {
        this. = solvedSolutionFilesDirectory;
    }
        return ;
    }
    public void setSolverStatisticFilesDirectory(File solverStatisticFilesDirectory) {
        this. = solverStatisticFilesDirectory;
    }
        return ;
    }
    public void setSolverStatisticTypeList(List<SolverStatisticTypesolverStatisticTypeList) {
        this. = solverStatisticTypeList;
    }
        return ;
    }
    public void setSolverBenchmarkComparator(Comparator<SolverBenchmarksolverBenchmarkComparator) {
        this. = solverBenchmarkComparator;
    }
    public Long getWarmUpTimeMillisSpend() {
        return ;
    }
    public void setWarmUpTimeMillisSpend(Long warmUpTimeMillisSpend) {
        this. = warmUpTimeMillisSpend;
    }
    public Long getWarmUpSecondsSpend() {
        return ;
    }
    public void setWarmUpSecondsSpend(Long warmUpSecondsSpend) {
        this. = warmUpSecondsSpend;
    }
    public Long getWarmUpMinutesSpend() {
        return ;
    }
    public void setWarmUpMinutesSpend(Long warmUpMinutesSpend) {
        this. = warmUpMinutesSpend;
    }
    public Long getWarmUpHoursSpend() {
        return ;
    }
    public void setWarmUpHoursSpend(Long warmUpHoursSpend) {
        this. = warmUpHoursSpend;
    }
        return ;
    }
    public void setSolverBenchmarkList(List<SolverBenchmarksolverBenchmarkList) {
        this. = solverBenchmarkList;
    }
    // ************************************************************************
    // Builder methods
    // ************************************************************************
    public void benchmarkingStarted() {
        if ( == null || .isEmpty()) {
            throw new IllegalArgumentException(
                    "Configure at least 1 <solverBenchmark> in the <solverBenchmarkSuite> configuration.");
        }
        Set<StringnameSet = new HashSet<String>(.size());
        Set<SolverBenchmarknoNameBenchmarkSet = new LinkedHashSet<SolverBenchmark>(.size());
        for (SolverBenchmark solverBenchmark : ) {
            if (solverBenchmark.getName() != null) {
                boolean unique = nameSet.add(solverBenchmark.getName());
                if (!unique) {
                    throw new IllegalStateException("The benchmark name (" + solverBenchmark.getName()
                            + ") is used in more than 1 benchmark.");
                }
            } else {
                noNameBenchmarkSet.add(solverBenchmark);
            }
            if ( != null) {
                solverBenchmark.inherit();
            }
            solverBenchmark.validate();
            solverBenchmark.resetSolverBenchmarkResultList();
        }
        int generatedNameIndex = 0;
        for (SolverBenchmark solverBenchmark : noNameBenchmarkSet) {
            String generatedName = "Config_" + generatedNameIndex;
            while (nameSet.contains(generatedName)) {
                generatedNameIndex++;
                generatedName = "Config_" + generatedNameIndex;
            }
            solverBenchmark.setName(generatedName);
            generatedNameIndex++;
        }
        if ( == null) {
            throw new IllegalArgumentException("The benchmarkDirectory (" +  + ") must not be null.");
        }
        .mkdirs();
        if ( == null) {
            String timestampDirectory = new SimpleDateFormat("yyyy-MM-dd_HHmmss").format(new Date());
             = new File(timestampDirectory);
        }
        if ( == null) {
             = new File("solved");
        }
        if ( == null) {
             = new File("statistic");
        }
        if ( == null) {
        }
//        resetSolverBenchmarkSuiteResultList();
    }
//    private void resetSolverBenchmarkSuiteResultList() {
//        solverBenchmarkSuiteResultList = new ArrayList<SolverBenchmarkSuiteResult>();
//        Map<File, SolverBenchmarkSuiteResult> unsolvedSolutionFileToSuiteResultMap
//                = new LinkedHashMap<File, SolverBenchmarkSuiteResult>();
//        for (SolverBenchmark solverBenchmark : solverBenchmarkList) {
//            for (File unsolvedSolutionFile : solverBenchmark.getUnsolvedSolutionFileList()) {
//                if (!unsolvedSolutionFileToSuiteResultMap.containsKey(unsolvedSolutionFile)) {
//                    SolverBenchmarkSuiteResult suiteResult = new SolverBenchmarkSuiteResult();
//                    suiteResult.setUnsolvedSolutionFile(unsolvedSolutionFile);
//                    suiteResult.setSolverBenchmarkResultList(new ArrayList<SolverBenchmarkResult>(
//                            solverBenchmarkList.size()));
//                    solverBenchmarkSuiteResultList.add(suiteResult);
//                    unsolvedSolutionFileToSuiteResultMap.put(unsolvedSolutionFile, suiteResult);
//                }
//            }
//        }
//    }
    public void benchmark(XStream xStream) { // TODO refactor out xstream
        benchmarkingStarted();
        // LinkedHashMap because order of unsolvedSolutionFile should be respected in output
        Map<FileList<SolverStatistic>> unsolvedSolutionFileToStatisticMap = new LinkedHashMap<FileList<SolverStatistic>>();
        if ( != null ||  != null ||  != null
                ||  != null) {
            .info("================================================================================");
            .info("Warming up");
            .info("================================================================================");
            long warmUpTimeMillisSpendTotal = 0L;
            if ( != null) {
                warmUpTimeMillisSpendTotal += ;
            }
            if ( != null) {
                warmUpTimeMillisSpendTotal +=  * 1000L;
            }
            if ( != null) {
                warmUpTimeMillisSpendTotal +=  * 60000L;
            }
            if ( != null) {
                warmUpTimeMillisSpendTotal +=  * 3600000L;
            }
            long startingTimeMillis = System.currentTimeMillis();
            long timeLeft = warmUpTimeMillisSpendTotal;
            Iterator<SolverBenchmarksolverBenchmarkIt = .iterator();
            int overallResultIndex = 0;
            while (timeLeft > 0L) {
                if (!solverBenchmarkIt.hasNext()) {
                    solverBenchmarkIt = .iterator();
                    overallResultIndex++;
                }
                SolverBenchmark solverBenchmark = solverBenchmarkIt.next();
                List<SolverBenchmarkResultsolverBenchmarkResultList = solverBenchmark.getSolverBenchmarkResultList();
                int resultIndex = overallResultIndex % solverBenchmarkResultList.size();
                SolverBenchmarkResult result = solverBenchmarkResultList.get(resultIndex);
                TerminationConfig originalTerminationConfig = solverBenchmark.getSolverConfig().getTerminationConfig();
                TerminationConfig tmpTerminationConfig = originalTerminationConfig.clone();
                tmpTerminationConfig.shortenMaximumTimeMillisSpendTotal(timeLeft);
                solverBenchmark.getSolverConfig().setTerminationConfig(tmpTerminationConfig);
                Solver solver = solverBenchmark.getSolverConfig().buildSolver();
                File unsolvedSolutionFile = result.getUnsolvedSolutionFile();
                Solution unsolvedSolution = readUnsolvedSolution(xStreamunsolvedSolutionFile);
                solver.setPlanningProblem(unsolvedSolution);
                solver.solve();
                solverBenchmark.getSolverConfig().setTerminationConfig(originalTerminationConfig);
                long timeSpend = System.currentTimeMillis() - startingTimeMillis;
                timeLeft = warmUpTimeMillisSpendTotal - timeSpend;
            }
            .info("================================================================================");
            .info("Finished warmUp");
            .info("================================================================================");
        }
        for (SolverBenchmark solverBenchmark : ) {
            for (SolverBenchmarkResult result : solverBenchmark.getSolverBenchmarkResultList()) {
                // Intentionally create a fresh solver for every result to reset Random, tabu lists, ...
                Solver solver = solverBenchmark.getSolverConfig().buildSolver();
                
                File unsolvedSolutionFile = result.getUnsolvedSolutionFile();
                Solution unsolvedSolution = readUnsolvedSolution(xStreamunsolvedSolutionFile);
                solver.setPlanningProblem(unsolvedSolution);
                List<SolverStatisticstatisticList = getOrCreateStatisticList(unsolvedSolutionFileToStatisticMapunsolvedSolutionFile);
                for (SolverStatistic statistic : statisticList) {
                    statistic.addListener(solversolverBenchmark.getName());
                }
                solver.solve();
                result.setTimeMillisSpend(solver.getTimeMillisSpend());
                Solution solvedSolution = solver.getBestSolution();
                result.setScore(solvedSolution.getScore());
                for (SolverStatistic statistic : statisticList) {
                    statistic.removeListener(solversolverBenchmark.getName());
                }
                writeSolvedSolution(xStreamsolverBenchmarkresultsolvedSolution);
            }
        }
        benchmarkingEnded(xStreamunsolvedSolutionFileToStatisticMap);
    }
            Map<FileList<SolverStatistic>> unsolvedSolutionFileToStatisticMapFile unsolvedSolutionFile) {
        if ( == null) {
            return Collections.emptyList();
        }
        List<SolverStatisticstatisticList = unsolvedSolutionFileToStatisticMap.get(unsolvedSolutionFile);
        if (statisticList == null) {
            statisticList = new ArrayList<SolverStatistic>(.size());
            for (SolverStatisticType solverStatisticType : ) {
                statisticList.add(solverStatisticType.create());
            }
            unsolvedSolutionFileToStatisticMap.put(unsolvedSolutionFilestatisticList);
        }
        return statisticList;
    }
    private Solution readUnsolvedSolution(XStream xStreamFile unsolvedSolutionFile) {
        Solution unsolvedSolution;
        Reader reader = null;
        try {
            reader = new InputStreamReader(new FileInputStream(unsolvedSolutionFile), "utf-8");
            unsolvedSolution = (SolutionxStream.fromXML(reader);
        } catch (XStreamException e) {
            throw new IllegalArgumentException("Problem reading unsolvedSolutionFile: " + unsolvedSolutionFilee);
        } catch (IOException e) {
            throw new IllegalArgumentException("Problem reading unsolvedSolutionFile: " + unsolvedSolutionFilee);
        } finally {
            IOUtils.closeQuietly(reader);
        }
        return unsolvedSolution;
    }
    private void writeSolvedSolution(XStream xStreamSolverBenchmark solverBenchmarkSolverBenchmarkResult result,
            Solution solvedSolution) {
        if ( == null) {
            return;
        }
        File solvedSolutionFile = null;
        String baseName = FilenameUtils.getBaseName(result.getUnsolvedSolutionFile().getName());
        String solverBenchmarkName = solverBenchmark.getName().replaceAll(" ""_").replaceAll("[^\\w\\d_\\-]""");
        String scoreString = result.getScore().toString().replaceAll("[\\/ ]""_");
        String timeString = .format(result.getTimeMillisSpend()) + "ms";
        solvedSolutionFile = new File(baseName + "_" + solverBenchmarkName
                + "_score" + scoreString + "_time" + timeString + ".xml");
        Writer writer = null;
        try {
            writer = new OutputStreamWriter(new FileOutputStream(solvedSolutionFile), "utf-8");
            xStream.toXML(solvedSolutionwriter);
        } catch (IOException e) {
            throw new IllegalArgumentException("Problem writing solvedSolutionFile: " + solvedSolutionFilee);
        } finally {
            IOUtils.closeQuietly(writer);
        }
    }
    public void benchmarkingEnded(XStream xStreamMap<FileList<SolverStatistic>> unsolvedSolutionFileToStatisticMap) {
        determineRankings();
        // 2 lines at 80 chars per line give a max of 160 per entry
        StringBuilder htmlFragment = new StringBuilder(unsolvedSolutionFileToStatisticMap.size() * 160);
        htmlFragment.append("  <h1>Summary</h1>\n");
        htmlFragment.append(writeBestScoreSummaryChart());
        htmlFragment.append(writeTimeSpendSummaryChart());
        // TODO scalability summary chart must be n based instead of score based (the latter is misleading)
//        htmlFragment.append(writeScalabilitySummaryChart());
        htmlFragment.append(writeBestScoreSummaryTable());
        htmlFragment.append("  <h1>Statistics</h1>\n");
        for (Map.Entry<FileList<SolverStatistic>> entry : unsolvedSolutionFileToStatisticMap.entrySet()) {
            File unsolvedSolutionFile = entry.getKey();
            List<SolverStatisticstatisticList = entry.getValue();
            String baseName = FilenameUtils.getBaseName(unsolvedSolutionFile.getName());
            htmlFragment.append("  <h2>").append(baseName).append("</h2>\n");
            for (SolverStatistic statistic : statisticList) {
                htmlFragment.append(statistic.writeStatistic(baseName));
            }
        }
        writeHtmlOverview(htmlFragment);
        // TODO Temporarily disabled because it crashes because of http://jira.codehaus.org/browse/XSTR-666
        // writeBenchmarkResult(xStream);
    }
    private void determineRankings() {
        List<SolverBenchmarksortedSolverBenchmarkList = new ArrayList<SolverBenchmark>();
        Collections.sort(sortedSolverBenchmarkList);
        Collections.reverse(sortedSolverBenchmarkList); // Best results first, worst results last
        for (SolverBenchmark solverBenchmark : ) {
            solverBenchmark.setRanking(sortedSolverBenchmarkList.indexOf(solverBenchmark));
        }
    }
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (SolverBenchmark solverBenchmark : ) {
            ScoreDefinition scoreDefinition = solverBenchmark.getSolverConfig().getScoreDefinitionConfig()
                    .buildScoreDefinition();
            for (SolverBenchmarkResult result : solverBenchmark.getSolverBenchmarkResultList()) {
                Score score = result.getScore();
                Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
                String solverLabel = solverBenchmark.getName();
                if (solverBenchmark.getRanking() == 0) {
                    solverLabel += " (winner)";
                }
                dataset.addValue(scoreGraphValuesolverLabelresult.getUnsolvedSolutionFile().getName());
            }
        }
        JFreeChart chart = ChartFactory.createBarChart(
                "Best score summary (higher score is better)""Data""Score",
                dataset, PlotOrientation.VERTICAL, truetruefalse
        );
        CategoryItemRenderer renderer = ((CategoryPlot) chart.getPlot()).getRenderer();
        renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
        renderer.setBaseItemLabelsVisible(true);
        BufferedImage chartImage = chart.createBufferedImage(1024, 768);
        File chartSummaryFile = new File("bestScoreSummary.png");
        OutputStream out = null;
        try {
            out = new FileOutputStream(chartSummaryFile);
            ImageIO.write(chartImage"png"out);
        } catch (IOException e) {
            throw new IllegalArgumentException("Problem writing graphStatisticFile: " + chartSummaryFilee);
        } finally {
            IOUtils.closeQuietly(out);
        }
        return "  <h2>Best score summary chart</h2>\n"
                + "  <img src=\"" + chartSummaryFile.getName() + "\"/>\n";
    }
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (SolverBenchmark solverBenchmark : ) {
            for (SolverBenchmarkResult result : solverBenchmark.getSolverBenchmarkResultList()) {
                long timeMillisSpend = result.getTimeMillisSpend();
                String solverLabel = solverBenchmark.getName();
                dataset.addValue(timeMillisSpendsolverLabelresult.getUnsolvedSolutionFile().getName());
            }
        }
        CategoryAxis xAxis = new CategoryAxis("Data");
        NumberAxis yAxis = new NumberAxis("Time millis spend");
        yAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
        BarRenderer renderer = new BarRenderer();
        ItemLabelPosition positiveItemLabelPosition = new ItemLabelPosition(
                ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER);
        renderer.setBasePositiveItemLabelPosition(positiveItemLabelPosition);
        ItemLabelPosition negativeItemLabelPosition = new ItemLabelPosition(
                ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER);
        renderer.setBaseNegativeItemLabelPosition(negativeItemLabelPosition);
        renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator(
                StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, new MillisecondsSpendNumberFormat()));
        renderer.setBaseItemLabelsVisible(true);
        CategoryPlot plot = new CategoryPlot(datasetxAxisyAxis,
                renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
        JFreeChart chart = new JFreeChart("Time spend summary (lower time is better)", JFreeChart.DEFAULT_TITLE_FONT,
                plottrue);
        BufferedImage chartImage = chart.createBufferedImage(1024, 768);
        File chartSummaryFile = new File("timeSpendSummary.png");
        OutputStream out = null;
        try {
            out = new FileOutputStream(chartSummaryFile);
            ImageIO.write(chartImage"png"out);
        } catch (IOException e) {
            throw new IllegalArgumentException("Problem writing graphStatisticFile: " + chartSummaryFilee);
        } finally {
            IOUtils.closeQuietly(out);
        }
        return "  <h2>Time spend summary chart</h2>\n"
                + "  <img src=\"" + chartSummaryFile.getName() + "\"/>\n";
    }
        NumberAxis xAxis = new NumberAxis("Score");
        xAxis.setInverted(true);
        NumberAxis yAxis = new NumberAxis("Time millis spend");
        yAxis.setNumberFormatOverride(new MillisecondsSpendNumberFormat());
        XYPlot plot = new XYPlot(nullxAxisyAxisnull);
        int seriesIndex = 0;
        for (SolverBenchmark solverBenchmark : ) {
            XYSeries series = new XYSeries(solverBenchmark.getName());
            ScoreDefinition scoreDefinition = solverBenchmark.getSolverConfig().getScoreDefinitionConfig()
                    .buildScoreDefinition();
            for (SolverBenchmarkResult result : solverBenchmark.getSolverBenchmarkResultList()) {
                Long timeMillisSpend = result.getTimeMillisSpend();
                Score score = result.getScore();
                Double scoreGraphValue = scoreDefinition.translateScoreToGraphValue(score);
                if (scoreGraphValue != null) {
                    series.add(scoreGraphValuetimeMillisSpend);
                }
            }
            XYSeriesCollection seriesCollection = new XYSeriesCollection();
            seriesCollection.addSeries(series);
            plot.setDataset(seriesIndexseriesCollection);
            XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
            // Use dashed line
            renderer.setSeriesStroke(0, new BasicStroke(
                    1.0f, .., 1.0f, new float[]{2.0f, 6.0f}, 0.0f
            ));
            plot.setRenderer(seriesIndexrenderer);
            seriesIndex++;
        }
        plot.setOrientation(PlotOrientation.VERTICAL);
        JFreeChart chart = new JFreeChart("Scalability summary (lower and lefter is better)",
                JFreeChart.DEFAULT_TITLE_FONT, plottrue);
        BufferedImage chartImage = chart.createBufferedImage(1024, 768);
        File chartSummaryFile = new File("scalabilitySummary.png");
        OutputStream out = null;
        try {
            out = new FileOutputStream(chartSummaryFile);
            ImageIO.write(chartImage"png"out);
        } catch (IOException e) {
            throw new IllegalArgumentException("Problem writing graphStatisticFile: " + chartSummaryFilee);
        } finally {
            IOUtils.closeQuietly(out);
        }
        return "  <h2>Scalability summary chart</h2>\n"
                + "  <img src=\"" + chartSummaryFile.getName() + "\"/>\n";
    }
        StringBuilder htmlFragment = new StringBuilder(.size() * 160);
        htmlFragment.append("  <h2>Best score summary table</h2>\n");
        htmlFragment.append("  <table border=\"1\">\n");
        htmlFragment.append("    <tr><th/>");
        if ( != null && .getUnsolvedSolutionFileList() != null) {
            for (File unsolvedSolutionFile : .getUnsolvedSolutionFileList()) {
                htmlFragment.append("<th>").append(unsolvedSolutionFile.getName()).append("</th>");
            }
        }
        htmlFragment.append("<th>Average</th><th>Ranking</th></tr>\n");
        boolean oddLine = true;
        for (SolverBenchmark solverBenchmark : ) {
            String backgroundColor = solverBenchmark.getRanking() == 0 ? "Yellow" : oddLine ? "White" : "LightGray";
            htmlFragment.append("    <tr style=\"background-color: ").append(backgroundColor).append("\"><th>")
                    .append(solverBenchmark.getName()).append("</th>");
            for (SolverBenchmarkResult result : solverBenchmark.getSolverBenchmarkResultList()) {
                Score score = result.getScore();
                htmlFragment.append("<td>").append(score.toString()).append("</td>");
            }
            htmlFragment.append("<td>").append(solverBenchmark.getAverageScore().toString())
                    .append("</td><td>").append(solverBenchmark.getRanking()).append("</td>");
            htmlFragment.append("</tr>\n");
            oddLine = !oddLine;
        }
        htmlFragment.append("  </table>\n");
        return htmlFragment.toString();
    }
    private void writeHtmlOverview(CharSequence htmlFragment) {
        File htmlOverviewFile = new File("index.html");
        Writer writer = null;
        try {
            writer = new OutputStreamWriter(new FileOutputStream(htmlOverviewFile), "utf-8");
            writer.append("<html>\n");
            writer.append("<head>\n");
            writer.append("  <title>Statistic</title>\n");
            writer.append("</head>\n");
            writer.append("<body>\n");
            writer.append(htmlFragment);
            writer.append("</body>\n");
            writer.append("</html>\n");
        } catch (IOException e) {
            throw new IllegalArgumentException("Problem writing htmlOverviewFile: " + htmlOverviewFilee);
        } finally {
            IOUtils.closeQuietly(writer);
        }
    }
    public void writeBenchmarkResult(XStream xStream) {
        File benchmarkResultFile = new File("benchmarkResult.xml");
        OutputStreamWriter writer = null;
        try {
            writer = new OutputStreamWriter(new FileOutputStream(benchmarkResultFile), "utf-8");
            xStream.toXML(thiswriter);
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException("This JVM does not support utf-8 encoding."e);
        } catch (FileNotFoundException e) {
            throw new IllegalArgumentException(
                    "Could not create benchmarkResultFile (" + benchmarkResultFile + ")."e);
        } finally {
            IOUtils.closeQuietly(writer);
        }
    }
New to GrepCode? Check out our FAQ X