Przeglądaj źródła

Added new attribute management functions

Yentl Van Tendeloo 9 lat temu
rodzic
commit
6562f396d8

+ 27 - 0
bootstrap/modelling.alc

@@ -189,6 +189,33 @@ Void function define_inheritance(model : Element, inheritance_name : String):
 
 	return
 
+Void function model_delete_link(model : Element, name : String):
+	// Remove the link
+	// 1) from the type mapping
+	dict_delete(model["type_mapping"], model["model"][name])
+
+	// 2) from the model
+	delete_element(model["model"][name])
+
+	// The entry in the model is automagically removed
+
+	return
+
+Void function unset_attribute(model : Element, element : String, attribute : String):
+	// Removes an attribute if it exists
+	Element attr_type
+	Element attr_links
+	Element attr_link
+	
+	attr_type = find_attribute_type(model, element, attribute)
+	attr_links = allOutgoingAssociationInstances(model, element, attr_type)
+
+	while (list_len(attr_links) > 0):
+		attr_link = set_pop(attr_links)
+		model_delete_link(model, getName(model, attr_link))
+
+	return
+
 Void function construct_model():
 	String command
 	log("Enter modelling constructs!")

+ 1 - 1
bootstrap/object_operations.alc

@@ -74,7 +74,7 @@ Element function findAttribute(source : Element, attr_name : Element, types : El
 		while (i < counter):
 			edge = read_out(source, i)
 			if (element_eq(dict_read_node(types, edge), inheritance_link)):
-				return find_attribute(read_edge_dst(edge), attr_name, types, inheritance_link)
+				return findAttribute(read_edge_dst(edge), attr_name, types, inheritance_link)
 			i = i + 1
 		// No return at the moment, as this crashes the MvK
 		log("ERROR: could not find attribute")

+ 8 - 0
integration/code/pn_interface.alc

@@ -5,6 +5,7 @@ include "library.alh"
 include "conformance_scd.alh"
 include "io.alh"
 include "metamodels.alh"
+include "modelling.alh"
 
 Element function pn_operations():
 	Element ops
@@ -65,12 +66,16 @@ Element function petrinet_fire(model : Element):
 			Element workset
 			Element working_place
 			Element working_arc
+			Integer new_value
 
 			// Consume tokens
 			workset = allIncomingAssociationInstances(model, transition, model["metamodel"]["model"]["P2T"])
 			while (0 < read_nr_out(workset)):
 				working_arc = set_pop(workset)
 				working_place = read_edge_src(working_arc)
+				new_value = integer_subtraction(readAttribute(model, working_place, "tokens"), readAttribute(model, working_arc, "weight"))
+				unset_attribute(model, getName(model, working_place), "tokens")
+				instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
 				//setAttribute(model, working_place, "tokens", integer_subtraction(readAttribute(model, working_place, "tokens"), readAttribute(model, working_arc, "weight")))
 				output((("  " + getName(model, working_place)) + ": ") + cast_i2s(readAttribute(model, working_place, "tokens")))
 
@@ -79,6 +84,9 @@ Element function petrinet_fire(model : Element):
 			while (0 < read_nr_out(workset)):
 				working_arc = set_pop(workset)
 				working_place = read_edge_dst(working_arc)
+				new_value = integer_addition(readAttribute(model, working_place, "tokens"), readAttribute(model, working_arc, "weight"))
+				unset_attribute(model, getName(model, working_place), "tokens")
+				instantiate_attribute(model, getName(model, working_place), "tokens", new_value)
 				//setAttribute(model, working_place, "tokens", integer_addition(readAttribute(model, working_place, "tokens"), readAttribute(model, working_arc, "weight")))
 				output((("  " + getName(model, working_place)) + ": ") + cast_i2s(readAttribute(model, working_place, "tokens")))
 			output("Transition fired!")

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

@@ -14,4 +14,5 @@ Void function instantiate_attribute(model : Element, element : String, attribute
 String function instantiate_link(model : Element, type : String, name : String, source : String, destination : String)
 Void function instantiate_named(model : Element, type : String, name : String, source : String, destination : String)
 Void function define_inheritance(model : Element, inheritance_name : String)
+Void function unset_attribute(model : Element, elem : String, name : String)
 Void function construct_model()