# Tag Info

## Hot answers tagged ampl

8

GAMS and AMPL are general purpose modelling languages and can he used to describe any type of nonlinear function, including some niche stuff like floor, ceil, max, etc (AMPL). I don't have experience with OPL so I can't comment on that. The purpose of these languages is twofold: They provide a solver interface for your math. Solvers typically require input ...

5

I am aware of models that model such constraints using a network-flow-type approach. The basic idea is to create a source node that send "flow" of an imaginary product for which all nodes have a demand of 1. There are no costs for the flows. In your case the problem is trickier because you would need two source nodes, and maybe two types of imaginary ...

5

I don't think there is anything special in AMPL for doing this, but it can be done. Option 1 is to add a term to the objective that penalizes the sum of all variables. (I'm assuming that all variables are nonnegative.) This will encourage the solver to force your "free" variables to zero. The catch is that you have to multiply this term by a ...

4

model; set energy:= el co th; set tech := cog tri; subject to cons1 {i in demand, j in facility}: y[i,j,'th'] <= sum{i in size} x[j,l,'tri']; subject to cons2 {i in demand, j in facility, k in energy}: y[i,j,k] <= sum{j in facility, l in size, m in tech} x[j,l,m]; The only thing that you need to change is in your first constraint 'CO' to 'TH'. A ...

4

The .. operator cannot be used in the data section (i.e. it won't be expanded, see the AMPL FAQ). What you can do is to declare the limits in the model, e.g. param n; set things := 1..n; and define them in the data file param n := 5;

4

Yes it is reasonable. For problems where closing the optimality gap is difficult, you may want to save e.g. the 10 best solutions found before termination. This is called a solution pool and it is a solver specific option that you must pass to the solver from AMPL (check the solvers' manuals for "solution pool"). Most linear solvers support this (including ...

3

Let $\rho$ be some small value. \begin{align}M \times f(x) &\geq x - 1 + \rho\\M \times (1 - f(x)) &\geq 1 - x - \rho\end{align} Here is the small working code in Python pulp import pulp as pl prob = pl.LpProblem("Problem", pl.LpMinimize) x = 1 f = pl.LpVariable("f_{0}", 0, 1, pl.LpBinary) prob += f M = 100 prob += M * f >= x - 1 + 0.001 prob +=...

3

Outside an exam scenario, the correct answer is "switch to a solver that supports alldiff", but I'm assuming you are required to solve this in Gurobi. One way to approach this within the confines of a linear integer problem is to make your decision variable a binary, with an extra dimension added. Hence, instead of "value of X at [i,j]" your decision ...

3

In AMPL's website, there is a code for solving sudoku which is very similar to your problem. In their code they also used alldiff. The only thing that you need to add to the following model is some constraint to consider the diagonal summation as well. By the way, "a Sudoku puzzle is defined as a logic-based, number-placement puzzle. The objective is to fill ...

3

The AMPL Solver Library (or ASL) is an open-source interface between solvers and modelling languages. As long as a solver can (i) read an .nl file and (ii) produce a .sol file, it will work out of the box with AMPL and any other modelling platform, such as Pyomo, that supports ASL. Unfortunately, many solvers do not come with an ASL interface out of the box....

3

Here is the AMPL interpretation of @RobPratt's answer which works perfectly using the gurobi in my local pc: model; param n := 22; set NODES = 1..n; param degree {NODES} := 5; set NODE_PAIRS = {i in NODES, j in NODES: i < j}; var X {NODE_PAIRS} binary; var Y {(i,j) in NODE_PAIRS, k in NODES diff {i,j}} binary; subject to DegreeCon {k in NODES}: ...

3

Here is the SAS code that I used to obtain the results in the linked thread. Maybe it will help you correct your AMPL errors. In particular, note that you should declare each variable only once. proc optmodel; num n = 22; set NODES = 1..n; num degree {NODES} = 5; set NODE_PAIRS = {i in NODES, j in NODES: i < j}; var X {NODE_PAIRS} binary;...

3

An alternative approach to binary variables or semicontinuous variables is the following cubic polynomial inequality: $$x(x-L_B)(U_B-x)\ge 0$$ Because $x \ge 0$, this constraint enforces $$(x = 0) \lor (x - L_B \ge 0 \land U_B - x \ge 0),$$ as desired. The case $(x - L_B \le 0 \land U_B - x \le 0)$ is prevented by $L_B < U_B$. After further consideration,...

3

Your ratio current/best possible is not itself a gap; it is part of what you would use to compute the relative gap. The relative gap defined by CPLEX is the absolute difference between the objective solution of the best known solution (the incumbent, "best integer" in the formula you quote) and the best known bound ("best bound" in the formula), divided by ...

3

One possible solution (not necessarily quick or efficient) is a lazy constraint approach: Solve your problem, ignoring the connection requirement Examine the solution and find the subgraph $H$ that is connected to $v$. If $H=G$, you are finished. Otherwise, add a constraint that at least one of the edges between $H$ and not-$H$ is connected, and repeat. ...

2

This looks most like the math (and avoids checking for every $(i,j,t)$ a logical condition that depends only on $i$ and $j$): {i in PP, j in PP diff {i}, t in TT}

1

You may have a look at this presentation about network flows implementations in AMPL. In the presentation, the authors talked about new AMPL implementations of "arc" and "node" especially on page 8 they mentioned keywords like from and to that I think will help you design your constraints in AMPL. There is also AMPL book chapter about network linear programs ...

1

Try the following syntax: subject to cons {i in PP,t in TT, j in PP : j diff i}: Or subject to cons {i in PP,t in TT, j in PP : j<>i}:

Only top voted, non community-wiki answers of a minimum length are eligible