Examples of IVecInt


Examples of org.sat4j.specs.IVecInt

      int indicatorVars = numberOfVertices * colors;
      solver.newVar(indicatorVars + colors);

      /* PB constraints to enforce assignment of exactly one color. */
      for (int i = 0; i < numberOfVertices; i++) {
        IVecInt literals = new VecInt(colors);
        IVec<BigInteger> coefficients = new Vec<BigInteger>(colors);
        for (int j = 1; j <= colors; j++) {
          literals.push(i * colors + j);
          coefficients.push(BigInteger.ONE);
        }
        solver.addPseudoBoolean(literals, coefficients, false,
            BigInteger.ONE);
        solver.addPseudoBoolean(literals, coefficients, true,
            BigInteger.ONE);
      }

      /*
       * CNF constraints enforcing that no adjacent vertices have the same
       * color.
       */
      for (int i = 0; i < vertices.size(); i++) {
        V u = vertices.get(i);
        for (int j = 0; j < vertices.size(); j++) {
          V v = vertices.get(j);
          if (graph.containsEdge(u, v)) {
            for (int k = 1; k <= colors; k++) {
              IVecInt literals = new VecInt(2);
              literals.push(-(i * colors + k));
              literals.push(-(j * colors + k));
              solver.addClause(literals);
            }
          }
        }
      }

      /*
       * CNF constraints (derived from propositional logic expression) to
       * set track variable, if a color has been assigned to one of the
       * indicator variables for a given bundle.
       */
      for (int k = 1; k <= colors; k++) {
        /* First term. */
        IVecInt literals = new VecInt(numberOfVertices + 1);
        literals.push(-(numberOfVertices * colors + k));
        for (int i = 0; i < numberOfVertices; i++) {
          literals.push(i * colors + k);
        }
        solver.addClause(literals);

        /* Second term. */
        for (int i = 0; i < numberOfVertices; i++) {
          literals.clear();
          literals.push(-(i * colors + k));
          literals.push(numberOfVertices * colors + k);
          solver.addClause(literals);
        }
      }

      /* Symmetry breaking. */
      selectiveColoring(colors, solver, vertices);

      IVecInt literals = new VecInt(2);
      for (int k = 1; k <= colors; k++) {
        literals.push(-(numberOfVertices * colors + k));
        for (int i = 1; i < k; i++) {
          literals.push(numberOfVertices * colors + i);
          solver.addClause(literals);
        }
        literals.clear();
      }

      /* Objective function. */
      literals = new VecInt(colors);
      IVec<BigInteger> coefficients = new Vec<BigInteger>(colors);
      for (int k = 1; k <= colors; k++) {
        literals.push(numberOfVertices * colors + k);
        coefficients.push(BigInteger.ONE);
      }
      ObjectiveFunction objFunc = new ObjectiveFunction(literals,
          coefficients);
      solver.setObjectiveFunction(objFunc);
View Full Code Here

Examples of org.sat4j.specs.IVecInt

      List<V> vertices) throws ContradictionException {
    VertexDegreeComparator<V, E> c = new VertexDegreeComparator<V, E>(graph);

    /* Precolor vertex v with maximum degree with first color. */
    V v = Collections.max(vertices, c);
    IVecInt literals = new VecInt(1);
    literals.push(vertices.indexOf(v) * colors + 1);
    solver.addClause(literals);
    literals.clear();

    /* Precolor neighbor of v with maximum degree with second color. */
    Collection<V> neighbors = graph.getNeighbors(v);
    if (!neighbors.isEmpty()) {
      v = Collections.max(neighbors, c);
      literals.push(vertices.indexOf(v) * colors + 2);
      solver.addClause(literals);
    }
  }
View Full Code Here

Examples of org.sat4j.specs.IVecInt

        try {
            final IProblem problem = reader.parseInstance(args[0]);
            if (problem.isSatisfiable()) {
                System.out.println(Messages.getString("MoreThanSAT.0")); //$NON-NLS-1$
                reader.decode(problem.model(), new PrintWriter(System.out));
                IVecInt backbone = RemiUtils.backbone(solver);
                System.out
                        .println(Messages.getString("MoreThanSAT.1") + backbone); //$NON-NLS-1$
                System.out.println(Messages.getString("MoreThanSAT.2")); //$NON-NLS-1$
                System.out.println(Messages.getString("MoreThanSAT.3") //$NON-NLS-1$
                        + sc.countSolutions());
View Full Code Here

Examples of org.sat4j.specs.IVecInt

            ParseFormatException, ContradictionException {
        String line;

        int realNbOfConstr = 0;

        IVecInt literals = new VecInt();

        while (true) {
            line = in.readLine();

            if (line == null) {
                // end of file
                if (literals.size() > 0) {
                    // no 0 end the last clause
                    solver.addClause(literals);
                    realNbOfConstr++;
                }
View Full Code Here

Examples of org.sat4j.specs.IVecInt

        }
        return -var;
    }

    private int readOutput(int nboutputs, Scanner scanner) {
        IVecInt outputs = new VecInt(nboutputs);
        for (int i = 0; i < nboutputs; i++) {
            outputs.push(scanner.nextInt());
        }
        return outputs.get(0);
    }
View Full Code Here

Examples of org.sat4j.specs.IVecInt

        return outputs.get(0);
    }


    private IVecInt readInput(int numberOfInputs, Scanner scanner) {
        IVecInt inputs = new VecInt(numberOfInputs);
        for (int i = 0; i < numberOfInputs; i++) {
            inputs.push(scanner.nextInt());
        }
        return inputs;
    }
View Full Code Here

Examples of org.sat4j.specs.IVecInt

        String line;
        StringTokenizer stk;

        int realNbOfClauses = 0;

        IVecInt literals = new VecInt();

        while (true) {
            line = in.readLine();

            if (line == null) {
                // end of file
                if (literals.size() > 0) {
                    // no 0 end the last clause
                    solver.addClause(literals);
                    realNbOfClauses++;
                }

                break;
            }

            if (line.startsWith("c ")) {
                // skip commented line
                continue;
            }
            if (line.startsWith("%") && expectedNbOfConstr == realNbOfClauses) {
                System.out
                        .println("Ignoring the rest of the file (SATLIB format");
                break;
            }
            stk = new StringTokenizer(line);
            String token;

            while (stk.hasMoreTokens()) {
                // on lit le prochain token
                token = stk.nextToken();

                if ("<=".equals(token) || ">=".equals(token)) {
                    // on est sur une contrainte de cardinalit?
                    readCardinalityConstr(token, stk, literals);
                    literals.clear();
                    realNbOfClauses++;
                } else {
                    lit = Integer.parseInt(token);
                    if (lit == 0) {
                        if (literals.size() > 0) {
                            solver.addClause(literals);
                            literals.clear();
                            realNbOfClauses++;
                        }
                    } else {
                        literals.push(lit);
                    }
                }
            }
        }
        if (expectedNbOfConstr != realNbOfClauses) {
View Full Code Here

Examples of org.sat4j.specs.IVecInt

     * @return true
     */
    @Override
    protected boolean handleConstr(int gateType, int output, int[] inputs)
            throws ContradictionException {
        IVecInt literals;
        switch (gateType) {
        case FALSE:
            assert inputs.length == 0;
            gater.gateFalse(output);
            break;
View Full Code Here

Examples of org.sat4j.specs.IVecInt

     */
    public boolean hasASingleSolution(IVecInt assumptions)
            throws TimeoutException {
        int[] firstmodel = model();
        assert firstmodel != null;
        IVecInt clause = new VecInt(firstmodel.length);
        for (int q : firstmodel) {
            clause.push(-q);
        }
        boolean result = false;
        try {
            IConstr added = addClause(clause);
            result = !isSatisfiable(assumptions);
View Full Code Here

Examples of org.sat4j.specs.IVecInt

     * @return the set of literals common to all models of the formula contained
     *         in the solver, in dimacs format.
     * @throws TimeoutException
     */
    public static IVecInt backbone(ISolver s) throws TimeoutException {
        IVecInt backbone = new VecInt();
        int nvars = s.nVars();
        for (int i = 1; i <= nvars; i++) {
            backbone.push(i);
            if (s.isSatisfiable(backbone)) {
                backbone.pop().push(-i);
                if (s.isSatisfiable(backbone)) {
                    backbone.pop();
                } else {
                    // -i is in the backbone
                    backbone.pop().push(i);
                }
            } else {
                // -i is in the backbone
                backbone.pop().push(-i);
            }
        }
        return backbone;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.