Allocation problem using fmincon
Show older comments
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.
Accepted Answer
More Answers (2)
Kyle Zarmair
on 15 Jul 2014
0 votes
1 Comment
Brian B
on 15 Jul 2014
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
Kyle Zarmair
on 15 Jul 2014
0 votes
Categories
Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!