-
Notifications
You must be signed in to change notification settings - Fork 5
/
LPOptim.scl
671 lines (652 loc) · 21 KB
/
LPOptim.scl
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
// Name: FB1844
// Symbolic Name: LPOptim
// Symbol Comment: Linear Optimization
// Family: Control
// Version: 2.1
// Author: AdvLib80
// Last modified: 08/07/2012
// Use:
// Size: 6576 bytes
// Signature: generiert vom SCL Übersetzer Version: SCLCOMP K05.03.07.00_01.02.00.01 release
{
Scl_ResetOptions ;
Scl_OverwriteBlocks:= 'y' ;
Scl_GenerateReferenceData := 'y' ;
Scl_S7ServerActive:= 'n' ;
Scl_CreateObjectCode:= 'y' ;
Scl_OptimizeObjectCode:= 'y' ;
Scl_MonitorArrayLimits:= 'n' ;
Scl_CreateDebugInfo := 'n' ;
Scl_SetOKFlag:= 'n' ;
Scl_SetMaximumStringLength:= '254'
}
FUNCTION_BLOCK FB11844
TITLE ='Linear Optimization'
AUTHOR : AdvLib80
FAMILY : Control
NAME : LPOptim
VERSION : '2.1'
// reversed by komatic
VAR_INPUT
J_Mini { S7_visible := 'false'; S7_link := 'false' }: BOOL ; //1=Mininmum J, 0=Maximum J
Start : BOOL ; //1 = Starts the calculation
X1 { S7_dynamic := 'true' }: REAL ; //Decision variable 1
X2 { S7_dynamic := 'true' }: REAL ; //Decision variable 2
X3 { S7_dynamic := 'true' }: REAL ; //Decision variable 3
X4 { S7_dynamic := 'true' }: REAL ; //Decision variable 4
J_0 { S7_dynamic := 'true' }: REAL ; //Working point
N_X { S7_dynamic := 'true' }: INT := 4; //Number of variables X to be optimized
N_b { S7_dynamic := 'true' }: INT := 8; //Number of constraints b
Gradient : STRUCT //Gradient vector
g1 : REAL := 1.000000e+000;
g2 : REAL := 1.000000e+000;
g3 : REAL := 1.000000e+000;
g4 : REAL := 1.000000e+000;
END_STRUCT ;
Constraints : STRUCT //Constraints
b1 : REAL ;
b2 : REAL ;
b3 : REAL ;
b4 : REAL ;
b5 : REAL ;
b6 : REAL ;
b7 : REAL ;
b8 : REAL ;
END_STRUCT ;
A1n : STRUCT //Factors for elements of X at the first constraint
a11 : REAL ;
a12 : REAL ;
a13 : REAL ;
a14 : REAL ;
END_STRUCT ;
A2n : STRUCT //Factors for elements of X at the second constraint
a21 : REAL ;
a22 : REAL ;
a23 : REAL ;
a24 : REAL ;
END_STRUCT ;
A3n : STRUCT //Factors for elements of X at the third constraint
a31 : REAL ;
a32 : REAL ;
a33 : REAL ;
a34 : REAL ;
END_STRUCT ;
A4n : STRUCT //Factors for elements of X at the fourth constraint
a41 : REAL ;
a42 : REAL ;
a43 : REAL ;
a44 : REAL ;
END_STRUCT ;
A5n : STRUCT //Factors for elements of X at the fifth constraint
a51 : REAL ;
a52 : REAL ;
a53 : REAL ;
a54 : REAL ;
END_STRUCT ;
A6n : STRUCT //Factors for elements of X at the sixth constraint
a61 : REAL ;
a62 : REAL ;
a63 : REAL ;
a64 : REAL ;
END_STRUCT ;
A7n : STRUCT //Factors for elements of X at the seventh constraint
a71 : REAL ;
a72 : REAL ;
a73 : REAL ;
a74 : REAL ;
END_STRUCT ;
A8n : STRUCT //Factors for elements of X at the eighth constraint
a81 : REAL ;
a82 : REAL ;
a83 : REAL ;
a84 : REAL ;
END_STRUCT ;
END_VAR
VAR_OUTPUT
Bad { S7_dynamic := 'true' }: BOOL ; //Calculation error
ErrorNum { S7_visible := 'false'; S7_dynamic := 'true' }: INT ; //Error Number
J_Opt { S7_dynamic := 'true' }: REAL ; //Optimal quality criterion
J_Act { S7_dynamic := 'true' }: REAL ; //Quality criterion by active decision variables
X1Opt { S7_dynamic := 'true' }: REAL ; //Optimal value for X1
X2Opt { S7_dynamic := 'true' }: REAL ; //Optimal value for X2
X3Opt { S7_dynamic := 'true' }: REAL ; //Optimal value for X3
X4Opt { S7_dynamic := 'true' }: REAL ; //Optimal value for X4
END_VAR
VAR
SiTa1 : ARRAY [1 .. 9, 1 .. 13 ] OF //Dimension: Simplex-tabelau
REAL ; //Dimension: Simplex-tabelau
SiTa1_one AT SiTa1 : ARRAY[0..116] OF REAL;
SiTa2 : ARRAY [1 .. 9, 1 .. 13 ] OF //Dimension: Simplex-tabelau
REAL ; //Dimension: Simplex-tabelau
Rech : BOOL ;
fact1 : REAL ;
fact2 : REAL ;
fact3 : REAL ;
fact4 : REAL ;
J_Mini_Alt : BOOL ;
N_X_Alt : INT := 4; //number of variables X to be optimized
N_b_Alt : INT := 8; //number of constrains b
Gradient_Alt : STRUCT
g1 : REAL := 1.000000e+000;
g2 : REAL := 1.000000e+000;
g3 : REAL := 1.000000e+000;
g4 : REAL := 1.000000e+000;
END_STRUCT ;
Constraints_Alt : STRUCT
b1 : REAL ;
b2 : REAL ;
b3 : REAL ;
b4 : REAL ;
b5 : REAL ;
b6 : REAL ;
b7 : REAL ;
b8 : REAL ;
END_STRUCT ;
A1n_Alt : STRUCT
a11 : REAL ;
a12 : REAL ;
a13 : REAL ;
a14 : REAL ;
END_STRUCT ;
A2n_Alt : STRUCT
a21 : REAL ;
a22 : REAL ;
a23 : REAL ;
a24 : REAL ;
END_STRUCT ;
A3n_Alt : STRUCT
a31 : REAL ;
a32 : REAL ;
a33 : REAL ;
a34 : REAL ;
END_STRUCT ;
A4n_Alt : STRUCT
a41 : REAL ;
a42 : REAL ;
a43 : REAL ;
a44 : REAL ;
END_STRUCT ;
A5n_Alt : STRUCT
a51 : REAL ;
a52 : REAL ;
a53 : REAL ;
a54 : REAL ;
END_STRUCT ;
A6n_Alt : STRUCT
a61 : REAL ;
a62 : REAL ;
a63 : REAL ;
a64 : REAL ;
END_STRUCT ;
A7n_Alt : STRUCT
a71 : REAL ;
a72 : REAL ;
a73 : REAL ;
a74 : REAL ;
END_STRUCT ;
A8n_Alt : STRUCT
a81 : REAL ;
a82 : REAL ;
a83 : REAL ;
a84 : REAL ;
END_STRUCT ;
END_VAR
VAR_TEMP
LowQuo : REAL ;
pivot_z : INT ;
z_ok : BOOL ;
Neg : BOOL ;
Unconstr : BOOL ;
Unend : BOOL ;
HighCo : REAL ;
pivot_s : INT ;
s_ok : BOOL ;
i_z : INT ;
i_s : INT ;
i : INT ;
Quotient : REAL ;
Invers : REAL ;
ValPivotSp : REAL ;
x1i : INT ;
x2i : INT ;
x3i : INT ;
x4i : INT ;
END_VAR
BEGIN
CASE N_X OF
1 :
Gradient.g2:=0.0;
Gradient.g3:=0.0;
Gradient.g4:=0.0;
2 :
Gradient.g3:=0.0;
Gradient.g4:=0.0;
3 :
Gradient.g4:=0.0;
END_CASE;
IF N_X_Alt<>N_X OR
N_b_Alt<>N_b OR
J_Mini_Alt <> J_Mini OR
Gradient_Alt.g1<>Gradient.g1 OR
Gradient_Alt.g2<>Gradient.g2 OR
Gradient_Alt.g3<>Gradient.g3 OR
Gradient_Alt.g4<>Gradient.g4 OR
Constraints_Alt.b1<>Constraints.b1 OR
Constraints_Alt.b2<>Constraints.b2 OR
Constraints_Alt.b3<>Constraints.b3 OR
Constraints_Alt.b4<>Constraints.b4 OR
Constraints_Alt.b5<>Constraints.b5 OR
Constraints_Alt.b6<>Constraints.b6 OR
Constraints_Alt.b7<>Constraints.b7 OR
Constraints_Alt.b8<>Constraints.b8 OR
A1n_Alt.a11<>A1n.a11 OR
A1n_Alt.a12<>A1n.a12 OR
A1n_Alt.a13<>A1n.a13 OR
A1n_Alt.a14<>A1n.a14 OR
A2n_Alt.a21<>A2n.a21 OR
A2n_Alt.a22<>A2n.a22 OR
A2n_Alt.a23<>A2n.a23 OR
A2n_Alt.a24<>A2n.a24 OR
A3n_Alt.a31<>A3n.a31 OR
A3n_Alt.a32<>A3n.a32 OR
A3n_Alt.a33<>A3n.a33 OR
A3n_Alt.a34<>A3n.a34 OR
A4n_Alt.a41<>A4n.a41 OR
A4n_Alt.a42<>A4n.a42 OR
A4n_Alt.a43<>A4n.a43 OR
A4n_Alt.a44<>A4n.a44 OR
A5n_Alt.a51<>A5n.a51 OR
A5n_Alt.a52<>A5n.a52 OR
A5n_Alt.a53<>A5n.a53 OR
A5n_Alt.a54<>A5n.a54 OR
A6n_Alt.a61<>A6n.a61 OR
A6n_Alt.a62<>A6n.a62 OR
A6n_Alt.a63<>A6n.a63 OR
A6n_Alt.a64<>A6n.a64 OR
A7n_Alt.a71<>A7n.a71 OR
A7n_Alt.a72<>A7n.a72 OR
A7n_Alt.a73<>A7n.a73 OR
A7n_Alt.a74<>A7n.a74 OR
A8n_Alt.a81<>A8n.a81 OR
A8n_Alt.a82<>A8n.a82 OR
A8n_Alt.a83<>A8n.a83 OR
A8n_Alt.a84<>A8n.a84
THEN
Start:=true;
END_IF;
J_Mini_Alt:=J_Mini;
N_X_Alt:=N_X;
N_b_Alt:=N_b;
Gradient_Alt.g1:=Gradient.g1;
Gradient_Alt.g2:=Gradient.g2;
Gradient_Alt.g3:=Gradient.g3;
Gradient_Alt.g4:=Gradient.g4;
Constraints_Alt.b1:=Constraints.b1;
Constraints_Alt.b2:=Constraints.b2;
Constraints_Alt.b3:=Constraints.b3;
Constraints_Alt.b4:=Constraints.b4;
Constraints_Alt.b5:=Constraints.b5;
Constraints_Alt.b6:=Constraints.b6;
Constraints_Alt.b7:=Constraints.b7;
Constraints_Alt.b8:=Constraints.b8;
A1n_Alt.a11:=A1n.a11;
A1n_Alt.a12:=A1n.a12;
A1n_Alt.a13:=A1n.a13;
A1n_Alt.a14:=A1n.a14;
A2n_Alt.a21:=A2n.a21;
A2n_Alt.a22:=A2n.a22;
A2n_Alt.a23:=A2n.a23;
A2n_Alt.a24:=A2n.a24;
A3n_Alt.a31:=A3n.a31;
A3n_Alt.a32:=A3n.a32;
A3n_Alt.a33:=A3n.a33;
A3n_Alt.a34:=A3n.a34;
A4n_Alt.a41:=A4n.a41;
A4n_Alt.a42:=A4n.a42;
A4n_Alt.a43:=A4n.a43;
A4n_Alt.a44:=A4n.a44;
A5n_Alt.a51:=A5n.a51;
A5n_Alt.a52:=A5n.a52;
A5n_Alt.a53:=A5n.a53;
A5n_Alt.a54:=A5n.a54;
A6n_Alt.a61:=A6n.a61;
A6n_Alt.a62:=A6n.a62;
A6n_Alt.a63:=A6n.a63;
A6n_Alt.a64:=A6n.a64;
A7n_Alt.a71:=A7n.a71;
A7n_Alt.a72:=A7n.a72;
A7n_Alt.a73:=A7n.a73;
A7n_Alt.a74:=A7n.a74;
A8n_Alt.a81:=A8n.a81;
A8n_Alt.a82:=A8n.a82;
A8n_Alt.a83:=A8n.a83;
A8n_Alt.a84:=A8n.a84;
J_Act:=Gradient.g1*X1+Gradient.g2*X2+Gradient.g3*X3+Gradient.g4*X4+J_0;
IF Start THEN
IF ((((Gradient.g1<>0.0) OR
(Gradient.g2<>0.0)) OR
(Gradient.g3<>0.0)) OR
(Gradient.g4<>0.0)) OR
(((((((Constraints.b1<>0.0) OR
(Constraints.b2<>0.0)) OR
(Constraints.b3<>0.0)) OR
((Constraints.b4<>0.0) AND
(Constraints.b5<>0.0))) OR
(Constraints.b6<>0.0)) OR
(Constraints.b7<>0.0)) OR
(Constraints.b8<>0.0))
THEN
IF J_Mini THEN
SiTa1[1, 1]:=Gradient.g1;
SiTa1[1, 2]:=Gradient.g2;
SiTa1[1, 3]:=Gradient.g3;
SiTa1[1, 4]:=Gradient.g4;
ELSE
SiTa1[1, 1]:=-Gradient.g1;
SiTa1[1, 2]:=-Gradient.g2;
SiTa1[1, 3]:=-Gradient.g3;
SiTa1[1, 4]:=-Gradient.g4;
END_IF;
SiTa1[1, 5]:=0.0;
SiTa1[1, 6]:=0.0;
SiTa1[1,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10]:=0.0;
IF N_b>6 THEN
SiTa1[8, 11]:=1.0;
ELSE
SiTa1[8, 11]:=0.0;
END_IF;
SiTa1[8, 12]:=0.0;
SiTa1[8, 13]:=Constraints.b7;
SiTa1[9, 1]:=A8n.a81;
SiTa1[9, 2]:=A8n.a82;
SiTa1[9, 3]:=A8n.a83;
SiTa1[9, 4]:=A8n.a84;
SiTa1[9, 5]:=0.0;
SiTa1[9, 6]:=0.0;
SiTa1[9, 7]:=0.0;
SiTa1[9, 8]:=0.0;
SiTa1[9, 9]:=0.0;
SiTa1[9, 10]:=0.0;
SiTa1[9, 11]:=0.0;
IF N_b>7 THEN
SiTa1[9, 12]:=1.0;
ELSE
SiTa1[9, 12]:=0.0;
END_IF;
SiTa1[9, 13]:=Constraints.b8;
Start:=false;
Rech:=true;
Bad:=false;
ErrorNum:=0;
ELSE
Bad:=true;
ErrorNum:=40;
END_IF;
END_IF;
IF Rech THEN
FOR i:=1 TO 100 BY 1 DO
Neg:=true;
FOR i_s:=1 TO 12 BY 1 DO
IF SiTa1[1,i_s]<0.0 THEN
Neg:=false;
END_IF;
END_FOR;
IF Neg THEN
Rech:=false;
EXIT;
END_IF;
HighCo:=SiTa1[1,i_s];
pivot_s:=0;
s_ok:=false;
FOR i_s:=1 TO 13 BY 1 DO
IF HighCo>SiTa1[1,i_s] THEN
HighCo:=SiTa1[1,i_s];
pivot_s:=i_s;
s_ok:=true;
END_IF;
END_FOR;
Unconstr:=true;
IF pivot_s<>0 THEN
FOR i_z:=2 TO 9 BY 1 DO
IF SiTa1[i_z,pivot_s]<>0 THEN
Unconstr:=false;
END_IF;
END_FOR;
END_IF;
IF Unconstr THEN
Bad:=true;
ErrorNum:=35;
Rech:=false;
EXIT;
END_IF;
LowQuo:=1.000000e+020;
pivot_z:=0;
z_ok:=false;
FOR i_z:=2 TO 9 BY 1 DO
IF SiTa1[i_z,pivot_s]<>0.0 THEN
Quotient:=SiTa1[i_z,13]/SiTa1[i_z,pivot_s];
IF Quotient<LowQuo AND Quotient>0.0 THEN
LowQuo:=Quotient;
pivot_z:=i_z;
z_ok:=true;
END_IF;
END_IF;
END_FOR;
IF z_ok AND s_ok THEN
Invers:=1.0/SiTa1[pivot_z,pivot_s];
FOR i_s:=1 TO 13 BY 1 DO
SiTa2[pivot_z,i_s]:=SiTa1[pivot_z,i_s]*Invers;
END_FOR;
FOR i_z:=1 TO 9 BY 1 DO
FOR i_s:=1 TO 13 BY 1 DO
IF pivot_z<>i_z THEN
ValPivotSp:=-SiTa1[i_z,pivot_s];
IF i_s=pivot_s THEN
SiTa2[i_z,i_s]:=SiTa1[i_z,i_s]+ValPivotSp;
ELSE
SiTa2[i_z,i_s]:=SiTa1[i_z,i_s]+SiTa1[pivot_z,i_s]*ValPivotSp*Invers;
END_IF;
END_IF;
END_FOR;
END_FOR;
Unend:=true;
FOR i_s:=1 TO 13 BY 1 DO
IF SiTa1[1,i_s]<>SiTa2[1,i_s] THEN
Unend:=false;
END_IF;
END_FOR;
FOR i_z:=1 TO 9 BY 1 DO
FOR i_s:=1 TO 13 BY 1 DO
SiTa1[i_z,i_s]:=SiTa2[i_z,i_s];
END_FOR;
END_FOR;
IF Unend THEN
Bad:=true;
ErrorNum:=20;
Rech:=false;
EXIT;
END_IF;
ELSE
Bad:=true;
ErrorNum:=10;
Rech:=false;
EXIT;
END_IF;
FOR i_z:=2 TO N_b+1 BY 1 DO
IF SiTa1[2,(INT_TO_DINT(i_z)-1)*13]=0.0 THEN
SiTa1[2,(INT_TO_DINT(i_z)-1)*13]:=1.000000e-006;
END_IF;
END_FOR;
END_FOR;
FOR i_z:=2 TO 9 BY 1 DO
IF SiTa1[i_z,1]=1.0 OR SiTa1[i_z,1]=-1.0 THEN
x1i:=i_z;
fact1:=SiTa1[i_z,1];
END_IF;
IF SiTa1_one[(INT_TO_DINT(i_z)-1)*13+1]=1.0 OR SiTa1_one[(INT_TO_DINT(i_z)-1)*13+1]=-1.0 THEN
x2i:=i_z;
fact2:=SiTa1_one[(INT_TO_DINT(i_z)-1)*13+1];
END_IF;
IF SiTa1_one[(INT_TO_DINT(i_z)-1)*13+2]=1.0 OR SiTa1_one[(INT_TO_DINT(i_z)-1)*13+2]=-1.0 THEN
x3i:=i_z;
fact3:=SiTa1_one[(INT_TO_DINT(i_z)-1)*13+2];
END_IF;
IF SiTa1_one[(INT_TO_DINT(i_z)-1)*13+3]=1.0 OR SiTa1_one[(INT_TO_DINT(i_z)-1)*13+3]=-1.0 THEN
x4i:=i_z;
fact4:=SiTa1_one[(INT_TO_DINT(i_z)-1)*13+3];
END_IF;
END_FOR;
IF Bad THEN
J_Opt:=0.0;
X1Opt:=0.0;
X2Opt:=0.0;
X3Opt:=0.0;
X4Opt:=0.0;
ELSE
CASE N_X OF
1 :
X1Opt:=SiTa1_one[(INT_TO_DINT(x1i)-1)*13+12]*fact1;
X2Opt:=0.0;
X3Opt:=0.0;
X4Opt:=0.0;
2 :
X1Opt:=SiTa1_one[(INT_TO_DINT(x1i)-1)*13+12]*fact1;
X2Opt:=SiTa1_one[(INT_TO_DINT(x2i)-1)*13+12]*fact2;
X3Opt:=0.0;
X4Opt:=0.0;
3 :
X1Opt:=SiTa1_one[(INT_TO_DINT(x1i)-1)*13+12]*fact1;
X2Opt:=SiTa1_one[(INT_TO_DINT(x2i)-1)*13+12]*fact2;
X3Opt:=SiTa1_one[(INT_TO_DINT(x3i)-1)*13+12]*fact3;
X4Opt:=0.0;
4 :
X1Opt:=SiTa1_one[(INT_TO_DINT(x1i)-1)*13+12]*fact1;
X2Opt:=SiTa1_one[(INT_TO_DINT(x2i)-1)*13+12]*fact2;
X3Opt:=SiTa1_one[(INT_TO_DINT(x3i)-1)*13+12]*fact3;
X4Opt:=SiTa1_one[(INT_TO_DINT(x4i)-1)*13+12]*fact4;
ELSE
Bad:=true;
ErrorNum:=15;
END_CASE;
END_IF;
J_Opt:=Gradient.g1*X1Opt+Gradient.g2*X2Opt+Gradient.g3*X3Opt+Gradient.g4*X4Opt+J_0;
END_IF;
END_FUNCTION_BLOCK