# [R] Multi-objective optimization

Duncan Murdoch murdoch at stats.uwo.ca
Thu Oct 18 02:08:31 CEST 2007

```Paul Smith wrote:
>
>> What if simultaneously maximizing f(x,y) and g(x,y) is an incompatible
>> objective?
>>
>> Modifying Duncan's example slightly, What if:
>>
>> f(x,y) = -(x-y)^2 and
>> g(x,y) = -(x-2)^2-(y-x-1)^2?
>>
>> Here:
>> (1) => x = y
>> (2) => y = x + 1
>> (3) => x = y => no solution!
>>
>> In order for a solution to necessarily exist, one needs to define a scalar
>> function that strikes a compromise between f and g.
>>
>
> But imagine that one is sure that there is no incompatibility, how can
> R get the solution? For instance, can R get the solution for Duncan's
> example?
>
I'm pretty sure there is nothing in base R designed to solve it, and I
don't know of any packages that do it:  but there are more than 1000
packages on CRAN, so I could easily have missed one.

I'd suggest looking for literature that describes methods for
numerically solving such systems, and then do a search on CRAN for
packages that mention those methods.

And if that fails, you could try putting something together by writing
functions that call optimize() for the one dimensional optimization
problem of finding x to optimize f given y, and finding y to optimize g
given x, then use optim to find (x,y) minimizing the distance between
these two solutions.  For example, something like this
might work

f <- function(x, y) -(x-y)^2
g <- function(x, y) -(x-2)^2 - (y-1)^2

f1 <- function(y) optimize( function(x) f(x,y), c(-10, 10),
maximum=TRUE)\$maximum
g1 <- function(x) optimize( function(y) g(x,y), c(-10, 10),
maximum=TRUE)\$maximum

sqdist <- function(xy) {
x <- xy
y <- xy
pt1 <- cbind(f1(y), y)
pt2 <- cbind(x, g1(x))
sum((pt1-pt2)^2)
}

optim(c(0,0), sqdist)

but I wouldn't trust it on a real problem: the results of f1 and g1 will
probably not be very smooth, and that will likely mess up optim if you
use a fast method (not Nelder-Mead, as I did).  But give it a try.

Duncan Murdoch

```