# Transposing player orders in a linear constraint

**URL:** <https://discourse.julialang.org/t/transposing-player-orders-in-a-linear-constraint/27945>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [August 24, 2019, 6:17pm UTC](https://discourse.julialang.org/t/transposing-player-orders-in-a-linear-constraint/27945 "2019-08-24T18:17:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saggaa](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Saggaa](https://discourse.julialang.org/u/Saggaa)\
**Post date:** [August 24, 2019, 6:17pm UTC](https://discourse.julialang.org/t/transposing-player-orders-in-a-linear-constraint/27945/1 "2019-08-24T18:17:13Z")

</div>

Hello everyone!

I am currently learning Julia in college and i would need your expert help to better define a linear constraint in the frame of an assignment.  
Our professor is passionate about MLB and our assignment is about optimizing a fantasy baseball game.  
Fantasy is about picking players during certain games. Based on their real life performances, these players score point.  
The constraints come from the game format : 8 hitters total and a salary cap not to exceed.

I have modeled all the basic constraints using JuMP & GLPK.

* * *

```
m = Model(with_optimizer(GLPK.Optimizer))

# Variable for hitters
@variable(m, hitters_lineup[i=1:num_hitters], Bin)

# Variable for pitchers in lineup.
@variable(m, pitchers_lineup[i=1:num_pitchers], Bin)

# 8 hitters total
@constraint(m, sum(hitters_lineup[i] for i=1:num_hitters) == 8)

# Two pitchers constraint
@constraint(m, sum(pitchers_lineup[i] for i=1:num_pitchers) == 2) 

```

# Financial Constraint

```
@constraint(m, sum(hitters[i,:Salary]*hitters_lineup[i] for i=1:num_hitters) + 
     sum(pitchers[j,:Salary]*pitchers_lineup[j] for j=1:num_pitchers) <= 50000)

```

* * *

After consulting the available benchmarks & state of the art on the subject, a common fantasy practice seems to be “stacking”. Due to the rules of baseball, the total point variace gets higher by stacking consecutive hitters from the same team.  
I have input data concerning each player, their team and their batting order.

* * *

## Name Salary Team Position Opponent Projection Order David Peralta 4500 ARI OF MIL 9.12 1 Eduardo Escobar 5400 ARI 2B/3B MIL 9.23 2 Jake Lamb 3800 ARI 1B/3B MIL 8.03 3 Yasmani Grandal 4300 MIL C ARI 8.6 6 Mike Moustakas 4800 MIL 2B/3B ARI 8.8 5 Christian Yelich 5900 MIL OF ARI 10.92 3 Ketel Marte 5600 ARI 2B/OF MIL 8.27 4 Jarrod Dyson 4800 ARI OF MIL 7.96 7 Luis Arraez 4100 MIN 2B/3B DET 6.94 3 Jake Cave 3200 MIN OF DET 6.1 8 Ehire Adrianza 3700 MIN 3B/SS DET 6.6 3 Jason Castro 3600 MIN C DET 6.01 3 Jordy Mercer 2900 DET SS MIN 5.94 3 Eric Thames 4600 MIL 1B ARI 7.79 4

Using this data, i am unsuccessful at defining a linear constraint forcing the model to pick 5 consecutive hitters from the same lineup ( there are 8 batters total, so the algorithm would need to pick a combination like (5 6 7 8 1 2) based on the batting order input).  
Would you be able to help me with that and point me in a more productive direction ?

Thank you a lot for your help and let me know you need more details!

---

<div class="post-metadata">

**Author:** ![Saggaa](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@Saggaa](https://discourse.julialang.org/u/Saggaa)\
**Post date:** [August 25, 2019, 3:54pm UTC](https://discourse.julialang.org/t/transposing-player-orders-in-a-linear-constraint/27945/2 "2019-08-25T15:54:45Z")

</div>

Hello all,

After getting some advice, i moved the thread to the optimization section of the forum.

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [August 25, 2019, 6:32pm UTC](https://discourse.julialang.org/t/transposing-player-orders-in-a-linear-constraint/27945/3 "2019-08-25T18:32:01Z")

</div>

Hi there. This forum isn’t a place to ask for homework help directly.

However, if you are struggling with JuMP syntax once you have a mathematical formulation, feel free to post a simplified or abstract version of what you are struggling with. Good luck!

---

<div class="post-metadata">

**Author:** ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)\
**Post date:** [August 26, 2019, 7:30am UTC](https://discourse.julialang.org/t/transposing-player-orders-in-a-linear-constraint/27945/4 "2019-08-26T07:30:28Z")

</div>

Maybe a more appropriate forum is the recently opened [Operations Research](https://or.stackexchange.com/) subdomain on StackOverflow. Although I’m not familiar with their homework policy.
