WIP
This commit is contained in:
parent
3435806007
commit
d92b653f0b
@ -159,7 +159,7 @@ def getter(node):
|
||||
|
||||
|
||||
def build_criteria_names(
|
||||
costs: List[int], opt_criteria: List["AspFunction"], max_depth: int, const_max_depth: int
|
||||
costs: List[int], opt_criteria: List["AspFunction"], max_depth: int
|
||||
) -> Dict[str, Union[int, List[Tuple[int, int]]]]:
|
||||
"""Construct an ordered mapping from criteria names to costs."""
|
||||
|
||||
@ -174,8 +174,12 @@ def build_criteria_names(
|
||||
# first non-error criterion
|
||||
solve_index = max_error_priority + 1
|
||||
|
||||
# each criterion is aggregated for each level in the graph
|
||||
max_leveled_costs = len(leveled_criteria) * const_max_depth
|
||||
# compute without needing max_depth from solve
|
||||
max_leveled_costs = (len(costs) - max_error_priority - 3) / 2
|
||||
assert max_leveled_costs * 2 == len(costs) - max_error_priority - 3
|
||||
assert max_leveled_costs % len(leveled_criteria) == 0
|
||||
max_leveled_costs = int(max_leveled_costs)
|
||||
|
||||
n_leveled_costs = len(leveled_criteria) * (max_depth + 1)
|
||||
|
||||
build_index = solve_index + 1 + max_leveled_costs
|
||||
@ -794,11 +798,11 @@ def on_model(model):
|
||||
# get optimization criteria
|
||||
criteria = extract_functions(best_model, "opt_criterion")
|
||||
depths = extract_functions(best_model, "depth")
|
||||
const_max_depth, *_ = extract_functions(best_model, "const_max_depth")
|
||||
const_max_depth = const_max_depth.args[0]
|
||||
max_depth = max(d.args[1] for d in depths)
|
||||
|
||||
result.criteria = build_criteria_names(min_cost, criteria, max_depth, const_max_depth)
|
||||
print("PRIO:", priorities)
|
||||
|
||||
result.criteria = build_criteria_names(min_cost, criteria, max_depth)
|
||||
|
||||
# record the number of models the solver considered
|
||||
result.nmodels = len(models)
|
||||
|
@ -1117,32 +1117,32 @@ build_priority(Package, build_prio) :- attr("node", Package), not optimize_for_r
|
||||
% Calculate min depth of nodes in the DAG
|
||||
% We use this to optimize nodes closer to roots with higher precedence.
|
||||
%-----------------------------------------------------------------------------
|
||||
#const max_depth = 5.
|
||||
const_max_depth(max_depth).
|
||||
#const max_depth = 10.
|
||||
|
||||
% roots have depth 0.
|
||||
depth(Package, 0) :- attr("root", Package).
|
||||
depth(Package, D+1) :- depth(Dependent, D), depends_on(Dependent, Package), D < max_depth.
|
||||
|
||||
|
||||
%parent_depth(Package, D) :-
|
||||
% depends_on(Dependent, Package),
|
||||
% depth(Dependent, D),
|
||||
% D < max_depth - 1.
|
||||
|
||||
%depth(Package, M+1) :-
|
||||
% M = #min{ D: parent_depth(Package, D); max_depth - 1 },
|
||||
% attr("node", Package).
|
||||
|
||||
% other nodes' depth is the minimum depth of any dependent plus one.
|
||||
min_parent_depth(Package, N) :-
|
||||
N = #min{
|
||||
D: depends_on(Dependent, Package),
|
||||
depth(Dependent, D),
|
||||
D = 0..max_depth - 1
|
||||
},
|
||||
N = 0..max_depth - 1,
|
||||
attr("node", Package).
|
||||
|
||||
depth(Package, max_depth - 1) :-
|
||||
min_parent_depth(Package, P),
|
||||
P >= max_depth - 1,
|
||||
attr("node", Package).
|
||||
|
||||
depth(Package, P+1) :-
|
||||
min_parent_depth(Package, P),
|
||||
P >= 0,
|
||||
P < max_depth - 1,
|
||||
attr("node", Package).
|
||||
%depth(Package, N + 1) :-
|
||||
% N = #min{
|
||||
% D: depends_on(Dependent, Package),
|
||||
% depth(Dependent, D),
|
||||
% D < max_depth;
|
||||
% max_depth - 1
|
||||
% },
|
||||
% N = 0..max_depth - 1,
|
||||
% attr("node", Package).
|
||||
|
||||
|
||||
%-----------------------------------------------------------------
|
||||
@ -1183,11 +1183,11 @@ depth(Package, P+1) :-
|
||||
% "leveled" criteria sum into a bucket per depth in the graph, per build priority
|
||||
#minimize{
|
||||
0@(((max_depth - D - 1) * depth_offset) + N + build_prio)
|
||||
: opt_criterion(N, "leveled", _), D = 0..max_depth - 1
|
||||
: opt_criterion(N, "leveled", _), depth(_, D)
|
||||
}.
|
||||
#minimize{
|
||||
0@(((max_depth - D - 1) * depth_offset) + N)
|
||||
: opt_criterion(N, "leveled", _), D = 0..max_depth - 1
|
||||
: opt_criterion(N, "leveled", _), depth(_, D)
|
||||
}.
|
||||
|
||||
% Try hard to reuse installed packages (i.e., minimize the number built)
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
% depths
|
||||
#show depth/2.
|
||||
#show const_max_depth/1.
|
||||
%#show parent_depth/2.
|
||||
|
||||
% debug
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user