Skip to content

Commit c6bd7ff

Browse files
authored
Merge pull request #1 from robbr48/update_tutorial_optimization
Update optimization tutorial
2 parents 4e7b26a + a1d2693 commit c6bd7ff

12 files changed

+42
-57
lines changed

gfx/Hopsan-Wizard.png

887 Bytes
Loading

gfx/optimization/screenshot-opt0.png

54.8 KB
Loading

gfx/optimization/screenshot-opt1.png

7.36 KB
Loading

gfx/optimization/screenshot-opt2.png

-32.7 KB
Loading

gfx/optimization/screenshot-opt3a.png

0 Bytes
Loading

gfx/optimization/screenshot-opt3b.png

0 Bytes
Loading

gfx/optimization/screenshot-opt4.png

-11 KB
Loading

gfx/optimization/screenshot-opt5a.png

9.57 KB
Loading

gfx/optimization/screenshot-opt5b.png

10.5 KB
Loading

gfx/optimization/screenshot-opt5c.png

1.28 KB
Loading

tutorial_optimization.pdf

-147 KB
Binary file not shown.

tutorial_optimization.tex

+42-57
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ \section*{Using the optimization dialog}
1818
\tutitem{Open the model}
1919
The \textit{Welcome} tab has a box with example models. Open the \textit{Position Servo} example model.
2020

21-
\FloatBarrier
22-
\begin{figure}[h]
23-
\center
21+
\begin{centering}
2422
\includegraphics[width=0.5\textwidth]{gfx/optimization/openmodel.png}
25-
\end{figure}
26-
\FloatBarrier
23+
\end{centering}
2724

2825
This model describes of a hydraulic position servo, where a PI-controller is used to control the position. This consists of a proportional gain ($K_{p}$) and an integrator gain ($K_{i}$). The values of these gains will decide the speed and stability of the servo. It is thus desirable to find as good controller parameters as possible.
2926

@@ -39,35 +36,39 @@ \section*{Using the optimization dialog}
3936

4037
\icon{0}{gfx/Hopsan-Optimize.png}{Open optimization dialog (Ctrl-Shift-Z)}
4138

42-
\pagebreak
4339

44-
\tutitem{Optimization settings}
45-
The first page should look like this:
40+
\begin{center}
41+
\includegraphics[width=0.7\textwidth]{gfx/optimization/screenshot-opt0.png}
42+
\end{center}
4643

47-
\FloatBarrier
48-
\begin{figure}[h]
49-
\center
50-
\includegraphics[width=0.7\textwidth]{gfx/optimization/screenshot-opt1.png}
51-
\end{figure}
52-
\FloatBarrier
44+
The first page should look like above. You can either write an optimization script by hand, load a script file or start the script wizard.
45+
Let us begin with the latter.
46+
Click on the wizard icon.
5347

54-
From here you can choose the general settings for the optimization.
48+
\icon{0}{gfx/Hopsan-Wizard.png}{Script Wizard}
49+
50+
\tutitem{Optimization settings}
51+
%
52+
The first wizard page will open. From here you can choose the general optimization settings.
53+
%
54+
\begin{center}
55+
\includegraphics[width=0.7\textwidth]{gfx/optimization/screenshot-opt1.png}
56+
\end{center}
57+
%
5558
\begin{itemize}
56-
\item Set \textit{Algorithm} to \textit{Complex}
59+
\item Set \textit{Algorithm} to \textit{Complex-RF}
5760
\item Set \textit{Number of iterations} to 1000
5861
\item Set \textit{Number of points} to 4
5962
\end{itemize}
6063
Leave all other settings unchanged for now.
6164

65+
\pagebreak
6266
\tutitem{Choose optimization parameters}
6367
Next page controls the parameters in the model that shall be optimized.
6468

65-
\FloatBarrier
66-
\begin{figure}[h]
67-
\center
69+
\begin{center}
6870
\includegraphics[width=0.7\textwidth]{gfx/optimization/screenshot-opt2.png}
69-
\end{figure}
70-
\FloatBarrier
71+
\end{center}
7172

7273
Check the following parameters in the list:
7374

@@ -96,12 +97,9 @@ \section*{Using the optimization dialog}
9697

9798
Then choose \enquote{Minimize} and \enquote{Absolute Average Difference} in the boxes. Click \enquote{Add Function}.
9899

99-
\FloatBarrier
100-
\begin{figure}[htb]
101-
\center
100+
\begin{center}
102101
\includegraphics[width=0.7\textwidth]{gfx/optimization/screenshot-opt3a.png}
103-
\end{figure}
104-
\FloatBarrier
102+
\end{center}
105103

106104
Apart from minimizing the average difference, we also want to minimize the overshoot of the step response.
107105
\begin{itemize}
@@ -110,55 +108,42 @@ \section*{Using the optimization dialog}
110108

111109
Now choose \enquote{Minimize} and \enquote{Overshoot}, and then click \enquote{Add Function}. In the box called \enquote{arg1}, change the value to 0.7.
112110

113-
\newpage
114111
Now we have added a second objective function. The total objective function will the sum of these. As they may not be equally important or equally scaled, it is possible to weight the individual functions. Change \enquote{Weight} for the first function to 10. Now the page should look like this:
115112

116-
\FloatBarrier
117-
\begin{figure}[htb]
118-
\center
113+
\begin{center}
119114
\includegraphics[width=0.7\textwidth]{gfx/optimization/screenshot-opt3b.png}
120-
\end{figure}
121-
\FloatBarrier
115+
\end{center}
122116

117+
\pagebreak
123118
\tutitem{Start the optimization}
124119
Next page shows the generated script code. Modifications can be made if necessary, but leave it as it is for now.
125120

126-
\FloatBarrier
127-
\begin{figure}[htb]
128-
\center
121+
\begin{center}
129122
\includegraphics[width=0.7\textwidth]{gfx/optimization/screenshot-opt4.png}
130-
\end{figure}
131-
\FloatBarrier
123+
\end{center}
132124

133-
\newpage
134-
Go to the next page. From here the optimization can be executed:
125+
Now change to the "run" tab. From here the execution of the optimization can be monitored:
135126

136-
\FloatBarrier
137-
\begin{figure}[htb]
138-
\center
127+
\begin{center}
139128
\includegraphics[width=0.7\textwidth]{gfx/optimization/screenshot-opt5a.png}
140-
\end{figure}
141-
\FloatBarrier
129+
\end{center}
130+
131+
Click on \enquote{Start Optimization}.
132+
133+
\icon{0}{gfx/Hopsan-Optimize.png}{Start Optimization}
142134

143-
Click on \enquote{Start Optimization}. During the optimization the objective function values and the values of the optimization parameters are shown for the different points. The best point is shown in green, and the worst in red.
135+
During the optimization the objective function values and the values of the optimization parameters are shown for the different points. The rows are sorted from best to worst.
144136

145-
\FloatBarrier
146-
\begin{figure}[htb]
147-
\center
137+
\begin{center}
148138
\includegraphics[width=0.7\textwidth]{gfx/optimization/screenshot-opt5b.png}
149-
\end{figure}
150-
\FloatBarrier
139+
\end{center}
151140

152-
\newpage
153141
\tutitem{Evaluate the results}
154142
Once the optimization has finished, we can evaluate the results. Parameters from a point can be written back to the original model by using the \enquote{Apply} buttons.
155143

156-
\FloatBarrier
157-
\begin{figure}[htb]
158-
\center
144+
\begin{center}
159145
\includegraphics[width=0.7\textwidth]{gfx/optimization/screenshot-opt5c.png}
160-
\end{figure}
161-
\FloatBarrier
146+
\end{center}
162147

163148
Click the \enquote{Apply} button for the point with green text (the best point). Then go back to the original model and click the Simulate button again.
164149

@@ -178,7 +163,7 @@ \section*{Optimizing from script files}
178163
Click on Save script file in the dialog.
179164

180165
\tutitem{Loading a script file}
181-
To load a previously saved script file, click on Load script file in the dialog. You will be taken directly to the code tab. Go to the last tab and start the optimization as before. Note that the settings on the first three pages are not updated by the script. Going back to these might re-generate the script and overwrite the loaded code.
166+
To load a previously saved script file, click on Load script file in the dialog. You will be taken directly to the code tab. Go to the "run" tab and start the optimization as before. Note that the settings on the first three pages are not updated by the script. Running the wizard again will re-generate the script and overwrite the loaded code.
182167

183168
\tutitem{Loading a script file from command terminal}
184169
It is also possible to load a script file from the command terminal. Just write \enquote{exec} followed by the path to the file. Hopsan will automatically understand that this is an optimization script and start the dialog. You can use \enquote{pwd} to show current directory and \enquote{cd} to change directory if necessary. Example: \texttt{>{}> exec ..\textbackslash folder\textbackslash myscript.hcom}

0 commit comments

Comments
 (0)