Adding new tutorial to Plasmo#134
Conversation
|
Hi @KiernanJ, thanks for your contribution! We had some issues with an old workflow. Can you try merging the latest main into your PR? It should re-trigger the checks. |
Added new line to fix some formatting
Fixing MD for clarity
docs/src/tutorials/MHMPC.md
Outdated
| We define our graph and subgraph structure. This encapsulates the MH-MPC approach for each $H$ sub-interval $i \in H$. Here $H = 5$. To run the entire optimization over a set time period, we will wrap the model construction and optimization (steps 2 through 5) in a function called ``MHMPC``. | ||
|
|
||
| ```julia | ||
| function MHMPC(x0) |
There was a problem hiding this comment.
Thank you for adding the MHMPC function! One last request on this: can put these blocks into their own function calls just to make the code a little easier to copy over for a potential user? Something like what is in the optimal control of a quadcopter example: https://plasmo-dev.github.io/Plasmo.jl/dev/tutorials/quadcopter/
I think you can do something like:
function add_horizon_subgraphs()
# All of the subgraphs
graph_SG1 = OptiGraph()
graph_SG2 = OptiGraph()
graph_SG3 = OptiGraph()
graph_SG4 = OptiGraph()
graph_SG5 = OptiGraph()
subgraphs_all = [graph_SG1, graph_SG2, graph_SG3, graph_SG4, graph_SG5]
# Initialize all nodes for subgraphs
@optinode(graph_SG1, nodes1[1:N_i[1]])
@optinode(graph_SG2, nodes2[1:N_i[2]])
@optinode(graph_SG3, nodes3[1:N_i[3]])
@optinode(graph_SG4, nodes4[1:N_i[4]])
@optinode(graph_SG5, nodes5[1:N_i[5]])
nodes_all = [graph_SG1[:nodes1], graph_SG2[:nodes2], graph_SG3[:nodes3], graph_SG4[:nodes4], graph_SG5[:nodes5]]
return subgraphs_all, nodes_all
endThen you can do something like this farther down
function MHMPC
graph = OptiGraph()
subgraphs_all, nodes_all = add_horizon_subgraphs(graph)
...
end| end | ||
| ``` | ||
|
|
||
| Now, plotting the values of $x$ from our program: |
There was a problem hiding this comment.
Maybe at the end of this last code snippet, add the code to call the run_sim function. Just something like:
x_sim, u_sim = run_sim()Add functions to make tutorial more accessible to reader
|
this looks good to me! |
New tutorial implementation of multi-horizon MPC to Plasmo. Super simple example for beginners in optimization, JuMP, and Plasmo.