Skip to content

Commit

Permalink
category method implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaRB committed Sep 29, 2023
1 parent 7f211ab commit 059bf38
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
21 changes: 11 additions & 10 deletions resources/crml_tutorial/traffic_light/Spec.crml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
model Spec is ETL union FORM_L union {
model Spec is //ETL union FORM_L union
{
// Requirement model for the traffic light example

// Definition of Requirement type
Type Requirement is Boolean forbid { *, +, integrate };
// Definition of Requirement type
Type Requirement is Boolean ;//forbid { *, +, integrate };

// List of external variables
Boolean red is external;
Expand All @@ -11,19 +12,19 @@ model Spec is ETL union FORM_L union {

// Definition of requirements
// req1: "After green, next step is yellow"
Requirement req1 is
'after' (green 'becomes true') 'before' (yellow 'becomes true')
'check count' (red 'becomes true') '==' 0;
Requirement req1 is
"after" (green "becomes true") "before" (yellow "becomes true")
"check count" (red "becomes true") "==" 0;

// req2: "Step green should stay active for at least 30 seconds"
Requirement req2 is
'after' (green 'becomes true') 'for' 30
'ensure' green;
"after" (green "becomes true") "for" 30
"ensure" green;

// req3: "After green becomes active + 30 seconds,
// next step should turn yellow within 0.2 seconds"
Requirement req3 is
'after' (green 'becomes true' + 30) 'for' 0.2
'check' yellow;
"after" (green "becomes true" + 30) "for" 0.2
"check" yellow;

};
15 changes: 14 additions & 1 deletion resources/modelica_libraries/CRMLtoModelica.mo
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ package CRMLtoModelica
undecided,
false4,
true4) "4-valued logic" annotation (Icon(graphics = {Text(extent = {{-58, 48}, {76, -38}}, textString = "")}, coordinateSystem(extent = {{-100, -100}, {100, 100}})));

model CRMLEvent

Reat occurence_time;

Boolean occurence_condition;

end CRMLEvent;

model CRMLPeriod
equation

end CRMLPeriod;
end Types;


Expand Down Expand Up @@ -225,4 +238,4 @@ end Integrate;

end Blocks;

end CRMLtoModelica;
end CRMLtoModelica;
17 changes: 14 additions & 3 deletions src/main/java/crml/translator/Category.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package crml.translator;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class Category {

String name;
HashMap<String,String> operator_set;


public Category(String category_name, List<List<String>> operator_mapping) {
// TODO Auto-generated constructor stub
name = category_name;
Iterator<List<String>> it = operator_mapping.iterator();
while (it.hasNext())
operator_set.put(it.next().get(0), it.next().get(1));
}
String name;
HashMap<String,String> operator_set;

public String getMappedOperaotr(String original_op){
return operator_set.get(original_op);
}



}
2 changes: 1 addition & 1 deletion src/main/java/crml/translator/CategoryMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void addAssociation(String name, String category_name, List<List<String>>

List<Category> cs = categoryMap.get(name); // check if already present

Category nc = new Category(category_name, operator_mapping);
//Category nc = new Category(category_name, operator_mapping);

if (cs == null) {
cs = new Vector<Category>();
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/specDocExamples/TestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand Down Expand Up @@ -70,6 +72,21 @@ public static void tearDown() {
logCaptor.close();
}

@DisplayName("Traffic lights use-case test")
@Test
void testTraficLight () throws InterruptedException, IOException{
String filePath = "resources/crml_tutorial/traffic_light/";

// try compiling crml to modelica
try {

crml.translator.Main.parse_file(filePath, "Spec.crml", parameters.Values.generatedTestRepository+"/traffic", true, true);

} catch (Exception e) {
fail("Unable to translate " + "Traffic light example" + "to Modelica :\n" + e.getMessage());
}
}

@ParameterizedTest
@MethodSource("fileNameSource")
void test(final String fileName) throws InterruptedException, IOException {
Expand Down

0 comments on commit 059bf38

Please sign in to comment.