Skip to content
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

Accept a sequence of variable names #507

Closed
sin3000x opened this issue Jul 18, 2024 · 2 comments · Fixed by #509
Closed

Accept a sequence of variable names #507

sin3000x opened this issue Jul 18, 2024 · 2 comments · Fixed by #509

Comments

@sin3000x
Copy link
Contributor

While creating an array of variables x0, x1, x2 = intvar(0, 10, shape=3, name='x'), it's fine to have the name of x0 as 'x[0]', x1 as 'x[1]' and so on.

However, if the name is given as a sequence (of the same length of the array), it would be convenient to assign the name to each variable accordingly, rather than use indexing.

E.g., x, y = intvar(0, 10, shape=2, name=['x', 'y']) should give x the name 'x' and y the name 'y', but we have "['x', 'y'][0]" and "['x', 'y'][1]" currently, which is less readable...

@tias
Copy link
Collaborator

tias commented Jul 18, 2024

I have been thinking about that, but I was held back because strings are enumerable so finding cases in which a string can be guessed to be a list of chars might mess up everything; unless of course we explicitly check that it is instance list/tuple as in your example, and that the dimensions map the shape. Then we can do things like x,y = intvar(0,10, shape=2, name=list("xy")) which would be nice in some of our lecture examples too...

We would accept such a change, do you want to give it a try (cpmpy/expressions/variables.py) and submit a pull request?

@sin3000x
Copy link
Contributor Author

Thanks for your reply. Things might be a bit tricky for higher dimensions (I haven't thought it through yet), but I'd be happy to give it a try when I have some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants