0

I found some problems where the optimization result from xpress does not follow the specified variable type. I set vartype=xp.binary when I create the xpress variables, but some of the results have values such as 0.13333, 0.36667, 0.5.

I found that this was caused by one of the constraints. When I disabled most of the constraints, the values are all binary. Then, I enabled the constraint one by one and found one set of constraints that is causing the value to be non-binary.

Has anyone observed this before? Any suggestion on how to enforce the variable value to be binary?

Thanks!

Daniel Junglas
  • 5,830
  • 1
  • 5
  • 22
Starz
  • 199
  • 1
  • 6

1 Answers1

1

For sake of completeness, expanding Erwin Kalvelagen's comment into an answer: Fractional values for integer variables usually happen when the problem is infeasible. After solve() returns, you need to check attributes.mipstatus to make sure you actually have a solution available (see also the potential values for the MIP status here):

p = xp.problem()
...
p.solve()
print(p.getProbStatus(), p.getProbStatusString())
if p.attributes.mipstatus == xp.mip_solution or \
   p.attributes.mipstatus == xp.mip_optimal:
    print(p.getProbStatusString())
    print(p.getSolution())
else:
    print('No feasible solution', p.getProbStatusString())

Another way to get the problem status is function p.getProbStatus().

Pietro
  • 41
  • 1
  • 5
Daniel Junglas
  • 5,830
  • 1
  • 5
  • 22