| 1640 | // / Demonstrate how to use #Eval. |
| 1641 | |
| 1642 | public void evalExample1(Context ctx) |
| 1643 | { |
| 1644 | System.out.println("EvalExample1"); |
| 1645 | Log.append("EvalExample1"); |
| 1646 | |
| 1647 | IntExpr x = ctx.mkIntConst("x"); |
| 1648 | IntExpr y = ctx.mkIntConst("y"); |
| 1649 | IntNum two = ctx.mkInt(2); |
| 1650 | |
| 1651 | Solver solver = ctx.mkSolver(); |
| 1652 | |
| 1653 | /* assert x < y */ |
| 1654 | solver.add(ctx.mkLt(x, y)); |
| 1655 | |
| 1656 | /* assert x > 2 */ |
| 1657 | solver.add(ctx.mkGt(x, two)); |
| 1658 | |
| 1659 | /* find model for the constraints above */ |
| 1660 | Model model = null; |
| 1661 | if (Status.SATISFIABLE == solver.check()) |
| 1662 | { |
| 1663 | model = solver.getModel(); |
| 1664 | System.out.println(model); |
| 1665 | System.out.println("\nevaluating x+y"); |
| 1666 | Expr<IntSort> v = model.evaluate(ctx.mkAdd(x, y), false); |
| 1667 | if (v != null) |
| 1668 | { |
| 1669 | System.out.printf("result = %s%n", v); |
| 1670 | } else |
| 1671 | { |
| 1672 | System.out.println("Failed to evaluate: x+y"); |
| 1673 | } |
| 1674 | } else |
| 1675 | { |
| 1676 | System.out.println("BUG, the constraints are satisfiable."); |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | // / Demonstrate how to use #Eval on tuples. |
| 1681 | |