Page 1 of 1

tricking in equation

Posted: Thu Aug 23, 2018 6:40 am
by Aminz
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?

Re: tricking in equation

Posted: Thu Aug 23, 2018 3:26 pm
by cbhomia
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.

Re: tricking in equation

Posted: Fri Aug 24, 2018 3:12 am
by Aminz
cbhomia wrote: 5 years ago 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.
thank u for your answer.
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

Posted: Fri Aug 24, 2018 6:39 am
by bussieck
Almost, you write smax(i,g(i)). A warning: the resulting models will be highly non-convex, so 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;
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

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
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

Re: tricking in equation

Posted: Fri Aug 24, 2018 8:33 am
by Aminz
bussieck wrote: 5 years ago Almost, you write smax(i,g(i)). A warning: the resulting models will be highly non-convex, so 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;
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

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
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

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