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?

 채택된 답변

Alan Weiss
Alan Weiss 2014년 12월 10일

1 개 추천

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

blitz
blitz 2014년 12월 11일
편집: blitz 2014년 12월 11일
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 2014년 12월 11일
편집: Alan Weiss 2014년 12월 11일
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 2014년 12월 11일
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 2014년 12월 11일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

질문:

2014년 12월 10일

댓글:

2014년 12월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by