tools
feasibility_checker
heuristic_feasibility_check(constraints, variable_name, variable_type, variable_bounds, samples=10000)
A tool for checking feasibility of the constraints.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
constraints
|
Annotated[List[str], "List of strings like 'x0+x1<=5'"]
|
list of strings like 'x0 + x1 <= 5', etc. |
required |
variable_name
|
Annotated[List[str], "List of strings like 'x0', 'x1', etc."]
|
list of strings containing variable names used in constraint expressions. |
required |
variable_type
|
Annotated[List[str], "List of strings like 'real', 'integer', 'boolean', etc."]
|
list of strings like 'real', 'integer', 'boolean', etc. |
required |
variable_bounds
|
Annotated[List[List[float]], "List of (lower bound, upper bound) tuples for x0, x1, ...'"]
|
list of (lower, upper) tuples for x0, x1, etc. |
required |
samples
|
Annotated[int, 'Number of random sample. Default 10000']
|
number of random samples, default value 10000 |
10000
|
Returns:
Type | Description |
---|---|
Tuple[str]
|
A string indicating whether a feasible solution was found. |
Source code in src/ursa/tools/feasibility_checker.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
feasibility_tools
Unified feasibility checker with heuristic pre-check and exact auto-routing.
Backends (imported lazily and used only if available): - PySMT (cvc5/msat/yices/z3) for SMT-style logic, disjunctions, and nonlinear constructs. - OR-Tools CP-SAT for strictly linear integer/boolean instances with integer coefficients. - OR-Tools CBC (pywraplp) for linear MILP/LP (mixed real + integer, or pure LP). - SciPy HiGHS (linprog) for pure continuous LP feasibility.
Install any subset you need
pip install pysmt && pysmt-install --cvc5 # or --z3/--msat/--yices pip install ortools pip install scipy pip install numpy
This file exposes a single LangChain tool: feasibility_check_auto
.
feasibility_check_auto(constraints, variable_name, variable_type, variable_bounds, prefer_smt_solver='cvc5', heuristic_enabled=True, heuristic_first=True, heuristic_samples=2000, heuristic_seed=None, heuristic_unbounded_radius_real=1000.0, heuristic_unbounded_radius_int=10 ** 6, numeric_tolerance=1e-08)
Unified feasibility checker with heuristic pre-check and exact auto-routing.
Performs an optional randomized feasibility search. If no witness is found (or the heuristic is disabled), the function auto-routes to an exact backend based on the detected problem structure (PySMT for SMT/logic/nonlinear, OR-Tools CP-SAT for linear integer/boolean, OR-Tools CBC for MILP/LP, or SciPy HiGHS for pure LP).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
constraints
|
Annotated[List[str], "Constraint strings like 'x0 + 2*x1 <= 5' or '(x0<=3) | (x1>=2)'"]
|
Constraint strings such as "x0 + 2*x1 <= 5" or "(x0<=3) | (x1>=2)". |
required |
variable_name
|
Annotated[List[str], ['x0', 'x1', ...]]
|
Variable names, e.g., ["x0", "x1"]. |
required |
variable_type
|
Annotated[List[str], ['real' | 'integer' | 'boolean', ...]]
|
Variable types aligned with |
required |
variable_bounds
|
Annotated[List[List[Optional[float]]], '[(low, high), ...] (use None for unbounded)']
|
Per-variable [low, high] bounds aligned with |
required |
prefer_smt_solver
|
Annotated[str, "SMT backend if needed: 'cvc5'|'msat'|'yices'|'z3'"]
|
SMT backend name used by PySMT ("cvc5", "msat", "yices", or "z3"). |
'cvc5'
|
heuristic_enabled
|
Annotated[bool, 'Run a fast randomized search first?']
|
Whether to run the heuristic sampler. |
True
|
heuristic_first
|
Annotated[bool, 'Try heuristic before exact routing']
|
If True, run the heuristic before exact routing; if False, run it after. |
True
|
heuristic_samples
|
Annotated[int, 'Samples for heuristic search']
|
Number of heuristic samples. |
2000
|
heuristic_seed
|
Annotated[Optional[int], 'Seed for reproducibility']
|
Random seed for reproducibility. |
None
|
heuristic_unbounded_radius_real
|
Annotated[float, 'Sampling range for unbounded real vars']
|
Sampling radius for unbounded real variables. |
1000.0
|
heuristic_unbounded_radius_int
|
Annotated[int, 'Sampling range for unbounded integer vars']
|
Sampling radius for unbounded integer variables. |
10 ** 6
|
numeric_tolerance
|
Annotated[float, 'Tolerance for relational checks (Eq/Lt/Le/etc.)']
|
Tolerance used in relational checks (e.g., Eq, Lt, Le). |
1e-08
|
Returns:
Type | Description |
---|---|
str
|
A message indicating the chosen backend and the feasibility result. On success, |
str
|
includes an example model (assignment). On infeasibility, includes a short |
str
|
diagnostic or solver status. |
Raises:
Type | Description |
---|---|
ValueError
|
If constraints cannot be parsed or an unsupported variable type is provided. |
Source code in src/ursa/tools/feasibility_tools.py
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 |
|
run_command
run_cmd(query, workspace_dir)
Run command from commandline in the directory workspace_dir
Source code in src/ursa/tools/run_command.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
write_code
write_python(code, filename, workspace_dir)
Writes code to a file in the given workspace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code
|
str
|
The code to write |
required |
filename
|
str
|
the filename to write |
required |
Returns:
Type | Description |
---|---|
str
|
File writing status: string |
Source code in src/ursa/tools/write_code.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|