Allocation problem using fmincon

1 回表示 (過去 30 日間)
Kyle Zarmair
Kyle Zarmair 2014 年 7 月 15 日
回答済み: Kyle Zarmair 2014 年 7 月 15 日
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.

採用された回答

Brian B
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.

その他の回答 (2 件)

Kyle Zarmair
Kyle Zarmair 2014 年 7 月 15 日
Thank you Brien. However I am faced with a problem where I need to allocated financial instruments, each of which have a predetermined size, to specific sectors. For example, I need to allocated 34 000$ to the agriculture sector. To reach this allocation I have to use the instruments at my disposal (example: stock #1 2000$, stock #2 3000, etc.). I must "fill up" thee sectors as closest as possible to the required weight, and I can only use every instrument only once. Do you still recommend me using the fmincon function?
Also, from my understanding, fmincon can only optimize a vector of unknown variables and not a matrix of unknown variables?
  1 件のコメント
Brian B
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:
  1. Carefully formulate the problem on paper, defining the optimization variables as a vector x.
  2. Decide which elements of x (if any) must be integers.
  3. Make sure the objective function is a scalar (if it is not, see http://www.mathworks.com/help/optim/ug/fgoalattain.html).
  4. 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.
  5. If, after discarding any constant offset, the objective is linear and there are no nonlinear constraints, DO NOT USE FMINCON.
  6. Try to work any equality or inequality constraints into one of the forms
  • A * x <= b
  • Aeq * x = beq
  • x <= ub
  • lb <= x

サインインしてコメントする。


Kyle Zarmair
Kyle Zarmair 2014 年 7 月 15 日
Is it possible to optimize not only a single number but an entire matrix? here is a smaller scale version of my problem.
As you can see my matrix of x's is a kinda Arrow Debreu Asset matrix, where every x can only be used once in our matrix. I don't think I can do this with the intlinprog function you previously mentioned.

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by