-
Notifications
You must be signed in to change notification settings - Fork 0
/
help.html
1293 lines (1199 loc) · 72 KB
/
help.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!-- Dyna-to-Html Version 1.6 - Copyright (c) 2018-2021 Alain J. Michiels. All rights reserved. -->
<html>
<head>
<style>
body.syntax {font-family: Verdana, Geneva, sans-serif; font-size: 14px;}
pre.syntax {border: 1px solid #C4CFE5; background-color: #FBFCFD; padding: 4px 6px; margin: 4px 8px 4px 2px; overflow: auto; word-wrap: break-word; font-size: 14px; line-height: 125%; font-family: Courier, "Courier New", monospace, fixed; font-weight: normal; font-style: normal;}
#tablesyntax {font-size: 14px; border-collapse: collapse;}
#tablesyntax td, #tablesyntax th {border: 1px solid #C4CFE5; padding: 2px; text-align: center;}
#tablesyntax tr:hover {background-color: #ddd; text-align: center;}
#tablesyntax th {padding-top: 4px; padding-bottom: 4px; padding-left: 8px; padding-right: 8px; text-align: center; background-color: #9ECECC; color: white;}
</style>
<script async="" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
</head>
<body class="syntax">
<!------------------------------------------------------------->
<h1 align="center" style="color:#7EAEAC">DYNA and DYNA2GAMS Reference Manual</h1>
<!------------------------------------------------------------->
<p>The following conventions apply in the syntax description of DYNA and DYNA2GAMS:
<ul>
<li>..|.. a choice, one out of many
<li>{..|..} a choice, one out of many
<li>L{..} a repetition, one or more times, delimited by a space
<li>Lc{..} a repetition, one or more times, delimited by the character "c"
<li>[..] optional
<li><[><]> the left and right square bracket characters
<li><|> the vertical bar character
</ul>
<!--chm bhhc -->
<!------------------------------------------------------------->
<h1 id="t" style="color:#7EAEAC">Table of content</h1>
<!------------------------------------------------------------->
<ol>
<li><a href="#s">Sections</a></li>
<ul>
<li><a href="#rem">Comments</a></li>
<li><a href="#run">Runtime directives</a></li>
<li><a href="#fun">Tabulated functions</a></li>
<li><a href="#set">Sets</a></li>
<li><a href="#par">Time-independent parameters</a></li>
<li><a href="#tpa">Time-dependent parameters</a></li>
<li><a href="#var">Static variables</a></li>
<li><a href="#dyn">Dynamic variables</a></li>
<li><a href="#obs">Observations</a></li>
<li><a href="#lim">Lower and upper constant limits</a></li>
<li><a href="#ttt">Boundary constant conditions</a></li>
<li><a href="#ini">Initialization</a></li>
<li><a href="#sca">Scaling</a></li>
<li><a href="#exp">Symbolic variables</a></li>
<li><a href="#tfm">Transfer function models</a></li>
<li><a href="#mpc">Model predictive control</a></li>
<li><a href="#equ">Equations</a></li>
<li><a href="#sim">Simulation</a></li>
<li><a href="#obj">Objective</a></li>
<li><a href="#mac">Macros</a></li>
<li><a href="#gms">GAMS code</a></li>
<li><a href="#gpl">Gnuplot code</a></li>
<li><a href="#put">Put to text files</a></li>
<li><a href="#gdx">Save/load to/from a GDX file</a></li>
<li><a href="#ovs">Optimization vs. Simulation</a></li>
</ul>
<p>
<li><a href="#i">Inline statements</a></li>
<ul>
<li><a href="#gcd" >GAMS compiler directives</a></li>
<li><a href="#dcd" >DYNA compiler directives</a></li>
<li><a href="#pgv" >Predefined GAMS variables</a></li>
<li><a href="#pdv" >Predefined DYNA system variables</a></li>
<li><a href="#sop" >Special (dummy) operators</a></li>
<li><a href="#smo" >Smart operators</a></li>
<li><a href="#sml" >Smart line replication</a></li>
<li><a href="#smq" >Smart quote</a></li>
<li><a href="#sch" >Special characters</a></li>
<li><a href="#ppar">Predefined constants and parameters</a></li>
<li><a href="#pset">Predefined sets</a></li>
<li><a href="#pvar">Predefined variables</a></li>
<li><a href="#pfun">Predefined functions</a></li>
<li><a href="#pmac">Predefined macros</a></li>
<li><a href="#owo" >Other words</a></li>
</ul>
<p>
<li><a href="#u">Useful DYNA2GAMS files</a></li>
<ul>
<li><a href="#fini">DYNA-CONFIG.INI</a></li>
<li><a href="#fcmd">Windows .CMD Files</a></li>
<li><a href="#fbat">GAMS $LIBINCLUDE Files</a></li>
</ul>
</ol>
<!--chm ehhc -->
<!------------------------------------------------------------->
<h1 id="s" style="color:#7EAEAC">Sections</h1>
<!------------------------------------------------------------->
<p>A DYNA model comprises a set of sections, which can be mixed and repeated. Only a few of them are mandatory.
Their order is relatively free. Yet there are a few exceptions. As a rule of the thumb, a section that
declares an object must appear before the sections that use the said object.
<p>The grammar and the input format are close to the one of GAMS.
<!------------------------------------------------------------->
<h2 id="rem" style="color:#7EAEAC">Comments</h2>
<p>A paragraph of free text.
<pre class="syntax">
<font color="#808080"><i>###:</i></font><font color="#808080"><i></i></font>
<font color="#808080"><i> <free-text></i></font>
</pre>
<p>The same with some care to properly format the content with Html tags.
<pre class="syntax">
<font color="red"><b>rem:</b></font>
<free-text>
</pre>
<!------------------------------------------------------------->
<h2 id="run" style="color:#7EAEAC">Runtime directives</h2>
<p>Creation of files.
<pre class="syntax">
<font color="red"><b>run:</b></font> <font color="#808080"><i>Notes:</i></font>
<file> < L|{<string>} <font color="#808080"><i>(1)</i></font>
<file> << L|{<string>} <font color="#808080"><i>(2)</i></font>
</pre>
<p>Notes:
<ol>
<li>Rewrite file. Vertical bar character (|) will be translated as a newline
<li>Append to file. Vertical bar character (|) will be translated as a newline
</ol>
<p>Parameters
<pre class="syntax">
<font color="red"><b>run:</b></font> <font color="#808080"><i>Default values:</i></font>
<font color="#39CCCC">COLLOCATION-FAMILY</font> | <font color="#39CCCC">CF</font> = <c-family> <font color="#808080"><i>default-collocation-family</i></font>
<font color="#39CCCC">COLLOCATION-METHOD</font> | <font color="#39CCCC">CM</font> = <c-method>[/<c-family>] <font color="#808080"><i>default-collocation-method</i></font>
<font color="#39CCCC">DEFAULT-COLLOCATION-FAMILY</font> = <c-family> <font color="#808080"><i>IL</i></font>
<font color="#39CCCC">DEFAULT-COLLOCATION-METHOD</font> = <c-method>[/<c-family>] <font color="#808080"><i>L3A4</i></font>
<font color="#39CCCC">DEFAULT-ITERATIONS-NUMBER</font> = <number> <font color="#808080"><i>4</i></font>
<font color="#39CCCC">DEFAULT-QUADRATURE-METHOD</font> = Rectangle | Trapeze <font color="#808080"><i>Trapeze</i></font>
<font color="#39CCCC">DEFAULT-SIMULATION-FAMILY</font> = <s-family> <font color="#808080"><i>SH</i></font>
<font color="#39CCCC">DEFAULT-SIMULATION-METHOD</font> = <s-method>[/<s-family>] <font color="#808080"><i>DP853</i></font>
<font color="#39CCCC">DEFAULT-TIME-STEPS-NUMBER</font> = <number> <font color="#808080"><i>48</i></font>
<font color="#39CCCC">DEFAULT-VARIABLE</font> = L|{<var>=<string>}
<font color="#39CCCC">DEFAULT-VARIABLES</font> = L|{<var>=<string>}
<font color="#39CCCC">DELETE-FIRST-GDX</font> = YES | NO <font color="#808080"><i>Yes</i></font>
<font color="#39CCCC">FINAL-TIME-SYMBOL</font> = <ident> <font color="#808080"><i>tf</i></font>
<font color="#39CCCC">GAMS-OPTION</font> = L|{<option>=<option-value>}
<font color="#39CCCC">GAMS-OPTIONS</font> = L|{<option>=<option-value>}
<font color="#39CCCC">INCLUDE-LIBRARIES</font> = Chebyshev | Chebyshev-Smolyak | Legendre | Hermite | Tauchen
<font color="#39CCCC">INCLUDE-LIBRARY</font> = Chebyshev | Chebyshev-Smolyak | Legendre | Hermite | Tauchen
<font color="#39CCCC">INITIAL-TIME-SYMBOL</font> = <ident> <font color="#808080"><i>""</i></font>
<font color="#39CCCC">ITERATIONS-NUMBER</font> | <font color="#39CCCC">IN</font> = <number> <font color="#808080"><i>default-iterations-number</i></font>
<font color="#39CCCC">MODEL-NAME</font> = <ident> <font color="#808080"><i>input file name</i></font>
<font color="#39CCCC">MODEL-OPTION</font> = L|{<option>=<option-value>}
<font color="#39CCCC">MODEL-OPTIONS</font> = L|{<option>=<option-value>}
<font color="#39CCCC">QUADRATURE-METHOD</font> | <font color="#39CCCC">QM</font> = Rectangle | Trapeze <font color="#808080"><i>default-quadrature-method</i></font>
<font color="#39CCCC">SAMPLING-TIME-SYMBOL</font> = <ident> <font color="#808080"><i>ts</i></font>
<font color="#39CCCC">SEARCH-STRING</font> | <font color="#39CCCC">SS</font> = <string> <font color="#808080"><i>""</i></font>
<font color="#39CCCC">SIMULATION-FAMILY</font> | <font color="#39CCCC">SF</font> = <s-family> <font color="#808080"><i>default-simulation-family</i></font>
<font color="#39CCCC">SIMULATION-LOOPS-NUMBER</font> = <number> <font color="#808080"><i>1</i></font>
<font color="#39CCCC">SIMULATION-METHOD</font> | <font color="#39CCCC">SM</font> = <s-method>[/<s-family>] <font color="#808080"><i>default-simulation-method</i></font>
<font color="#39CCCC">SIMULATION-REORDER-EQUATIONS</font> = YES | NO <font color="#808080"><i>Yes</i></font>
<font color="#39CCCC">SIMULATION-TOLERANCE-ABSOLUTE</font> = <val> <font color="#808080"><i>1e-6</i></font>
<font color="#39CCCC">SIMULATION-TOLERANCE-RELATIVE</font> = <val> <font color="#808080"><i>1e-6</i></font>
<font color="#39CCCC">SMART-DUPLICATION</font> = YES | NO <font color="#808080"><i>Yes</i></font>
<font color="#39CCCC">STEADY-STATE</font> = YES | NO <font color="#808080"><i>No</i></font>
<font color="#39CCCC">SUBSTITUTE-CHARACTER</font> = L|{iC|iHH|iDDD>oC|oHH|oDDD}
<font color="#39CCCC">SUBSTITUTE-CHARACTERS</font> = L|{iC|iHH|iDDD>oC|oHH|oDDD}
<font color="#39CCCC">SUBSTITUTE-SYMBOL</font> = L|{isymbol>osymbol}
<font color="#39CCCC">SUBSTITUTE-SYMBOLS</font> = L|{isymbol>osymbol}
<font color="#39CCCC">TABULATION-KNOTS-NUMBER</font> = <number> <font color="#808080"><i>256</i></font>
<font color="#39CCCC">TIME-MODEL</font> = Continuous | Discrete | None <font color="#808080"><i>Continuous</i></font>
<font color="#39CCCC">TIME-STEPS-NUMBER</font> | <font color="#39CCCC">N</font> = <number> <font color="#808080"><i>default-time-steps-number</i></font>
<font color="#39CCCC">TRANSFER-FUNCTION-SYNTAX</font> = EQU | SIM <font color="#808080"><i>EQU</i></font>
<font color="#39CCCC">VARIABLE</font> = L|{<var>=<string>}
<font color="#39CCCC">VARIABLES</font> = L|{<var>=<string>}
<c-family> :-
IL|IR|IG|DL|DR|DG|NA
<c-method> :-
L3A2|L3A3|L3A4|L3A5|L3A6|L3A7|L3A8 <font color="#808080"><i>when</i></font> CF=IL|DL
LGR2|LGR3|LGR4|LGR5|LGR6|LGR7|LGR8 <font color="#808080"><i>when</i></font> CF=IR|DR
MP1|GL2|GL3|GL4|GL5|GL6|CN2|R1A3|R2A2|R2A3|L3A2|L3A3|L3A4|L3A5|L3B4|L3C4|RK4 <font color="#808080"><i>when</i></font> CF=IG
MP1|GL2|GL3|GL4|GL5|GL6|R1A3|R2A2|R2A3|L3B4|L3C4|RK4 <font color="#808080"><i>when</i></font> CF=DG
<s-family> :-
SI|SH|SS|NA
<s-method> :-
NA|RK4|ODE23|ODE45|ODE78|F23|F34|F45|F56|F65|F78|DP54|DPS54|CK54|BS32|BS54| ...
V56|V65|V67|V65E|V65R|V76E|V76R|V87E|V87R|V98E|V98R|T54|H65|M45|Z43|SDE <font color="#808080"><i>when</i></font> SF=SI
NA|RK4HC|DP853 <font color="#808080"><i>when</i></font> SF=SH
NA|SHAMP|GRK4A|GRK4T|VELDS|VELDD|LSTAB <font color="#808080"><i>when</i></font> SF=SS
</pre>
<!------------------------------------------------------------->
<h2 id="fun" style="color:#7EAEAC">Tabulated functions</h2>
<pre class="syntax">
<font color="red"><b>fun:</b></font>
<ident> [<ident>] L{§<ident>}
L{<val>} <font color="#808080"><i>(*)</i></font>
§<ident> :: <font color="#7FDBFF">NLP</font> | <font color="#7FDBFF">LIN</font> | <font color="#7FDBFF">CUB</font> | <font color="#7FDBFF">DNLP</font> | <font color="#7FDBFF">DLIN</font> | <font color="#7FDBFF">SP1</font> | <font color="#7FDBFF">SP2</font>
§<ident> = <font color="#7FDBFF">GridXY</font> | <font color="#7FDBFF">Spline3X</font> | <font color="#7FDBFF">Spline3DX</font> | <font color="#7FDBFF">PolyX</font> | <font color="#7FDBFF">PolyDX</font>
<font color="#8A2BE2">@readcsv</font> ifile=<ifile>
<font color="#8A2BE2">@readxls</font> ifile=<ifile>, range=<range>
</pre>
<p>(*) Notes regarding the numerical values:
<ul>
<li>GridXY: the X values are tabulated in rows, the Y’s in columns.
<li>Spline3X: the coefficients \(C_3 \, C_2 \, C_1 \, C_0\) of a cubic spline \(C_3 x^3 + C_2 x^2 + C_1 x + C_0\).
<li>PolyX: the coefficients \(C_n \, \dots \, C_2 \, C_1 \, C_0\) of a polynomial \(C_n x^n + \dots + C_2 x^2 + C_1 x + C_0\).
The degree of the polynomial is deduced from the number of coefficients.
<li>Spline3DX: the coefficients \(C_3 \, C_2 \, C_1 \, C_0\) of a cubic spline \(C_3 (x-lb)^3 + C_2 (x-lb)^2 + C_1 (x-lb) + C_0\)
where \(lb\) is the left bound of the interval on which the spline is defined.
<li>PolyDX: the coefficient \(C_n \, \dots \, C_2 \, C_1 \, C_0\) of a polynomial \(C_3 (x-lb)^n + \dots + C_2 (x-lb)^2 + C_1 (x-lb) + C_0\)
where \(lb\) is the left bound of the interval on which the polynomial is defined.
The degree of the polynomial is deduced from the number of coefficients.
</ul>
<!------------------------------------------------------------->
<h2 id="set" style="color:#7EAEAC">Sets</h2>
<pre class="syntax">
<font color="red"><b>set:</b></font>
<<font color="#3D9970">set</font>>[(L,{<<font color="#3D9970">set</font>>})] = [<l-delim>] <ident>:<ident> | <ident>*<ident> [<r-delim>]
<<font color="#3D9970">set</font>>[(L,{<<font color="#3D9970">set</font>>})] = <l-delim> L,{<ident>|<ident>:<ident>|<ident>*<ident>} <r-delim>
<<font color="#3D9970">set</font>>[(L,{<<font color="#3D9970">set</font>>})][[$<condition>] = <exp>]
<font color="#8A2BE2">alias</font>(L,{<<font color="#3D9970">set</font>>},<<font color="#3D9970">set</font>>) <font color="#808080"><i>Note: the rightmost <set> must have been declared already</i></font>
<l-delim> :- ( | <[> | / | <|>
<r-delim> :- ) | <]> | / | <|>
</pre>
<!------------------------------------------------------------->
<h2 id="par" style="color:#7EAEAC">Time-independent parameters</h2>
<pre class="syntax">
<font color="red"><b>par:</b></font>
<par>[[$<condition>] = <exp>]
<par> {+|-|*|/}= <exp> <font color="#808080"><i>Compound assignment</i></font>
<par> = <l-delim> L,{L.{<ident>} <val>} <r-delim> <font color="#808080"><i>Gams parameter format</i></font>
<par> = <ll-delim> [<EOL>] <Gams-<font color="#3D9970">table</font>-data> [<EOL>] <rr-delim> <font color="#808080"><i>Gams tabular format</i></font>
<par> = <[> L,{L{<exp>}} <]> <font color="#808080"><i>Matlab-like syntax (with comma instead of semicolon)</i></font>
L{<par>}
<exp> :- <val> | <par> | <expression-thereof>
<l-delim> :- / | <|>
<r-delim> :- / | <|>
<ll-delim> :- // | <|><|>
<rr-delim> :- // | <|><|>
</pre>
<!------------------------------------------------------------->
<h2 id="tpa" style="color:#7EAEAC">Time-dependent parameters</h2>
<pre class="syntax">
<font color="red"><b>tpa:</b></font>
<tpa> [= <tex>]
<tpa> {+|-|*|/}= <tex> <font color="#808080"><i>Compound assignment</i></font>
<tpa> = <font color="#8A2BE2">@readcsv</font> ifile=<ifile> [,colval=<<font color="#3D9970">integer</font>>] [,colset=L{<<font color="#3D9970">integer</font>>}] [,skipheader=<font color="#3D9970">yes</font>|<font color="#3D9970">NO</font>]
L{<tpa>}
<tex> :- <val> | <exp> | <tpa> | <expression-thereof>
</pre>
<!------------------------------------------------------------->
<h2 id="var" style="color:#7EAEAC">Static variables</h2>
<p>Static variables are not time dependent.
<pre class="syntax">
<font color="red"><b>var:</b></font>
L{<var>}
</pre>
<!------------------------------------------------------------->
<h2 id="dyn" style="color:#7EAEAC">Dynamic variables</h2>
<p>Dynamic variables are time dependent.
<pre class="syntax">
<font color="red"><b>dyn:</b></font>
L{<dyn>[:<decl>]} [:: <cast>]
<decl> :- <font color="#3D9970">sos1</font> | <font color="#3D9970">sos2</font> | <font color="#3D9970">positive</font> | <font color="#3D9970">negative</font> | <font color="#3D9970">binary</font> | <font color="#3D9970">integer</font>
<cast> :- <font color="#7FDBFF">control</font> | <font color="#7FDBFF">controls</font> | <font color="#7FDBFF">state</font> | <font color="#7FDBFF">states</font> | <font color="#7FDBFF">ancillary</font> | <font color="#7FDBFF">ancillaries</font>
</pre>
<p>By default, DYNA casts as state all the variables that are differentiated in the equations section.
<!------------------------------------------------------------->
<h2 id="obs" style="color:#7EAEAC">Observations</h2>
<pre class="syntax">
<font color="red"><b>obs:</b></font>
{T | <font color="#0074D9">Time</font> | Tau} L{<dyn>}
L{<val>}
<font color="#8A2BE2">@readcsv</font> ifile=<ifile>
<font color="#8A2BE2">@readxls</font> ifile=<ifile>, range=<range>
</pre>
<p>NA can be used as a numeric value to indicate a missing observation.
<!------------------------------------------------------------->
<h2 id="lim" style="color:#7EAEAC">Lower and upper constant limits</h2>
<pre class="syntax">
<font color="red"><b>lim:</b></font>
<tex> <= <dyn>[$<condition>] <= <tex>
<exp> <= <var>[$<condition>] <= <exp>
</pre>
<!------------------------------------------------------------->
<h2 id="ttt" style="color:#7EAEAC">Boundary constant conditions</h2>
<pre class="syntax">
<font color="red"><b>t=t0:</b></font> <font color="#808080"><i>Initial (or start) conditions</i></font>
<font color="red"><b>t=tf:</b></font> <font color="#808080"><i>Final conditions</i></font>
<font color="red"><b>k=k0:</b></font> <font color="#808080"><i>Initial (or start) conditions (discrete model)</i></font>
<font color="red"><b>k=kf:</b></font> <font color="#808080"><i>Final conditions (discrete model)</i></font>
<dyn>[$<condition>] <relational-operator> <tex>
<tex> <= <dyn>[$<condition>] <= <tex>
<relational-operator> :- <= | = | >=
</pre>
<p>Formally, there is no difference between 't=t{0,f}' and 'k=k{0,f}'. The latter is perhaps visually more attractive
for a time discrete model.
<!------------------------------------------------------------->
<h2 id="ini" style="color:#7EAEAC">Initialization</h2>
<p>This section provides the solvers with choke values for the variables to optimize.
<pre class="syntax">
<font color="red"><b>ini:</b></font>
<dyn>[$<condition>] = <tex>
<var>[$<condition>] = <exp>
</pre>
<p>By default, the midpoint is used when finite lower and upper limits are set. In case of a semi-infinite interval,
the lower or upper limit is used.
<p>This section must appear after 'lim:' and 't=t{0,f}:' sections otherwise the initialization values are reset
to their default.
<!------------------------------------------------------------->
<h2 id="sca" style="color:#7EAEAC">Scaling</h2>
<p>Optional scaling of variables.
<pre class="syntax">
<font color="red"><b>sca:</b></font>
<dyn>[$<condition>] = <tex>
<var>[$<condition>] = <exp>
<font color="#8A2BE2">%OBJECTIVE%</font> = <exp>
</pre>
<!------------------------------------------------------------->
<h2 id="exp" style="color:#7EAEAC">Symbolic variables</h2>
<p>Symbolic variables are shortcuts for algebraic expressions.
<pre class="syntax">
<font color="red"><b>exp:</b></font>
<sym> == <expression>
<expression> :- <val> | <par> | <tpa> | <var> | <dyn> | <expression-thereof>
</pre>
<!------------------------------------------------------------->
<h2 id="tfm" style="color:#7EAEAC">Transfer function models</h2>
<pre class="syntax">
<font color="red"><b>tfm:</b></font>
<tfm-statement>
<tfm-statement> :-
<font color="#39CCCC">Num</font> = <polynomial>[*<polynomial>]
<font color="#39CCCC">Den</font> = <polynomial>[*<polynomial>]
<font color="#39CCCC">Out</font> = <dyn>
[<font color="#39CCCC">SSMF</font> = Controllable | Observable | None]
[<font color="#39CCCC">Delay</font> = <val>]
[<font color="#39CCCC">In</font> = <dyn> | <val>]
[<font color="#39CCCC">Name</font> = <ident>]
[<font color="#39CCCC">X0</font> = <val>]
[<font color="#39CCCC">CLTF</font> = <ident> * <ident> | <ident> % <ident> | <ident> * <ident> % <ident>]
<polynomial> :- [(]L{<val>}[)] | <indexed-parameter> <font color="#808080"><i>Note: colon is allowed for a numeric range</i></font>
</pre>
<p>For a continuous model, the polynomial gives the coefficients of \([s^n \, s^{n-1} \, ... \, s \, 1]\).
For a discrete model, the transfer function is written in \(z\): \([z^n \, z^{n-1} \, ... \, z \, 1]\).
Undeclared symbols at this stage will be declared as static or dynamic variables.
<!------------------------------------------------------------->
<h2 id="mpc" style="color:#7EAEAC">Model predictive control</h2>
<p>Model predictive control (MPC) is an effective means of dealing with large multivariable constrained control
problems. The main idea is to choose the control action by repeatedly solving online an optimal control problem,
aiming to minimize a performance criterion over a future horizon, possibly subject to constraints on the manipulated
inputs and outputs. Future behavior is computed according to a model of the plant.
<p>The cost function which DYNA actually minimizes is
\[
J(k) = \sum_{i \in \mathbb{Q}} \|\hat{y}(k+i|k)-z(k+i)\|^2_{Q(i)}
+ \sum_{i \in \mathbb{R}} \|\hat{u}(k+i|k)\|^2_{R(i)}
+ \sum_{i \in \mathbb{R}} \|\Delta \hat{u}(k+i|k)\|^2_{R´(i)}
\]
under the constraints
\[
x(k+1) = A x(k) + B u(k) + G w(k) \qquad \text{if linear} \\
x(k+1) = f \big(x(k),u(k),w(k)\big) \qquad \text{if non-linear} \\
y(k) = C x(k) + D u(k) \qquad \text{if linear} \\
y(k) = g \big(x(k),u(k))\big) \qquad \text{if non-linear} \\
\Delta \hat{u}(k+i|k) = \hat{u}(k+i|k) - \hat{u}(k+i-1|k) \\
z(k+i) = y_d(k+i) - \lambda^i \big(y_d(k+i)-\hat{y}(k+i|k)\big) \\
x_{\text{LB}} \leq x \leq x_{\text{UB}} \\
u_{\text{LB}} \leq u \leq u_{\text{UB}} \\
\Delta u_{\text{LB}} \leq \Delta u \leq \Delta u_{\text{UB}}
\]
where
\(x\) is the vector of state variables,
\(u\) is the vector of input variables,
\(w\) is the vector of disturbances,
\(y\) is the vector of output variables,
\(y_d\) is the vector of desired outputs,
\(\mathbb{Q}\) and \(\mathbb{R}\) are subsets of the controller horizon \(\mathbb{H}\), and
\(\lambda\) is the decay factor.
<pre class="syntax">
<font color="red"><b>mpc:</b></font>
<mpc-statement>
<mpc-statement> :-
[<font color="#39CCCC">SAMPLING-TIME</font> = <val>|<par>] <font color="#808080"><i>Needed if predictive model is continuous.</i></font>
[<font color="#39CCCC">STAGES</font> = <val>|<par>] <font color="#808080"><i>Number of stages for a continuous model. Default is 1.</i></font>
<font color="#39CCCC">HORIZON</font> = <set-definition>
<font color="#39CCCC">STATE</font>|<font color="#39CCCC">STATES</font> = L{<dyn>}
<font color="#39CCCC">INPUT</font>|<font color="#39CCCC">INPUTS</font> = L{<dyn>}
[<font color="#39CCCC">DISTURBANCE</font>|<font color="#39CCCC">DISTURBANCES</font> = L{<dyn>|<tpa>}]
<font color="#39CCCC">OUTPUT</font>|<font color="#39CCCC">OUTPUTS</font> = L{<dyn>}
[<font color="#39CCCC">ANCILLARY</font>|<font color="#39CCCC">ANCILLARIES</font> = L{<dyn>}]
<font color="#39CCCC">EQUATION</font>|<font color="#39CCCC">EQUATIONS</font> = L{<equ>}
[<font color="#39CCCC">A</font> = <matrix>] <font color="#808080"><i>Alternative definition of linear equations by the usual matrix notation.</i></font>
[<font color="#39CCCC">B</font> = <matrix>]
[<font color="#39CCCC">G</font> = <matrix>]
[<font color="#39CCCC">C</font> = <matrix>]
[<font color="#39CCCC">D</font> = <matrix>]
[<font color="#39CCCC">LB</font> = L{<var>[´] <val>}] <font color="#808080"><i>Lower bound on variable [rate].</i></font>
[<font color="#39CCCC">UB</font> = L{<var>[´] <val>}] <font color="#808080"><i>Upper bound on variable [rate].</i></font>
<font color="#39CCCC">Q</font> = <matrix> <font color="#808080"><i>Weighting matrix for states.</i></font>
<font color="#39CCCC">HORIZON-Q</font> = <set-definition>
<font color="#39CCCC">R</font> = <matrix> <font color="#808080"><i>Weighting matrix for inputs.</i></font>
<font color="#39CCCC">R´</font> = <matrix> <font color="#808080"><i>Weighting matrix for derivatives of inputs.</i></font>
<font color="#39CCCC">HORIZON-R</font> = <set-definition>
<font color="#39CCCC">DECAY</font> = <val>|<par>
</pre>
<!------------------------------------------------------------->
<h2 id="equ" style="color:#7EAEAC">Equations</h2>
<p>The order in which the equations appear doesn’t matter.
<pre class="syntax">
<font color="red"><b>equ:</b></font>
[[<equ>][$<condition>]..] <dyn>´ <relational-operator> <expression>
[[<equ>][$<condition>]..] <expression> <relational-operator> <expression>
[[<equ>][$<condition>]..] <expression> <= <expression> <= <expression>
[[<equ>][$<condition>]..] <expression> :: <type>[(<exp>)]
<tpa>[$<condition>] ~~ <stoch-cast>
<font color="#8A2BE2">@tfm</font> L,{<tfm-statement>} <font color="#808080"><i>Transfer function model (see <a href="#tfm">tfm section</a>)</i></font>
<font color="#8A2BE2">@pid</font> L,{<pid-statement>} <font color="#808080"><i>Filtered PID transfer function model</i></font>
<font color="#8A2BE2">@linkphases</font> [<phase-<font color="#3D9970">set</font>> [-x L{<dyn>}]] <font color="#808080"><i>Link dynamic variables across phases. -x means variables to exclude.</i></font>
<relational-operator> :- <= | == | >=
<type> :- <font color="#7FDBFF">spline3</font>[(arg)] | <font color="#7FDBFF">constant</font>[(arg)] <font color="#808080"><i>Default value for arg is -3 i.e. a sampling rate of 1 out of 3 knots</i></font>
<stoch-cast> :- <font color="#7FDBFF">Wiener</font> | <font color="#7FDBFF">PJump</font>(arg) | <font color="#7FDBFF">NPJump</font>(arg1,arg2) | <font color="#7FDBFF">EPJump</font>(arg1,arg2)
<pid-statement> :- <font color="#808080"><i>PID regulator K * (1 + 1/(s*Ti) + s*Td/(s*Td*Theta+1))</i></font>
K = <val> | <par> | <var>
Ti = <val> | <par> | <var>
Td = <val> | <par> | <var>
Out = <dyn> | <tex>
In = <dyn> | <tex>
[SSMF = Controllable | Observable]
[Theta = <val> | <par> | <var>] <font color="#808080"><i>Default value for Theta = 0.05</i></font>
</pre>
<p>By default, DYNA declares equations with a default name and the same indices as the rightmost symbol of the left hand side of
the '==' equation or the middle term of the box constraints ('.. ≤ .. ≤ ..').
Accordingly, equations can be implicitly declared time-dependent or not.
Special keywords for $<condition>, $ONCE and $ALL, alter this behavior:
<ul>
<li>$ONCE: when an equation will implicitly be indexed over time, $ONCE forces its execution only once
<li>$ALL: when an equation won’t implicitly be indexed over time, $ALL forces its declaration over time
</ul>
So, if the left hand term is a constant, the equation won’t be indexed over time. This is a useful feature to express for instance
that a final value and an initial value of a variable have to be equal.
On the other hand, it is a difficulty when the equation has to be enforced on every time segment. In that event,
instead of adding the dummy condition $ALL, another workaround is to add zero times a variable with the right dimension.
Anyway, in case of doubt, the user can provide explicit indexes.
He can also provide an explicit name for the equations, which is useful if attention is paid to the costate variables.
<p>In addition, two keywords limit the scope of the time indexation:
<ul>
<li>$NT0: all over the time horizon but initial time
<li>$NTF: all over the time horizon but final time
</ul>
<p>Note 1:
Unknown symbols in @pid will be declared as static or dynamic variables.
<p>Note 2:
@linkphases should ideally be placed after all the dot equations to benefit from the implicit declaration of state variables.
If state variables have been explicitly declared (:: <cast>), its position doesn’t matter.
<!------------------------------------------------------------->
<h2 id="sim" style="color:#7EAEAC">Simulation</h2>
<p>This section is similar to the 'equations' section but for a simulation. Contrary to the 'equation' section, this one
is procedural i.e. the order of the equations matters. Unless required not to do so, DYNA sorts the equations in
a way that all the variables listed on the right of the assignment operator (:=) have been defined already.
<pre class="syntax">
<font color="red"><b>sim:</b></font>
[[$<condition>]..] <dyn>´ := <expression>
[[$<condition>]..] <dyn> := <expression> [:+ L{<dyn>] [:- L{<dyn>}]
<tpa>[$<condition>] ~~ <stoch-cast>
<font color="#8A2BE2">@tfm</font> L,{<tfm-statement>} <font color="#808080"><i>Transfer function model</i></font>
<font color="#8A2BE2">@pid</font> L,{<pid-statement>} <font color="#808080"><i>PID function model</i></font>
<font color="#8A2BE2">@dcm</font> L,{<dcm-statement>} <font color="#808080"><i>Digital control model (for continuous model only)</i></font>
<font color="#8A2BE2">@newtonraphsonloop</font> L,{<<font color="#0074D9">n</font>-r-statement>} <font color="#808080"><i>Newton-Raphson iteration to break a circularity</i></font>
<stoch-cast> :- <font color="#7FDBFF">Wiener</font> | <font color="#7FDBFF">PJump</font>(arg) | <font color="#7FDBFF">NPJump</font>(arg1,arg2) | <font color="#7FDBFF">EPJump</font>(arg1,arg2)
<dcm-statement> :- <font color="#808080"><i>The transfer function is written in polynomials of z</i></font>
Num = <polynomial>[*<polynomial>]
Den = <polynomial>[*<polynomial>]
Out = <dyn> | <exp> <font color="#808080"><i>Unknown symbols will be declared as static or dynamic variables</i></font>
In = <dyn> | <exp> | <val>
Ts = <val> | <par>
[SSMF = Controllable | Observable]
[Delay = <val>]
[Name = <ident>]
[X0 = <val>]
<polynomial> :- [(]L{<val>}[)] | <indexed-parameter> <font color="#808080"><i>Note: colon is allowed for a numeric range</i></font>
<n-r-statement> :-
Var = <dyn>
Ini = <val>
[Tol = <val>]
[MaxIter = <number>]
</pre>
<p>\(:-\) (\(:+\)) is a dummy operator that can be used to remove (add) an explicit (implicit) dependency of the assigned
variable to other variables. This guarantees the execution of the assignment and all the following instructions
when all the dependent variables are known.
<!------------------------------------------------------------->
<h2 id="obj" style="color:#7EAEAC">Objective</h2>
<p>Objective of optimization (when 'equ:' is present)
<pre class="syntax">
<font color="red"><b>obj:</b></font>
<font color="#8A2BE2">minimize</font>|<font color="#8A2BE2">maximize</font> <expression> <font color="#8A2BE2">using</font> <modeltype> [<font color="#8A2BE2">with</font> {NONE | L|{<solver>}}]
<modeltype> :- DNLP|EMP|LP|MINLP|MIP|MIQCP|NLP|QCP|RMINLP|RMIP|RMIQCP
<solver> :- CONOPT|IPOPT|KNITRO|... <font color="#808080"><i>See GAMS documentation for an exhaustive list</i></font>
</pre>
<p>NONE suppresses the solve statement. The user has to optimize the model in the gms section.
<!------------------------------------------------------------->
<h2 id="mac" style="color:#7EAEAC">Macros</h2>
<pre class="syntax">
<font color="red"><b>mac:</b></font>
@<name>[(L,{<argument>})] <gams-code>
</pre>
<p>Implicit arguments are %1%, %2% ...
<p>In case of explicitly named arguments, use &<argument> in the piece of GAMS code.
<p>Caution:
<ul>
<li>macro name and arguments are case sensitive;
<li>a macro must always be invoked with () even if there isn’t any argument;
<li>a lexical substitution occurs during the macro expansion, not a value substitution.
</ul>
<!------------------------------------------------------------->
<h2 id="gms" style="color:#7EAEAC">GAMS code</h2>
<pre class="syntax">
<font color="red"><b>gms:</b></font>
<gams-statement>;
<font color="#8A2BE2">@abltimeput</font> 'min|max' L/{var} L/{equ}; <font color="#808080"><i>Put all but last dynamic variables and equations to file</i></font>
<font color="#8A2BE2">@alltimeput</font> 'min|max' L/{var} L/{equ}; <font color="#808080"><i>Put all dynamic variables and equations to file</i></font>
<font color="#8A2BE2">@costates</font> [(POLY|ZERO|PREV)]; <font color="#808080"><i>Costates calculation (must be used before any call to costate(.) function</i></font>
<font color="#8A2BE2">@csvmute</font> L{<dyn>|<equ>}; <font color="#808080"><i>Remove dynamic variables or equations from the CSV files</i></font>
<font color="#8A2BE2">@csvsave</font> L{<dyn>}; <font color="#808080"><i>Save dynamic variables in the CSV files</i></font>
<font color="#8A2BE2">@error</font> [L{<dyn>}]; <font color="#808080"><i>Estimate error of dynamic variables</i></font>
<font color="#8A2BE2">@export</font> L,{<export-statement>}; <font color="#808080"><i>Export a variable to a text file</i></font>
<font color="#8A2BE2">@gdxsave</font> [<gdx-statement>]; <font color="#808080"><i>Save objects to a GDX file for a later warm restart</i></font>
<font color="#8A2BE2">@observedrip</font> L{<var>}; <font color="#808080"><i>Insert report on identified parameters</i></font>
<font color="#8A2BE2">@par</font> <par> [= <exp>]; <font color="#808080"><i>Declare and instantiate parameter</i></font>
<font color="#8A2BE2">@rank</font> L,{<rank-statement>}; <font color="#808080"><i>Compute given percentiles of a single-index variable</i></font>
<font color="#8A2BE2">@seekcia</font> L,{<seekcia-statement>}; <font color="#808080"><i>Combinatorial Integral Approximation</i></font>
<font color="#8A2BE2">@seekmax</font> L,{<seekm-statement>}; <font color="#808080"><i>Section search maximum</i></font>
<font color="#8A2BE2">@seekmin</font> L,{<seekm-statement>}; <font color="#808080"><i>Section search minimum</i></font>
<font color="#8A2BE2">@seeksur</font> L,{<seeksur-statement>}; <font color="#808080"><i>Combinatorial Integral Approximation</i></font>
<font color="#8A2BE2">@setlim</font> L,{<setlim-statement>}; <font color="#808080"><i>Define lower and upper bound over the entire horizon</i></font>
<font color="#8A2BE2">@setlim0</font> L,{<setlim-statement>}; <font color="#808080"><i>Define lower and upper bound on t=t0</i></font>
<font color="#8A2BE2">@setlimf</font> L,{<setlim-statement>}; <font color="#808080"><i>Define lower and upper bound on t=tf</i></font>
<font color="#8A2BE2">@smooth</font> L,{<smooth-statement>}; <font color="#808080"><i>Smooth a variable or a parameter</i></font>
<font color="#8A2BE2">@solve</font> [<font color="#8A2BE2">using</font> <modeltype>] [<font color="#8A2BE2">with</font> L|{<solver>}]; <font color="#808080"><i>Reoptimize the model with new type or new solver</i></font>
<font color="#8A2BE2">@solveloop</font> L,{<solveloop-statement>}; <font color="#808080"><i>Iterative solve after smoothing of some variables</i></font>
<font color="#8A2BE2">@tpa</font> <tpa> [= <tex>]; <font color="#808080"><i>Declare and instantiate a time-dependent parameter</i></font>
<font color="#8A2BE2">@verbatim</font> <gams-statement>; <font color="#808080"><i>Instruct DYNA to keep statement untouched</i></font>
<export-statement> :-
Grid = L{<font color="#0074D9">Time</font>|<par>} <font color="#808080"><i>The abscissas, up to four</i></font>
Var = <dyn>|<tpa>|<var>|<par> <font color="#808080"><i>Indexed variable (or parameter) to export</i></font>
<font color="#3D9970"><font color="#3D9970">File</font></font> = <<font color="#3D9970"><font color="#3D9970">file</font></font>> <font color="#808080"><i>File name</i></font>
[Every = <number>] <font color="#808080"><i>A divisor of <font color="#8A2BE2">%N%</font> (default is 1)</i></font>
<rank-statement> :-
iVar = <dyn> <font color="#808080"><i>Input variable (or parameter)</i></font>
oPar = <tpa> <font color="#808080"><i>Output parameter</i></font>
Pctl = L{<number>} <font color="#808080"><i>Percentiles of interest</i></font>
[Method = GDXRANK|HEAPSORT]
<seekm-statement> :-
Var = <par>|<var>
Vlo = <val> <font color="#808080"><i>Lower bound</i></font>
Vup = <val> <font color="#808080"><i>Upper bound</i></font>
[Tol = <val>] <font color="#808080"><i>Tolerance</i></font>
[Method = BRENT|GOLDEN] <font color="#808080"><i>Method</i></font>
<seekcia-statement> :-
ControlVar = <var> <font color="#808080"><i>Control variable</i></font>
[SwitchVar = <var>|<font color="#3D9970">NA</font>] <font color="#808080"><i>Switching variable</i></font>
[SwitchMax = <par>|<val>|+<font color="#3D9970">INF</font>] <font color="#808080"><i>Maximum number of switching</i></font>
[CumulPar = <par>|<font color="#3D9970">NA</font>] <font color="#808080"><i>Upper bound on integral of control variable</i></font>
[optca = <par>|<val>] <font color="#808080"><i>optca</i></font>
[optcr = <par>|<val>] <font color="#808080"><i>optcr</i></font>
[cutoff = <par>|<val>|+<font color="#3D9970">INF</font>] <font color="#808080"><i>cutoff</i></font>
[Method = PLAIN|SHORT|ROUND] <font color="#808080"><i>method</i></font>
<seeksur-statement> :-
ControlVar = <var> <font color="#808080"><i>Control variable</i></font>
[BinSize = <par>|+<font color="#3D9970">INF</font>] <font color="#808080"><i>Bin size (max number of variables to be fixed at once)</i></font>
<setlim-statement> :-
Var = <dyn>|<var>
[Vlo = <tex>|-<font color="#3D9970">INF</font>] <font color="#808080"><i>Lower bound</i></font>
[Vup = <tex>|+<font color="#3D9970">INF</font>] <font color="#808080"><i>Upper bound</i></font>
<smooth-statement> :-
[Method = MOVAVG|MOVAVG-MP|BUTTERWORTH]
Paraml = L{<number>}
Parl|Varl = L{<tpa>}|L{<dyn>}
<solveloop-statement>} :-
Method = MOVAVG|BNDOBJ
Paraml = L{<number>}
Varl = L{<dyn>|<tpa>}
[Target = OPTIM|INFES]
[MaxIter = <number>|+<font color="#3D9970">INF</font>]
</pre>
<!------------------------------------------------------------->
<h2 id="gpl" style="color:#7EAEAC">Gnuplot code</h2>
<pre class="syntax">
<font color="red"><b>gpl:</b></font>
<gnuplot-statement>
<font color="#8A2BE2">@plotYT</font> <yvar>, <title> [,<ylabel> [,<tlabel>]]
<font color="#8A2BE2">@plotYYT</font> n L,{<yvar>}, <title> [,<ylabel> [,<tlabel> [L,{<ytitle>}]]]
<font color="#8A2BE2">@plotYX</font> <yvar>, <xvar>, <title> [,<ylabel> [,<xlabel>]]
<font color="#8A2BE2">@plotYYX</font> n L,{<yvar>}, <xvar>, <title> [,<ylabel> [,<xlabel> [L,{<ytitle>}]]]
<font color="#8A2BE2">@plotZXY</font> <zvar>, <xvar>, <yvar>, <title> [,<zlabel> [,<xlabel> [,<ylabel>]]]
<font color="#8A2BE2">@splotZXT</font> <zvar>, <xtic>, <title> [,<zlabel> [,<xlabel>]]
</pre>
<p>DYNA will create an output file with the given or generated statements but will not dynamically invoke Gnuplot.
<!------------------------------------------------------------->
<h2 id="put" style="color:#7EAEAC">Put to text files</h2>
<p>The PUT section writes its content to text files. Quoted strings are interpreted as follows:
<pre class="syntax">
<font color="red"><b>put:</b></font>
"<file><[<]" <font color="#808080"><i>Write or append following lines to <file></i></font>
"<[<]" <font color="#808080"><i>Close current file</i></font>
"<var>[<index>]['][:m]:[n][<c>]" <font color="#808080"><i>Write the value of <var> with GAMS format :m:n. (defaults are m=13 and n=5)</i></font>
<font color="#808080"><i><c> is a one-character row delimiter (space by default)</i></font>
"{<file>|*}<[<][+]<var>[<index>]" <font color="#808080"><i>Write or append <var> values to <file> in csv format</i></font>
<font color="#808080"><i>* means previous csv <file></i></font>
<font color="#808080"><i>+ requires adding labels for <var> name and indices</i></font>
"`<gams-code>`" <font color="#808080"><i>Genuine GAMS code</i></font>
"" <font color="#808080"><i>Quotation mark character</i></font>
<font color="#8A2BE2">@verbatim</font> <font color="#808080"><i>No prior DYNA translation of remaining string on this line</i></font>
</pre>
<!------------------------------------------------------------->
<h2 id="gdx" style="color:#7EAEAC">Save/load to/from a GDX file</h2>
<p>DYNA uses GAMS GDX files to save data or to load data from a previous run.
By default, all the static and dynamic variables are involved in this process.
The user can list here additional objects such time-dependent parameters, equations or variables created in a GAMS code section.
<pre class="syntax">
<font color="red"><b>gdx:</b></font>
L{<tpa>|<gams-var>|<gams-equ>}
</pre>
<p>Actually two GDX files are created.
A first one contains the required objects.
A second one is created with the dynamic variables interpolated on a finer time grid, which will be used in a later run
as a starting point.
<p>If the user’s sole purpose is to create a GDX file with all the data regardless of the automated process of DYNA, the
easiest way is to execute GAMS with the command-line option GDX=<ofile>.
<!------------------------------------------------------------->
<h2 id="ovs" style="color:#7EAEAC">Optimization vs. Simulation</h2>
<p>DYNA works two ways: either in optimization mode or in simulation mode. In which case, the model consists of a different set of sections.
The table here below sets forth which section is valid in which mode.
<p>
<table id="tablesyntax">
<tr><th>Sections</th> <th>Optimization</th> <th>Simulation</th></tr>
<tr><td>rem:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>###:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>run:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>fun:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>set:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>par:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>tpa:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>var:</td> <td>Yes</td> <td>-</td></tr>
<tr><td>dyn:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>obs:</td> <td>Yes</td> <td>-</td></tr>
<tr><td>lim:</td> <td>Yes</td> <td>-</td></tr>
<tr><td>t=t0:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>t=tf:</td> <td>Yes</td> <td>-</td></tr>
<tr><td>k=k0:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>k=kf:</td> <td>Yes</td> <td>-</td></tr>
<tr><td>ini:</td> <td>Yes</td> <td>Yes(*)</td></tr>
<tr><td>sca:</td> <td>Yes</td> <td>-</td></tr>
<tr><td>exp:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>tfm:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>mpc:</td> <td>-</td> <td>Yes</td></tr>
<tr><td>equ:</td> <td>Yes</td> <td>-</td></tr>
<tr><td>sim:</td> <td>-</td> <td>Yes</td></tr>
<tr><td>obj:</td> <td>Yes</td> <td>-</td></tr>
<tr><td>mac:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>gms:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>gpl:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>put:</td> <td>Yes</td> <td>Yes</td></tr>
<tr><td>gdx:</td> <td>Yes</td> <td>-</td></tr>
</table>
<p>(*) e.g., to define the control or the disturbance variables.
<!------------------------------------------------------------->
<h1 id="i" style="color:#7EAEAC">Inline statements</h1>
<!------------------------------------------------------------->
<!------------------------------------------------------------->
<h2 id="gcd" style="color:#7EAEAC">GAMS compiler directives</h2>
<pre class="syntax">
$<gams-$-directive>
</pre>
<p>The $ sign must be in column one.
<!------------------------------------------------------------->
<h2 id="dcd" style="color:#7EAEAC">DYNA compiler directives</h2>
<pre class="syntax">
<font color="#8B0000">@case</font> <var>
<font color="#8B0000">@cmd</font> <line>
<font color="#8B0000">@define</font> <var>
<font color="#8B0000">@dset</font> <var>[=]<token>
<font color="#8B0000">@echo</font> <line>
<font color="#8B0000">@else</font>
<font color="#8B0000">@endcase</font>
<font color="#8B0000">@endif</font>
<font color="#8B0000">@get</font> <var>[<]<file>
<font color="#8B0000">@ifdef</font> L{<var>}
<font color="#8B0000">@ifndef</font> L{<var>}
<font color="#8B0000">@macro</font> <name>[(L,{<argument>})] <expression>
<font color="#8B0000">@otherwise</font>
<font color="#8B0000">@set</font> <var>[=]<token>
<font color="#8B0000">@when</font> L{[,]<token>}
<font color="#8B0000">@whennset</font>
</pre>
<p>The @ sign must be in column one.
<!------------------------------------------------------------->
<h2 id="pgv" style="color:#7EAEAC">Predefined GAMS variables</h2>
<p>Variables and their default values. Note they can be changed dynamically when invoking GAMS (--<var>=<val>).
<pre class="syntax">
<font color="#8A2BE2">%CF%</font> IL
<font color="#8A2BE2">%CM%</font> L3A4
<font color="#8A2BE2">%DEBUG%</font> 0
<font color="#8A2BE2">%DFGDX%</font> 1
<font color="#8A2BE2">%DYNA_IFILE%</font> filename.filetype
<font color="#8A2BE2">%DYNA_IFNAM%</font> filename
<font color="#8A2BE2">%FN%</font> filename
<font color="#8A2BE2">%GOPT%</font> ""
<font color="#8A2BE2">%HOME%</font> <user-defined>
<font color="#8A2BE2">%IN%</font> 4
<font color="#8A2BE2">%ITER%</font> 1..<font color="#8A2BE2">%IN%</font> <font color="#808080"><i>Current iteration</i></font>
<font color="#8A2BE2">%ITERMAX%</font> <font color="#8A2BE2">%IN%</font> <font color="#808080"><i>Is equivalent to <font color="#8A2BE2">%IN%</font></i></font>
<font color="#8A2BE2">%MODEL%</font> filename <font color="#808080"><i>with - translated as _</i></font>
<font color="#8A2BE2">%MULTI%</font> <font color="#3D9970">YES</font>
<font color="#8A2BE2">%N%</font> 48 <font color="#808080"><i>Is equivalent to card(N)-1</i></font>
<font color="#8A2BE2">%OBJECTIVE%</font> <font color="#0074D9">dyna_ksi</font>
<font color="#8A2BE2">%QM%</font> 1
<font color="#8A2BE2">%SF%</font> SH
<font color="#8A2BE2">%SM%</font> DP853
<font color="#8A2BE2">%SS%</font> ""
<font color="#8A2BE2">%TF%</font> tf
<font color="#8A2BE2">%TS%</font> ts
</pre>
<!------------------------------------------------------------->
<h2 id="pdv" style="color:#7EAEAC">Predefined DYNA system variables</h2>
<p>DYNA system variables will be substituted by their value when reading the model.
Their name is not case sensitive.
Here follow the variables that are predefined.
<pre class="syntax">
<font color="#8B0000">@HOME@</font>
<font color="#8B0000">@TITLE@</font>
<font color="#8B0000">@IFNAM@</font>
</pre>
<!------------------------------------------------------------->
<h2 id="sop" style="color:#7EAEAC">Special (dummy) operators</h2>
<pre class="syntax">
:+ L{<var>} <font color="#808080"><i>Add an explicit dependence to <var></i></font>
:- L{<var>} <font color="#808080"><i>Remove an explicit dependence to <var></i></font>
</pre>
<p>In some cases it is useful to explicitly indicate the dependence to some variables to help DYNA to properly sort
the equations of the simulation section. Such case occurs when a symbolic variable or a macro is called upon that uses
implicit arguments or global variables.
<!------------------------------------------------------------->
<h2 id="smo" style="color:#7EAEAC">Smart operators</h2>
<pre class="syntax">
Oper{a[[:b]:c],u{:}}
will be translated as
u<a> oper u<a+b> oper ... oper <c>
where
Oper :- sum | prod | comma | space
oper :- + | * | , | <space>
</pre>
<p>Examples:
<pre class="syntax">
sum{1:2:5,x{:}}
x1+x3+x5
space{1:3,x{:}}
x1 x2 x3
</pre>
<!------------------------------------------------------------->
<h2 id="sml" style="color:#7EAEAC">Smart line replication</h2>
<pre class="syntax">
{L{<word>}} <font color="#808080"><i>As many lines will be generated as there are words, one for each word</i></font>
{<integer1>[[:<integer2>]:<integer3>]} <font color="#808080"><i>Will be replaced by n, n being instantiated from integer-1 to integer-3 by integer-2</i></font>
</pre>
<p>Examples:
<pre class="syntax">
{a b c}
a
b
c
x{1:2}
x1
x2
x{1:10} x{01:10}
x1 x01
x2 x02
...
x9 x09
x10 x10
x{1:3} = {0.47 0.87 0.34}
x1 = 0.47
x2 = 0.87
x3 = 0.34
x{1 2 4} = x{3 5 6}
x1 = x3
x2 = x5
x4 = x6
</pre>
<!------------------------------------------------------------->
<h2 id="smq" style="color:#7EAEAC">Smart quote</h2>
<p>DYNA enquotes pure numeric index in bracketed variables/equations i.e. automatically replaces x[<digits>] by x['<digits>'].
<!------------------------------------------------------------->
<h2 id="sch" style="color:#7EAEAC">Special characters</h2>
<pre class="syntax">
# <font color="#808080"><i>starts a comment - anything to the right will be ignored</i></font>
@ <font color="#808080"><i>indicates a user/system macro</i></font>
\ <font color="#808080"><i>is a line continuation character</i></font>
§ <font color="#808080"><i>indicates a tabulated function</i></font>
´ <font color="#808080"><i>indicates derivative</i></font>
^ <font color="#808080"><i>is translated as **</i></font>
¨ <font color="#808080"><i>is translated as ^</i></font>
</pre>
<!------------------------------------------------------------->
<h2 id="ppar" style="color:#7EAEAC">Predefined constants and parameters</h2>
<pre class="syntax">
<font color="#0074D9">dyna_eps</font> <font color="#808080"><i>machine precision</i></font>
<font color="#0074D9">dyna_iter</font> <font color="#8A2BE2">%ITER%</font>
<font color="#0074D9">dyna_iter_max</font> <font color="#8A2BE2">%IN%</font>
<font color="#0074D9">dyna_drk</font>
<font color="#0074D9">dyna_irk</font>
<font color="#0074D9">dyna_krd</font>
<font color="#0074D9">dyna_kri</font>
<font color="#0074D9">dyna_pi</font> <font color="#808080"><i>Pi</i></font>
</pre>
<p>Note that Pi (\(\pi\)) is predefined in GAMS.
<!------------------------------------------------------------->
<h2 id="pset" style="color:#7EAEAC">Predefined sets</h2>
<pre class="syntax">
<font color="#0074D9">CartesianCoordinates</font> /x,y,z/
<font color="#0074D9">SphericalCoordinates</font> /rho,tta,phi/
<font color="#0074D9">Observation</font>
</pre>
<!------------------------------------------------------------->
<h2 id="pvar" style="color:#7EAEAC">Predefined variables</h2>
<p>Predefined variables are implemented as GAMS macros or variables.
<pre class="syntax">
<font color="#0074D9">Time</font> <font color="#808080"><i>The independent integration variable</i></font>
<font color="#0074D9">dTime</font> <font color="#808080"><i>Increment of the independent variable in <a href="#equ">equ section</a></i></font>
<font color="#0074D9">SimDT_</font> <font color="#808080"><i>Increment of the independent variable in <a href="#sim">sim section</a></i></font>
<font color="#0074D9">dyna_ksi</font> <font color="#808080"><i>Same as <font color="#8A2BE2">%OBJECTIVE%</font>, which reads better</i></font>
</pre>
<!------------------------------------------------------------->
<h2 id="pfun" style="color:#7EAEAC">Predefined functions</h2>
<p>Predefined functions are implemented as GAMS macros.
Here follows the list of function classes.
<ul>
<li><a href="#tirf">Time related functions</a></li>
<li><a href="#frac">Fractional derivative</a></li>
<li><a href="#povd">Polynomials of various degrees</a></li>
<li><a href="#pirf">Parameters identification related functions</a></li>
<li><a href="#corf">Coordinates related functions</a></li>
<li><a href="#trrf">Trigonometric related functions</a></li>
<li><a href="#wafu">Waveform functions</a></li>
<li><a href="#shfu">Smooth homotopy of non-differentiable functions</a></li>
<li><a href="#mifu">Miscellaneous functions</a></li>
<li><a href="#1dls">1-dimension interpolation - linear smooth</a></li>
<li><a href="#1dln">1-dimension interpolation - linear non-smooth</a></li>
<li><a href="#1dcs">1-dimension interpolation - cubic spline smooth</a></li>
<li><a href="#1dcn">1-dimension interpolation - cubic spline non-smooth</a></li>
<li><a href="#1dqs">1-dimension interpolation - quintic spline smooth</a></li>
<li><a href="#1dqn">1-dimension interpolation - quintic spline non-smooth</a></li>
<li><a href="#2dls">2-dimension interpolation - linear smooth</a></li>
<li><a href="#2dln">2-dimension interpolation - linear non-smooth</a></li>
<li><a href="#tiin">Time interpolation</a></li>
<li><a href="#sofu">Series of functions</a></li>
<li><a href="#chel">Chebyshev library</a></li>
<li><a href="#chsl">Chebyshev-Smolyak library</a></li>
<li><a href="#legl">Legendre library</a></li>
<li><a href="#herl">Hermite library</a></li>
<li><a href="#taul">Tauchen library</a></li>
</ul>
<h4 id="tirf">Time related functions</h4>
<pre class="syntax">
<font color="#0074D9">AllTimeAvg</font>(X)
<font color="#0074D9">AllTimeMax</font>(X)
<font color="#0074D9">AllTimeMin</font>(X)
<font color="#0074D9">AllTimeSum</font>(X)
<font color="#0074D9">AllTimeAvgIF</font>(X,Y)
<font color="#0074D9">AllTimeMaxIF</font>(X,Y)
<font color="#0074D9">AllTimeMinIF</font>(X,Y)
<font color="#0074D9">AllTimeSumIF</font>(X,Y)
<font color="#0074D9">costate</font>(X)
<font color="#0074D9">curr</font>(X)
<font color="#0074D9">delay</font>(X,tau)
<font color="#0074D9">derivative</font>(X)
<font color="#0074D9">eval</font>(X,tau)
<font color="#0074D9">final</font>(X)
<font color="#0074D9">initial</font>(X)
<font color="#0074D9">integ</font>(X)
<font color="#0074D9">last</font>(X)
<font color="#0074D9">pred</font>(X)
<font color="#0074D9">slope</font>(X)
<font color="#0074D9">start</font>(X)
<font color="#0074D9">succ</font>(X)
<font color="#0074D9">TimeJump</font>(tau)
<font color="#0074D9">TimeIsEq</font>(tau)
<font color="#0074D9">TimeIsGT</font>(tau)
<font color="#0074D9">TimeIsGE</font>(tau)
<font color="#0074D9">TimeIsLT</font>(tau)
<font color="#0074D9">TimeIsLE</font>(tau)
<font color="#0074D9">TimeImpulse</font>(tau)
<font color="#0074D9">TimeStep</font>(tau)
<font color="#0074D9">TimeRamp</font>(tau)
<font color="#0074D9">linspace</font>(a,b)
</pre>
<h4 id="frac">Fractional derivative</h4>
<pre class="syntax">
<font color="#0074D9">fractder</font>(x,order)
<font color="#0074D9">fractint</font>(x,order)
</pre>
<h4 id="povd">Polynomials of various degrees</h4>
<pre class="syntax">
<font color="#0074D9">poly1</font>(x,a1,a0)
<font color="#0074D9">poly2</font>(x,a2,a1,a0)
<font color="#0074D9">poly3</font>(x,a3,a2,a1,a0)
<font color="#0074D9">poly4</font>(x,a4,a3,a2,a1,a0)
<font color="#0074D9">poly5</font>(x,a5,a4,a3,a2,a1,a0)
<font color="#0074D9">poly6</font>(x,a6,a5,a4,a3,a2,a1,a0)
<font color="#0074D9">poly7</font>(x,a7,a6,a5,a4,a3,a2,a1,a0)
<font color="#0074D9">poly8</font>(x,a8,a7,a6,a5,a4,a3,a2,a1,a0)
<font color="#0074D9">poly9</font>(x,a9,a8,a7,a6,a5,a4,a3,a2,a1,a0)
</pre>
<h4 id="pirf">Parameters identification related functions</h4>
<pre class="syntax">
<font color="#0074D9">ObservedSSE</font>(x)
<font color="#0074D9">ObservedSSEC</font>(x,mx)
<font color="#0074D9">ObservedSXE</font>(x,y)
<font color="#0074D9">ObservedSXEC</font>(x,y,mx,my)
<font color="#0074D9">ObservedMSE</font>(x)
<font color="#0074D9">ObservedMSEC</font>(x,mx)
<font color="#0074D9">ObservedMAE</font>(x)
<font color="#0074D9">ObservedMAEC</font>(x,mx)
<font color="#0074D9">ObservedVal</font>(x)
<font color="#0074D9">ObservedMax</font>(x)
<font color="#0074D9">ObservedMin</font>(x)
<font color="#0074D9">ObservedNum</font>(x)
<font color="#0074D9">ObservedSet</font>(x,i)
<font color="#0074D9">ObservedGap</font>(x,i)
<font color="#0074D9">ObservedTau</font>(x,i)