Adding spesific constraint for optimization problem in MATLAB usin fmincon function
Show older comments
I'm using the fmincon Function of Matlab to find an optimal solution of power assignments of users in a communication system.
An example scenario includes 3 users and the optimization function tries to find optimal power level assignment. The 'x' variable represents the power level assignments of each users.
Total power is equal to 1 and added as Linear equality constraint for the problem. Aeq*x=beq.
The lower bound and upper bound of each user power level is 0 and 1 consecutively.
The script below solves this optimization problem clearly and gives optimal power levels for all three users.
x0=[0.3,0.2,0.5];
lb=[0 0 0];
ub=[1 1 1];
Aeq = [1,1,1];
beq = [1];
options = optimoptions('fmincon','Algorithm','interior-point','Display','iter');
[x,fval,exitflag,output] = fmincon(@myOpt,x0,[],[],Aeq,beq,lb,ub,[],options);
-----------------------------------------------------------------------------
Here is my question.
I want to add a constraint that maximum two users can be assigned power level at the same time (i.e., x1=[0.1,0.9,0], x2=[0.2,0,0.8] or x2=[0,1,0]).
How can enable this constraint in the fmincon function or other functions in optimization toolbox?
Answers (1)
Matt J
on 28 Jun 2018
0 votes
You cannot handle this through constraints. Just solve the problem 3 times corresponding to the three cases x1=0,x2=0, and x3=0. Then see which of the 3 cases leads to the lowest myOpt value.
9 Comments
Hi Matt J,
thank you for the feedback - again learned a lesson...
I think the problem has to be solved 6 times, because:
x = [0, 0, 1]
x = [0, 1, 0]
x = [1, 0, 0]
are also solutions which are possible additionally to the cases you told.
What to do when problem size is growing up? Would you change to another algorithm? Which one would you suggest in that case?
Would the constraint:
c = sum(round(x,4)~=0) - 2;
work reliable with ga?
Best regards
Stephan
Matt J
on 28 Jun 2018
I think the problem has to be solved 6 times, because:
No, I don't think so, because for example with
x = [0, 0, 1]
x = [0, 1, 0]
Both of these are feasible solutions within the set {x: x(1)=0 }. They should be covered just by making the restriction x(1)=0 in the problem. The other cases you mentioned are similarly covered by one of the original three.
Would the constraint c = sum(round(x,4)~=0) - 2; work reliable with ga?
ga definitely has a better chance of handling it than fmincon, but it is a stochastic algorithm and the problem has an uncertain number of local minima, so you can never be sure how reliable.
In any case, rather than using non-linear discontinuous constraint functions, I would probably recommend expressing it using a combination of integer and inequality constraints. For example, in the 3-variable situation of the OP, you could include three additional binary variables z(i), i=1,2,3 in the problem and impose the linear constraints,
x(i)<=z(i), i=1,2,3
z(1)+z(2)+z(3)<=2
Because the z(i) are binary x(j)>0 would imply z(j)=1 and the sum over z(j) would tell you how many power users are active.
What to do when problem size is growing up?
Note that if the objective function is linear (the OP hasn't told us), then the above could be robustly solved with intlinprog, even in larger dimensional versions of the problem. Otherwise, you would indeed have to resort to ga().
omer faruk gemici
on 29 Jun 2018
omer faruk gemici
on 30 Jun 2018
omer faruk gemici
on 2 Jul 2018
No, I don't think so. Firstly, there are only C(50,2)=1225 combinations per sub-carrier. The C(50,1) combinations are already accounted for, as I explained to Stephan.
Secondly, the optimization as you've described it is separable across sub-carriers. There are no constraints which cause pik, k=1...50, for the i-th carrier to interact with pjk,k=1...50 for the j-th carrier. Therefore, you can solve for each carrier separately, as if it is a 50 variable, 1-carrier problem.
So there are 20*1225=24500 combinations. Doesn't seem too bad.
Categories
Find more on Get Started with Optimization Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!