Guys

I have 2 questions and appreciate if anyone answer

1. there is a function that can pick the Largest value among all arguments. Do u know any function that can be used in equations?

2. i want to write a<x<b in equations (a,x,b are variables). the common way is that use 2 equations(one for a<x and one for x<b). is there any way to write both side in one equation?

## tricking in equation

### Re: tricking in equation

Hello,

For indexed arguments, or rather parameter values, one can use the smin() operation, which works similar to sum() operation.

For equations, you can use the max() function. Goes something like max(arg1,arg2,arg3).

a<x<b is actually two separate inequalities, and should be written as such.

For indexed arguments, or rather parameter values, one can use the smin() operation, which works similar to sum() operation.

For equations, you can use the max() function. Goes something like max(arg1,arg2,arg3).

a<x<b is actually two separate inequalities, and should be written as such.

### Re: tricking in equation

thank u for your answer.cbhomia wrote: ↑6 months agoHello,

For indexed arguments, or rather parameter values, one can use the smin() operation, which works similar to sum() operation.

For equations, you can use the max() function. Goes something like max(arg1,arg2,arg3).

a<x<b is actually two separate inequalities, and should be written as such.

i want to find the maximum value of g(i),

*g*is a variable and

*i*is set, in an equation. i should write sth like this : max(i,g(i)) ???????

### Re: tricking in equation

Almost, you write smax(i,g(i)). A warning: the resulting models will be highly non-convex, so

Local solvers like Conopt and MINOS will find the solution (50,0) with objective 100. Only global solvers will give you (*,200) with objective 200. But many global solvers (Antigone, Baron, Couenne) don't like max or smax. The only ones in the GAMS portfolio are LindoGlobal and SCIP. LindoGlobal can also reformulate min, max, abs, etc with linear constraints and additional binary variables, so LindoGLobal actually will finally solve a MIP (from the LindoGlobal log):
You could do this reformulation by hand (search the literature or use https://math.stackexchange.com/question ... -variables as a starter) if the max is the only non-linearity in your model.

Hope this helps,

- Michael

*local*solvers will most likely miss the global optimum. For example:Code: Select all

```
set i / 1,2 /;
Table idat
c up
1 2 50
2 1 200;
variable z; positive variable x(i);
equation e; e.. z =e= smax(i,idat(i,'c')*x(i));
model m /e/;
x.up(i) = idat(i,'up');
solve m using dnlp max z;
```

Code: Select all

```
The problem is a MILP
Startpoint info (not feasible):
Objvalue : 0.000000e+00 (startpoint)
Infeasibility of solution : 1.0e+02
Integer infeasibility of solution: 0.0e+00
Ori. size (m, n, nz, nip): 6, 6, 14, 2
```

Hope this helps,

- Michael

### Re: tricking in equation

bussieck wrote: ↑5 months agoAlmost, you write smax(i,g(i)). A warning: the resulting models will be highly non-convex, solocalsolvers will most likely miss the global optimum. For example:

Local solvers like Conopt and MINOS will find the solution (50,0) with objective 100. Only global solvers will give you (*,200) with objective 200. But many global solvers (Antigone, Baron, Couenne) don't like max or smax. The only ones in the GAMS portfolio are LindoGlobal and SCIP. LindoGlobal can also reformulate min, max, abs, etc with linear constraints and additional binary variables, so LindoGLobal actually will finally solve a MIP (from the LindoGlobal log):Code: Select all

`set i / 1,2 /; Table idat c up 1 2 50 2 1 200; variable z; positive variable x(i); equation e; e.. z =e= smax(i,idat(i,'c')*x(i)); model m /e/; x.up(i) = idat(i,'up'); solve m using dnlp max z;`

You could do this reformulation by hand (search the literature or use https://math.stackexchange.com/question ... -variables as a starter) if the max is the only non-linearity in your model.Code: Select all

`The problem is a MILP Startpoint info (not feasible): Objvalue : 0.000000e+00 (startpoint) Infeasibility of solution : 1.0e+02 Integer infeasibility of solution: 0.0e+00 Ori. size (m, n, nz, nip): 6, 6, 14, 2`

Hope this helps,

- Michael

thank you. that's a very thorough explanation. actually, my work is MILP and that link really helps me to write my model