Package org.sat4j.specs

Examples of org.sat4j.specs.IOptimizationProblem


      ObjectiveFunction objFunc = new ObjectiveFunction(literals,
          coefficients);
      solver.setObjectiveFunction(objFunc);

      /* Solve */
      IOptimizationProblem op = (IOptimizationProblem) solver;
      int[] model = null;
      try {
        if (deadline != Long.MAX_VALUE) {
          solver.setTimeoutMs(deadline - System.currentTimeMillis());
        }
        long stepref = System.nanoTime();
        while (System.currentTimeMillis() < deadline
            && !Thread.currentThread().isInterrupted()
            && op.admitABetterSolution()) {
          model = solver.model();
          GraphColoring<V, E> coloring = this.getColoring(colors,
              vertices, numberOfVertices, model);
          long now = System.nanoTime();
          LOGGER.debug(
              "solution found with {} colors and objective value {} in {}/{} ns",
              new Object[] { coloring.getNumberOfColors(),
                  op.getObjectiveValue(), now - stepref,
                  now - baseref });
          if (listener != null) {
            listener.handle(this, coloring);
          }
          op.discardCurrentSolution();
          stepref = System.nanoTime();
          long nextTO = Math.max(0,
              deadline - System.currentTimeMillis());
          solver.setTimeoutMs(nextTO);
          LOGGER.debug("timeout set to {} ms", nextTO);
View Full Code Here


        if (exitCode == ExitCode.SATISFIABLE
                || exitCode == ExitCode.OPTIMUM_FOUND) {
            out.print(SOLUTION_PREFIX);
            getReader().decode(solver.model(), out);
            out.println();
            IOptimizationProblem optproblem = (IOptimizationProblem) solver;
            if (!optproblem.hasNoObjectiveFunction()) {
                log("objective function=" + optproblem.calculateObjective()); //$NON-NLS-1$
            }
        }
    }
View Full Code Here

    @Override
    protected void solve(IProblem problem) throws TimeoutException {
        boolean isSatisfiable = false;

        IOptimizationProblem optproblem = (IOptimizationProblem) problem;

        try {
            while (optproblem.admitABetterSolution()) {
                if (!isSatisfiable) {
                    if (optproblem.nonOptimalMeansSatisfiable()) {
                        setExitCode(ExitCode.SATISFIABLE);
                        if (optproblem.hasNoObjectiveFunction()) {
                            return;
                        }
                        log("SATISFIABLE"); //$NON-NLS-1$
                    }
                    isSatisfiable = true;
                    log("OPTIMIZING..."); //$NON-NLS-1$
                }
                log("Got one! Elapsed wall clock time (in seconds):" //$NON-NLS-1$
                        + (System.currentTimeMillis() - getBeginTime())
                        / 1000.0);
                getLogWriter().println(
                        CURRENT_OPTIMUM_VALUE_PREFIX
                                + optproblem.calculateObjective());
                optproblem.discard();
            }
            if (isSatisfiable) {
                setExitCode(ExitCode.OPTIMUM_FOUND);
            } else {
                setExitCode(ExitCode.UNSATISFIABLE);
View Full Code Here

TOP

Related Classes of org.sat4j.specs.IOptimizationProblem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.