| 1835 | // / Demonstrate how to use #Eval. |
| 1836 | |
| 1837 | public void evalExample1(Context ctx) |
| 1838 | { |
| 1839 | System.out.println("EvalExample1"); |
| 1840 | Log.append("EvalExample1"); |
| 1841 | |
| 1842 | IntExpr x = ctx.mkIntConst("x"); |
| 1843 | IntExpr y = ctx.mkIntConst("y"); |
| 1844 | IntExpr two = ctx.mkInt(2); |
| 1845 | |
| 1846 | Solver solver = ctx.mkSolver(); |
| 1847 | |
| 1848 | /* assert x < y */ |
| 1849 | solver.add(ctx.mkLt(x, y)); |
| 1850 | |
| 1851 | /* assert x > 2 */ |
| 1852 | solver.add(ctx.mkGt(x, two)); |
| 1853 | |
| 1854 | /* find model for the constraints above */ |
| 1855 | Model model = null; |
| 1856 | if (Status.SATISFIABLE == solver.check()) |
| 1857 | { |
| 1858 | model = solver.getModel(); |
| 1859 | System.out.println(model); |
| 1860 | System.out.println("\nevaluating x+y"); |
| 1861 | Expr v = model.evaluate(ctx.mkAdd(x, y), false); |
| 1862 | if (v != null) |
| 1863 | { |
| 1864 | System.out.println("result = " + (v)); |
| 1865 | } else |
| 1866 | { |
| 1867 | System.out.println("Failed to evaluate: x+y"); |
| 1868 | } |
| 1869 | } else |
| 1870 | { |
| 1871 | System.out.println("BUG, the constraints are not satisfiable."); |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | // / Demonstrate how to use #Eval on tuples. |
| 1876 | |