-1

Thanks ahead for your time! I have the following data:

    Name    Group    ID    Grade
    Bill    A        1     89
    Jill    A        2     70
    Bob     A        3     99
    Chad    A        4     5
    Molly   B        5     12
    Bill    B        1     100
    Jill    B        2     88

I am using Pulp to maximize the points, but I only need 1 of group B and 3 of group A. The constraint I am having issues with is generating a list without any duplicated names. So what I'm receiving is this: (2 Bills)

    Name    Group    ID    Grade
    Bill    A        1     89
    Jill    A        2     70
    Bob     A        3     99
    Bill    B        1     100

I have generated the ID column by myself in hopes I'd be able to set up the constraint with it, but I've failed multiple times. The correct solution would be something like: (zero duplicated people)

    Name    Group    ID    Grade
    Bill    A        1     89
    Jill    A        2     70
    Bob     A        3     99
    Chad    A        4     5
    Molly   B        5     12

I couldn't find anything on here or anywhere else on the web that provided me with advice or a solution. Any help is greatly appreciated :)

  • Please post what you have done so far. Also could you be clearer on your constraints and objective? From your text I understand that you want to select 1 group B, 3 group As without any duplicate names, whilst maximising selected number of points - but in your correct solution you have 4 group As. – kabdulla Nov 13 '18 at 18:50

1 Answers1

0

Is is unclear without looking at your variables and code, but the idea is to add constraints to entries with same names:

for name in names:
    prob += sum(isEntryUsed[x] for x in range(len(entries)) if entries[x].name == name) <= 1

This can be done more efficiently if you group entries by name.

juvian
  • 15,875
  • 2
  • 37
  • 38