-2

I stumbled upon a piece of software that I'd like to convert from Julia to Python (don't have much experience with Julia). The main problem I'm having is I don't understand exactly what is going on in the section I've marked with comments #PROBLEM BELOW/ABOVE

skaters_teams is a 180 x 10 matrix (180 skaters and 10 teams) and the team is stored as a binary array where skaters_teams[0] gives the array of player 0 ex:[1, 0, 0, 0, 0, 0, 0, 0, 0, 0].

m = Model(solver=GLPKSolverMIP()) 
# Variable for skaters in lineup 
@defVar(m, skaters_lineup[i=1:num_skaters], Bin) 

# Variable for goalie in lineup 
@defVar(m, goalies_lineup[i=1:num_goalies], Bin) 

# One goalie constraint 
@addConstraint(m, sum{goalies_lineup[i], i=1:num_goalies} == 1) 

# Eight Skaters constraint 
@addConstraint(m, sum{skaters_lineup[i], i=1:num_skaters} == 8) 

# between 2 and 3 centers 
@addConstraint(m, sum{centers[i]*skaters_lineup[i], i=1:num_skaters} <= 3) 
@addConstraint(m, 2 <= sum{centers[i]*skaters_lineup[i], i=1:num_skaters}) 

# between 3 and 4 wingers 
@addConstraint(m, sum{wingers[i]*skaters_lineup[i], i=1:num_skaters} <= 4) 
@addConstraint(m, 3<=sum{wingers[i]*skaters_lineup[i], i=1:num_skaters}) 

# between 2 and 3 defenders 
@addConstraint(m, 2 <= sum{defenders[i]*skaters_lineup[i], i=1:num_skaters}) 
@addConstraint(m, sum{defenders[i]*skaters_lineup[i], i=1:num_skaters} <= 3) 

# Financial Constraint 
@addConstraint(m, sum{skaters[i,:Salary]*skaters_lineup[i], i=1:num_skaters} + sum{goalies[i,:Salary]*goalies_lineup[i], i=1:num_goalies} <= 50000) 

# exactly 3 different teams for the 8 skaters constraint 
@defVar(m, used_team[i=1:num_teams], Bin)

#PROBLEM BELOW
@addConstraint(m, constr[i=1:num_teams], used_team[i] <= sum{skaters_teams[t, i]*skaters_lineup[t], t=1:num_skaters}) 
@addConstraint(m, constr[i=1:num_teams], sum{skaters_teams[t, i]*skaters_lineup[t], t=1:num_skaters} <= 6*used_team[i]) 
#PROBLEM ABOVE

@addConstraint(m, sum{used_team[i], i=1:num_teams} == 3) 

Is it looping like so:

for i in range(num_teams):
    for t in range(num_skaters):
        m += sum(skaters_teams[i][t]*skaters_lineup[t]) >=ut[i]
        m += sum(skaters_teams[i][t]*skaters_lineup[t]) <=6*ut[i]

Also I can't find any documentation on using 3 parameters with @addConstraint. The first is the problem you're adding it to and the third is the constraint you're adding. What is the second?

@addConstraint(m, constr[i=1:num_teams], sum{skaters_teams[t, i]*skaters_lineup[t], t=1:num_skaters} <= 6*used_team[i]) 
Frames Catherine White
  • 27,368
  • 21
  • 87
  • 137
  • 1
    Welcome to Stack Overflow! Here are some guidelines for asking questions in order to get the most helpful responses from people: http://stackoverflow.com/help/how-to-ask **and** http://stackoverflow.com/help/mcve – Michael Ohlrogge Aug 23 '16 at 13:58
  • I think the key is to (a) read some basic tutorials on the languages to get you started with a foundation understanding, (b) post a question with a very specific issue (i.e. when I do this I get that error). Just posting a general block of code and asking for it to be reviewed doesn't fit well with the goals of this site. Try reading through those links I gave above and give it another shot! – Michael Ohlrogge Aug 23 '16 at 14:51
  • You're getting closer. But, still, the "I don't understand these lines, explain them please" is too broad for this site. I would (a) give as much information as you can about your understanding of what the lines are doing, (b) explain the code that you've written based on that understanding, and (c) explain what problems you are encountering with that code. Also, to be warned, it looks like this is a question pertinent to specific modules in Python and Julia, and there might or might not be a lot of people familiar with them, so even a well posed question isn't guaranteed success. – Michael Ohlrogge Aug 23 '16 at 14:58
  • My suggestion would be: don't make it about Julia. Your problem is about Python. As it stands, people familiar with Julia should read and understand your model, they should also be familiar enough with PuLP so they can answer your question. Share your mathematical model instead, share your attempts at solving with Python with [mcve] and ask a specific question. – ayhan Aug 23 '16 at 14:59
  • 1
    Thanks for your help! I'll work on the problem more and edit my question when I have a better grip on the exact issue I'm having. – Neil Coughlin Aug 23 '16 at 15:14

1 Answers1

1

After playing around with it for a bit longer I found a solution. In case anyone has similar issues with pulp and jump here is what I used.

for i in range(num_teams):
    m += sum(x * st[i] for x,st in zip (skaters_lineup, skaters_teams[:])) >= used_team[i]
    m += sum(x * st[i] for x,st in zip (skaters_lineup, skaters_teams[:])) <= 6*used_team[i]