Clover coverage report -
Coverage timestamp: jeu. juin 15 2006 08:24:33 CEST
file stats: LOC: 87   Methods: 2
NCLOC: 63   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractOptimizationLauncher.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Created on 29 mars 2006
 3    *
 4    * To change the template for this generated file go to
 5    * Window>Preferences>Java>Code Generation>Code and Comments
 6    */
 7    package org.sat4j;
 8   
 9   
 10    import java.io.PrintWriter;
 11   
 12    import org.sat4j.specs.ContradictionException;
 13    import org.sat4j.specs.IOptimizationProblem;
 14    import org.sat4j.specs.IProblem;
 15    import org.sat4j.specs.TimeoutException;
 16   
 17    /**
 18    * This class is intended to be used by launchers to solve optimization problems,
 19    * i.e. problems for which a loop is needed to find the optimal solution.
 20    *
 21    * @author leberre
 22    *
 23    */
 24    @SuppressWarnings("PMD")
 25    public abstract class AbstractOptimizationLauncher extends AbstractLauncher {
 26   
 27    private static final String CURRENT_OPTIMUM_VALUE_PREFIX = "o "; //$NON-NLS-1$
 28   
 29  0 @Override
 30    protected void displayResult() {
 31  0 if (solver == null)
 32  0 return;
 33  0 PrintWriter out = getLogWriter();
 34  0 solver.printStat(out, COMMENT_PREFIX);
 35  0 ExitCode exitCode = getExitCode();
 36  0 out.println(ANSWER_PREFIX + exitCode);
 37  0 if (exitCode == ExitCode.SATISFIABLE
 38    || exitCode == ExitCode.OPTIMUM_FOUND) {
 39  0 out.println(SOLUTION_PREFIX + getReader().decode(solver.model()));
 40  0 IOptimizationProblem optproblem = (IOptimizationProblem)solver;
 41  0 if (!optproblem.hasNoObjectiveFunction()) {
 42  0 log("objective function=" + optproblem.calculateObjective()); //$NON-NLS-1$
 43    }
 44   
 45    }
 46  0 log("Total wall clock time (ms): " //$NON-NLS-1$
 47    + (System.currentTimeMillis() - getBeginTime()) / 1000.0);
 48    }
 49   
 50  0 @Override
 51    protected void solve(IProblem problem) throws TimeoutException {
 52  0 boolean isSatisfiable = false;
 53   
 54  0 IOptimizationProblem optproblem = (IOptimizationProblem) problem;
 55   
 56  0 try {
 57  0 while (optproblem.admitABetterSolution()) {
 58  0 if (!isSatisfiable) {
 59  0 if (optproblem.nonOptimalMeansSatisfiable()) {
 60  0 setExitCode(ExitCode.SATISFIABLE);
 61  0 if (optproblem.hasNoObjectiveFunction()) {
 62  0 return;
 63    }
 64  0 log("SATISFIABLE"); //$NON-NLS-1$
 65    }
 66  0 isSatisfiable = true;
 67  0 log("OPTIMIZING..."); //$NON-NLS-1$
 68    }
 69  0 log("Got one! Elapsed wall clock time (in seconds):" //$NON-NLS-1$
 70    + (System.currentTimeMillis() - getBeginTime())
 71    / 1000.0);
 72  0 getLogWriter().println(CURRENT_OPTIMUM_VALUE_PREFIX
 73    + optproblem.calculateObjective());
 74  0 optproblem.discard();
 75    }
 76  0 if (isSatisfiable) {
 77  0 setExitCode(ExitCode.OPTIMUM_FOUND);
 78    } else {
 79  0 setExitCode(ExitCode.UNSATISFIABLE);
 80    }
 81    } catch (ContradictionException ex) {
 82    assert isSatisfiable;
 83  0 setExitCode(ExitCode.OPTIMUM_FOUND);
 84    }
 85    }
 86   
 87    }