给定R中的一组约束,如何优化多个目标/变量? [英] How to optimize over multiple objectives/variables given a set of constraints in R?

查看:41
本文介绍了给定R中的一组约束,如何优化多个目标/变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出2个未知变量 x =(x1,x2),我想找到 x1,x2 的最小值,从而使一组约束 Ax> = c 成立.这是一个玩具示例,我分别在 x1 x2 上进行了优化(后来我意识到这不是正确的方法!):

Given 2 unknown variables x = (x1, x2), I want to find the minimum values of x1, x2 such that a set of constraints Ax >= c holds. Here is a toy example where I optimized over x1 and x2, separately (I realized afterwards that this was not the correct approach!):

我在R中对此进行了编码:

I coded this up in R:

library(lpSolveAPI)
c_vec <- c(0, 0, -0.42, 0.42, -0.81)
A_mat_col1 <- c(16, -15, -2, 3, 0.027)
A_mat_col2 <- c(15, 13, 16, 12, 13)
my.lp <- make.lp(nrow = 5, ncol = 2)
set.constr.type(my.lp, rep(">=", 5))
set.rhs(my.lp, c_vec)
set.column(my.lp, 1, A_mat_col1)
set.column(my.lp, 2, A_mat_col2)
set.bounds(my.lp, lower = rep(-Inf, 2), upper = rep(Inf, 2))
> my.lp
Model name: 
             C1     C2           
Minimize      0      0           
R1           16     15  >=      0
R2          -15     13  >=      0
R3           -2     16  >=  -0.42
R4            3     12  >=   0.42
R5        0.027     13  >=  -0.81
Kind        Std    Std           
Type       Real   Real           
Upper       Inf    Inf           
Lower      -Inf   -Inf  

然后循环遍历以将 x1 x2 最小化,如下所示:

And then looped over minimizing x1 and x2 as follows:

lower <- vector()
for(i in 1:2){
  set.objfn(my.lp, make_basis(i, p = 2))
  lp.control(my.lp, sense = "min")
  # If return value is 0, then problem is solved successfully
  if(solve(my.lp) == 0){
    lower[i] <- get.objective(my.lp)
  # If return value is 3, then it's unbounded and I set lower bound to -Inf
  }else if(solve(my.lp) == 3){
    lower[i] <- -Inf
  }
}
> lower
[1]       -Inf 0.02876712

所以x1的最小值为-Infx2的最小值为0.02876712.但是,这不满足约束条件集.例如,第一个约束是 16x1 + 15x2> = 0 ,因为 x1 -Inf ,所以结果将为负.因此不满足第一个约束条件.

So the minimum value of x1 is -Inf, and the minimum value of x2 is 0.02876712. However, this does not satisfy the set of constraints. For example, the first constraint is 16x1 + 15x2 >= 0, since x1 is -Inf, then the result will be negative. So the first constraint is not satisfied.

所以现在我在想,也许我应该解决以下问题:

So now I'm thinking that perhaps I should be solving the following problem instead:

有没有一种方法可以优化R中的多个目标?

Is there a way to optimize over multiple objectives in R?

推荐答案

有多个目标,通常最好的方法是找到有效点的 set (也称为Pareto最优或非支配点).这些点使得没有其他点具有至少一个更好的目标值,而所有其他目标至少都同样好.不幸的是,在手头的问题上没有有效的点,因为对于x1的任何值,我们都可以通过使x2足够大来满足所有约束,因此,给定x1和x2,我们可以发现x1'>x1和x2'>满足约束的x2.

With multiple objectives the best one can do, in general, is to find the set of efficient points (also called Pareto optimal or nondominated points). These are points such that there is no other other point which has at least one objective value that is better while all other objectives are at least as good. Unfortunately in the problem at hand there are no efficient points because for any value of x1 we can satisfy all constraints by making x2 sufficiently large therefore given any x1 and x2 we can find x1' > x1 and x2' > x2 that also satisfy the constraints.

(顺便说一下,请注意lpSolveAPI假定约束x> 0 = 0.)

(By the way, note that lpSolveAPI assumes the constraint x >= 0.)

这篇关于给定R中的一组约束,如何优化多个目标/变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆