Skip to content

Commit

Permalink
Grouping top-down obligations by result.
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleroy committed Mar 23, 2024
1 parent a60c912 commit adaf383
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
17 changes: 6 additions & 11 deletions ide/packages/panoptes/src/TreeView/TopDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useInteractions,
} from "@floating-ui/react";
import classNames from "classnames";
import _ from "lodash";
import _, { sortBy } from "lodash";
import React, { useContext, useState } from "react";

import { IcoTreeDown } from "../Icons";
Expand Down Expand Up @@ -80,21 +80,16 @@ const TopDown = () => {

// Sort the candidates by the #infer vars / height of the tree
const getGoalChildren = (kids: ProofNodeIdx[]) =>
_.sortBy(kids, k => {
const inferVars = tree.inferVars(k);
const height = tree.maxHeigh(k);
return inferVars / height;
});
_.sortBy(kids, [k => -tree.maxHeight(k)]);

const getCandidateChildren = (kids: ProofNodeIdx[]) =>
_.sortBy(
kids,
_.sortBy(_.uniq(kids), [
k => {
const node = tree.node(k);
return "Goal" in node && tree.goal(node.Goal).isMainTv ? 1 : 0;
},
k => {
switch (tree.result(k) ?? "yes") {
switch (tree.nodeResult(k)) {
case "no":
return 0;
case "maybe-overflow":
Expand All @@ -106,8 +101,8 @@ const TopDown = () => {
default:
return 4;
}
}
);
},
]);

const getChildren = (idx: ProofNodeIdx) => {
const node = tree.node(idx);
Expand Down
12 changes: 6 additions & 6 deletions ide/packages/panoptes/src/TreeView/TreeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface TreeView {
type ControlFlow = "keep" | "remove-tree" | "remove-node";

export class TreeInfo {
private maxHeight: Map<ProofNodeIdx, number>;
private _maxHeight: Map<ProofNodeIdx, number>;
private numInferVars: Map<ProofNodeIdx, number>;

static new(tree: SerializedTree, showHidden: boolean = false) {
Expand Down Expand Up @@ -117,7 +117,7 @@ export class TreeInfo {
readonly showHidden: boolean = false,
readonly view: TreeView
) {
this.maxHeight = new Map();
this._maxHeight = new Map();
this.numInferVars = new Map();
}

Expand Down Expand Up @@ -282,14 +282,14 @@ export class TreeInfo {
return niv;
}

public maxHeigh(n: ProofNodeIdx): number {
const current = this.maxHeight.get(n);
public maxHeight(n: ProofNodeIdx): number {
const current = this._maxHeight.get(n);
if (current !== undefined) {
return current;
}
const childHeights = _.map(this.children(n), k => this.maxHeigh(k));
const childHeights = _.map(this.children(n), k => this.maxHeight(k));
const height = 1 + (_.max(childHeights) ?? 0);
this.maxHeight.set(n, height);
this._maxHeight.set(n, height);
return height;
}
}
Expand Down

0 comments on commit adaf383

Please sign in to comment.