Order Constraint
Overview
Order Constraints in Verteego ensure that variables within a dataset follow a specified order. This type of constraint is critical for operations where the sequence of values must adhere to a logical or business rule-defined order.
Applications
Order Constraints are typically applied to scenarios such as pricing models where items must escalate in cost based on size, quality, or other factors. They ensure that products or services are correctly sequenced, such as ensuring that heavier products are priced higher than lighter ones within the same category.
Parameters
where: Optional. Filters rows based on specified conditions.
Example:
where={"month": [1, 2, 3], "year": 2022}
applies the constraint only to the first trimester of 2022.
variable_column: Specifies the column containing the variable to be ordered (e.g., "price", "qty_to_buy").
order_by: Identifies the column used to determine the order.
ordering: Optional. Specifies custom ordering, overriding natural order. Unspecified values are ignored.
Example:
ordering=["Citadine Manuel", "Citadine Auto", "Citadine Sport"]
enforces an order only for listed car types.
operator: Determines the direction of the order comparison (
asc
for ascending,desc
for descending). Defaults toasc
.left_column_weight/right_column_weight: Optional weights applied to the variable before ordering.
factor: Multiplicative factor used in comparisons, defaults to
1
.delta: Additive factor used in comparisons, defaults to
0
.group_by: Optional. Specifies columns that define unique groups for ordering.
Example:
group_by="duration"
orders prices separately for each rental duration.
relax: Whether the constraint can be relaxed with a penalty, defaults to
false
.allow_aggregation: Specifies if aggregation is permitted in cases where multiple variables share the same order value, useful for select variables.
Examples
To illustrate with a simple example, with this configuration:
variable_column
price
order_by
duration
ordering
[“1J”, “7J”, “30J”]
operator
desc
delta
1
groupby
category, rate
For a given category and rate, the price variable in the row with duration=1J, must be less than price - 1 in the row with duration=7J. Likewise for the rows with durations 7J and 30J.
that is, for each category and rate:
For instance, with a minimum price of 1, an objective to minimize, and an order constraint with delta=-1, order_by=ord_col, group_by=group, operator=asc:
NA
1
1
NA
4
1
NA
3
2
NA
4
2
NA
7
2
could get solved as:
1
1
1
2
4
1
1
3
2
2
4
2
3
7
2
Last updated