Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc3c542

Browse files
Restructure priority reestablishing and allow for an object of strategy to be completely crossed out
Implements #27 while the same time making reestablishing priority function more readable. At the same time, penalizing now happens Within the result accumulateor
1 parent 8666dbc commit bc3c542

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

‎queries/strategies/primitives.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def root_level_order(accumulator,root,level,index,only_information,priority,pena
1010
else:
1111
first_option = None
1212
if not only_information or True:
13-
accumulator.push(second_option,priorityif not first_option elsepriority+ penalty)
13+
accumulator.push(second_option,priority,penalty=0if not first_option else penalty)
1414

1515
def root_lexical_order(accumulator,root,level_nodes,information_nodes,index,
1616
only_information,priority,penalty,lca = None,constrained_space = None):
@@ -30,8 +30,7 @@ def root_lexical_order(accumulator,root,level_nodes,information_nodes,index,
3030
else:
3131
first_option = None
3232
if not only_information or True:
33-
accumulator.push(second_option,priority if not first_option else priority + penalty)
34-
33+
accumulator.push(second_option,priority,penalty = 0 if not first_option else penalty)
3534

3635
def child_level_older(accumulator,child_list,level,index,only_information,priority):
3736
for i, child in enumerate(child_list) :
@@ -41,7 +40,7 @@ def child_level_older(accumulator,child_list,level,index,only_information,priori
4140
# print("rejected_candidate", candidate, "from child", child)
4241
if candidate in level.special and (only_information == False or y==True):
4342
# from
44-
accumulator.push(candidate,priority+ i + counter)
43+
accumulator.push(candidate,priority,penalty= i + counter)
4544
counter += 1
4645

4746

‎queries/utility.py‎

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import ast
2-
31
def reestablish_priority(initial,adjusted):
4-
z = {initial[v]:v for v in initial}
5-
w = {adjusted[v]:v for v in adjusted}
6-
x = sorted(z.keys())
7-
y = sorted(w.keys())
8-
s = set(y)
9-
if len(y)!=len(s):
10-
return initial
11-
output=adjusted
12-
index = 1
13-
for i in x:
14-
if z[i] not in output:
15-
while index in s:
16-
index += 1
17-
output[z[i]] = index
18-
s.add(index)
2+
output={}
3+
to_be_removed = {k for k,v in adjusted.items() if v<0}
4+
initial_order = sorted(initial.items(),key=lambda x:x[1])
5+
adjusted_order = sorted(adjusted.items(),key=lambda x:x[1])
6+
already_assigned_values = set(adjusted.values())
7+
for k,v in adjusted_order:
8+
output[k] = v
9+
for k,v in initial_order:
10+
if k not in output:
11+
while v in already_assigned_values:
12+
v = v + 1
13+
output[k] = v
14+
already_assigned_values.add(v)
15+
16+
if len(set(adjusted.keys())-to_be_removed)!=len(set(adjusted.values()))-(1 if to_be_removed else 0):
17+
raise Exception("you cannot assign the same priority for two strategies",adjusted)
18+
1919
return output
2020

2121

@@ -29,21 +29,26 @@ def __init__(self,penalized=[], penalty=0):
2929
self.penalty = penalty
3030
self.history = []
3131

32-
def push(self,node,priority):
32+
def push(self,node,priority,penalty=0):
3333
self.history.append((node,priority))
34-
# print(" pushing", priority )
35-
# if not isinstance( node,ast.AST ) and not node is None:
36-
# for x in node:
37-
# print(ast.dump(x))
3834
if not node:
3935
return None
4036
if node in self.penalized:
41-
priority = priority + self.penalty
42-
if priority not in self.accumulator:
37+
priority = self.penalize(priority,self.penalty)
38+
priority = self.penalize(priority,penalty)
39+
if priority < 0:
40+
return
41+
elif priority not in self.accumulator:
4342
self.accumulator[priority] = [node]
4443
else:
4544
self.accumulator[priority].append(node)
4645

46+
def penalize(self,priority,penalty):
47+
if priority<0:
48+
return priority
49+
else:
50+
return priority+penalty
51+
4752
def get_result(self):
4853
visited = set()
4954
finalists = []

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /