Struggling with simple constraints in constrOptim

后端 未结 1 466
执笔经年
执笔经年 2021-01-06 13:52

I have a function in R that I wish to maximise subject to some simple constraints in optim or constrOptim, but I\'m struggling to get my head aroun

相关标签:
1条回答
  • 2021-01-06 14:09

    According to ?constrOptim:

    The feasible region is defined by ‘ui %*% theta - ci >= 0’. The
    starting value must be in the interior of the feasible region, but
    the minimum may be on the boundary.
    

    So it is just a matter of rewriting your constraints in matrix format. Note, an identity constraint is just two inequality constraints.

    Now we can define in R:

    ## define by column
    ui = matrix(c(1,-1,0,0,1,-1,1,-1,
                  0,0,1,-1,1,-1,1,-1,
                  0,0,0,0,0,0,1,-1,
                  0,0,0,0,0,0,1,-1,
                  0,0,0,0,0,0,1,-1,
                  0,0,0,0,0,0,1,-1), ncol = 6)
    
    ci = c(0, -1000000, 5000, -1000000, 5000000, 90000000, -90000000)
    

    Additional Note

    I think there is something wrong here. sp1 + sp2 = 5000000, but both sp1 and sp2 can not be greater than 1000000. So there is no feasible region! Please fix your question first.

    Sorry, I was using sample data that I hadn't fully checked; the true optimisation is for 40 sp values with 92 constraints which would if I'd replicated here in full would have made the problem more difficult to explain. I've added a few extra zeroes to make it feasible now.

    0 讨论(0)
提交回复
热议问题