Commit 5091e494 authored by Yoann Dufresne's avatar Yoann Dufresne

greedy optimizations

parent d1ff2f33
......@@ -22,6 +22,12 @@ class Optimizer:
total_nb_steps = 0
first_pass = True
max_cov = set()
for node in self.d2g.nodes():
v = self.d2g.get_covering_variable_node(node)
max_cov.update(v)
max_cov = len(max_cov)
used_nodes = {n:False for n in self.d2g.nodes()}
coverage = Counter()
......@@ -55,6 +61,9 @@ class Optimizer:
last_increase_node = current_node
if verbose:
print(f"New best: {len(best_path)} {best_score}")
if len(coverage) == max_cov:
return best_path
else:
nb_steps_since_last_score_up += 1
......@@ -65,8 +74,8 @@ class Optimizer:
def node_sorting_value(node):
u = opt.d2g.node_by_idx[int(node)]
return (0 if len(Counter(opt.d2g.get_covering_variable_node(int(node))) - coverage) == 0 else 1,
- u.get_link_divergence(),
- self.d2g[str(u.idx)][str(current_node)]["distance"])
- self.d2g[str(u.idx)][str(current_node)]["distance"],
- u.get_link_divergence())
neighbors.sort(key=node_sorting_value)
stack.append(neighbors)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment