Optimization: Capacitated Facility Location Problem
Show older comments
Am tasked to solve the capacitated facility location problem, i.e.,
subject to

I've looked at intlinprog, but I don't understand how to use this function (if it's possible) to solve this type of problem due to the summations.
If it's possible, how would I go about?
Answers (2)
x=optimvar('x',[n,m],'Upper',0);
y=optimvar('y',n,'type','integer','Lower',0,'Upper',1);
objective=sum(f(:).*y(:))+sum(c(:).*x(:));
constraints.colsum=sum(x,1)==d(:).';
constraints.rowsum=sum(x,2)<=s(:).*y(:);
solution=solve( optimproblem('Objective', objective,'Constraints', constraints ) );
8 Comments
John D'Errico
on 24 Nov 2022
Good. I do too often forget about using this formulation for optimizations.
Sebastian Daneli
on 24 Nov 2022
Edited: Sebastian Daneli
on 24 Nov 2022
You can obtain the matrix forms used by intlinprog by doing,
p = prob2struct( optimproblem('Objective', objective,'Constraints', constraints ) )
According to the OP's formula, the objective
objective=sum(f(:).*y(:))+sum(c(:).*x(:));
is not correct. The inner summation starts at i, not at 1. But I doubt that this is wanted.
Sebastian Daneli
on 24 Nov 2022
To fix the issue mentioned by Torsten, if indeed we only wish to sum over the upper triangle of x, then this is the required modification.
T=triu(c);
objective=sum(f(:).*y(:))+sum(T(:).*x(:));
Sebastian Daneli
on 28 Nov 2022
Edited: Sebastian Daneli
on 28 Nov 2022
The problem is not feasible because the d(j) values that you have supplied are all positive, while xij are constrained to be negative. That makes it impossible to satisfy
.
Your second call to intlinprog doesn't show this because you have mixed up the order of some of the inputs:
[x,fval,exitflat,output]=intlinprog(p.f,p.intcon,p.Aineq,p.bineq,p.Aeq,p.beq,p.lb,p.ub)
John D'Errico
on 24 Nov 2022
1 vote
First, what is the difference between the summation over i in a sum like this:
sum(f(i)*yi))
and the dot product of two vectors:
f' * y
where f and y are column vectors of the same lengths?
Answer: Nothing, as long as the vectors are real numbers. If they could be complex, then I might need to worry about conjugate tranpose, versus transpose, but that is irrlevant here.
Is that not the first part of your objective? Next, look at the second term in the objective. x is apparently an array, of size n by m. Can you represent that double sum as a linear combination of the elements of x? (Yes.) You will need to use kron to do it.
Next, both x AND y are unknowns in the problem. So you will need to treat x and y as part of the same vector. essentially, you need to pack it all into one long vector.
I won't get more into those questions, since your problem as stated is meaningless. You have a fundamental flaw in the equatinos you wrote as equaity constraints.
You show the sum over i, of the matrix x(i,j). Once you sum over i, i goes away. The result cannot be another matrix d(i,j). Until you resolve that, this problem has no solution.
5 Comments
Sebastian Daneli
on 24 Nov 2022
John D'Errico
on 24 Nov 2022
Edited: John D'Errico
on 24 Nov 2022
Better now. Suppose you have the array x(i,j). Can you convert that set of equality constraints into a problem that a solver like intlinprog would handle? Of course.
INTLINPROG assumes a matrix formulation for the equality constraints, where the objective (x) is a VECTOR. Forget about y for now. Can we write that summation as a set of linear equality constraints?
For example, suppose x was a 2x3 array? So n = 2, m = 3? What would we do?
n = 2;
m = 3;
I'll write x us a symbolic array, so you can visualize what is happening.
x = sym('x',[n,m])
Now, that sum you want to compute is the sum in MATLAB of
sum(x,1)
Do you agree? But can we form that same sum if x were unrolled into a vector? We can see how the elements of x appear, when we treat that matrix as a vector.
xunrolled = x(:)
Now, we need to use a variation of what I long ago called the kron trick.
Aeq = kron(eye(m),ones(1,n))
You may not see where this is going immediately, but now try this.
Aeq*xunrolled
Do you see we have created the very same sums of elements? That equality constraint now becomes
A*xunrolled == d
where d is a known vector of length m.
Similarly, all of those expressions can be written in terms of matrices and vectors. A matrix times a vector is just a sum of products of elements in the end. So just take each expression in that problem, converting it into what you need in terms of matrices and vectors. Do one piece at a time. Take your time. Get each piece right, then move to the next one.
I'll even give you a hint about how to handle the inequality constraints. That is, what does this do?
Aineq = kron([1 1 1],eye(2))
Again, a variation of the kron trick. kron is terribly useful in these problems. So now, try this:
Aineq*xunrolled
Don't forget that you will need to treat the unknowns as a vector that combines x and y, as one long vector. Some of the unknowns will be boolean, so integers from the set {0,1}. But intlinprog can handle a partially integer problem.
Sebastian Daneli
on 24 Nov 2022
Sebastian Daneli
on 24 Nov 2022
Edited: Sebastian Daneli
on 24 Nov 2022
Torsten
on 24 Nov 2022
You have c_ij for 1 <= i < = 5 and 1 <= j <= 3
So c in your example should be 5x3, not 3x5.
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

