-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Compiler API #51
Comments
Currently, you can compile and solve instances in sequence (by calling clear() between each problem). An example below xith cells from a notebook: from pycsp3 import * x = VarArray(size=3, dom=range(3))
satisfy(
AllDifferent(x)
)
instance1 = compile() print(instance1)
ace = solver(ACE)
result = ace.solve(instance1)
print(result, values(x))
result = ace.solve(instance1)
print(result, values(x))
clear()
result = ace.solve(instance1)
y = VarArray(size=3, dom=range(3))
satisfy(
AllEqual(y)
)
instance2 = compile()
print(instance1 == instance2)
result = ace.solve(instance2)
print(result, values(y))
|
I didn't realize the compile function existed! I didn't see it in the docs... But what I'd really like is for the "state" of PyCSP3 to not be global, meaning I can add new constraints to different instances, in the same execution, without "clearing". csp1 = CSP()
x = csp1.VarArray(size=3, dom=range(3))
csp2 = CSP()
y = csp2.VarArray(size=5, dom=range(5))
csp1.satisfy(AllDifferent(x))
csp2.satisfy(...)
instance1 = csp1.compile()
instance2 = csp2.compile()
ace = solver(ACE)
ace.solve(instance1)
ace.solve(instance2)
# add more stuff to csp1
z = csp1.VarArray(...)
csp1.satisfy(...)
# etc. |
I will think about it soon and let you informed |
Right now when working with PyCSP3, you create one model in a script, which is then compiled to XCSP3 when executed.
I would much rather have the option to script the actual compilation process, so I can create multiple different models through the PyCSP3 API, compile them through the API, and then solve them with whatever XCSP3 capable solver I choose.
Consider for example a single Jupyter notebook that models different constraint problems and wants to solve them separately.
The alternative is to generate the XML directly myself but that's not nearly as convenient as using the API, or to generate a python string in memory and then "exec" it to do the compilation.
The text was updated successfully, but these errors were encountered: