Browse Source

Add simple constraint for integers in the metamodel

Yentl Van Tendeloo 9 years ago
parent
commit
a361c36714
3 changed files with 13 additions and 4 deletions
  1. 10 0
      bootstrap/metamodels.alc
  2. 2 4
      bootstrap/modelling.alc
  3. 1 0
      interface/HUTN/includes/modelling.alh

+ 10 - 0
bootstrap/metamodels.alc

@@ -4,6 +4,12 @@ include "library.alh"
 include "conformance_scd.alh"
 include "modelling.alh"
 
+Element function constraint_integer(model : Element, name : String):
+	if (is_physical_int(model["model"][name])):
+		return "OK"
+	else:
+		return "Integer has non-integer instance"
+
 Element function create_metamodels():
 	if (bool_not(dict_in(dict_read(read_root(), "__hierarchy"), "models"))):
 		Element scd
@@ -147,6 +153,10 @@ Element function create_metamodels():
 		instantiate_attribute(pn, "T2P_weight", "target_lower_cardinality", 1)
 		instantiate_attribute(pn, "T2P_weight", "target_upper_cardinality", 1)
 
+		// Add constraint on the Integer
+		add_constraint(pn, "Integer", constraint_integer)
+
+		// Add global constraints
 		set_model_constraints(pn, petrinet_constraints)
 		export_node("models/PetriNets", pn)
 

+ 2 - 4
bootstrap/modelling.alc

@@ -348,14 +348,12 @@ String function add_AL(model : Element, element : Element):
 
 	return reverseKeyLookup(model["model"], element)
 
-Void function add_constraint(model : Element, element : String):
+Void function add_constraint(model : Element, element : String, constraint : Action):
 	// Add local constraints to an element
-	Action constraint
 	Element attr_type
 	String link_name
 	String constraint_name
 
-	constraint = construct_function()
 	constraint_name = add_AL(model, constraint)
 	attr_type = find_attribute_type(model, element, "constraint")
 	instantiate_link(model, attr_type, "", element, constraint_name)
@@ -391,6 +389,6 @@ Void function construct_model():
 		elif (command == "define_inheritance"):
 			define_inheritance(input(), input())
 		elif (command == "add_constraint"):
-			add_constraint(input(), input())
+			add_constraint(input(), input(), construct_function())
 		else:
 			log("Modelling error: did not understand command " + command)

+ 1 - 0
interface/HUTN/includes/modelling.alh

@@ -17,3 +17,4 @@ Void function unset_attribute(model : Element, elem : String, name : String)
 Void function construct_model()
 Element function read_attribute(model : Element, elem : String, name : String)
 Void function model_delete_element(model : Element, name : String)
+Void function add_constraint(model : Element, name : String, constraint : Action)