# \#modeling-tips

**URL:** https://discuss.ampl.com/tag/modeling-tips/50.md

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

---

## [Fixing and unfixing a series of variables before a second solve](https://discuss.ampl.com/t/fixing-and-unfixing-a-series-of-variables-before-a-second-solve/2233)

<div class="topic-metadata">

**Author:** [@marnie2k](https://discuss.ampl.com/u/marnie2k)\
**Replies:** 1\
**Last updated:** [April 13, 2026, 12:57am UTC](https://discuss.ampl.com/t/fixing-and-unfixing-a-series-of-variables-before-a-second-solve/2233 "2026-04-13T00:57:06Z")

</div>

Good afternoon, Lately I have been working on a model that requires me to, after a first optimization, fix a series of variables and unfix some according to a certain condition and after that, perform a second solve. D…

---

## [Performance difference between defined variables and s.t. or syntatic sugar?](https://discuss.ampl.com/t/performance-difference-between-defined-variables-and-s-t-or-syntatic-sugar/2228)

<div class="topic-metadata">

**Author:** [@\_nr](https://discuss.ampl.com/u/_nr)\
**Replies:** 3\
**Last updated:** [March 14, 2026, 4:43am UTC](https://discuss.ampl.com/t/performance-difference-between-defined-variables-and-s-t-or-syntatic-sugar/2228 "2026-03-14T04:43:27Z")

</div>

I appreciate how defined variables, e.g., var x {...} = ...; helps keep my AMPL code maintainable. However, for performance reasons, should I prefer something like var x {...}; s.t. X {...} : x\[...\] = ...; instead? How…

---

## [Request for Support in Fixing the Errors](https://discuss.ampl.com/t/request-for-support-in-fixing-the-errors/2062)

<div class="topic-metadata">

**Author:** [@Davids\_David2](https://discuss.ampl.com/u/Davids_David2)\
**Replies:** 1\
**Last updated:** [February 19, 2025, 8:45pm UTC](https://discuss.ampl.com/t/request-for-support-in-fixing-the-errors/2062 "2025-02-19T20:45:40Z")

</div>

Dear Team, I am writing to request support with my model. I am trying to simulate a small system for a public call center, where multiple phone rooms are available, and people arrive to make calls. When a person arrives…

---

## [Warmstarting an LP with an added equality constraint](https://discuss.ampl.com/t/warmstarting-an-lp-with-an-added-equality-constraint/2007)

<div class="topic-metadata">

**Author:** [@eturan](https://discuss.ampl.com/u/eturan)\
**Replies:** 6\
**Last updated:** [January 12, 2025, 7:59pm UTC](https://discuss.ampl.com/t/warmstarting-an-lp-with-an-added-equality-constraint/2007 "2025-01-12T19:59:25Z")

</div>

Hi, I am solving a large LP with AMPL and Gurobi. As part of exploring the optimal solution I find one solution, add a constraint to fix (some) design variables to their optimal values, and then resolve the system using…

---

## [Debugging Error: RuntimeError: Unexpected end of file while reading AMPL output](https://discuss.ampl.com/t/debugging-error-runtimeerror-unexpected-end-of-file-while-reading-ampl-output/1100)

<div class="topic-metadata">

**Author:** [@Sonny](https://discuss.ampl.com/u/Sonny)\
**Replies:** 7\
**Last updated:** [December 12, 2024, 12:35pm UTC](https://discuss.ampl.com/t/debugging-error-runtimeerror-unexpected-end-of-file-while-reading-ampl-output/1100 "2024-12-12T12:35:11Z")

</div>

I’m working on a simple optimization problem for selecting bids from advertising campaigns on available ad spaces, subject to several constraints: (1) only one bid per ad space can be selected, (2) campaigns are subjec…

---

## [Warm start in IPOPT](https://discuss.ampl.com/t/warm-start-in-ipopt/1043)

<div class="topic-metadata">

**Author:** [@salvapineda](https://discuss.ampl.com/u/salvapineda)\
**Replies:** 1\
**Last updated:** [April 10, 2024, 4:49pm UTC](https://discuss.ampl.com/t/warm-start-in-ipopt/1043 "2024-04-10T16:49:55Z")

</div>

Hi, I’m trying to warm start a model in IPOPT. This is what my code looks like: ampl.setOption('solver', 'ipopt') ampl.param\['FIX'\] = 1 ampl.solve() ---- FIRST RUN OF THE MODEL ampl.param\['FIX'\] = 0 ampl.solve() ---- S…

---

## [Summation Syntax Question](https://discuss.ampl.com/t/summation-syntax-question/988)

<div class="topic-metadata">

**Author:** [@N\_P](https://discuss.ampl.com/u/N_P)\
**Replies:** 1\
**Last updated:** [March 8, 2024, 5:26pm UTC](https://discuss.ampl.com/t/summation-syntax-question/988 "2024-03-08T17:26:40Z")

</div>

Hello, I am trying to use a double summation in my Objective function - first sum over i from 1 to n, second sum over j from 1 to n ; where j is not i. Not sure how to write this in AMPL, so what I got is (sum{i in 1.…

---

## [Adjust mu for bounds to promote Sparsity in Knitro Interior/Direct algorithm](https://discuss.ampl.com/t/adjust-mu-for-bounds-to-promote-sparsity-in-knitro-interior-direct-algorithm/957)

<div class="topic-metadata">

**Author:** [@Richard\_Chen](https://discuss.ampl.com/u/Richard_Chen)\
**Replies:** 1\
**Last updated:** [February 22, 2024, 10:08pm UTC](https://discuss.ampl.com/t/adjust-mu-for-bounds-to-promote-sparsity-in-knitro-interior-direct-algorithm/957 "2024-02-22T22:08:14Z")

</div>

I am using the Knitro solver, alg=1 (Interior/Direct) for my problem which tries to match a predicted matrix to an observed matrix. The predicted matrix should be sparse, and values should be between 0 and 1. I bound the…

---

## [Strict inequality constraints](https://discuss.ampl.com/t/strict-inequality-constraints/682)

<div class="topic-metadata">

**Author:** [@Monish\_Kumar](https://discuss.ampl.com/u/Monish_Kumar)\
**Replies:** 3\
**Last updated:** [August 15, 2023, 3:56pm UTC](https://discuss.ampl.com/t/strict-inequality-constraints/682 "2023-08-15T15:56:19Z")

</div>

Why can’t we use strict inequality constraints in IPOPT solver in amplpy @fdabrandao Caution: Treating strict inequality constraint as a logical constraint. context: subject to nod\_SiSf: SInitial + i\_SInitial \> \>\>\> S…

---

## [AMPL Modeling Tips #7: Logistic Regression with Exponential Cones](https://discuss.ampl.com/t/ampl-modeling-tips-7-logistic-regression-with-exponential-cones/657)

<div class="topic-metadata">

**Author:** [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Replies:** 0\
**Last updated:** [July 27, 2023, 12:08pm UTC](https://discuss.ampl.com/t/ampl-modeling-tips-7-logistic-regression-with-exponential-cones/657 "2023-07-27T12:08:44Z")

</div>

Given a sequence of training examples x\_i \\in \\mathbf{R}^m, each labelled with its class y\_i\\in \\{0,1\\} and we seek to find the weights \\theta \\in \\mathbf{R}^m which maximize the function: \\sum\_{i:y\_i=1} \\log(S(\\theta^…

---

## [AMPL Modeling Tips #6: Robust Linear Programming with Ellipsoidal Uncertainty](https://discuss.ampl.com/t/ampl-modeling-tips-6-robust-linear-programming-with-ellipsoidal-uncertainty/487)

<div class="topic-metadata">

**Author:** [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Replies:** 0\
**Last updated:** [April 10, 2023, 4:34pm UTC](https://discuss.ampl.com/t/ampl-modeling-tips-6-robust-linear-programming-with-ellipsoidal-uncertainty/487 "2023-04-10T16:34:31Z")

</div>

Sometimes values are not known exactly In the diet problem we want to find a diet that satisfies certain nutricial requiments while also minimizing the total cost. What if the costs were not know exactly? One simple …

---

## [AMPL Modeling Tips #5: Non-contiguous variable domains](https://discuss.ampl.com/t/ampl-modeling-tips-5-non-contiguous-variable-domains/387)

<div class="topic-metadata">

**Author:** [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Replies:** 0\
**Last updated:** [February 20, 2023, 6:02pm UTC](https://discuss.ampl.com/t/ampl-modeling-tips-5-non-contiguous-variable-domains/387 "2023-02-20T18:02:05Z")

</div>

Sometimes variable values are restricted to non-contiguous sets. Finite domain: var Buy {FOOD} in {0, 10, 30, 45, 55}; Finite domains as unions of integer sets: var Buy {FOOD} in 0..4 union 9..13 union 17..20; A …

---

## [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, …
