Search code examples
optimizationlinear-programmingpyomo

Pyomo: Why is the solver finding a value outside the specified domain?


Editing to better address my question.

Have a variable x that represents day of the year, so 1-365. There are some days that are not allowed. So I create a list with the valid day options and then a pyomo set with model.jan = pyo.Set(initialize=month_lists[1]).

I define my mapping as follows:

def x_domain(model, i, j):
    domain_mapping = {
        0: model.pdec,
        1: model.jan,
        2: model.feb,
        ...
    }
    return domain_mapping.get(i)

Then create my variable x:

model.x = pyo.Var(model.months, model.cycles, domain=x_domain)

The domain looks exactly as I would expect when I inspect it, but the solver is still finding solutions that violate the domain. January Domain

Key | Lower | Value | Upper | Fixed | Stale | Domain

(1, 6) : 1 : 7.0 : 31 : False : False : jan

So the variable finds 7 as a value when that is explicitly not in the domain.

I can figure out other ways to write this up, just confused as to why this approach does not seem to work. The pyomo documentation seems to support discrete integer sets.


Solution

  • I would model this differently. In pseudo-code:

     set wd (working days)
     binary variable x(wd)
     sum(wd,x(wd)) = 1
    

    It may be easier to make wd a large one-dimensional set (instead of (month,dayofmonth) tuple).