Hello all, I have questions related to calculating the min and max of set of variables. First I need to calculate the max(x1,x2,x3) and then the min(x1,x2,x3) after that I want to minimize the difference between the max and the min. How do we formulate and linearize such problem (in the constraints)? Thanks asked 31 May '16, 13:32 hdauod1 
min z  y y <= x1 <= z y <= x2 <= z y <= x3 <= z answered 01 Jun '16, 04:20 opti100 This only gives me the max but it doesnt work for the min. When I run it gives me that y=z, which is not true.
(01 Jun '16, 10:02)
hdauod1
1
But this is the correct version for what you requested. Take a look at the values of the variables x1, x2, x3, you might have an error somewhere.
(01 Jun '16, 11:11)
opti100

Can you use integer variables ? It's very straightforward using them. max(x1,x2,x3): real var max; binary var not1, not2, not3; max >= x1; max >= x2; max >= x3; max <= x1 + bigM * not1; max <= x2 + bigM * not2; max <= x3 + bigM * not3; bigM is a constant always >= any possible value for {x1, x2, x3}. not1 + not2 + not3 = 2 (you are cancelling just 2 of these 3 constraints). Without using IP and using only linear constraints I don't think it's possible. answered 03 Jul '16, 11:32 Rafael Arakaki 
What is the context of the model? Is minimizing the difference the only thing in the objective? Do you need to know the max and/or min for any purpose in the model other than the objective?
Its a scheduling problem for orders. for each order i, I want to calculate the difference between max{c1,c2,c3} and min{c1,c2,c3} where c is the job completion time. After that I want to minimize the total sum of differences of all orders (sum i in orders) diff[i]
so I only need this difference in objective function
Thank you