-1

I'm trying to write the following constraints in PuLP.

  1. Choose between A and B; I can select atmost one and can't select both.
  2. There are a total of 10 variables A-J. Out of A-F, I have to select at least 3 in my solution.

Can you please advise on how to write these constraints?

Dave2e
  • 22,192
  • 18
  • 42
  • 50
aseem puri
  • 61
  • 1
  • 7

1 Answers1

0

A simple formulation over 10 binary variables would be as follows (corresponding to A-J)

x1=LpVariable("x1",0,1,LpInteger)
x2=LpVariable("x2",0,1,LpInteger)
...
x10=LpVariable("x10",0,1,LpInteger)
# add an appropriate objective
...
# A or B or none but not both
prob += x1 + x2 <= 1
# At least 3 out of 10
prob += x1 + x2 + ... + x10 >= 3
mka
  • 53
  • 5