/
TFC5.mos
106 lines (94 loc) · 2.82 KB
/
TFC5.mos
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
// name: testFinalCon_5
// status: correct
setCommandLineOptions("+gDynopt");
getErrorString();
loadString("
model testFinalCon5
Real x1;
Real x2;
Real y1;
Real y2;
Real y3(start = -1);
input Real u;
Real final_con1(min = 0, max = 0) annotation(isFinalConstraint = true);
Real final_con2(min = 0, max = 0) annotation(isFinalConstraint = true);
Real cost annotation(isLagrange = true);
equation
der(x1) = x2*u - x1;
der(x2) = x1 + y1;
final_con1 = x1 - 2; //0 <= x1 - 2 <= 0 for t = tf
final_con2 = x2 - 3;
0 = 3*y1 + y2 - exp(1 + u);
0 = y1 - 5*y2 - exp(1 + time);
y3^2 = 1 + time;
cost = u^2;
end testFinalCon5;
model testFinalCon5_
extends testFinalCon5;
end testFinalCon5_;
");
getErrorString();
setCommandLineOptions("+maxSizeSolveLinearSystem=0");
getErrorString();
echo(false);
res:=optimize(testFinalCon5_, numberOfIntervals=20, tolerance = 1e-08, stopTime = 5, simflags="-optimizerNP 1");
messages:=res.messages;
echo(true);
res.resultFile;
if regexBool(messages, "No optimal solution found") then
print("No optimal solution found");
else
print("Optimal solution found? Weird...\n");
exit(1);
end if;
getErrorString();
res := OpenModelica.Scripting.compareSimulationResults("testFinalCon5__res.mat","ReferenceFiles/testFinalCon5_ref.mat","testFinalCon_diff.csv",0.01,0.0001); // Files not equal!!! Testing other convergence with solveLinearSystem
getErrorString();
setCommandLineOptions("+maxSizeSolveLinearSystem=20"); getErrorString();
echo(false);
res := optimize(testFinalCon5, numberOfIntervals=700, tolerance = 1e-08, stopTime = 5, simflags="-lv LOG_IPOPT -optimizerNP 1");
messages:=res.messages;
echo(true);
res.resultFile;
if regexBool(messages, "EXIT: Optimal Solution Found.") then
if regexBool(messages, "Number of Iterations....: 40") then
print("Number of Iterations....: 40\nEXIT: Optimal Solution Found.");
else
print("Number of Iterations changed.\tUpdate test\n");
exit(1);
end if;
else
print("No optimal solution found");
exit(1);
end if;
getErrorString();
getErrorString();
res := OpenModelica.Scripting.compareSimulationResults("testFinalCon5_res.mat","ReferenceFiles/testFinalCon5_ref.mat","testFinalCon_diff.csv",0.01,0.0001);
getErrorString();
// Result:
// true
// ""
// true
// ""
// true
// ""
// true
// "testFinalCon5__res.mat"
// No optimal solution found
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
// "
// {"Files not Equal!","y2","y1","x2","x1","u","final_con2","final_con1","der(x2)","der(x1)","cost"}
// "Warning: Files not Equal
// "
// true
// ""
// true
// "testFinalCon5_res.mat"
// Number of Iterations....: 40
// EXIT: Optimal Solution Found.
// "Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
// "
// ""
// {"Files Equal!"}
// ""
// endResult