Browse Source

Fixed tests; made library more consistent in its use of names instead of IDs

Yentl Van Tendeloo 9 years ago
parent
commit
966bc9ab6d

+ 2 - 2
bootstrap/conformance_scd.alc

@@ -213,14 +213,14 @@ String function conformance_scd(model : Element):
 		attr_value = read_attribute(metamodel, metamodel_element, "lower_cardinality")
 		if (element_neq(attr_value, read_root())):
 			// We have defined a lower cardinality, so check number of instances!
-			if (attr_value > list_len(allInstances(model, metamodel["model"][metamodel_element]))):
+			if (attr_value > list_len(allInstances(model, metamodel_element))):
 				return "Lower cardinality violated for class: " + metamodel_element
 
 		// Upper multiplicities
 		attr_value = read_attribute(metamodel, metamodel_element, "upper_cardinality")
 		if (element_neq(attr_value, read_root())):
 			// We have defined a lower cardinality, so check number of instances!
-			if (attr_value < list_len(allInstances(model, metamodel["model"][metamodel_element]))):
+			if (attr_value < list_len(allInstances(model, metamodel_element))):
 				return "Upper cardinality violated for class: " + metamodel_element
 
 	// Structure seems fine, now do static semantics

+ 11 - 11
bootstrap/metamodels.alc

@@ -107,26 +107,26 @@ Element function create_metamodels():
 String function petrinet_constraints(model : Element):
 	// Check places to have positive number of tokens
 	Element all_elems
-	Element elem_constraint
-	all_elems = allInstances(model, model["metamodel"]["model"]["Place"])
+	String elem_constraint
+	
+	all_elems = allInstances(model, "Place")
 	while (0 < read_nr_out(all_elems)):
 		elem_constraint = set_pop(all_elems)
-		if (integer_lt(read_attribute(model, getName(model, elem_constraint), "tokens"), 0)):
-			return "Negative number of tokens in Place " + getName(model, elem_constraint)
+		if (integer_lt(read_attribute(model, elem_constraint, "tokens"), 0)):
+			return "Negative number of tokens in Place " + elem_constraint
 
 	// Check P2T transitions to have positive weight
-	all_elems = allInstances(model, model["metamodel"]["model"]["P2T"])
+	all_elems = allInstances(model, "P2T")
 	while (0 < read_nr_out(all_elems)):
 		elem_constraint = set_pop(all_elems)
-		if (integer_lt(read_attribute(model, getName(model, elem_constraint), "weight"), 0)):
-			return "Negative weight in arc " + getName(model, elem_constraint)
+		if (integer_lt(read_attribute(model, elem_constraint, "weight"), 0)):
+			return "Negative weight in arc " + elem_constraint
 
 	// Check T2P transitions to have positive weight
-	all_elems = allInstances(model, model["metamodel"]["model"]["T2P"])
+	all_elems = allInstances(model, "T2P")
 	while (0 < read_nr_out(all_elems)):
 		elem_constraint = set_pop(all_elems)
-		if (integer_lt(read_attribute(model, getName(model, elem_constraint), "weight"), 0)):
-			return "Negative weight in arc " + getName(model, elem_constraint)
+		if (integer_lt(read_attribute(model, elem_constraint, "weight"), 0)):
+			return "Negative weight in arc " + elem_constraint
 
 	return "OK"
-

+ 4 - 2
bootstrap/object_operations.alc

@@ -2,10 +2,12 @@ include "primitives.alh"
 include "conformance_scd.alh"
 include "constructors.alh"
 
-Element function allInstances(model : Element, type : Element):
+Element function allInstances(model : Element, type_name : String):
 	Element type_mapping
 	Element result
+	Element type
 
+	type = model["metamodel"]["model"][type_name]
 	type_mapping = model["type_mapping"]
 	result = create_node()
 
@@ -20,7 +22,7 @@ Element function allInstances(model : Element, type : Element):
 		edge = read_out(type_mapping, counter)
 		if (element_eq(read_edge_dst(edge), type)):
 			// Found an element of the specified type
-			set_add(result, read_edge_dst(read_out(edge, 0)))
+			set_add(result, getName(model, read_edge_dst(read_out(edge, 0))))
 		counter = counter + 1
 	
 	return result

+ 28 - 26
integration/code/pn_interface.alc

@@ -19,34 +19,36 @@ Element function petrinet_enabled(model : Element):
 	set_enabled = petrinet_enabled_set(model)
 	output("Enabled transitions:")
 	while (0 < read_nr_out(set_enabled)):
-		output(getName(model, set_pop(set_enabled)))
+		output(set_pop(set_enabled))
 	return model
 
 Element function petrinet_enabled_set(model : Element):
 	Element all_transitions
-	all_transitions = allInstances(model, model["metamodel"]["model"]["Transition"])
-
 	Element enabled_transitions
-	enabled_transitions = create_node()
-
-	Element under_study
+	String under_study
 	Element in_arcs
-	Element arc_under_study
+	String arc_under_study
 	Boolean enabled
+
+	all_transitions = allInstances(model, "Transition")
+	enabled_transitions = create_node()
+
 	while (0 < read_nr_out(all_transitions)):
 		under_study = set_pop(all_transitions)
 		enabled = True
 
 		// Find all incoming transitions
-		in_arcs = allIncomingAssociationInstances(model, reverseKeyLookup(model["model"], under_study), "P2T")
+		in_arcs = allIncomingAssociationInstances(model, under_study, "P2T")
 
 		while (0 < read_nr_out(in_arcs)):
 			arc_under_study = set_pop(in_arcs)
 
 			Integer present_tokens
 			Integer required_tokens
-			required_tokens = read_attribute(model, getName(model, arc_under_study), "weight")
-			present_tokens = read_attribute(model, getName(model, read_edge_src(arc_under_study)), "tokens")
+			required_tokens = read_attribute(model, arc_under_study, "weight")
+			log("Weight: " + cast_i2s(required_tokens))
+			present_tokens = read_attribute(model, getName(model, read_edge_src(model["model"][arc_under_study])), "tokens")
+			log("Tokens: " + cast_i2s(present_tokens))
 			if (present_tokens < required_tokens):
 				// Less tokens than required, so disable the transition completely
 				enabled = False
@@ -54,39 +56,39 @@ Element function petrinet_enabled_set(model : Element):
 		if (enabled):
 			set_add(enabled_transitions, under_study)
 
+	log("Got all enabled transitions!")
 	return enabled_transitions
 
 Element function petrinet_fire(model : Element):
 	output("Transition to fire?")
-	Element transition
+	String transition
 	transition = input()
 	if (dict_in(model["model"], transition)):
-		transition = model["model"][transition]
 		if (set_in(petrinet_enabled_set(model), transition)):
 			Element workset
-			Element working_place
-			Element working_arc
+			String working_place
+			String working_arc
 			Integer new_value
 
 			// Consume tokens
-			workset = allIncomingAssociationInstances(model, reverseKeyLookup(model["model"], transition), "P2T")
+			workset = allIncomingAssociationInstances(model, transition, "P2T")
 			while (0 < read_nr_out(workset)):
 				working_arc = set_pop(workset)
-				working_place = read_edge_src(working_arc)
-				new_value = integer_subtraction(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
-				unset_attribute(model, getName(model, working_place), "tokens")
-				instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
-				output((("  " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
+				working_place = getName(model, read_edge_src(model["model"][working_arc]))
+				new_value = integer_subtraction(read_attribute(model, working_place, "tokens"), read_attribute(model, working_arc, "weight"))
+				unset_attribute(model, working_place, "tokens")
+				instantiate_attribute(model, working_place, "tokens", new_value)
+				output((("  " + working_place) + ": ") + cast_i2s(read_attribute(model, working_place, "tokens")))
 
 			// Add tokens
-			workset = allOutgoingAssociationInstances(model, reverseKeyLookup(model["model"], transition), "T2P")
+			workset = allOutgoingAssociationInstances(model, transition, "T2P")
 			while (0 < read_nr_out(workset)):
 				working_arc = set_pop(workset)
-				working_place = read_edge_dst(working_arc)
-				new_value = integer_addition(read_attribute(model, getName(model, working_place), "tokens"), read_attribute(model, getName(model, working_arc), "weight"))
-				unset_attribute(model, getName(model, working_place), "tokens")
-				instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
-				output((("  " + getName(model, working_place)) + ": ") + cast_i2s(read_attribute(model, getName(model, working_place), "tokens")))
+				working_place = getName(model, read_edge_dst(model["model"][working_arc]))
+				new_value = integer_addition(read_attribute(model, working_place, "tokens"), read_attribute(model, working_arc, "weight"))
+				unset_attribute(model, working_place, "tokens")
+				instantiate_attribute(model, working_place, "tokens", new_value)
+				output((("  " + working_place) + ": ") + cast_i2s(read_attribute(model, working_place, "tokens")))
 			output("Transition fired!")
 		else:
 			output("Cannot fire if not enabled; aborting")