Allocation problem using fmincon
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kyle Zarmair
el 15 de Jul. de 2014
Respondida: Kyle Zarmair
el 15 de Jul. de 2014
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 comentarios
Respuesta aceptada
Brian B
el 15 de Jul. de 2014
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 comentarios
Más respuestas (2)
Kyle Zarmair
el 15 de Jul. de 2014
1 comentario
Brian B
el 15 de Jul. de 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
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!