Explorar o código

changed grammar according to skype call

updated ....tests/input/powerwindow*.sa files so that all tests succeed
These tests may have to be updated semantically.
Bart Meyers %!s(int64=8) %!d(string=hai) anos
pai
achega
5a700241a6
Modificáronse 18 ficheiros con 292 adicións e 98 borrados
  1. 10 0
      .gitignore
  2. 61 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/controller_sa.sa
  3. 10 8
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow.sa
  4. 2 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_algebraic_loop_delay.sa
  5. 7 5
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_algebraic_loop_delay_BASE.sa
  6. 4 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_algebraic_loop_iteration.sa
  7. 18 14
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_algebraic_loop_iteration_BASE.sa
  8. 5 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_controller_delay.sa
  9. 11 10
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_controller_delay_BASE.sa
  10. 58 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_inline.sa
  11. 12 17
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_model_only.sa
  12. 2 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_multi_rate.sa
  13. 7 4
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_multi_rate_BASE.sa
  14. 26 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/window_obstacle_sa_multirate_BASE_new.sa
  15. 1 0
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/SemanticAdaptationParsingTest.xtend
  16. 52 27
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/SemanticAdaptation.xtext
  17. 3 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/generator/SemanticAdaptationPythonGenerator.xtend
  18. 3 3
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/scoping/SemanticAdaptationScopeProvider.xtend

+ 10 - 0
.gitignore

@@ -9,3 +9,13 @@
 /SemanticAdaptationForFMI/FMIAbstraction/src/master/*.pyc
 /DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/.antlr-generator-3.2.0-patch.jar
 /SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/fmu/cs/log_statemachine.txt
+/DSL_SemanticAdaptation/copy.cmd
+/DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/model/generated/SemanticAdaptation.ecore
+/DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/model/generated/SemanticAdaptation.genmodel
+/SemanticAdaptationForFMI/Experiments/hierarchical_fmu/fmu20/src/models/mass_spring_damper_hierarchical/Thumbs.db
+/SemanticAdaptationForFMI/Experiments/hierarchical_fmu/doc/Thumbs.db
+/SemanticAdaptationForFMI/Experiments/power_window_case_study/fmu20/src/co_simulation/vc100.pdb
+/SemanticAdaptationForFMI/FMIAbstraction/src/results.html
+/SemanticAdaptationForFMI/FMIAbstraction/src/results_F.html
+/SemanticAdaptationForFMI/FMIAbstraction/src/results_x.html
+/SemanticAdaptationForFMI/FMIAbstraction/src/case_study/scenarios/setpythonpath.cmd

+ 61 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/controller_sa.sa

@@ -0,0 +1,61 @@
+import PowerWindowModel
+
+module Controller_SA
+
+semantic adaptation controller_sa
+for fmu controller
+input ports armature_current -> obj_detected, passenger_up, passenger_down, driver_up, driver_down
+output ports up, down
+param REL_TOL = 0.0001;
+param ABS_TOL = 1e-8;
+param CROSSING = 5;
+param init_armature_current = CROSSING;
+param init_up = 0;
+param init_down = 0;
+control var internal_transition;
+control rules { // overwriting master! What to do in case of roll back? How to reuse generic algorithm
+	if (not is_set(internal_transition)) { // only at start of simulation
+		var state := get_state(controller);
+		internal_transition := do_step(controller, MAX) + t; // may return internal transition time or MAX
+		set_state(controller, state);
+	}
+	var step_size; // may be used to determine roll-back
+	if (signal == true or t >= internal_transition) {
+		step_size := do_step(controller, H); // do a step, then decide next internal transition
+		var state := get_state(controller);
+		internal_transition := do_step(controller, MAX) + t;
+		set_state(controller, state);
+	}
+	return step_size;
+}
+in var stored_armature_current := init_armature_current;
+in rules {
+	true -> {
+		obj_detected := false;
+		if (not (not is_close(stored_armature_current, CROSSING, REL_TOL, ABS_TOL) and stored_armature_current > CROSSING)
+					and (not is_close(armature_current, CROSSING, REL_TOL, ABS_TOL) and armature_current > CROSSING)) { // crossing, but not within tolerance
+			var negative_value := stored_armature_current - CROSSING;
+			var positive_value := armature_current - CROSSING;
+			var new_step_size := (H * (- negative_value)) / (positive_value - negative_value);
+			discard(new_step_size);
+		} else {
+			if (not (not is_close(stored_armature_current, CROSSING, REL_TOL, ABS_TOL) and stored_armature_current > CROSSING)
+						and is_close(armature_current, CROSSING, REL_TOL, ABS_TOL)) { // crossing within tolerance found
+				obj_detected := true;
+			}
+		}
+		stored_armature_current := armature_current;
+	} --> { };
+}
+out var stored_up := init_up;
+out var stored_down := init_down;
+out rules {
+	up == true -> { up := 1; } --> { };
+	otherwise up -> { } --> { };
+	down == true -> { down := 1; } --> { };
+	otherwise down -> { } --> { };
+	stop == true -> { up := 0; down := 0; } --> { };
+	otherwise stop -> { } --> { };
+	true -> { up := stored_up; stored_up := up; } --> { };
+	true -> { down := stored_down; stored_down := down; } --> { }; 
+}

+ 10 - 8
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow.sa

@@ -1,13 +1,12 @@
 import PowerWindowModel
 
-semantic adaptation controller_sa
+semantic adaptation ArmatureCurrentSA armature_current_sa
+at "./path/to/ArmatureCurrentSA.fmu"
 for fmu controller
-input ports armature_current -> obj_detected, passenger_up, passenger_down, driver_up, driver_down, next
-output ports up, down
-triggered by signal == true or t >= get_next_time_step(controller)
+triggered by signal == true
 in rules with crossing absolute tolerance = 1e-8 and relative tolerance = 0.0001, no hold {
 	armature_current >! 5 -> obj_detected := true;
-	otherwise(armature_current) -> obj_detected := false;
+	otherwise -> obj_detected := false;
 }
 out rules with zero order hold {
 	"up" -> up := 1;
@@ -16,17 +15,20 @@ out rules with zero order hold {
 	delay at up and down;
 }
 
-semantic adaptation window_sa
+semantic adaptation WindowSA window_sa
+at "./path/to/WindowSA.fmu"
 for fmu window
 out rules {
 	reaction_torque := -reaction_torque;
 }
 
-semantic adaptation window_obstacle_sa
+semantic adaptation WindowObstacleSA window_obstacle_sa
+at "./path/to/WindowObstacleSA.fmu"
 for fmu window_sa, obstacle
 multiply rate 10 times with first order interpolation
 successive substitution starts at height with absolute tolerance = 1e-8 and relative tolerance = 0.0001
 
-semantic adaptation plant_sa
+semantic adaptation PlantSA plant_sa
+at "./path/to/PlantSA.fmu"
 for fmu power, window_obstacle_sa
 successive substitution starts at reaction_torque with absolute tolerance = 1e-6 and relative tolerance = 1e-6

+ 2 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_algebraic_loop_delay.sa

@@ -4,7 +4,8 @@ import Controller_SA
 module Algebraic_Loop_SA
 
 // this one could be joined with the one below, if we assume certain priorities in executing the rules
-semantic adaptation window_sa
+semantic adaptation WindowSA window_sa
+at "./path/to/WindowSA.fmu"
 for fmu window
 out rules {
 	reaction_torque := -reaction_torque;

+ 7 - 5
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_algebraic_loop_delay_BASE.sa

@@ -2,17 +2,19 @@ import PowerWindowModel
 import Controller_SA
 
 // this one could be joined with the one below, if we assume certain priorities in executing the rules
-semantic adaptation window_sa
+semantic adaptation WindowSA window_sa
+at "./path/to/WindowSA.fmu"
 for fmu window
 out rules {
-	true -> {reaction_torque := -reaction_torque; } --> { };
+	true -> { } --> { reaction_torque := -reaction_torque; };
 }
 
 // algebraic loop, simply use delay... written in baseDSL
-semantic adaptation window_sa_delay //with master
+semantic adaptation WindowSADelay window_sa_delay //with master
+at "./path/to/WindowSADelay.fmu"
 for fmu window_sa // inner SA, makes it possible to enforce order among adaptations this way
-param init_height = 0;
-param init_reaction_torque = 0;
+param init_height := 0;
+param init_reaction_torque := 0;
 out var stored_height := init_height;
 out var stored_reaction_torque := init_reaction_torque;
 out rules {

+ 4 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_algebraic_loop_iteration.sa

@@ -2,14 +2,16 @@ import PowerWindowModel
 import Controller_SA
 
 // this one could be joined with the one below, if we assume certain priorities in executing the rules
-semantic adaptation window_sa
+semantic adaptation WindowSA window_sa
+at "./path/to/WindowSA.fmu"
 for fmu window
 out rules {
 	reaction_torque := -reaction_torque;
 }
 
 // algebraic loop
-semantic adaptation power_window_obstacle_sa
+semantic adaptation PowerWindowObstacleSA power_window_obstacle_sa
+at "./path/to/PowerWindowObstacleSA.fmu"
 for fmu power, window_sa, obstacle
 input ports up, down // optional, can be figured out from model
 output ports armature_current // optional, can be figured out from model

+ 18 - 14
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_algebraic_loop_iteration_BASE.sa

@@ -2,21 +2,23 @@ import PowerWindowModel
 import Controller_SA
 
 // this one could be joined with the one below, if we assume certain priorities in executing the rules
-semantic adaptation window_sa
+semantic adaptation WindowSA window_sa
+at "./path/to/WindowSA.fmu"
 for fmu window
 out rules {
-	true -> {reaction_torque := -reaction_torque; } --> { };
+	true -> { } --> { reaction_torque := -reaction_torque; };
 }
 
 // algebraic loop
-semantic adaptation power_window_obstacle_sa // without master -> not necessary: custom control rules override master
+semantic adaptation PowerWindowObstacleSA power_window_obstacle_sa // without master -> not necessary: custom control rules override master
+at "./path/to/PowerWindowObstacleSA.fmu"
 for fmu power, window_sa, obstacle
 input ports up, down
 output ports armature_current
 //algebraic loop fix point iteration at reaction_torque and height with absolute tolerance = 1e-8 and relative tolerance = 0.0001
-param MAXITER = 100;
-param REL_TOL = 1e-8;
-param ABS_TOL = 1e-8;
+param MAXITER := 100;
+param REL_TOL := 1e-8;
+param ABS_TOL := 1e-8;
 control {
 	// do_step will always use the last values, do_step does not advance time so will replace the last signal values! 
 	// therefore, we must set the signal at time t+h of reaction_torque and height
@@ -51,13 +53,14 @@ control {
 }
 
 // this is the one for the paper
-semantic adaptation window_obstacle_sa_loop// overrides master -> not necessary: custom control rules override master
+semantic adaptation WindowObstacleSALoop window_obstacle_sa_loop// overrides master -> not necessary: custom control rules override master
+at "./path/to/WindowObstacleSALoop.fmu"
 for fmu window_sa, obstacle
 input ports motor_speed
 output ports reaction_torque
-param MAXITER = 100;
-param REL_TOL = 1e-8;
-param ABS_TOL = 1e-8;
+param MAXITER := 100;
+param REL_TOL := 1e-8;
+param ABS_TOL := 1e-8;
 control {
 	var prev_height; // to compare new value with previous value
 	var window_state;
@@ -76,13 +79,14 @@ control {
 }
 
 // other version without local_step
-semantic adaptation window_obstacle_sa_loop2// overrides master -> not necessary: custom control rules override master
+semantic adaptation WindowObstacleSALoop2 window_obstacle_sa_loop2// overrides master -> not necessary: custom control rules override master
+at "./path/to/WindowObstacleSALoop2.fmu"
 for fmu window_sa, obstacle
 input ports motor_speed
 output ports reaction_torque
-param MAXITER = 100;
-param REL_TOL = 1e-8;
-param ABS_TOL = 1e-8;
+param MAXITER := 100;
+param REL_TOL := 1e-8;
+param ABS_TOL := 1e-8;
 control {
 	var prev_height; // to compare new value with previous value
 	var window_state;

+ 5 - 3
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_controller_delay.sa

@@ -2,15 +2,17 @@ import PowerWindowModel
 
 module Controller_SA
 
-semantic adaptation armature_current_sa
+semantic adaptation ArmatureCurrentSA armature_current_sa
+at "./path/to/ArmatureCurrentSA.fmu"
 for fmu controller
 triggered by signal == true
 in rules with crossing absolute tolerance = 1e-8 and relative tolerance = 0.0001, no hold {
 	armature_current >! 5 -> obj_detected := true;
-	otherwise(armature_current) -> obj_detected := false;
+	otherwise -> obj_detected := false;
 }
 
-semantic adaptation in_out_sa
+semantic adaptation InOutSA in_out_sa
+at "./path/to/InOutSA.fmu"
 for fmu controller
 out rules with zero order hold {
 	"up" -> up := 1;

+ 11 - 10
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_controller_delay_BASE.sa

@@ -2,16 +2,17 @@ import PowerWindowModel
 
 module Controller_SA
 
-semantic adaptation controller_sa
+semantic adaptation ControllerSA controller_sa
+at "./path/to/ControllerSA.fmu"
 for fmu controller
 input ports armature_current -> obj_detected, passenger_up, passenger_down, driver_up, driver_down
 output ports up, down
-param REL_TOL = 0.0001;
-param ABS_TOL = 1e-8;
-param CROSSING = 5;
-param init_armature_current = CROSSING;
-param init_up = 0;
-param init_down = 0;
+param REL_TOL := 0.0001;
+param ABS_TOL := 1e-8;
+param CROSSING := 5;
+param init_armature_current := CROSSING;
+param init_up := 0;
+param init_down := 0;
 control { // overwriting master! What to do in case of roll back? How to reuse generic algorithm
 	var step_size; // may be used to determine roll-back
 	if (signal == true or t >= internal_transition) {
@@ -46,11 +47,11 @@ out var stored_down := init_down;
 out rules {
 	true -> { internal_transition := get_next_time_step(controller) + t; } --> {};
 	up == true -> { up := 1; } --> { };
-	otherwise up -> { } --> { };
+	up == false -> { } --> { };
 	down == true -> { down := 1; } --> { };
-	otherwise down -> { } --> { };
+	down == false -> { } --> { };
 	stop == true -> { up := 0; down := 0; } --> { };
-	otherwise stop -> { } --> { };
+	stop == false -> { } --> { };
 	true -> { up := stored_up; stored_up := up; } --> { };
 	true -> { down := stored_down; stored_down := down; } --> { }; 
 }

+ 58 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_inline.sa

@@ -0,0 +1,58 @@
+module PowerWindowModel
+
+fmu Environment environment
+at "./path/to/Environment.fmu"
+output ports passenger_up, passenger_down, driver_up, driver_down
+
+semantic adaptation ControllerSA controller_sa
+at "./path/to/ControllerSA.fmu"
+for inner fmu Controller controller
+	at "./path/to/Controller.fmu"
+	with input ports obj_detected, passenger_up, passenger_down, driver_up, driver_down
+	with output ports up, down, stop
+input ports armature_current -> obj_detected, passenger_up, passenger_down, driver_up, driver_down
+triggered by signal == true
+in rules with crossing absolute tolerance = 1e-8 and relative tolerance = 0.0001, no hold {
+	armature_current >! 5 -> obj_detected := true;
+	otherwise -> obj_detected := false;
+}
+out rules with zero order hold {
+	"up" -> up := 1;
+	"stop" -> { up := 0; down := 0; };
+	"down" -> down := 1;
+	delay at up and down;
+}
+
+semantic adaptation WindowSA window_sa
+at "./path/to/WindowSA.fmu"
+for inner fmu Window window
+	at "./path/to/Window.fmu"
+	with input ports motor_speed (m/s), reaction_force (N)
+	with output ports height (cm), reaction_torque (N.m)
+out rules {
+	reaction_torque := -reaction_torque;
+}
+
+semantic adaptation WindowObstacleSA window_obstacle_sa
+at "./path/to/WindowObstacleSA.fmu"
+for inner fmu WindowSA window_sa
+	with input ports motor_speed (m/s), reaction_force (N)
+	with output ports height (cm), reaction_torque (N.m)
+for inner fmu Obstacle obstacle
+	at "./path/to/Obstacle.fmu"
+	with input ports height (m)
+	with output ports reaction_force (N)
+multiply rate 10 times with first order interpolation
+successive substitution starts at height with absolute tolerance = 1e-8 and relative tolerance = 0.0001
+
+semantic adaptation PlantSA plant_sa
+at "./path/to/PlantSA.fmu"
+for inner fmu Power power
+	at "./path/to/Power.fmu"
+	with input ports up, down, reaction_torque (N.m)
+	with output ports armature_current (mA), motor_speed (m/s)
+for inner fmu WindowSA window_sa
+	with input ports motor_speed (m/s), reaction_force (N)
+	with output ports height (cm), reaction_torque (N.m)
+successive substitution starts at reaction_torque with absolute tolerance = 1e-6 and relative tolerance = 1e-6
+

+ 12 - 17
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_model_only.sa

@@ -1,32 +1,27 @@
 module PowerWindowModel
 
-fmu environment
-type discrete event
+fmu Environment environment
+at "./path/to/Environment.fmu"
 output ports passenger_up, passenger_down, driver_up, driver_down
-full internal dependencies
 
-fmu controller
-type discrete event
+fmu Controller controller
+at "./path/to/Controller.fmu"
 input ports obj_detected, passenger_up, passenger_down, driver_up, driver_down
 output ports up, down, stop
-full internal dependencies
 
-fmu power
-type continuous time
+fmu Power power
+at "./path/to/Power.fmu"
 input ports up, down, reaction_torque (N.m)
 output ports armature_current (mA), motor_speed (m/s)
-full internal dependencies
 
-fmu window
-type continuous time
+fmu Window window
+at "./path/to/Window.fmu"
 input ports motor_speed (m/s), reaction_force (N)
-output ports height (cm), window_reaction_torque (N.m)
-full internal dependencies
+output ports height (cm), reaction_torque (N.m)
 
-fmu obstacle
-type continuous time
+fmu Obstacle obstacle
+at "./path/to/Obstacle.fmu"
 input ports height (m)
 output ports reaction_force (N)
-full internal dependencies
 
-armature_current -> obj_detected // only ports that change names need to be connected
+power.armature_current -> controller.obj_detected

+ 2 - 1
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_multi_rate.sa

@@ -3,7 +3,8 @@ import Controller_SA
 import Algebraic_Loop_SA
 
 // multi-rate for window and object
-semantic adaptation window_obstacle_sa
+semantic adaptation WindowObstacleSA window_obstacle_sa
+at "./path/to/WindowObstacleSA.fmu"
 for fmu window_sa, obstacle
 multiply rate 10 times with first order interpolation
 successive substitution starts at height with absolute tolerance = 1e-8 and relative tolerance = 0.0001

+ 7 - 4
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_multi_rate_BASE.sa

@@ -1,20 +1,23 @@
 import PowerWindowModel
 
-semantic adaptation window_sa
+semantic adaptation WindowSA window_sa
+at "./path/to/WindowSA.fmu"
 for fmu window
 out rules {
 	true -> { } --> { reaction_torque := -reaction_torque; };
 }
 
-semantic adaptation window_obstacle_sa_loop
+semantic adaptation WindowObstacleSALoop window_obstacle_sa_loop
+at "./path/to/WindowObstacleSALoop.fmu"
 for fmu window_sa, obstacle
 // just for the sake of declaring this, look at algebraic loop iteration
 
-semantic adaptation window_obstacle_sa_multirate //with master // multi-rate for window and object
+semantic adaptation WindowObstacleSAMultirate window_obstacle_sa_multirate //with master // multi-rate for window and object
+at "./path/to/WindowObstacleSAMultirate.fmu"
 for fmu window_obstacle_sa_loop
 input ports motor_speed
 output ports reaction_torque
-param init_motor_speed = 0;
+param init_motor_speed := 0;
 control {
 	var h := H/10;
 	var proposed_h := H;

+ 26 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/window_obstacle_sa_multirate_BASE_new.sa

@@ -0,0 +1,26 @@
+semantic adaptation window_obstacle_sa_multirate
+for fmu window_obstacle_sa_loop
+input ports motor_speed
+output ports reaction_torque
+param init_motor_speed = 0;
+control rules {
+	var h := H/10;
+	var proposed_h := H;
+	for (var iter in 0 .. 10) {
+		var returned_h := do_step(window_obstacle_sa_loop, h);
+		if (returned_h != h) { // for backtracking
+			 proposed_h := iter*h + returned_h;
+		}
+	}
+	return proposed_h;
+}
+in var stored_motor_speed := init_motor_speed;
+in var linear_increment;
+in rules {
+	true -> {
+		linear_increment := (motor_speed - stored_motor_speed) / 10;
+		stored_motor_speed := motor_speed;
+	} --> {
+		motor_speed := motor_speed + linear_increment;
+	};
+}

+ 1 - 0
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/SemanticAdaptationParsingTest.xtend

@@ -45,6 +45,7 @@ class SemanticAdaptationParsingTest extends AbstractSemanticAdaptationTest{
 	@Test def powerwindow_multi_rate() { __parseNoErrors('input/powerwindow_multi_rate.sa') }
 	@Test def powerwindow_multi_rate_BASE() { __parseNoErrors('input/powerwindow_multi_rate_BASE.sa') }
 	@Test def powerwindow() { __parseNoErrors('input/powerwindow.sa') }
+	@Test def powerwindow_inline() { __parseNoErrors('input/powerwindow_inline.sa') }
 	
 	def __parseNoErrors(String filename) {
 		val root = __parse(filename)

+ 52 - 27
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/SemanticAdaptation.xtext

@@ -12,35 +12,48 @@ Import:
 	'import' module=[SemanticAdaptation];
 	
 Component:
-	FMU | Connection;
+	GlobalFMU | Connection;
 
 Connection:
-	src=[SpecifiedPort] '->' tgt=[SpecifiedPort];
+	src=SpecifiedPort '->' tgt=SpecifiedPort;
 
-FMU:
+GlobalFMU:
 	AtomicFMU | CompositeFMU | Adaptation;
 
+FMU:
+	AtomicFMU | InnerFMU | CompositeFMU | Adaptation;
+
 AtomicFMU:
-	'fmu' name=ID
-	('type' type=ModelType)?
-	('input' 'ports' inports+=Port ("," inports+=Port)*)?
+	'fmu' type=FMUType name=ID
+	//('type' type=ModelType)?
+	'at' path=STRING // to be found here
+	('input' 'ports' inports+=Port ("," inports+=Port)* )?
 	('output' 'ports' outports+=Port ("," outports+=Port)* )?
-	('full' 'internal' 'dependencies')?
+	//('full' 'internal' 'dependencies')? // not needed but extracted from the FMU (at-clause)
 	;
 
+InnerFMU: // slightly different syntax
+	'inner' 'fmu' type=FMUType name=ID
+	('at' path=STRING)? // optional in case of a semantic adaptation, where we still want to specify the ports
+	('with' 'input' 'ports' inports+=Port ("," inports+=Port)* )?
+	('with' 'output' 'ports' outports+=Port ("," outports+=Port)* )?
+	;
+	
 CompositeFMU:
-	'fmu' name=ID
+	'fmu' type=FMUType name=ID
+	'at' path=STRING // to be generated here
 	'composed' 'of' instances+=[FMU] (',' instances+=[FMU])*
 	('input' 'ports' inports+=Port ("," inports+=Port)*)?
 	('output' 'ports' outports+=Port ("," outports+=Port)* )?;
 
 Adaptation:
-	({Adaptation} 'semantic' 'adaptation' name=ID | 
-	{AdaptationWithSpecificMaster} 'semantic' 'adaptation' name=ID 'without' 'master')
-	/*'for' type=ModelType*/ ('for' ('fmu' instances+=[FMU] (',' instances+=[FMU])* /*| 'signal' ports+=[SpecifiedPort] (',' ports+=[SpecifiedPort])**/) )? // only multiple instances in case of CT because we only have CT master?
+	({Adaptation} 'semantic' 'adaptation' (reactiveness=ReactiveOrDelayed)? (machine=MooreOrMealy)? type=FMUType (name=ID)? | // this is a type or a name?
+	{AdaptationWithSpecificMaster} 'semantic' 'adaptation' (reactiveness=ReactiveOrDelayed)? (machine=MooreOrMealy)? type=FMUType (name=ID)? 'without' 'master')
+	'at' path=STRING // to be generated here
+	inner=InnerFMUDeclaration
 	('input' 'ports' inports+=Port ("," inports+=Port)*)? // only in case of instance-specific SA
 	('output' 'ports' outports+=Port ("," outports+=Port)* )? // only in case of instance-specific SA
-	('param' params+=ParamDeclaration)*
+	(params+=ParamDeclaration)*
 //	(globalvars+=Declaration)*
 	// algebraic loop generates an FMU encapsulating the loop
 	// note that the order of semantic adaptations is prefixed in case of a algebraic loop:
@@ -51,6 +64,15 @@ Adaptation:
 	(out=OutRulesBlock)?
 //	('contains' '{' adaptations+=Adaptation+ '}')? // I prefer no structural information here, this belongs to a graphical model
 	;
+
+enum ReactiveOrDelayed:
+	REACTIVE='reactive' | DELAYED='delayed';
+
+enum MooreOrMealy:
+	MOORE='moore' | MEALY='mealy';
+
+FMUType:
+	name=ID; // TODO: maybe better to declare types and 
 	
 ModelType: DE | UT | CT | DT;
 	
@@ -59,12 +81,17 @@ UT: 'UT' | 'ut' | 'Untimed' | 'untimed';
 CT: 'CT' | 'ct' | 'ContinuousTime' | 'Continuous' 'Time' | 'continuous' 'time';
 DT: 'DT' | 'dt' | 'DiscreteTime' | 'Discrete' 'Time' | 'discrete' 'time';
 
+InnerFMUDeclaration:
+	/*'for' type=ModelType*/ {InnerFMUDeclarationList} 'for' ('fmu' instances+=[FMU] (',' instances+=[FMU])* /*| 'signal' ports+=SpecifiedPort (',' ports+=SpecifiedPort)**/) | // only multiple instances in case of CT because we only have CT master?
+	{InnerFMUDeclarationFull} ( 'for' fmus+=InnerFMU )+ (connection+=Connection)*
+;
+
 GeneraleRule:
 	AlgebraicLoopSolution | MultiRate | Derivative;
 
 AlgebraicLoopSolution:
-	{AlgebraicLoopSolutionFixPointIteration} 'successive' 'substitution' 'starts' 'at' signals+=[SpecifiedPort] (('and'|',') signals+=[SpecifiedPort])? 'with' params+=SettingAssignment ('and' params+=SettingAssignment)* | 
-	{AlgebraicLoopSolutionDelayIntroduction} 'delay' 'at' signals+=[SpecifiedPort] (('and'|',') signals+=[SpecifiedPort])?; // TODO: must be in in or out rule
+	{AlgebraicLoopSolutionFixPointIteration} 'successive' 'substitution' 'starts' 'at' signals+=SpecifiedPort (('and'|',') signals+=SpecifiedPort)? 'with' params+=SettingAssignment ('and' params+=SettingAssignment)* | 
+	{AlgebraicLoopSolutionDelayIntroduction} 'delay' 'at' signals+=SpecifiedPort (('and'|',') signals+=SpecifiedPort)?; // TODO: must be in in or out rule
 	
 MultiRate:
 	'multiply' 'rate' rate=INT 'times' ('with' interpolation=Interpolation)?; // default first order interpolation
@@ -90,7 +117,7 @@ OutRulesBlock:
 	{OutRulesBlock} ('out' globalvars+=Declaration)* 'out' 'rules' ('with' setting+=GeneralSetting (',' setting+=GeneralSetting)*)? '{' iterationvars+=Declaration* rules+=DataRule* '}';
 
 ControlRuleBlock:
-	/*('control' globalvars+=Declaration)**/ ControlRule; // TODO: multiple rules or just one?
+	('control' globalvars+=Declaration)* rule=ControlRule; // TODO: multiple rules or just one?
 
 DataRule: // condition -> state transition --> output function
 	(((condition=RuleCondition "->" statetransitionfunction=StateTransitionFunction) | ConditionStateTransition | ConditionLessRule) ("-->" outputfunction=OutputFunction)? | AlgebraicLoopSolution) ';';
@@ -128,9 +155,9 @@ ConditionStateTransition:
 	quantization=Quantize;
 
 Quantize returns ConditionStoreStrategy:
-	{FiniteQuantize} 'quantize' '(' signal=[SpecifiedPort] ',' zones+=StringLiteral (',' boundaries+=ArithmeticExpression ',' zones+=StringLiteral)* ')' |
-	{FunctionQuantize} 'quantize' '(' signal=[SpecifiedPort] ',' '=' function=ArithmeticExpression ')' |
-	{LinearQuantize} 'quantize' signal=[SpecifiedPort] 'every' steps=ArithmeticExpression ('with'? 'offset' offset=ArithmeticExpression)?;
+	{FiniteQuantize} 'quantize' '(' signal=SpecifiedPort ',' zones+=StringLiteral (',' boundaries+=ArithmeticExpression ',' zones+=StringLiteral)* ')' |
+	{FunctionQuantize} 'quantize' '(' signal=SpecifiedPort ',' '=' function=ArithmeticExpression ')' |
+	{LinearQuantize} 'quantize' signal=SpecifiedPort 'every' steps=ArithmeticExpression ('with'? 'offset' offset=ArithmeticExpression)?;
 	
 OutputFunction:
 	{NoHold} 'no' 'hold' |
@@ -151,17 +178,14 @@ AnonymousFunction: // has access to ports
 	{FunctionBody} '{' statements+=Statement* returnstatement=ReturnStatement '}' |  // should return something
 	FunctionDeclaration; // TODO: should return something
 	
-/*[SpecifiedPort]: // if ports need owners
-	port=[Port] |
-	{Output[SpecifiedPort]} owner=[FMU] '.' port=[Port] | 
-	{Input[SpecifiedPort]} owner=[FMU] '<-' port=[Port];*/
-SpecifiedPort: Port;
+SpecifiedPort: // if ports need owners
+	(owner=[FMU] '.' )? port=[Port];
 
 Port:
 	// TODO: add initial values to ports (to do 1st, 2nd, ... order stuff)
 	// TODO: add internal destination/source of port
 	// Unity conversions: https://pint.readthedocs.io/en/0.7.2/
-	name=ID (':=' initval=LiteralOrArray)? ( multiplicity=Multiplicity )? ( '(' unity=Unity ')' )? ('->' target=[SpecifiedPort] | '-->' dependency+=[SpecifiedPort] (dependency+=[SpecifiedPort])*)?;
+	name=ID (':=' initval=LiteralOrArray)? ( multiplicity=Multiplicity )? ( '(' unity=Unity ')' )? ('->' target=SpecifiedPort | '-->' dependency+=SpecifiedPort (dependency+=SpecifiedPort)*)?;
 	// TODO: -> output port of wrapped FMU to output port of SA FMU (only used in SA!)
 
 Multiplicity:
@@ -202,7 +226,7 @@ Declaration:
 	'var' name=ID (':=' expr=Expression)? ';';
 
 ParamDeclaration:
-	name=ID '=' expr=Expression ';';
+	'param' name=ID ':=' expr=Expression ';';
 
 ReturnStatement:
 	'return' Expression ';';
@@ -260,8 +284,9 @@ CrossesFromAboveExpression returns Expression:
 	BooleanFunction ({CrossesFromAbove.left=current} '<!' right=BooleanFunction)?;
 	
 BooleanFunction returns Expression:
-	{Otherwise} 'otherwise' '(' ref=[SpecifiedPort] ')' |
-	{Otherwise} 'otherwise' ref=[SpecifiedPort] |
+	//{Otherwise} 'otherwise' '(' ref=SpecifiedPort ')' |
+	//{Otherwise} 'otherwise' ref=SpecifiedPort | // AMBIGUOUS!
+	{Otherwise} 'otherwise' |
 	ArithmeticExpression;
 
 ArithmeticExpression returns Expression:

+ 3 - 3
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/generator/SemanticAdaptationPythonGenerator.xtend

@@ -31,12 +31,12 @@ import logging
 
 from abstract_units.AbstractSimulationUnit import AbstractSimulationUnit, \
     STEP_ACCEPT
-«FOR fmu:a.instances.filter(AtomicFMU)»
/*FOR fmu:a.inner.instances.filter(AtomicFMU)»
 from case_study.units.ct_based.«fmu.name» import «fmu.name»
 «ENDFOR»
-«FOR i:a.instances.filter(Adaptation)»
+«FOR i:a.inner.instances.filter(Adaptation)»
 NOT YET IMPLEMENTED
-«ENDFOR»
+«ENDFOR*/»
 
 l = logging.getLogger()
 

+ 3 - 3
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/scoping/SemanticAdaptationScopeProvider.xtend

@@ -105,9 +105,9 @@ class SemanticAdaptationScopeProvider extends AbstractDeclarativeScopeProvider
 		return __getImportedScope(context, r)
 	}
 	
-	def scope_Step_fmu(Step context, EReference r) {
-		return Scopes.scopeFor(EcoreUtil2.getContainerOfType(context, Adaptation).instances, IScope.NULLSCOPE)
-	}
+	/*def scope_Step_fmu(Step context, EReference r) {
+		return Scopes.scopeFor(EcoreUtil2.getContainerOfType(context, Adaptation).inner.instances, IScope.NULLSCOPE)
+	}*/
 	
 	/*def EObject __getAncestorOfType(EObject object, Class<?> type) { // same as EcoreUtil2.getContainerOfType
 		val parent = object.eContainer