# \#logical-constraints

**URL:** https://discuss.ampl.com/tag/logical-constraints/43.md

[Latest](https://discuss.ampl.com/latest.md) · [Categories](https://discuss.ampl.com/categories.md) · [Tags](https://discuss.ampl.com/tags.md)

---

## [Constraint that verify binary variable get the same value for at least 4 consecutive points. not sure what approach should i take](https://discuss.ampl.com/t/constraint-that-verify-binary-variable-get-the-same-value-for-at-least-4-consecutive-points-not-sure-what-approach-should-i-take/1168)

<div class="topic-metadata">

**Author:** [@Kobi\_Zohar](https://discuss.ampl.com/u/Kobi_Zohar)\
**Replies:** 1\
**Last updated:** [July 26, 2024, 12:59am UTC](https://discuss.ampl.com/t/constraint-that-verify-binary-variable-get-the-same-value-for-at-least-4-consecutive-points-not-sure-what-approach-should-i-take/1168 "2024-07-26T00:59:52Z")

</div>

set T := 1…card(I); #I is timestamp, so i converted to number param idx\_to\_time {T} symbolic := ord(I, I); subject to 4\_consecutive\_points {t in T: t \>=1,\<= card(I) - 4}: y\_ind\[t\] != y\_ind\[t-1\] ==\> y\_ind\[t\] + y…

---

## [AMPL Modeling Tips #4: If-Then](https://discuss.ampl.com/t/ampl-modeling-tips-4-if-then/354)

<div class="topic-metadata">

**Author:** [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Replies:** 0\
**Last updated:** [February 2, 2023, 12:32pm UTC](https://discuss.ampl.com/t/ampl-modeling-tips-4-if-then/354 "2023-02-02T12:32:31Z")

</div>

Assume that production of a specific item i costs u\_i per unit, but there is an additional fixed charge of w\_i if we produce item i at all. For instance, w\_i could be the cost of setting up a production plant, initia…

---

## [AMPL Modeling Tips #3: Alldifferent](https://discuss.ampl.com/t/ampl-modeling-tips-3-alldifferent/305)

<div class="topic-metadata">

**Author:** [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Replies:** 0\
**Last updated:** [January 10, 2023, 5:35pm UTC](https://discuss.ampl.com/t/ampl-modeling-tips-3-alldifferent/305 "2023-01-10T17:35:23Z")

</div>

Consider the N-Queens problem: How can N queens be placed on an NxN chessboard so that no two of them attack each other? \[ Solve it on Google Colab! \] Constraint alldiff enforces a set of integer variables to take d…

---

## [AMPL Modeling Tips #2: Equivalence](https://discuss.ampl.com/t/ampl-modeling-tips-2-equivalence/268)

<div class="topic-metadata">

**Author:** [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Replies:** 0\
**Last updated:** [December 15, 2022, 1:03pm UTC](https://discuss.ampl.com/t/ampl-modeling-tips-2-equivalence/268 "2022-12-15T13:03:05Z")

</div>

“Of two variables x and y, exactly one should be positive”: how to model this constraint? This is a stricter condition that in the previous Tip #1. For the new MP Library-based drivers (e.g., gurobi, highs, cbc, copt, x…

---

## [AMPL Modeling Tips #1: Disjunctions](https://discuss.ampl.com/t/ampl-modeling-tips-1-disjunctions/166)

<div class="topic-metadata">

**Author:** [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Replies:** 1\
**Last updated:** [December 2, 2022, 12:22pm UTC](https://discuss.ampl.com/t/ampl-modeling-tips-1-disjunctions/166 "2022-12-02T12:22:47Z")

</div>

“Two variables x and y cannot be positive at the same time”: how to model this constraint? For the new MP Library-based drivers (e.g., gurobi, highs, copt), as well as for Constraint Programming solvers (ilogcp, gecode, …
