# Problem with implementing the objective function with minimum and maximum functions simultaneously!

Hi
Good morning!

I am working on an optimization problem and it has a user defined objective function. the problem is now working well with a simple cost objective function, but I am not able to change it to the attached picture;

The e(t) is a an unknown variable of the problem which is a vector of symbolic variables for 24 hours like [e1,e2,e3,e4,…,e24]. Pb and Qb are also the same. Could you please help me to find out how can I define such objective function in julia which has maximum and minimum functions simultaneously! I was trying to use findmax() for finding the maximum variable but it is not working well and it is mentioned that the method is not matched.

I am using Ipopt.Optimizer!

To model `min { max_{t in T} f(t)}`, you can use the trick

``````T = 3
model = Model()
@variable(model, f_t[1:T])
@variable(model, f_t_max)
# Assume f_t[t] is defined by other constraints
@constraint(model, [t=1:T], f_t_max >= f_t[t])
@objective(model, Min, f_t_max)
``````

you can use that for your two `max` terms. Then the `-min f(x)` term can be converted into `max -f(x)`.

2 Likes

Thank you so much for your kind support. I implemented the objective function and my code is running well now but only with quadratic form of it!

``````
@variable(bb, e_t_max);
@constraint(bb, [t=1:24], e_t_max >= e[t])
@variable(bb, e_t_min);
@constraint(bb, [t=1:24], e_t_min <= e[t])
@variable(bb, Pb_max);
@constraint(bb, [t=1:24],Pb_max >= Pb[t])

@objective(bb, Min, 0.4*(e_t_max-e_t_min)^2 + 0.3* Pb_max  for t in LoadData.Hour))
``````