> For the complete documentation index, see [llms.txt](https://doc.verteego.com/verteego-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.verteego.com/verteego-doc/pipelines/optimization-pipelines/constraints/binary-constraint.md).

# Binary Constraint

### Overview

Binary Constraints in Verteego enable direct comparison or interaction between two columns within a dataset, which can be either variable or static. This type of constraint is applied on a row-by-row basis, making it suitable for conditions where variables within the same dataset must maintain a specific relationship to one another.

### Application

Binary Constraints are commonly used to enforce relationships such as ensuring one value remains greater than or less than another (e.g., a product’s price must always be higher than a competitor’s price).

### Parameters

* **where:** An optional dictionary of key-value pairs that filters rows based on specified conditions. For instance, setting `where={"month": [1, 2, 3], "year": 2022}` would apply the constraint only to rows from the first quarter of 2022, ignoring all others.
* **left\_column:** Specifies the column containing the variable or static number to be constrained.
* **left\_column\_weight:** Optional. A column containing weights to be applied to values in the `left_column`.
* **operator:** Defines the relationship between the left and right column values. Options are `equal`, `lesser` (less than or equal to), and `greater` (greater than or equal to).
* **right\_column:** Specifies the column against which the `left_column` is being constrained.
* **right\_column\_weight:** Similar to `left_column_weight`, for applying weights to the `right_column`.
* **delta:** An optional numerical value that offsets the constraint, adding flexibility to the condition (e.g., `price must be greater than competition_price + 1`).
* **relax:** Indicates whether the constraint can be relaxed (with a penalty that gets reported). Defaults to `false`.

### Examples

Below are examples of YAML configurations for binary constraints:

* **Setting a Minimum Price Above Competition:**

```yaml
yamlCopy codecompetition_lower_bound:
  constraint_type: binary
  left_column: price
  operator: greater
  right_column: competition_price
  delta: 0
  relax: false
```

* **Setting a Maximum Price Below an Upper Limit:**

```yaml
yamlCopy codecompetition_upper_bound:
  constraint_type: binary
  left_column: price
  operator: lesser
  right_column: competition_upper_bound_price
  delta: 0
  relax: false
```

### Best Practices

When implementing Binary Constraints, it is crucial to:

* **Select relevant columns** for the left and right sides of the equation to ensure meaningful comparisons.
* **Use appropriate weights and deltas** to refine the conditions under which constraints apply.
* **Consider using the `relax` parameter** for scenarios where strict adherence to constraints might not always be possible or desirable, allowing for more flexible optimization solutions.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://doc.verteego.com/verteego-doc/pipelines/optimization-pipelines/constraints/binary-constraint.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
