I have 3 functions which consist of 6 variables $p_1,p_2,p_3,p_4,p_5,p_6$. The value of each function is equal to $x$ (say):

\begin{align} f_1 &= \operatorname{sign}(2-p_1) \sqrt{|2-p_1|} + \operatorname{sign}(2-p_2)\sqrt{|2-p_2|} + \operatorname{sign}(2-p_3)\sqrt{|2-p_3|}\cr f_2 &= \operatorname{sign}(p_4-2)\sqrt{|p_4-2|} + \operatorname{sign}(p_5-2)\sqrt{|p_5-2|} + \operatorname{sign}(p_6-2)\sqrt{|p_6-2|}\cr f_3 &= \operatorname{sign}(p_1-p_4)\sqrt{|p_1-p_4|} + \operatorname{sign}(p_2-p_5)\sqrt{|p_2-p_5|} + \operatorname{sign}(p_3-p_6)\sqrt{|p_3-p_6|} \end{align}

I want to find the combination of values of $p_1,p_2,p_3,p_4,p_5$ and $p_6$ for which $x$ is maximum. Constraints are: $$0 <= p_1,p_2,p_3,p_4,p_5,p_6 <= 4$$

Simply varying every variable from $0$ to $4$ taking small steps is not a good solution. Can someone tell me an efficient method to optimise the solution (preferably in python).

  • 2
    $\begingroup$ As you have described it, your problem is not well-posed. Do you want the sum of the $f_i$ to be a maximum? $\endgroup$ Jun 23 '17 at 12:11
  • $\begingroup$ No. I want each function to be maximum at the same value. $\endgroup$ Jun 23 '17 at 13:10
  • $\begingroup$ I don't understand what that means. For a given set of values $p_i$, the functions $f_k$ will be different. Concretely what is it that you want to maximize? $\endgroup$ Jun 26 '17 at 14:00

Do you want f1 = f2 = f3 at the maximum? If so, maximize x with respect to x,p1,p2,p3,p4,p5,p6, subject to f1 = x, f2 = x, f3 = x, 0 <= p1,p2,p3,p4,p5,p6 <= 4.

Here is the solution using the BARON global solver with YALMIP under MATLAB. The first argument of optimize is the constraints. The second argument of optimize is the objective function, which is -x, because optimize always minimizes, so minimizing -x is the same as maximizing x.

>> sdpvar x p1 p2 p3 p4 p5 p6
>> f1 = [sign(2-p1)*sqrtm(abs(2-p1))+sign(2-p2)*sqrtm(abs(2-p2))+sign(2-p3)*sqrtm(abs(2-p3))==x];
>> f2 = [sign(p4-2)*sqrtm(abs(p4-2))+sign(p5-2)*sqrtm(abs(p5-2))+sign(p6-2)*sqrtm(abs(p6-2))==x];
>> f3 = [sign(p1-p4)*sqrtm(abs(p1-p4))+sign(p2-p5)*sqrtm(abs(p2-p5))+sign(p3-p6)*sqrtm(abs(p3-p6))==x];
>> optimize([0<=[p1 p2 p3 p4 p5 p6]<=4,f1,f2,f3],-x,sdpsettings('solver','baron'))

% Optimal values

>> disp(value([x p1 p2 p3 p4 p5 p6]))
    0.6065    1.3333    4.0000    0.5501         0    2.6667    3.4499
  • $\begingroup$ Thanks for the solution. It works great. But, I think Baron is licensed and I am not able to run it. So, is there any other method? $\endgroup$ Jun 24 '17 at 22:05
  • $\begingroup$ There are other local and global solvers. The free "demo" version of BARON will do up to 10 variables and 10 constraints (your problem is under that) and up to 50 nonlinear operations in the problem definition. I think the problem you have provided will make it under that limit, but I'm not sure (exactly how the number of nonlinear operations is counted). You can get a free trial of the full version. You don't need to use YALMIP to run BARON, you can enter in BARON's native format which is not too bad with a problem as small and simple as yours. $\endgroup$ Jun 24 '17 at 22:33
  • $\begingroup$ Anyhow, I've shown you how to mathematically formulate your problem, which seems like a big hurdle you had to get over. now you can implement it in many different modeling systems or solvers. $\endgroup$ Jun 24 '17 at 22:33
  • $\begingroup$ Baron solver said that the model exceeded the demo size and license required. Then, I will try with different solver. However, I was not sure if solvers optimise multiple functions. I was using python 'optimize' library but they are used for single function hence I wanted help for this problem. $\endgroup$ Jun 26 '17 at 8:42
  • $\begingroup$ The formulation I showed you is only optimizing a single function, but subject to multiple constraints. This is a very standard type of optimization problem formulation handled by many solvers. In particular, it involves nonlinear equality constraints. $\endgroup$ Jun 26 '17 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.