dimod icon indicating copy to clipboard operation
dimod copied to clipboard

Add a method to specify the value domain of a variable in CQM

Open ghost opened this issue 4 years ago • 3 comments

Description Is it possible to add a method to specify the value domain of an integer variable while defining it in CQM? For example, I can define an integer variable by x = dimod.Integer(lower_bound=0, upper_bound=10). However, in some cases, I would like to define it with a specific domain (maybe a list) such as x = dimod.Integer(domain=[0, 1, 3, 4, 8]).

Possible solution I noticed this is similar to the fix_variable() method in BQM. Since we can fix the value of a binary variable, maybe it is also necessary to fix some possible values for an integer variable.

Or, is it possible to add a != constraint to CQM?

Would you please tell me if I missed some information?

ghost avatar Oct 20 '21 06:10 ghost

Hi @qinmaomao, we don't currently support != constraints, although that it something that we're looking into for future releases.

For now, if your domain is small, you could use a discrete variable. E.g. if you have a variable "i" that you wish to take [0, 1, 3, 4, 8]

cqm.add_discrete([("i", 0), ("i", 1), ("i", 3), ("i", 4), ("i", 8)])
i = 0*dimod.Binary(('i', 0)) + 1*dimod.Binary(('i', 1)) + 3*dimod.Binary(('i', 3)) + ...

this will create 5 binary variables, one for each value of "i". You can then use i in expressions like usual. The cqm.add_discrete() will automatically enforce a 1-hot constraint over the binary variables.

arcondello avatar Oct 20 '21 16:10 arcondello

Another solution to add the x != a constraint is to add an extra binary variable y to the model and add the following constraint: 2 x*y - x > 2b*y -b. It may be useful if you only have a small amount of these type of constraints.

alexzucca90 avatar Oct 20 '21 16:10 alexzucca90

we don't currently support != constraints, although that it something that we're looking into for future releases.

@arcondello , Thank you for your reply. I am very happy to hear that you will add this feature. And I will try your method for my problem.

@alexzucca90 , Thank you for your solution. Although I am not sure whether it will make my model too big, I will try.

ghost avatar Oct 21 '21 00:10 ghost