dwavesystems / dwavesystems/dwave-optimization
Consider adding categorical variables
- Dominant language
- C++
- Stars
- 31
- Forks
- 36
- Avg merge
- 16h 55m
- Merged PRs (30d)
- 8
Description
### Example
Say one wants to model choosing between four different stocks, each with an expected return and a volatility. One might currently model it like
```python
model = Model()
expected_return = model.constant([...])
volatility = model.constant([...])
stock = model.integer(lower_bound=0, upper_bound=3)
stock_return = expected_return[stock]
stock_volatility = volatility[stock]
```
This works OK but `stock` isn't really modelling an integer variable in the sense that the ordering of the stocks in the relevant arrays does not hold any semantic meaning.
### Feature Request
In such cases a user might wish to use a [categorical variable](https://en.wikipedia.org/wiki/Categorical_variable). This might have a similar API
```python
model = Model()
expected_return = model.constant([...])
volatility = model.constant([...])
stock = model.categorical(num_categories=4)
stock_return = expected_return[stock]
stock_volatility = volatility[stock]
```
but semantically the solver would not consider the variable to be ordered.
### Other thoughts
This needs more thought, but something like
```python
stock = model.categorical(["a", "b", "c"]) # takes values in [0, 1, 2] as usual
stock == stock.category("a") # equivalent to stock == model.constant(0)
```
might be convenient. Or might just introduce a mess.
Contributor guide
Assessment
This issue has not been assessed yet.