def extract_disabled_clusters(queue): clusters = set() for skeleton in queue.skeletons: # TODO: include costs within clustering? # What is goal is to be below a cost threshold? # In satisfaction, no need because costs are fixed # Make stream_facts for externals to prevent use of the same ones # This ordering is why it's better to put likely to fail first # Branch on the different possible binding outcomes # TODO: consider a nonlinear version of this that evaluates out of order # Need extra sampling effort to identify infeasible subsets # Treat unevaluated optimistically, as in always satisfiable # Need to keep streams with outputs to connect if downstream is infeasible # TODO: prune streams that always have at least one success # TODO: CSP identification of irreducible unsatisfiable subsets # TODO: take into consideration if a stream is enumerated to mark as a hard failure # Decompose down optimizers #cluster_plans = [skeleton.stream_plan] partial_orders = get_partial_orders(skeleton.stream_plan) cluster_plans = get_connected_components(skeleton.stream_plan, partial_orders) binding = skeleton.best_binding if not binding.is_bound(): # TODO: block if cost sensitive to possibly get cheaper solutions #cluster_plans = current_failed_cluster(binding) cluster_plans = current_failure_contributors(binding) for cluster_plan in cluster_plans: clusters.add(frozenset(cluster_plan)) return clusters
def combine_optimizer_plan(stream_plan, functions): if not stream_plan: return stream_plan optimizer = get_optimizer(stream_plan[-1]) if optimizer is None: return stream_plan function_plan = list( filter( lambda r: get_prefix(r.instance.external.head) in optimizer. objectives, functions)) external_plan = stream_plan + function_plan if CLUSTER: partial_orders = get_partial_orders(external_plan) cluster_plans = get_connected_components(external_plan, partial_orders) else: cluster_plans = [external_plan] optimizer_plan = [] for cluster_plan in cluster_plans: if all(isinstance(r, FunctionResult) for r in cluster_plan): continue #if len(cluster_plan) == 1: # optimizer_plan.append(cluster_plan[0]) # continue stream = OptimizerStream(optimizer, cluster_plan) instance = stream.get_instance(stream.input_objects, fluent_facts=stream.fluent_facts) result = instance.get_result(stream.output_objects) optimizer_plan.append(result) return optimizer_plan
def compute_component_mst(node_points, ground_nodes, unprinted, initial_position=None): # Weighted A* start_time = time.time() point_from_vertex = dict(enumerate(node_points)) vertices = {v for e in unprinted for v in e} components = get_connected_components(vertices, unprinted) entry_nodes = set(ground_nodes) if initial_position is not None: point_from_vertex[INITIAL_NODE] = initial_position components.append([INITIAL_NODE]) entry_nodes.add(INITIAL_NODE) edge_weights = {} for c1, c2 in combinations(range(len(components)), r=2): # TODO: directed edges from all points to entry nodes nodes1 = set(components[c1]) nodes2 = set(components[c2]) if (c1 == [INITIAL_NODE]) or (c2 == [INITIAL_NODE]): nodes1 &= entry_nodes nodes2 &= entry_nodes edge_weights[c1, c2] = min( get_distance(point_from_vertex[n1], point_from_vertex[n2]) for n1, n2 in product(nodes1, nodes2)) tree = compute_spanning_tree(edge_weights) weight = sum(edge_weights[e] for e in tree) print( 'Elements: {} | Components: {} | Tree: {} | Weight: {}: Time: {:.3f} '. format(len(unprinted), len(components), tree, weight, elapsed_time(start_time))) return weight
def compute_euclidean_tree(node_points, ground_nodes, elements, initial_position=None): # remove printed elements from the tree # TODO: directed version start_time = time.time() point_from_vertex, edges = embed_graph(elements, node_points, ground_nodes, initial_position) edge_weights = {(n1, n2): get_distance(point_from_vertex[n1], point_from_vertex[n2]) for n1, n2 in edges} components = get_connected_components(point_from_vertex, edge_weights) tree = compute_spanning_tree(edge_weights) from extrusion.visualization import draw_model draw_model(tree, point_from_vertex, ground_nodes, color=BLUE) draw_model(edges - tree, point_from_vertex, ground_nodes, color=RED) weight = sum(edge_weights[e] for e in tree) print(len(components), len(point_from_vertex), len(tree), weight, elapsed_time(start_time)) wait_for_user() return weight
def get_stream_plan_components(external_plan): partial_orders = get_partial_orders(external_plan) return get_connected_components(external_plan, partial_orders)
def get_connected_structures(elements): edges = {(e1, e2) for e1, neighbors in get_element_neighbors(elements).items() for e2 in neighbors} return get_connected_components(elements, edges)
def get_cluster_plans(self): # TODO: split the optimizer into clusters when provably independent external_plan = self.stream_plan + self.function_plan partial_orders = get_partial_orders(external_plan) return get_connected_components(external_plan, partial_orders)