Comments (4)
It is possible to manage variables on the fly in certain cases for 1-dimensional array now.
You need the last commited version (for the Pypi version, you need to wait for the next published version ; planned to be next week).
As an example, the following code is working. x is an array with holes (this is visible when you observe the result of AllDifferent).
I don't know if it is a sufficient answer for all the cases you may need to address.
from pycsp3 import *
y = VarArray(size=10, dom=lambda i: {0, 1})
t = list()
for i in range(10):
if i % 2 == 0:
t.append(None)
else:
t.append(Var(range(10)))
# array x
x = VarArray(t)
satisfy(
AllDifferent(x)
)
from pycsp3.
Ok, thanks for the answer. I don't think it covers what I want to achieve. For future version, maybe it would be nice to have the possibility to use an argument in Var
and VarArray
to set names of variables.
from pycsp3.
Hi,
In the last version of the code, you can do that. This is not documented yet.
Here are a few examples:
from pycsp3 import *
x = Var(range(10))
y = Var(dom=range(5), id="yy_12")
Var(dom=range(10), id="z")
d = dict()
a = 1
d[0] = Var(0, 1, id="d_0")
d[a] = Var(0, 1, id="d_1")
satisfy(
x >= 3,
var("x") <= 6,
y > 2,
var("yy_12") < 4,
var("z") != 4,
d[0] + d[1] != 0,
var("d_0") + var("d_1") != 2
)
from pycsp3 import *
x = VarArray(size=3, dom={0, 1})
y = VarArray(size=3, dom={0, 1}, id="yy")
VarArray(size=3, dom={0, 1}, id="zz")
d = dict()
a = 1
d[0] = VarArray(size=3, dom={0, 1}, id="d0")
d[a] = VarArray(size=3, dom={0, 1}, id="d_a")
satisfy(
Sum(x) == 1,
Sum(y) > 0,
Sum(var("yy")) < 2,
Sum(var("zz")) < 2,
Sum(d[0] + d[a]) > 0,
Sum(var("d0") + var("d_a")) < 2,
var("d_a")[1] == 1
)
from pycsp3.
This will be visible in the documentation very soon.
Indeed, Version 2.1 will be published in November 2022.
from pycsp3.
Related Issues (15)
- Running `csp_single.py` fails HOT 1
- Wrong lib call in test HOT 2
- -data gets concatenated to xml filename HOT 2
- Some typos in the online documentation http://pycsp.org HOT 1
- TypeError when defining constrains HOT 2
- pycsp3 fails to solve anything HOT 4
- Add the possibility to store log of solver and generated xml files in a specific directory. HOT 1
- TypeError: list indices must be integers or slices, not VariableInteger HOT 3
- Possible error in the Taillard-js-015-15-1.json data file! HOT 2
- Syntax warning: "is" used with literal. Did you mean "==" in compiler.py:271 HOT 1
- 'ValueError encountered when using predicate 0.5'
- Error when initializing solve() function with 'options' parameter HOT 3
- Variable name "values" should be avoided HOT 1
- is the BinPacking constraint working properly? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pycsp3.