Allocation problem using fmincon
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
I am having a hard time with the following allocation problem. The problem requires the user to distribute, as efficiently as possible, 100 instruments among 60 different sectors. There is a target amount for each sector, however due to a granularity problem; the optimal amount may not always be achieved. I thought of using fmincon, and set up the following codes:
Linear constraints:
Aeq =
100 200 0 0 0 0
0 0 300 400 0 0
0 0 0 0 500 600
beq =
300 0 0
0 800 0
0 0 1100
Lower bounds:
lb =
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
Upper bounds:
Ub =
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
objective function:
F=@(x)(m*x')-yy;
Where
m =
100
200
300
400
500
600
and
yy =
100
1000
1100
My fmincon formula is
WW= fmincon(F,ones(6,3),[],[],m',sum(m),zeros(6,3),ones(6,3));
however I keep on getting the following error message:
Error using fmincon (line 286)
Aeq must have 18 column(s).
Can anyone provide me with a little insight?
Thank you.
0 件のコメント
採用された回答
Brian B
2014 年 7 月 15 日
The syntax for fmincon is
WW = fmincon(F,x0,A,b,Aeq,beq,lb,ub)
In your code, the initial guess x0 is a 6x3 matrix, but fmincon expects the optimization variable x to be a vecto. You could form x instead by stacking the columns of the original matrix.
Then there is some confusion about your equality constraints. Did you mean to use Aeq and beq defined earlier? If so, it appears that you want to define 9 equality constraints. These can be written in terms of the vector x as Aeq2 * x = beq2, where
Aeq2 = blkdiag(Aeq, Aeq, Aeq);
beq2 = beq(:); % stack columns of beq to form a vector
and Aeq is defined in your original question. But the actual call uses m' and sum(m) in place of Aeq and beq. These do not make sense mathematically (even if x is 6x3), as m'*x would be a 1x3 row vector and sum(m) is a scalar.
The upper and lower bounds are easily made into vectors.
Finally, the dimensions in your objective function do not make sense mathematically.
0 件のコメント
その他の回答 (2 件)
Kyle Zarmair
2014 年 7 月 15 日
1 件のコメント
Brian B
2014 年 7 月 15 日
Correct: fmincon will only optimize a vector, not a matrix. But the difference between optimizing a vector and optimizing a matrix is only syntactic; it is just a matter of expressing the problem in a form that fmincon expects.
Whether fmincon is the right tool or not depends on what the problem formulation looks like, which in turn depends on a correctly-written cost function. But it looks like you may end up with a linear program, or possibly a mixed-integer linear program. See http://www.mathworks.com/help/optim/ug/linprog.html or, if some of the variables must be integers, http://www.mathworks.com/help/optim/ug/intlinprog.html.
Here is what I suggest:
- Carefully formulate the problem on paper, defining the optimization variables as a vector x.
- Decide which elements of x (if any) must be integers.
- Make sure the objective function is a scalar (if it is not, see http://www.mathworks.com/help/optim/ug/fgoalattain.html).
- If the cost function involves a constant offset (such as F = @(x) m'*x - c), you can discard the constant offset and add it to the optimal value.
- If, after discarding any constant offset, the objective is linear and there are no nonlinear constraints, DO NOT USE FMINCON.
- Try to work any equality or inequality constraints into one of the forms
- A * x <= b
- Aeq * x = beq
- x <= ub
- lb <= x
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!