# CVX status: infeasible although there are solutions

The following is the code:

``````cvx_begin
variable bor_brwr_lndr(no_cells,no_cells)  nonnegative
expression supply(no_cells,1);
supply = supply+capacity;

for brwr=1:no_cells
for lndr =1:no_cells
supply(brwr) = supply(brwr) + neighs_mapping(brwr,lndr) * bor_brwr_lndr(brwr,lndr); % borrowed, supply increases
supply(lndr) = supply(lndr) - neighs_mapping(brwr,lndr) * bor_brwr_lndr(brwr,lndr); % lent, supply decreases
end
end

minimize sum(demand - supply)
for iter_ci=1:no_cells
sum(bor_brwr_lndr(:,iter_ci)) <= capacity- demand(iter_ci); % Lend only the surplus
supply(iter_ci)<=demand(iter_ci); % Don't borrow after meeting the demand
end

cvx_end
``````

The initial values are the follows:

demand=
1080
1510
710
1700
970
420
750
990
970
920

neighs_mapping=
0 0 0 0 0 1 1 0 0 0
0 0 0 0 0 0 1 0 0 1
0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

capacity = 1000
no_cells = 10

It is a load distribution problem. There are 10 cells and the initial supply is 1000 in each cell. If the demand is more than the supply in a given cell, such a deficit cell can borrow from its neighbouring surplus cells. The neighbours mapping is given by the matrix neighs_mapping (rows indicate borrower and columns indicate lender). The task is to determine who should borrow how much from whom: in bor_brwr_lndr matrix, with the objective that the deficit is minimized.

It can be seen that some borrowing is possible. However, the CVX says that the problem is infeasible. Kindly help me

I really have no idea what you’re doing. You keep overwriting elements of `supply` in the double for loop.

I advise you to stick to the documented features of CVX, which `cvx(zeros(1,no_cells))+capacity` is not. Use an expression array (holder instead). And carefully work through the logic of assigning its elements Then hopefully you will be submitting the problem to CVX that you intend.

if you still are getting infeasible, re-read the link you were previously provided Debugging infeasible models - YALMIP , all of which except for section 1 also applies to CVX.

Hi Mark,

Thanks for the time and reply. I added an explanation below the code. Could you go through it and suggest me what I am missing?

It is basically load distribution problem

I have declared the supply using and expression holder and updated the posted code. @Mark_L_Stone

The error still doesn’t go

You still keep overwriting elements of `supply in the double for loop. You need to reexamine that and figure out what it should be, which I doubt is what it is.

I was only changing the iterator variable to make it more user-readable.

When we borrow, supply should increase, so we add. However, we can only borrow from neighbours - so I am multplying with the indicator neighs_mapping

Maybe your code makes sense to you, but it doesn’t make sense to me. And the infeasibility doesn’t make sense to you. So perhaps that’s a clue you need to fix your code.