Giter Club home page Giter Club logo

Comments (4)

xcsp3team avatar xcsp3team commented on July 18, 2024 1

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.

maxtremblay avatar maxtremblay commented on July 18, 2024

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.

xcsp3team avatar xcsp3team commented on July 18, 2024

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.

xcsp3team avatar xcsp3team commented on July 18, 2024

This will be visible in the documentation very soon.
Indeed, Version 2.1 will be published in November 2022.

from pycsp3.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.