Browse Source

Patches to a (working?) BFS algorithm to make it faster: crashes...

Yentl Van Tendeloo 8 years ago
parent
commit
d107b457bc
2 changed files with 28 additions and 7 deletions
  1. 0 4
      core/core_algorithm.alc
  2. 28 3
      models/bfs.alc

+ 0 - 4
core/core_algorithm.alc

@@ -497,7 +497,6 @@ Boolean function enact_action(pm : Element, element : String, prefix : String, u
 		value = read_attribute(pm, readAssociationDestination(pm, consumes_link), "name")
 		dict_add(inputs, name, prefix + value)
 		dict_add(types, name, read_attribute(pm, readAssociationDestination(pm, consumes_link), "type"))
-		log("Added inputs: " + cast_v2s(prefix + value))
 
 	// Find all outputs and their types (i.e., key)
 	lst = allAssociationDestinations(pm, element, "Produces")
@@ -547,7 +546,6 @@ Boolean function enact_action(pm : Element, element : String, prefix : String, u
 			input_keys = dict_keys(inputs)
 			while (read_nr_out(input_keys) > 0):
 				key = set_pop(input_keys)
-				log("READ model with name " + cast_v2s(inputs[key]))
 				model_join(merged_model, get_full_model(get_model_id(inputs[key])), string_join(types[key], "/"))
 
 			// 3) Transform
@@ -564,8 +562,6 @@ Boolean function enact_action(pm : Element, element : String, prefix : String, u
 				desired_metamodel_id = get_model_id(key)
 				split_off_model = model_split(merged_model, get_full_model(desired_metamodel_id), key + "/")
 
-				log("Wrote model to " + cast_v2s(outputs[key]))
-
 				// Check if the destination model already exists
 				if (get_model_id(outputs[key]) == ""):
 					// New model

+ 28 - 3
models/bfs.alc

@@ -11,18 +11,30 @@ Element function bfs(params : Element, output_mms : Element):
 	String state
 	Element path
 	Element path_copy
+	Element visited
+	Element visited_copy
 	String option
+	String dest
 
 	model = params["reachability_graph"]
 
 	worklist = create_node()
 	initial = set_pop(allInstances(model, "InitialState"))
-	list_append(worklist, create_tuple(initial, create_node()))
+	work_unit = create_node()
+	list_append(work_unit, initial)
+	path = create_node()
+	list_append(work_unit, path)
+	visited = create_node()
+	set_add(visited, initial)
+	list_append(work_unit, visited)
+
+	list_append(worklist, work_unit)
 
 	while (read_nr_out(worklist) > 0):
 		work_unit = list_pop(worklist, 0)
 		state = work_unit[0]
 		path = work_unit[1]
+		visited = work_unit[2]
 		log("Searching for length " + cast_v2s(read_nr_out(path)))
 
 		if (value_eq(read_attribute(model, state, "error"), True)):
@@ -34,11 +46,24 @@ Element function bfs(params : Element, output_mms : Element):
 			break!
 
 		options = allOutgoingAssociationInstances(model, state, "Transition")
-
 		while (read_nr_out(options) > 0):
 			option = set_pop(options)
+			dest = readAssociationDestination(model, option)
+			
+			if (set_in(visited, dest)):
+				// Already visited this node, so skip
+				continue!
+
 			path_copy = dict_copy(path)
+			visited_copy = set_copy(visited)
+
+			set_add(visited_copy, dest)
 			list_append(path_copy, read_attribute(model, option, "name"))
-			list_append(worklist, create_tuple(readAssociationDestination(model, option), path_copy))
+
+			work_unit = create_node()
+			list_append(work_unit, dest)
+			list_append(work_unit, path_copy)
+			list_append(work_unit, visited_copy)
+			list_append(worklist, work_unit)
 
 	return create_node()!