DECIDE queries
In DeQL, a DECIDE statement tells Decisionhouse what to choose from a
candidate set.
DECIDE INTO knapsackFROM itemsDECISION COLUMNS ( is_selected INTEGER BETWEEN 0 AND 1)SUBJECT TO CONSTRAINT budget: SUM(weight * is_selected) <= 25MAXIMIZE SUM(value * is_selected);Statement anatomy
Section titled “Statement anatomy”| Clause | Purpose |
|---|---|
DECIDE INTO knapsack | Names the result |
FROM items | Selects a candidate set |
DECISION COLUMNS (...) | Declares the unknown values |
SUBJECT TO | Lists constraints, separated by commas |
MAXIMIZE or MINIMIZE | Defines one objective |
FROM must name a candidate set. It cannot name a raw source table.
Decision columns
Section titled “Decision columns”Each decision column becomes a new column in the result. Its value is selected by the solver for each candidate row.
DECISION COLUMNS ( is_selected INTEGER BETWEEN 0 AND 1)A decision column cannot reuse the name of a column already present in the candidate set.
Constraints
Section titled “Constraints”Aggregate across candidates with SUM(...).
CONSTRAINT budget: SUM(weight * is_selected) <= 25A constraint without SUM(...) applies to every row individually.
CONSTRAINT per_item_limit: allocation <= availableSupported constraint senses are <=, >=, and =. The right-hand side may be
a literal or a candidate column.
Grouped constraints
Section titled “Grouped constraints”Use BY (...) to repeat an aggregate constraint for each group.
SUBJECT TO CONSTRAINT capacity: SUM(gpus) <= capacity BY (pool_id), CONSTRAINT demand: SUM(gpus) = demand BY (workload_id)The first constraint limits each pool independently. The second satisfies each workload independently.
Objectives
Section titled “Objectives”A query has one linear objective.
MAXIMIZE SUM(value * is_selected)Sums can be added and subtracted, and the expression may include a constant term.
MAXIMIZE SUM(value * pick) - SUM(DISTINCT fixed_cost * open)For a decision column grouped with BY, SUM(DISTINCT ...) counts its single
group value once instead of repeating it for every candidate row in that
group.