Hello,
I am trying to solve a depot location allocation problem . I am unable to formulate and solve it in MATLAB. Can anyone help me solve this problem?

 Réponse acceptée

Alan Weiss
Alan Weiss le 10 Déc 2014

1 vote

Maybe you could put your problem in an MILP framework, along the lines as this Travelling Salesman Problem example. Notice that, despite the nonlinear distances, the problem itself is linear.
This example might also be relevant: Factory, Warehouse, Sales Allocation Model.
Alan Weiss
MATLAB mathematical toolbox documentation

4 commentaires

blitz
blitz le 11 Déc 2014
Modifié(e) : blitz le 11 Déc 2014
Thanks Alan, I have figured out to code this but still my solution doesn't converge to optimum rather it stays at my initial guess of depot locations. Here is my code. This is for 4 customers and 3 depots. Code doesn't give any error but location of my depot doesn't change from what i give in initial guess. Can you find out what I am missing here? Thanks
fun2=@(z)cost_function2(zvectorized,Cvec,M,N); options = optimoptions(@fmincon,'Algorithm','sqp'); options.Display='iter'; [zfinal,fval,exitflag,output]=fmincon(fun2,z0,[],[],Aeq,beq,lb,[],[],options);
Cost function:
function cost = cost_function2(Z,Cvec,M,N) %UNTITLED4 Summary of this function goes here xcoeff=Z(1:2*M,1); Xvec=reshape(xcoeff,2,M); tcoeff=Z((2*M)+1:(M*N)+2*M,1); t=reshape(tcoeff,M,N); cost=0;
for i=1:M for j=1:N cost=cost+t(i,j)*sqrt((Xvec(:,i)-Cvec(:,j))'*(Xvec(:,i)-Cvec(:,j))); end end end
OUTPUT:
zfinal =
0
0
0
0
0
0
1.6667
1.6667
1.6667
2.0000
2.0000
2.0000
2.3333
2.3333
2.3333
1.3333
1.3333
1.3333
So locations are all zeros which mean the solution wasn't obtained. Please help.
Alan Weiss
Alan Weiss le 11 Déc 2014
Modifié(e) : Alan Weiss le 11 Déc 2014
It would be much easier for us to read your question if you would format the MATLAB code using the {} Code button.
I do not understand your code, but then I have trouble reading it because of the formatting. Nevertheless, I think I found an error:
fun2=@(z)cost_function2(zvectorized,Cvec,M,N);
It seems to me that fun2 returns a constant no matter what value you put in for z. Perhaps you meant
fun2=@(zvectorized)cost_function2(zvectorized,Cvec,M,N);
Alan Weiss
MATLAB mathematical toolbox documentation
blitz
blitz le 11 Déc 2014
Thank you so much! You're awesome, that worked. I just couldn't believe I was missing such a detail. I up-voted the answer. Sorry about the bad arrangement of code. I am new to this and didn't know about it. I thank you once again.
Image Analyst
Image Analyst le 11 Déc 2014
In the meantime, Mathworkers and others with enough reputation points can "Edit" the post to see the code in a form better for viewing and copying and pasting.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by