Skip to content

Commit c0445c6

Browse files
update docs
1 parent a0d32b3 commit c0445c6

File tree

7 files changed

+59
-102
lines changed

7 files changed

+59
-102
lines changed

class01/background_materials/basics_math.jl renamed to class01/background_materials/math_basics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using InteractiveUtils
77
# ╔═╡ 9fffca86-aec9-4c26-bced-3edaa1af9a22
88
begin
99
using Pkg; Pkg.activate("..")
10+
Pkg.instantiate()
1011
end
1112

1213
# ╔═╡ 00cc1e5e-f10e-4559-b9d9-8aba44eb493e

class01/background_materials/optimization_homework.jl renamed to class01/background_materials/optimization_basics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using InteractiveUtils
77
# ╔═╡ 881eed45-e7f0-4785-bde8-530e378d7050
88
begin
99
using Pkg; Pkg.activate("..")
10+
Pkg.instantiate()
1011
end
1112

1213
# ╔═╡ 9f5675a3-07df-4fb1-b683-4c5fd2a85002

class01/Optimization.jl renamed to class01/background_materials/optimization_motivation.jl

Lines changed: 40 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using InteractiveUtils
77
# ╔═╡ f0c826c7-b2e3-4dbf-b29d-37623aa4d7c6
88
begin
99
import Pkg
10-
Pkg.activate(".")
10+
Pkg.activate("..")
1111
Pkg.status()
1212
end
1313

@@ -110,8 +110,8 @@ begin
110110
for (ri,y) in enumerate(h_cs), (ci,x) in enumerate(v_cs)
111111
global vid
112112
# skip the outer frame
113-
if !(ri == n_rows -5 && ci == 4)
114-
if ri <= 27 || ri >= n_rows - 3 || ci <= 6 || ci >= n_cols - 3
113+
if !(ri == n_rows -5 && ci ==3)
114+
if ri <= 25 || ri >= n_rows - 4 || ci <= 8 || ci >= n_cols - 2
115115
continue
116116
end
117117
end
@@ -129,7 +129,12 @@ begin
129129
end
130130
@info "Vertices = $(nv(g)) | Edges = $(ne(g))"
131131

132-
add_edge!(g, 211, 212)
132+
# add entrance
133+
add_edge!(g, 173, 174)
134+
135+
# TODO: Automate ensure connectivity
136+
add_edge!(g, 104, 83)
137+
add_edge!(g, 104, 105)
133138

134139
overlay_img = overlay(img, h_cs, v_cs, verts)
135140
end
@@ -167,7 +172,7 @@ begin
167172

168173
sort(sel)
169174
end
170-
function overlay_items(img_rgb, hcs, vcs, verts, list, start_node=211, end_node=102; dot_half = 3, fade::Float64 = 0.40, gradc=false
175+
function overlay_items(img_rgb, hcs, vcs, verts, list, start_node=173, end_node=46; dot_half = 3, fade::Float64 = 0.40, gradc=false
171176
)
172177
grey = RGB.(Gray.(img_rgb))
173178
ol = map(c -> RGB((1 - fade) * c.r + fade,
@@ -253,15 +258,15 @@ Date: 28 of July, 2025
253258
# ╔═╡ 01c44cc2-68d5-11f0-2860-05c9ffbde13a
254259
md"# Decisions Decisions: A Path to optimality
255260
256-
Once upon a time, a boy named **Pedro Paulo** 🤵 loved **Costco** supermarket 🛒. However, everytime there, he spendt more time ⏱️ and money 💸 than needed.
261+
Once upon a time, a boy named **Pedro Paulo** 🤵 loved shopping at his local supermarket 🛒. However, everytime there, he spendt more time ⏱️ and money 💸 than needed.
257262
258263
Let's help Pedro out!
259264
"
260265

261266
# ╔═╡ 8d0fe751-aeb1-4ad1-a076-4c7bcd863a55
262267
md"## Problem Setting
263268
264-
After some investigation, we got a hold of a real Costco layout! 🎉🎉 🗺️ 🎉🎉
269+
After some investigation, we got a hold of the market layout! 🎉🎉 🗺️ 🎉🎉
265270
"
266271

267272
# ╔═╡ 9eb11624-17db-438e-86e4-77b313da268b
@@ -360,7 +365,7 @@ begin
360365
end
361366

362367
# ╔═╡ 8705f186-8af4-4f6b-bb53-c3fa46d0b8ba
363-
function greedy_tour(list, dist; start_node=211, end_node=102)
368+
function greedy_tour(list, dist; start_node=173, end_node=46)
364369
tour = [start_node]
365370
remaining = Set([list[1:end]; end_node])
366371
while !isempty(remaining)
@@ -430,7 +435,7 @@ question_box(md"### How to model it as an integer programing problem?")
430435

431436
# ╔═╡ acb9d0fd-c024-44b7-b549-78875068050f
432437
begin
433-
nverts=length(verts); nitems=length(plist);start_node=211;end_node=102;
438+
nverts=length(verts); nitems=length(plist);start_node=173;end_node=46;
434439
md"""
435440
#### What we have:
436441
@@ -476,41 +481,16 @@ begin
476481
# BASIC SETS
477482
_V = vertices(g)
478483
_A = [(u,v) for e in edges(g) for (u,v) in ((src(e),dst(e)), (dst(e),src(e)))]
479-
_s, _e = 211, 102 # start, end
484+
_s, _e = 173, 46 # start, end
480485
_items = setdiff(Set(plist), [_s,_e])
481486
K = length(_items) + 1 # units of flow we must deliver
482487

483488
# MODEL
484489
model = Model(HiGHS.Optimizer)
485490

486-
@variable(model, x[_A], Bin)
487-
@variable(model, 0 f[_A] K)
488-
489-
out(v) = sum(x[(v,w)] for w in _V if (v,w) in _A)
490-
inn(v) = sum(x[(u,v)] for u in _V if (u,v) in _A)
491-
fout(v) = sum(f[(v,w)] for w in _V if (v,w) in _A)
492-
finn(v) = sum(f[(u,v)] for u in _V if (u,v) in _A)
493-
494-
## degree / balance
495-
@constraint(model, out(_s) - inn(_s) == 1) # Costco Entrance
496-
@constraint(model, inn(_e) - out(_e) == 1) # Payment Exit
497-
@constraint(model, [i in _items], inn(i) 1) # Pick up items
498-
@constraint(model, [i in _items], out(i) 1)
499-
@constraint(model, [v in setdiff(_V, [_s,_e])], inn(v) == out(v))
500-
501-
## multi-unit single-commodity flow
502-
@constraint(model, [a in _A], f[a] K * x[a]) # deactivate on unused arcs
503-
504-
@constraint(model, fout(_s) - finn(_s) == K) # source injects K units
505-
@constraint(model, finn(_e) - fout(_e) == 1) # _e ‘consumes’ one unit
506-
@constraint(model, [i in _items], finn(i) - fout(i) == 1) # each item consumes 1
507-
@constraint(model, [v in setdiff(_V, [_s,_e] _items)],
508-
fout(v) == finn(v)) # pure transshipment elsewhere
509-
510-
## objective
511-
@objective(model, Min, sum(D[u,v] * x[(u,v)] for (u,v) in _A))
512-
513-
optimize!(model)
491+
# Write your Model Here
492+
493+
itinerary_answer = missing # replace missing with the optimal itinerary
514494
end
515495

516496
# ╔═╡ 8e507678-5d40-4a44-9aac-5701cc27f8ad
@@ -534,59 +514,42 @@ A[i,j] =
534514
535515
")
536516

537-
# ╔═╡ f7dc2333-d85f-44d7-bd5e-2f497a23f32b
538-
function euler!(adj, start)
539-
st=[start]; path=Int[]
540-
while !isempty(st)
541-
u = st[end]
542-
if isempty(get(adj,u,Int[]))
543-
push!(path, pop!(st))
544-
else
545-
push!(st, pop!(adj[u])) # consume arc once
546-
end
547-
end
548-
reverse(path) # ends at _e by construction
549-
end
550-
551-
# ╔═╡ 7db1a83c-0100-4b6b-a97b-a7d59520dc22
552-
begin
553-
adj = Dict{Int,Vector{Int}}()
554-
for (u,v) in _A
555-
if value(x[(u,v)]) > 0.5
556-
push!(get!(adj,u,Int[]), v)
557-
end
558-
end
559-
itinerary_answer = euler!(deepcopy(adj), _s)
560-
@assert itinerary_answer[1] == _s && itinerary_answer[end] == _e
561-
itinerary_answer
562-
end
563-
564-
# ╔═╡ 1c527fc1-f4fd-4a59-8f0b-63413b1bea56
565-
# itinerary_answer = missing # replace with your answer
566-
567517
# ╔═╡ f5faca5f-abc3-49f1-add5-385de0ddb5b7
568518
begin
569519
if ismissing(itinerary_answer)
570520
still_missing()
571521
else
572522
length_walk = itinerary_distance(itinerary_answer, D)
573-
if length_walk <= 312
523+
if length_walk <= 312 && itinerary_answer[1] == _s && itinerary_answer[end] == _e
574524
correct(md" $(round(length_walk)) meters. You have found the optimal path!")
575-
elseif length_walk <= total_length
525+
elseif length_walk <= total_length && itinerary_answer[1] == _s && itinerary_answer[end] == _e
576526
almost(md" $(round(length_walk)) meters. Nice you have beaten the greedy algorithm! But there is still room for improvement.")
577527
else
578528
keep_working(md" $(round(length_walk)) meters. You should at least beat the greedy algorithm. I thrust in you!")
579529
end
580530
end
581531
end
582532

533+
# ╔═╡ f7dc2333-d85f-44d7-bd5e-2f497a23f32b
534+
function euler!(adj, start)
535+
st=[start]; path=Int[]
536+
while !isempty(st)
537+
u = st[end]
538+
if isempty(get(adj,u,Int[]))
539+
push!(path, pop!(st))
540+
else
541+
push!(st, pop!(adj[u])) # consume arc once
542+
end
543+
end
544+
reverse(path) # ends at _e by construction
545+
end
546+
583547
# ╔═╡ 5de8429f-349d-4441-90b4-6f7caaf6b5e4
584548
if !ismissing(itinerary_answer)
585549
overlay_items(img, h_cs, v_cs, verts, full_itinerary; gradc=true)
586-
end
587-
588-
# ╔═╡ e7cc612d-fc6a-4976-89b2-821064dc612c
589-
still_missing()
550+
else
551+
still_missing()
552+
end
590553

591554
# ╔═╡ e04cfe19-5827-4bf2-8183-a13bad579497
592555
md"## Now Let's get a bit crazy!
@@ -620,19 +583,7 @@ begin
620583
end
621584

622585
# ╔═╡ 6ab03a08-6cda-4f35-bd80-e0ace02b86b5
623-
Foldable(md"#### Can we know the position of Pedro and his cart at any given moment?", md"""
624-
625-
```math
626-
x[t+1] = x[t] + \dot{x}[t] * \Delta_t
627-
```
628-
```math
629-
\dot{x}[t] = \dot{x}[t-1] + \ddot{x}
630-
```
631-
632-
""")
633-
634-
# ╔═╡ e4baeff0-f380-4269-9818-9fc43c1f802d
635-
586+
question_box(md"#### Can we know the position of Pedro and his cart at any given moment?")
636587

637588
# ╔═╡ f31d8852-ca07-46c9-bbea-5dd8f476c25c
638589
md"## References"
@@ -651,9 +602,6 @@ begin
651602
)
652603
end
653604

654-
# ╔═╡ 2e57bcd7-af6a-4813-8a2a-f7a71752a2de
655-
656-
657605
# ╔═╡ Cell order:
658606
# ╟─f0c826c7-b2e3-4dbf-b29d-37623aa4d7c6
659607
# ╟─054eb7cf-cb60-41a0-9a87-215e36dcf53d
@@ -684,20 +632,15 @@ end
684632
# ╟─083ddea0-f1db-46ef-b82c-5e10499bfb9d
685633
# ╠═7c889414-b9c4-477d-8e57-79ee1518dc8c
686634
# ╟─8e507678-5d40-4a44-9aac-5701cc27f8ad
687-
# ╠═f7dc2333-d85f-44d7-bd5e-2f497a23f32b
688-
# ╠═7db1a83c-0100-4b6b-a97b-a7d59520dc22
689-
# ╠═1c527fc1-f4fd-4a59-8f0b-63413b1bea56
690635
# ╟─f5faca5f-abc3-49f1-add5-385de0ddb5b7
636+
# ╟─f7dc2333-d85f-44d7-bd5e-2f497a23f32b
691637
# ╟─5de8429f-349d-4441-90b4-6f7caaf6b5e4
692-
# ╠═e7cc612d-fc6a-4976-89b2-821064dc612c
693638
# ╟─e04cfe19-5827-4bf2-8183-a13bad579497
694639
# ╟─263969f2-5e0f-4d7b-9b42-eb033861e4e9
695640
# ╟─bf94beb1-f5c9-45b0-a864-94f773a3c198
696641
# ╟─85f6ac91-bcc7-44de-948c-5a631a82c846
697642
# ╠═bcaf8412-964e-4d79-8db8-d69754fe4b83
698643
# ╠═c0cdf191-5350-4738-882f-8ded20168dbb
699-
# ╠═6ab03a08-6cda-4f35-bd80-e0ace02b86b5
700-
# ╠═e4baeff0-f380-4269-9818-9fc43c1f802d
644+
# ╟─6ab03a08-6cda-4f35-bd80-e0ace02b86b5
701645
# ╟─f31d8852-ca07-46c9-bbea-5dd8f476c25c
702646
# ╟─178c6168-b515-4220-b37f-2c31b34e045c
703-
# ╠═2e57bcd7-af6a-4813-8a2a-f7a71752a2de

class01/class01.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,19 @@ julia> Pluto.run()
6464

6565
#### Step 5: Opening an existing notebook file
6666

67-
To run a local notebook file that you have not opened before, then you need to enter its full path (e.g. `path/to/basics_math.jl`) into the blue box in the main menu.
67+
To run a local notebook file that you have not opened before, then you need to enter its full path (e.g. `path/to/math_basics.jl`) into the blue box in the main menu.
6868

6969
### **Linear Algebra**:
70-
We have prepared a basic (Pluto) [Linear Algebra Primer](https://learningtooptimize.github.io/LearningToControlClass/dev/class01/background_materials/basics_math.html) to help you brush up on essential concepts. This primer covers key topics such as matrix operations, eigenvalues, and eigenvectors besides other fundamental calculus concepts. It is recommended to review this primer before the first class.
70+
We have prepared a basic (Pluto) [Linear Algebra Primer](https://learningtooptimize.github.io/LearningToControlClass/dev/class01/background_materials/math_basics.html) to help you brush up on essential concepts. This primer covers key topics such as matrix operations, eigenvalues, and eigenvectors besides other fundamental calculus concepts. It is recommended to review this primer before the first class.
7171

7272
### **Optimization**:
7373
We will use JuMP for some optimization tasks. If you are new to JuMP, please review the [JuMP Tutorial](https://jump.dev/JuMP.jl/stable/tutorials/getting_started/getting_started_with_JuMP/) to familiarize yourself with its syntax and capabilities.
7474

75-
Test your knowledge with this (Pluto) [Modeling Exercise](https://learningtooptimize.github.io/LearningToControlClass/dev/class01/background_materials/optimization_homework.html).
75+
Test your knowledge with this (Pluto) [Modeling Exercise](https://learningtooptimize.github.io/LearningToControlClass/dev/class01/background_materials/optimization_basics.html).
76+
77+
*Final 🧠*: The (Pluto) [Motivational Exercise](https://learningtooptimize.github.io/LearningToControlClass/dev/class01/background_materials/optimization_motivation.html) will test what you have learned and motivate what we will research in the course.
78+
79+
## In-Class Material
80+
81+
Besides the administrative topics, we will cover the structure of the problem we are trying to solve and start with the basics of how to model it.
82+
The main (Pluto) [Class 01 Notebook](https://learningtooptimize.github.io/LearningToControlClass/dev/class01/class01_intro.html) contains the in-class material.

class01/layout.png

-40.1 KB
Loading

docs/make.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ repo_dir = dirname(@__DIR__)
77
build_dir = joinpath(repo_dir, "docs", "build")
88

99
plutos = [
10-
joinpath(repo_dir, "class01", "background_materials", "basics_math.jl"),
10+
joinpath(repo_dir, "class01", "background_materials", "math_basics.jl"),
11+
joinpath(repo_dir, "class01", "background_materials", "optimization_basics.jl"),
12+
joinpath(repo_dir, "class01", "background_materials", "optimization_motivation.jl"),
13+
joinpath(repo_dir, "class01", "class01_intro.jl"),
1114
]
1215

1316
if !isdir(build_dir)
@@ -30,7 +33,9 @@ makedocs(
3033
),
3134
pages = [
3235
"Home" => "index.md",
33-
"Class 1" => ["class01/class01.md"],
36+
"Class 1" => ["class01/class01.md",
37+
"class01/background_materials/git_adventure_guide.md",
38+
],
3439
],
3540
)
3641

0 commit comments

Comments
 (0)