Browse Source

changed the language according to discussions and table4

Bart Meyers 4 years ago
parent
commit
7da4f42195
11 changed files with 58 additions and 51 deletions
  1. 2 0
      .gitignore
  2. 2 4
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/META-INF/MANIFEST.MF
  3. 15 14
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_algebraic_loop_iteration_BASE.sa
  4. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_controller_delay_BASE.sa
  5. 4 4
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/input/powerwindow_multi_rate_BASE.sa
  6. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/AbstractSemanticAdaptationParserTest.xtend
  7. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/AbstractSemanticAdaptationTest.xtend
  8. 1 1
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/SemanticAdaptationGeneratorTest.xtend
  9. 5 5
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/src/be/uantwerpen/ansymo/semanticadaptation/tests/SemanticAdaptationParsingTest.xtend
  10. 1 2
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/GenerateSemanticAdaptation.mwe2
  11. 25 18
      DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/SemanticAdaptation.xtext

+ 2 - 0
.gitignore

@@ -35,3 +35,5 @@ generated-sources/
 src-gen/
 xtend-gen/
 .DS_Store
+/DSL_SemanticAdaptation/copy.bat
+/DSL_SemanticAdaptation/copyfiles.bat

+ 2 - 4
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation.tests/META-INF/MANIFEST.MF

@@ -10,11 +10,9 @@ Require-Bundle: be.uantwerpen.ansymo.semanticadaptation,
  org.eclipse.xtext.junit4,
  org.eclipse.xtext.xbase.junit,
  org.eclipse.xtext.xbase.lib,
- org.eclipse.jdt.core,
- org.eclipse.xtext.testing,
- org.eclipse.xtext.xbase.testing
+ org.eclipse.jdt.core
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Export-Package: be.uantwerpen.ansymo.semanticadaptation.tests;x-internal=true
+Export-Package: be.uantwerpen.ansymo.semanticadaptation.tests
 Import-Package: org.hamcrest.core,
  org.junit;version="4.5.0",
  org.junit.runners.model;version="4.5.0",

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

@@ -33,26 +33,27 @@ control {
 	var converged := false;
 	var temp_height; // to compare new value with previous value
 	var temp_reaction_torque; // to compare new value with previous value
+	// from here on: taken from Claudio's example
+	var prev_height := window_sa.height;
+	var inner_time := t;
 	for (var iter in 0 .. MAXITER) {
-		if (converged) {
+		save_state(obstacle); // Inspired by transactions in databases.
+		save_state(window_sa);
+		do_step(obstacle, inner_time,h);
+		do_step(window_sa,inner_time,h);
+		
+		if (is_close(prev_height, height, REL_TOL, ABS_TOL)) {
 			break;
-		}
-		temp_height := height;
-		temp_reaction_torque := reaction_torque;
-		//local_step(power); // with delayed input for reaction_torque
-		//local_step(obstacle); // with delayed input for height
-		local_step(power);
-		local_step(obstacle);
-		local_step(window_sa);
-		//local_step(H, power, obstacle, window_sa); // acts like the Local master but cannot not advance time, so will always roll-back for safety (must be in one statements because a full step is done here), but how do we get the inner
-		if (is_close(temp_height, height, REL_TOL, ABS_TOL) and is_close(temp_reaction_torque, reaction_torque, REL_TOL, ABS_TOL)) { // todo: set tolerance
-			converged := true;
+		} else {
+			prev_height := height;
+			rollback(obstacle);
+			rollback(window_sa);
 		}
 	}
 	return H;
 }
 
-// this is the one for the paper
+/*// this is the one for the paper
 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
@@ -106,5 +107,5 @@ control {
 	}
 	return H;
 }
-
+*/
 

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

@@ -16,7 +16,7 @@ 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) {
-		step_size := do_step(controller, e+H); // do a step, then decide next internal transition
+		step_size := do_step(controller, t, e+H); // do a step, then decide next internal transition
 	}
 	return step_size;
 }

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

@@ -19,12 +19,12 @@ input ports motor_speed
 output ports reaction_torque
 param init_motor_speed := 0;
 control {
-	var h := H/10;
+	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;
+		var returned_h := do_step(window_obstacle_sa_loop, t, h_);
+		if (returned_h != h_) { // for backtracking
+			 proposed_h := iter*h_ + returned_h;
 		}
 	}
 	return proposed_h;

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

@@ -11,7 +11,7 @@ import org.eclipse.xtext.junit4.util.ParseHelper
 import org.junit.runner.RunWith
 
 @RunWith(XtextRunner)
-@org.eclipse.xtext.testing.InjectWith(SemanticAdaptationInjectorProvider)
+@InjectWith(SemanticAdaptationInjectorProvider)
 abstract class AbstractSemanticAdaptationParserTest extends AbstractSemanticAdaptationTest {
 
 	@Inject extension ParseHelper<SemanticAdaptation>

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

@@ -20,7 +20,7 @@ import java.io.File
 import org.eclipse.emf.ecore.resource.ResourceSet
 
 @RunWith(XtextRunner)
-@org.eclipse.xtext.testing.InjectWith(SemanticAdaptationInjectorProvider)
+@InjectWith(SemanticAdaptationInjectorProvider)
 abstract class AbstractSemanticAdaptationTest {
 	
 	ArrayList<Integer> visited = new ArrayList<Integer>

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

@@ -12,7 +12,7 @@ import org.eclipse.xtext.junit4.XtextRunner
 import java.io.File
 
 @RunWith(XtextRunner)
-@org.eclipse.xtext.testing.InjectWith(SemanticAdaptationInjectorProvider)
+@InjectWith(SemanticAdaptationInjectorProvider)
 class SemanticAdaptationGeneratorTest extends AbstractSemanticAdaptationTest{
 	
 	@Inject extension CompilationTestHelper

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

@@ -3,20 +3,20 @@
  */
 package be.uantwerpen.ansymo.semanticadaptation.tests
 
-import org.eclipse.xtext.testing.InjectWith
-import org.eclipse.xtext.testing.XtextRunner
+import org.eclipse.xtext.junit4.InjectWith
+import org.eclipse.xtext.junit4.XtextRunner
 import org.junit.Assert
 import org.junit.Test
 import org.junit.runner.RunWith
-import org.eclipse.xtext.testing.util.ParseHelper
+import org.eclipse.xtext.junit4.util.ParseHelper
 import com.google.inject.Inject
-import org.eclipse.xtext.testing.validation.ValidationTestHelper
+import org.eclipse.xtext.junit4.validation.ValidationTestHelper
 import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.*
 import org.eclipse.emf.ecore.EObject
 import java.util.regex.Pattern
 
 @RunWith(XtextRunner)
-@org.eclipse.xtext.testing.InjectWith(SemanticAdaptationInjectorProvider)
+@InjectWith(SemanticAdaptationInjectorProvider)
 class SemanticAdaptationParsingTest extends AbstractSemanticAdaptationTest{
 	
 	@Inject extension ParseHelper<SemanticAdaptation>

+ 1 - 2
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/GenerateSemanticAdaptation.mwe2

@@ -3,8 +3,7 @@ module be.uantwerpen.ansymo.semanticadaptation.GenerateSemanticAdaptation
 import org.eclipse.xtext.xtext.generator.*
 import org.eclipse.xtext.xtext.generator.model.project.*
 
-var runtimeProject = "../"
-var rootPath = "${runtimeProject}"
+var rootPath = ".."
 
 Workflow {
 	

+ 25 - 18
DSL_SemanticAdaptation/be.uantwerpen.ansymo.semanticadaptation/src/be/uantwerpen/ansymo/semanticadaptation/SemanticAdaptation.xtext

@@ -83,7 +83,7 @@ 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)*
+	{InnerFMUDeclarationFull} ( 'for' fmus+=InnerFMU )+ ('with' connection+=Connection)*
 ;
 
 GeneraleRule:
@@ -185,7 +185,13 @@ 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 ')' )? 
+	(('->' targetdependency+=SpecifiedPort)
+		| ('<-' sourcedependency+=SpecifiedPort)
+	)?;
 	// TODO: -> output port of wrapped FMU to output port of SA FMU (only used in SA!)
 
 Multiplicity:
@@ -237,11 +243,11 @@ BreakStatement:
 DeclaredParameter:
 	name=ID;
 	
-AbstractDeclaration: // can contain overlapping elements as long as it is only used as reference
-	Port | ParamDeclaration | Declaration | DeclaredParameter | FunctionDeclaration;
+//AbstractDeclaration: // can contain overlapping elements as long as it is only used as reference
+//	Port | ParamDeclaration | Declaration | DeclaredParameter | FunctionDeclaration;
 
 LValueDeclaration: // can contain overlapping elements as long as it is only used as reference
-	Port | ParamDeclaration | Declaration | DeclaredParameter; // TODO: fmu.port
+	Port | ParamDeclaration | Declaration | DeclaredParameter;
 
 Assignment:
 	lvalue=Variable ':=' expr=Expression; // TODO: to what can be assigned? only local vars?
@@ -343,23 +349,24 @@ BuiltinFunction:
 	{Min} name='min' '(' args+=ArithmeticExpression ',' args+=ArithmeticExpression ')' |
 	{Abs} name='abs' '(' args=ArithmeticExpression ')' |
 	{Close} name='is_close' '(' args+=ArithmeticExpression ',' args+=ArithmeticExpression ',' args+=ArithmeticExpression ',' args+=ArithmeticExpression ')' |  // a, b, relative tolerance, absolute tolerance 
-	{IsSet} name='is_set' '(' args=Variable ')' | 
-	{DoStepFun} name='do_step' '(' fmu=[FMU] ',' H=ArithmeticExpression ')' |
-	{GetState} name='get_state' '(' fmu=[FMU] ')' |
+	{IsSet} name='is_set' '(' args=Var ')' | 
+//	{DoStepFun} name='do_step' '(' fmu=[FMU] ',' t=ArithmeticExpression ',' h=ArithmeticExpression ')' |
 	{GetNextInternalTimeStep} name='get_next_time_step' '(' fmu=[FMU] ')' | // is actually the time step returned by do_step(fmu), preceded by get_state and succeeded by set_state
-	{Elapsed} name='elapsed' '(' fmu=[FMU] ')';
+	{Elapsed} name='elapsed' '(' fmu=[FMU] ')' |
+	{LastExecutionTime} name='last_execution_time' '(' fmu=[FMU] ')';
 	
 Procedure:
-	{Reject} name='reject' |
-	{Step} name='local_step' '(' fmu=[FMU] ')' |
-	{Discard} name='discard' '(' args=Variable ')' |
-	{DoStep} name='do_step' '(' fmu=[FMU] ',' H=ArithmeticExpression ')' |
-	{SetState} name='set_state' '(' fmu=[FMU] ',' state=Var ')'; // arg: new proposed step size
+	{Rollback} name='rollback' '(' fmu=[FMU] ')' |
+	{DoStep} name='do_step' '(' fmu=[FMU] ',' t=ArithmeticExpression ','  h=ArithmeticExpression ')' |
+	{Discard} name='discard' '(' args=Var ')' |
+	{SaveState} name='save_state' '(' fmu=[FMU] ')';
 	
 Var:
-	{StepSize} name='H' | 
-	{CurrentTime} name='t' |
-	{ElapsedTime} name='e' | // min (elapsed(fmu1), elapsed(fmu2), ...)
+	{StepSize} name='H' | // available in ctrl
+	{StepSize} name='h' | // available in mapin/mapout
+	{CurrentTime} name='t' | // available in ctrl
+	{PassedTime} name='dt' | // available in mapin/mapout
+	{ElapsedTime} name='e' | // available in ctrl
 	{Max} name='MAX' |
 	{GenericSignal} name='signal' ('[' (
 		index=NOW | 
@@ -371,7 +378,7 @@ Var:
 	FunctionCall; // add "directionalderivative"
 	
 Variable:
-	ref=[LValueDeclaration] ('[' (
+	(owner=[FMU] '.' ref=[Port]) | (ref=[LValueDeclaration]) ('[' (
 		index=NOW | 
 		index=PREV | 
 		index=INTTYPE |