Skip to content

Commit

Permalink
filter out empty walk lists + strengthen minimality check + add todo …
Browse files Browse the repository at this point in the history
…for swing profile filter
  • Loading branch information
dm0n3y committed Nov 27, 2024
1 parent d0d89a9 commit 1404266
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/core/material/Walk.re
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ module Index = {
| None => Some([w])
| Some(ws) => Some([w, ...ws]),
);
let fil = filter;
let filter = f => map(List.filter(f));
let map = f => map(List.map(f));
let iter = f => iter((dst, ws) => List.iter(f(dst), ws));
Expand Down
51 changes: 48 additions & 3 deletions src/core/material/Walker.re
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,26 @@ let bfs = (~from: Dir.t, q: Queue.t((End.t, Walk.t))): Index.t => {
index^;
};

// if bottom (head) of swing is Tile, need to check the top (foot) of swing for
// whether it's also a Tile of the same sort. if so, combine the prec bounds of top
// and bottom to produce bounded_sort. otherwise, just use the prec bound of the
// bottom and have the other side bound be Bound.Root.
type bounded_sort = (Bound.t(Prec.t), Sort.t, Bound.t(Prec.t));
type swing_profile = Mtrl.t(Space.NT.t, Grout.NT.t, bounded_sort);
type swings_profile = list(swing_profile);

// notes:
// - [DONE] strengthen minimality check to rule out multiple grout levels
// - apply additional filter that rules outs walks that accommodate the same thing as another existing walk

let is_minimal = (w: Walk.t) =>
!(Walk.is_neq(w) && List.exists(Mtrl.is_tile, Chain.links(w)));
!(
Walk.is_neq(w)
&& (
List.exists(Mtrl.is_tile, Chain.links(w))
|| List.length(List.filter(Mtrl.is_grout, Chain.links(w))) > 1
)
);

let walk_all =
Memo.general(((from: Dir.t, src: End.t)) => {
Expand All @@ -233,6 +251,12 @@ let walk_all =
bfs(~from, q)
|> Index.filter(Walk.is_valid)
|> Index.filter(is_minimal)
|> Index.fil(_ =>
fun
| [] => false
| _ => true
)
// todo: apply swings_profile filter here
|> Index.sort;
});
let walk_all = (~from: Dir.t, src: End.t): End.Map.t(list(T.t)) =>
Expand All @@ -247,12 +271,16 @@ let enter_all =
bfs(~from, q)
|> Index.filter(Walk.is_valid)
|> Index.filter(is_minimal)
|> Index.fil(_ =>
fun
| [] => false
| _ => true
)
// todo: apply swings_profile filter here
|> Index.sort;
});
let enter_all = (~from: Dir.t, nt) => enter_all((from, nt));

//TODO: change functions below to call the new serialized versions of walk_all and enter_all

let walk_l_map = ref(End.Map.empty);
let walk_r_map = ref(End.Map.empty);
let enter_l_map = ref(Mtrl.NT.Map.empty);
Expand Down Expand Up @@ -338,6 +366,23 @@ let read_warmed = () => {
print_endline("read warmed stances nts");
read_warmed_walked();
print_endline("read warmed walked");
End.Map.bindings(walk_l_map^)
|> List.iteri((i, (src, index)) =>
if (i < 1) {
P.show("src", End.show(src));
Index.bindings(index)
|> List.iteri((_i, (dst, ws)) => {
// if (i < 5) {
P.show("- dst", End.show(dst));
ws
|> List.iteri((_i, w)
// if (i < 3) {
=> P.show("--- w", Walk.show(w)));
// }
// }
});
}
);
Gc.full_major();
// read_warmed_enter();
// print_endline("read warmed entered");
Expand Down
30 changes: 15 additions & 15 deletions src/core/material/Warmup.re
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,21 @@ let warmup = () => {

print_endline("got root walks");

let walk_count = ref(0);
let total_walk_size = ref(0);
root_l_walk
|> Walk.Index.to_list
|> List.rev_map(snd)
|> List.concat
|> List.iteri((idx, walk) => {
walk_count := idx + 1;
total_walk_size := total_walk_size^ + Chain.length(walk);
();
});
print_endline("Walk Count: " ++ string_of_int(walk_count^));
print_endline(
"Average Walk Size: " ++ string_of_int(total_walk_size^ / walk_count^),
);
// let walk_count = ref(0);
// let total_walk_size = ref(0);
// root_l_walk
// |> Walk.Index.to_list
// |> List.rev_map(snd)
// |> List.concat
// |> List.iteri((idx, walk) => {
// walk_count := idx + 1;
// total_walk_size := total_walk_size^ + Chain.length(walk);
// ();
// });
// print_endline("Walk Count: " ++ string_of_int(walk_count^));
// print_endline(
// "Average Walk Size: " ++ string_of_int(total_walk_size^ / walk_count^),
// );

process_ts_l_walks(ts, root_l_walk);
Gc.full_major();
Expand Down

0 comments on commit 1404266

Please sign in to comment.