CVC5_API_TRY_CATCH_END;
}
-Term Solver::mkCardinalityConstraint(const Sort& sort, uint32_t ubound) const
+Term Solver::mkCardinalityConstraint(const Sort& sort, uint32_t upperBound) const
{
CVC5_API_TRY_CATCH_BEGIN;
CVC5_API_SOLVER_CHECK_SORT(sort);
CVC5_API_ARG_CHECK_EXPECTED(sort.isUninterpretedSort(), sort)
<< "an uninterpreted sort";
- CVC5_API_ARG_CHECK_EXPECTED(ubound > 0, ubound) << "a value > 0";
+ CVC5_API_ARG_CHECK_EXPECTED(upperBound > 0, upperBound) << "a value > 0";
//////// all checks before this line
Node cco =
- d_nodeMgr->mkConst(cvc5::CardinalityConstraint(*sort.d_type, ubound));
+ d_nodeMgr->mkConst(cvc5::CardinalityConstraint(*sort.d_type, upperBound));
Node cc = d_nodeMgr->mkNode(cvc5::Kind::CARDINALITY_CONSTRAINT, cco);
return Term(this, cc);
////////
/**
* Create a cardinality constraint for an uninterpreted sort.
* @param sort the sort the cardinality constraint is for
- * @param val the upper bound on the cardinality of the sort
+ * @param upperBound the upper bound on the cardinality of the sort
* @return the cardinality constraint
*/
- Term mkCardinalityConstraint(const Sort& sort, uint32_t ubound) const;
+ Term mkCardinalityConstraint(const Sort& sort, uint32_t upperBound) const;
/* .................................................................... */
/* Create Variables */
private native long mkFloatingPoint(long pointer, int exp, int sig, long valPointer);
+ /**
+ * Create a cardinality constraint for an uninterpreted sort.
+ * @param sort the sort the cardinality constraint is for
+ * @param upperBound the upper bound on the cardinality of the sort
+ * @return the cardinality constraint
+ */
+ public Term mkCardinalityConstraint(Sort sort, int upperBound) throws CVC5ApiException
+ {
+ Utils.validateUnsigned(upperBound, "upperBound");
+ long termPointer = mkCardinalityConstraint(pointer, sort.getPointer(), upperBound);
+ return new Term(this, termPointer);
+ }
+
+ private native long mkCardinalityConstraint(long pointer, long sortPointer, int upperBound);
+
/* .................................................................... */
/* Create Variables */
/* .................................................................... */
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
}
+/*
+ * Class: io_github_cvc5_api_Solver
+ * Method: mkCardinalityConstraint
+ * Signature: (JJI)J
+ */
+JNIEXPORT jlong JNICALL Java_io_github_cvc5_api_Solver_mkCardinalityConstraint(
+ JNIEnv* env, jobject, jlong pointer, jlong sortPointer, jint upperBound)
+{
+ CVC5_JAVA_API_TRY_CATCH_BEGIN;
+ Solver* solver = reinterpret_cast<Solver*>(pointer);
+ Sort* sort = reinterpret_cast<Sort*>(sortPointer);
+ Term* retPointer =
+ new Term(solver->mkCardinalityConstraint(*sort, (int32_t)upperBound));
+ return reinterpret_cast<jlong>(retPointer);
+ CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
+}
+
/*
* Class: io_github_cvc5_api_Solver
* Method: mkConst
DatatypeDecl* ret = new DatatypeDecl();
return reinterpret_cast<jlong>(ret);
CVC5_JAVA_API_TRY_CATCH_END_RETURN(env, 0);
-}
\ No newline at end of file
+}
Term mkUninterpretedConst(Sort sort, int32_t index) except +
Term mkAbstractValue(const string& index) except +
Term mkFloatingPoint(uint32_t exp, uint32_t sig, Term val) except +
+ Term mkCardinalityConstraint(Sort sort, int32_t index) except +
Term mkConst(Sort sort, const string& symbol) except +
# default value for symbol defined in cpp/cvc5.h
Term mkConst(Sort sort) except +
term.cterm = self.csolver.mkFloatingPoint(exp, sig, val.cterm)
return term
+ def mkCardinalityConstraint(self, Sort sort, int index):
+ """Create cardinality constraint.
+
+ :param sort: Sort of the constraint
+ :param index: The upper bound for the cardinality of the sort
+ """
+ cdef Term term = Term(self)
+ term.cterm = self.csolver.mkCardinalityConstraint(sort.csort, index)
+ return term
+
def mkConst(self, Sort sort, symbol=None):
"""
Create (first-order) constant (0-arity function symbol).
with pytest.raises(RuntimeError):
slv.mkFloatingPoint(3, 5, t1)
+def test_mk_cardinality_constraint(solver):
+ su = solver.mkUninterpretedSort("u")
+ si = solver.getIntegerSort()
+ solver.mkCardinalityConstraint(su, 3)
+ with pytest.raises(RuntimeError):
+ solver.mkEmptySet(solver.mkCardinalityConstraint(si, 3))
+ with pytest.raises(RuntimeError):
+ solver.mkEmptySet(solver.mkCardinalityConstraint(su, 0))
+ slv = pycvc5.Solver()
+ with pytest.raises(RuntimeError):
+ slv.mkCardinalityConstraint(su, 3)
def test_mk_empty_set(solver):
slv = pycvc5.Solver()
assertDoesNotThrow(() -> d_solver.mkRoundingMode(RoundingMode.ROUND_TOWARD_ZERO));
}
- @Test void mkUninterpretedConst() throws CVC5ApiException
- {
- assertDoesNotThrow(() -> d_solver.mkUninterpretedConst(d_solver.getBooleanSort(), 1));
- assertThrows(
- CVC5ApiException.class, () -> d_solver.mkUninterpretedConst(d_solver.getNullSort(), 1));
- Solver slv = new Solver();
- assertThrows(
- CVC5ApiException.class, () -> slv.mkUninterpretedConst(d_solver.getBooleanSort(), 1));
- }
-
@Test void mkAbstractValue() throws CVC5ApiException
{
assertDoesNotThrow(() -> d_solver.mkAbstractValue(("1")));
assertThrows(CVC5ApiException.class, () -> slv.mkFloatingPoint(3, 5, t1));
}
+ @Test void mkCardinalityConstraint() throws CVC5ApiException
+ {
+ Sort su = d_solver.mkUninterpretedSort("u");
+ Sort si = d_solver.getIntegerSort();
+ assertDoesNotThrow(() -> d_solver.mkCardinalityConstraint(su, 3));
+ assertThrows(
+ CVC5ApiException.class, () -> d_solver.mkCardinalityConstraint(si, 3));
+ assertThrows(
+ CVC5ApiException.class, () -> d_solver.mkCardinalityConstraint(su, 0));
+ Solver slv = new Solver();
+ assertThrows(
+ CVC5ApiException.class, () -> slv.mkCardinalityConstraint(su, 3));
+ }
+
@Test void mkEmptySet() throws CVC5ApiException
{
Solver slv = new Solver();