Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
languages
EmbeddedMontiArcMathOpt
Commits
f2ba373a
Commit
f2ba373a
authored
Jun 18, 2018
by
Christoph Richter
Browse files
Added test models
parent
54e36f5e
Pipeline
#56264
passed with stage
in 21 minutes and 55 seconds
Changes
13
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/mathopt/_symboltable/EmbeddedMontiArcMathOptSymbolTableCreator.java
→
src/main/java/de/monticore/lang/
embeddedmontiarc
mathopt/_symboltable/EmbeddedMontiArcMathOptSymbolTableCreator.java
View file @
f2ba373a
...
@@ -17,11 +17,12 @@
...
@@ -17,11 +17,12 @@
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
* *******************************************************************************
*/
*/
package
de.monticore.lang.mathopt._symboltable
;
package
de.monticore.lang.
embeddedmontiarc
mathopt._symboltable
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._symboltable.EmbeddedMontiArcMathSymbolTableCreator
;
import
de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._symboltable.EmbeddedMontiArcMathSymbolTableCreator
;
import
de.monticore.lang.embeddedmontiarcmathopt._visitor.EmbeddedMontiArcMathOptDelegatorVisitor
;
import
de.monticore.lang.embeddedmontiarcmathopt._visitor.EmbeddedMontiArcMathOptDelegatorVisitor
;
import
de.monticore.lang.embeddedmontiarcmathopt._visitor.EmbeddedMontiArcMathOptVisitor
;
import
de.monticore.lang.embeddedmontiarcmathopt._visitor.EmbeddedMontiArcMathOptVisitor
;
import
de.monticore.lang.mathopt._symboltable.MathOptSymbolTableCreator
;
import
de.monticore.symboltable.MutableScope
;
import
de.monticore.symboltable.MutableScope
;
import
de.monticore.symboltable.ResolvingConfiguration
;
import
de.monticore.symboltable.ResolvingConfiguration
;
...
@@ -52,7 +53,7 @@ public class EmbeddedMontiArcMathOptSymbolTableCreator extends EmbeddedMontiArcM
...
@@ -52,7 +53,7 @@ public class EmbeddedMontiArcMathOptSymbolTableCreator extends EmbeddedMontiArcM
super
.
initSuperSTC
(
resolvingConfig
);
super
.
initSuperSTC
(
resolvingConfig
);
// init math opt symbol table creator
// init math opt symbol table creator
mathOptSTC
=
new
MathOptSymbolTableCreator
(
resolvingConfig
,
scopeStack
);
mathOptSTC
=
new
MathOptSymbolTableCreator
(
resolvingConfig
,
scopeStack
);
// init visitor delegator for optimization languages
// init visitor delegator for
test.emam.
optimization languages
visitorOpt
.
setExpressionsBasisVisitor
(
mathOptSTC
);
visitorOpt
.
setExpressionsBasisVisitor
(
mathOptSTC
);
visitorOpt
.
setCommonExpressionsVisitor
(
mathOptSTC
);
visitorOpt
.
setCommonExpressionsVisitor
(
mathOptSTC
);
visitorOpt
.
setAssignmentExpressionsVisitor
(
mathOptSTC
);
visitorOpt
.
setAssignmentExpressionsVisitor
(
mathOptSTC
);
...
...
src/test/java/de/monticore/lang/embeddedmontiarcmathopt/_ast/ASTEmbeddedMontiArcMathOptNodesTest.java
0 → 100644
View file @
f2ba373a
package
de.monticore.lang.embeddedmontiarcmathopt._ast
;
import
static
org
.
junit
.
Assert
.*;
public
class
ASTEmbeddedMontiArcMathOptNodesTest
{
}
\ No newline at end of file
src/test/java/de/monticore/lang/embeddedmontiarcmathopt/_parser/EmbeddedMontiArcMathOptParserTest.java
0 → 100644
View file @
f2ba373a
package
de.monticore.lang.embeddedmontiarcmathopt._parser
;
import
static
org
.
junit
.
Assert
.*;
public
class
EmbeddedMontiArcMathOptParserTest
{
}
\ No newline at end of file
src/test/java/de/monticore/lang/embeddedmontiarcmathopt/_symboltable/EmbeddedMontiArcMathOptSymbolTableCreatorTest.java
0 → 100644
View file @
f2ba373a
package
de.monticore.lang.embeddedmontiarcmathopt._symboltable
;
import
static
org
.
junit
.
Assert
.*;
public
class
EmbeddedMontiArcMathOptSymbolTableCreatorTest
{
}
\ No newline at end of file
src/test/resources/test/emam/optimization/MinimizePortsTest.emam
0 → 100644
View file @
f2ba373a
package
test
.
emam
.
optimization
;
component
MinimizePortsTest
{
ports
in
Q
u
;
out
Q
y
implementation
Math
{
y
=
minimize
(
u
)
(
u
*
u
)
-
2
*
u
+
1
;
subject
to
u
>=
0
;
end
}
}
\ No newline at end of file
src/test/resources/test/math/optimization/BoundedConditionsTest.emam
0 → 100644
View file @
f2ba373a
package
test
.
math
.
optimization
;
component
BoundedConditionsTest
{
implementation
Math
{
Q
y
=
minimize
(
Q
x
)
(
x
*
x
)
-
2
*
x
+
1
;
subject
to
0
<=
x
<=
1
;
0
<=
2
*
x
<=
1
;
end
}
}
\ No newline at end of file
src/test/resources/test/math/optimization/ExistingOptimizationVariableTest.emam
0 → 100644
View file @
f2ba373a
package
test
.
math
.
optimization
;
component
ExistingOptimizationVariableTest
{
implementation
Math
{
//
1.
scalar
Q
x
=
3
;
minimize
(
x
)
2
*
x
+
1
;
subject
to
-
1
<=
x
<=
1
;
end
//
2.
matrix
Q
^{
3
,
3
}
a
=
zeros
(
3
,
3
);
Q
b
=
minimize
(
a
)
a
*
a
;
subject
to
-
10
<=
a
<=
10
;
end
//
3.
substituted
Q
^{
3
,
3
}
squared
=
a
*
a
;
Q
c
=
minimize
(
a
)
squared
*
squared
;
subject
to
-
20
<=
a
<=
20
;
end
}
}
\ No newline at end of file
src/test/resources/test/math/optimization/ForLoopConditionsTest.emam
0 → 100644
View file @
f2ba373a
package
test
.
math
.
optimization
;
component
ForLoopConditionsTest
{
implementation
Math
{
Q
y
=
minimize
(
Q
^{
3
}
x
)
x
(
1
)
*
x
(
1
)
+
x
(
2
)
*
x
(
2
)
+
x
(
3
)
*
x
(
3
);
subject
to
for
i
=
1
:
3
x
(
i
)
>=
0
;
0
<=
2
*
x
(
i
)
<=
2
;
end
end
}
}
\ No newline at end of file
src/test/resources/test/math/optimization/LPOptimizationTest.emam
0 → 100644
View file @
f2ba373a
//
transportation
problem
example
(
linear
)
//
see
https
://
www
.
gams
.
com
/
products
/
simple
-
example
/
package
test
.
math
.
optimization
;
component
LPOptimizationTest
{
implementation
Math
{
//
define
problem
Q
m
=
3
;
Q
n
=
2
;
//
define
A
,
b
Q
^{
3
,
1
}
A
=
[
45
;
60
;
35
];
Q
^{
2
,
1
}
b
=
[
50
;
60
];
//
cost
matrix
Q
^{
m
,
n
}
c
=
[
3
,
2
;
1
,
5
;
5
,
4
];
//
minimization
problem
minimize
(
Q
^{
3
,
2
}
x
)
sum
(
c
.*
x
);
subject
to
sum
(
x
,
2
)
==
A
;
sum
(
x
,
1
)
==
b
;
x
>=
0
;
end
}
}
\ No newline at end of file
src/test/resources/test/math/optimization/ScalarMaximizationTest.emam
0 → 100644
View file @
f2ba373a
package
test
.
math
.
optimization
;
component
ScalarMaximizationTest
{
implementation
Math
{
Q
z
=
maximize
(
Q
x
)
-
x
*
x
+
42
;
subject
to
x
>=
-
10
;
x
<=
10
;
end
}
}
\ No newline at end of file
src/test/resources/test/math/optimization/ScalarMinimizationTest.emam
0 → 100644
View file @
f2ba373a
package
test
.
math
.
optimization
;
component
ScalarMinimizationTest
{
implementation
Math
{
Q
y
=
minimize
(
Q
x
)
(
x
*
x
)
-
2
*
x
+
1
;
subject
to
x
>=
0
;
end
}
}
\ No newline at end of file
src/test/resources/test/math/optimization/StandardIpoptOptimizationTest.emam
0 → 100644
View file @
f2ba373a
//
example
problem
,
number
71
from
the
Hock
-
Schittkowsky
test
suite
//
W
.
Hock
and
K
.
Schittkowski
.
//
Test
examples
for
nonlinear
programming
codes
.
//
Lecture
Notes
in
Economics
and
Mathematical
Systems
,
187
,
1981.
//
doi
:
10.1007
/
978
-
3
-
642
-
48320
-
2.
package
test
.
math
.
optimization
;
component
StandardIpoptOptimizationTest
{
implementation
Math
{
Q
y
=
minimize
(
Q
^{
4
}
x
)
x
(
1
)
*
x
(
4
)
*
(
x
(
1
)
+
x
(
2
)
+
x
(
3
))
+
x
(
3
);
subject
to
x
(
1
)
*
x
(
2
)
*
x
(
3
)
*
x
(
4
)
>=
25
;
x
(
1
)
*
x
(
1
)
+
x
(
2
)
*
x
(
2
)
+
x
(
3
)
*
x
(
3
)
+
x
(
4
)
*
x
(
4
)
==
40
;
1
<=
x
;
x
<=
5
;
end
}
}
\ No newline at end of file
src/test/resources/test/math/optimization/mpc/KinematicBicycleMPC.emam
0 → 100644
View file @
f2ba373a
//
Kinematic
Bicycle
model
//
@
author
Christoph
Richter
package
test
.
math
.
optimization
.
mpc
;
component
KinematicBicycleMPC
{
ports
in
Q
^{
4
,
3
}
z_ref
,
in
Q
^{
4
}
z_t
,
in
Q
^{
2
}
u_prev
,
out
Q
^{
2
}
u
;
implementation
Math
{
//
constant
mpc
parameters
Q
t_s
=
0.1
;
//
sampling
time
Q
hp
=
3
;
//
prediction
horizon
//
constant
vehicle
parameters
Q
l_f
=
1
;
//
length
center
to
front
Q
l_r
=
1
;
//
length
center
to
back
//
static
bounds
on
u
Q
^{
2
}
u_min
=
[-
1.5
;
-
37
];
Q
^{
2
}
u_max
=
[
1
;
37
];
Q
^{
2
}
du_min
=
[-
3
;
-
10
];
Q
^{
2
}
du_max
=
[
1.5
;
10
];
//
declare
optimization
variable
Q
^{
2
,
3
}
u_i
=
zeros
(
2
,
3
);
Q
^{
4
,
3
}
z
=
zeros
(
4
,
3
);
//
read
last
output
values
u_i
(:,
1
)
=
[
u_prev
(
1
);
u_prev
(
2
)];
z
(:,
1
)
=
z_t
;
for
i
=
2
:
hp
//
update
state
Q
x
=
z
(
1
,
i
-
1
);
//
x
position
Q
y
=
z
(
2
,
i
-
1
);
//
y
position
Q
psi
=
z
(
3
,
i
-
1
);
//
angle
the
vehicle
faces
Q
v
=
z
(
4
,
i
-
1
);
//
velocity
//
last
output
u
Q
a
=
u_i
(
1
,
i
-
1
);
//
previous
acceleration
Q
delta_f
=
u_i
(
1
,
i
-
1
);
//
previous
steering
angle
of
the
front
wheel
//
calculate
state
updates
and
update
function
Q
beta
=
arctan
(
l_r
/
(
l_f
+
l_r
)
*
tan
(
delta_f
));
Q
dx
=
v
*
cos
(
psi
+
beta
);
Q
dy
=
v
*
sin
(
psi
+
beta
);
Q
dpsi
=
v
/
l_r
*
sin
(
beta
);
Q
dv
=
a
;
//
update
function
Q
^{
4
}
update
=
[
x
+
dx
*
t_s
;
y
+
dy
*
t_s
;
psi
*
dpsi
*
t_s
;
v
+
dv
*
t_s
];
//
assign
next
predicted
state
z
(:,
i
)
=
update
;
end
//
define
cost
matrices
Q
^{
4
,
4
}
costQ
=
eye
(
4
,
4
);
Q
^{
2
,
2
}
costR
=
eye
(
2
,
2
);
Q
^{
2
,
2
}
costRBar
=
eye
(
2
,
2
);
//
minimization
statement
Q
error
=
minimize
(
Q
^{
2
,
3
}
u_i
)
(
sum
(((
z
(:,
i
)
-
z_ref
(:,
i
))
' * costQ * (z(:,i) - z_ref(:,i))), i, 0, h_p))
+ sum(((u_i(:,i) - u_i(:,i-1))'
*
costRBar
*
(
u_i
(:,
i
)
-
u_i
(:,
i
-
1
)
+
u_i
(:,
i
)
' * costR * u(:,i))), i, 2, h_p);
subject to
for j = 1:hp
u_min <= u_i(:,j) <= u_max;
end
for i = 2:hp
du_min <= u_i(:,i) - u_i(:,i-1) <= du_max;
end
end
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment