-
-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[docs] tweak diet.jl tutorial to use more DataFrame logic #3213
Conversation
Codecov ReportBase: 98.06% // Head: 97.93% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #3213 +/- ##
==========================================
- Coverage 98.06% 97.93% -0.14%
==========================================
Files 34 34
Lines 4597 4597
==========================================
- Hits 4508 4502 -6
- Misses 89 95 +6
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
I think it improves the overall clarity. I added two comments that might help. |
|
||
@variable(model, x[foods.name] >= 0); | ||
@variable(model, x[foods.name] >= 0) | ||
foods.x = Array(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jd-foster: I changed it to this so that x
has meaningful indices instead of x[1]
through x[n]`. Too magical?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this change, and concluded it didn't matter if the index matched the name since it's row already has the key column. It matters if you split the JuMP variable column off the dataframe.
But personally prefer the way you've changed it to now.
Here's the preview: https://jump.dev/JuMP.jl/previews/PR3213/tutorials/linear/diet/. I think I need to show the data frame with the |
Hmm. The doc failure is problematic and has exposed a subtle bug. It's because of this: julia> foods
9×7 DataFrame
Row │ name cost calories protein fat sodium x
│ Any Any Any Any Any Any Variable…
─────┼───────────────────────────────────────────────────────────────
1 │ hamburger 2.49 410 24 26 730 x[hamburger]
2 │ chicken 2.89 420 32 10 1190 x[chicken]
3 │ hot dog 1.5 560 20 32 1800 x[hot dog]
4 │ fries 1.89 380 4 19 270 x[fries]
5 │ macaroni 2.09 320 12 10 930 x[macaroni]
6 │ pizza 1.99 320 15 12 820 x[pizza]
7 │ salad 2.49 320 31 12 1230 x[salad]
8 │ milk 0.89 100 8 2.5 125 x[milk]
9 │ ice cream 1.59 330 8 10 180 x[ice cream]
julia> show(stdout, MIME("text/latex"), foods)
\begin{tabular}{r|ccccccc}
& name & cost & calories & protein & fat & sodium & x\\
\hline
& Any & Any & Any & Any & Any & Any & Variable…\\
\hline
1 & hamburger & 2.49 & 410 & 24 & 26 & 730 & $$ x_{hamburger} $$ \\
2 & chicken & 2.89 & 420 & 32 & 10 & 1190 & $$ x_{chicken} $$ \\
3 & hot dog & 1.5 & 560 & 20 & 32 & 1800 & $$ x_{hot dog} $$ \\
4 & fries & 1.89 & 380 & 4 & 19 & 270 & $$ x_{fries} $$ \\
5 & macaroni & 2.09 & 320 & 12 & 10 & 930 & $$ x_{macaroni} $$ \\
6 & pizza & 1.99 & 320 & 15 & 12 & 820 & $$ x_{pizza} $$ \\
7 & salad & 2.49 & 320 & 31 & 12 & 1230 & $$ x_{salad} $$ \\
8 & milk & 0.89 & 100 & 8 & 2.5 & 125 & $$ x_{milk} $$ \\
9 & ice cream & 1.59 & 330 & 8 & 10 & 180 & $$ x_{ice cream} $$ \\
\end{tabular} The variable is being typeset as I wonder what the impact is if we wrote everything as an inline equation. |
Preview: https://jump.dev/JuMP.jl/previews/PR3213/tutorials/linear/diet/
x-ref #3212
@jd-foster is this better or worse?