Clover Coverage Report
Coverage timestamp: mer. juin 27 2007 07:27:16 CEST
33   108   11   16,5
18   66   0,36   2
2     6  
1    
 
  AbstractOptimizationLauncher       Line # 43 33 11 0% 0.0
 
No Tests
 
1    /*
2    * SAT4J: a SATisfiability library for Java Copyright (C) 2004-2006 Daniel Le Berre
3    *
4    * Based on the original minisat specification from:
5    *
6    * An extensible SAT solver. Niklas E?n and Niklas S?rensson. Proceedings of the
7    * Sixth International Conference on Theory and Applications of Satisfiability
8    * Testing, LNCS 2919, pp 502-518, 2003.
9    *
10    * This library is free software; you can redistribute it and/or modify it under
11    * the terms of the GNU Lesser General Public License as published by the Free
12    * Software Foundation; either version 2.1 of the License, or (at your option)
13    * any later version.
14    *
15    * This library is distributed in the hope that it will be useful, but WITHOUT
16    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17    * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18    * details.
19    *
20    * You should have received a copy of the GNU Lesser General Public License
21    * along with this library; if not, write to the Free Software Foundation, Inc.,
22    * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23    *
24    */
25    package org.sat4j;
26   
27    import java.io.PrintWriter;
28   
29    import org.sat4j.specs.ContradictionException;
30    import org.sat4j.specs.IOptimizationProblem;
31    import org.sat4j.specs.IProblem;
32    import org.sat4j.specs.TimeoutException;
33   
34    /**
35    * This class is intended to be used by launchers to solve optimization
36    * problems, i.e. problems for which a loop is needed to find the optimal
37    * solution.
38    *
39    * @author leberre
40    *
41    */
42    @SuppressWarnings("PMD")
 
43    public abstract class AbstractOptimizationLauncher extends AbstractLauncher {
44   
45    private static final String CURRENT_OPTIMUM_VALUE_PREFIX = "o "; //$NON-NLS-1$
46   
 
47  0 toggle @Override
48    protected void displayResult() {
49  0 if (solver == null)
50  0 return;
51  0 PrintWriter out = getLogWriter();
52  0 solver.printStat(out, COMMENT_PREFIX);
53  0 ExitCode exitCode = getExitCode();
54  0 out.println(ANSWER_PREFIX + exitCode);
55  0 if (exitCode == ExitCode.SATISFIABLE
56    || exitCode == ExitCode.OPTIMUM_FOUND) {
57  0 out.print(SOLUTION_PREFIX);
58  0 getReader().decode(solver.model(), out);
59  0 out.println();
60  0 IOptimizationProblem optproblem = (IOptimizationProblem) solver;
61  0 if (!optproblem.hasNoObjectiveFunction()) {
62  0 log("objective function=" + optproblem.calculateObjective()); //$NON-NLS-1$
63    }
64   
65    }
66  0 log("Total wall clock time (ms): " //$NON-NLS-1$
67    + (System.currentTimeMillis() - getBeginTime()) / 1000.0);
68    }
69   
 
70  0 toggle @Override
71    protected void solve(IProblem problem) throws TimeoutException {
72  0 boolean isSatisfiable = false;
73   
74  0 IOptimizationProblem optproblem = (IOptimizationProblem) problem;
75   
76  0 try {
77  0 while (optproblem.admitABetterSolution()) {
78  0 if (!isSatisfiable) {
79  0 if (optproblem.nonOptimalMeansSatisfiable()) {
80  0 setExitCode(ExitCode.SATISFIABLE);
81  0 if (optproblem.hasNoObjectiveFunction()) {
82  0 return;
83    }
84  0 log("SATISFIABLE"); //$NON-NLS-1$
85    }
86  0 isSatisfiable = true;
87  0 log("OPTIMIZING..."); //$NON-NLS-1$
88    }
89  0 log("Got one! Elapsed wall clock time (in seconds):" //$NON-NLS-1$
90    + (System.currentTimeMillis() - getBeginTime())
91    / 1000.0);
92  0 getLogWriter().println(
93    CURRENT_OPTIMUM_VALUE_PREFIX
94    + optproblem.calculateObjective());
95  0 optproblem.discard();
96    }
97  0 if (isSatisfiable) {
98  0 setExitCode(ExitCode.OPTIMUM_FOUND);
99    } else {
100  0 setExitCode(ExitCode.UNSATISFIABLE);
101    }
102    } catch (ContradictionException ex) {
103  0 assert isSatisfiable;
104  0 setExitCode(ExitCode.OPTIMUM_FOUND);
105    }
106    }
107   
108    }