Problem with a constraint in the optimisation problem

68 views
Skip to first unread message

glanke92

unread,
Jan 21, 2020, 11:57:46 PM1/21/20
to YALMIP
Hi I am having an issue with a constraint in the optimisation problem that I have developed.

I am using the following constraint.


P = sdpvar(Nunits,1, 'full');

DemandSlack
= sdpvar(1, 1) ;

DemandPenalty = 10 ;

Constraints = [Constraints, (sum(P)+ DemandSlack == Pdemand):'SumPower'];

I actually need to keep the 
sum(P) as close as possible to Pdemand which is a constant.

Actually I get a feasible solution to the above problem. But the problem is no matter the Pdemand it gives the same sum(P) and most of the time it is greater than the Pdemand given.


But when I define the constraint in the following form,

Constraints = [Constraints, (sum(P)<= Pdemand):'SumPower'];

The sum(P) is always very much less than the Pdemand which I do not want to happen.

Can anyone please help me with this.

Johan Löfberg

unread,
Jan 22, 2020, 2:29:47 AM1/22/20
to YALMIP
Impossible to answer as we don't know how you actually penalize the slack etc.

glanke92

unread,
Jan 22, 2020, 2:44:58 AM1/22/20
to YALMIP
Hi Johan !

Can you please tell me what information should I provide here to get a better response regarding the doubt that I have ?

Thank you.,



Johan Löfberg

unread,
Jan 22, 2020, 2:47:25 AM1/22/20
to YALMIP
Complete reproducible code, or at least a description on how you penalize the slack

tulip tulip

unread,
Jan 22, 2020, 4:21:05 AM1/22/20
to YALMIP
Would you please present what your equation and constraints are?

I got that your are looking for solving power system optimization. If you introduce your problem (equation), Frinds are much more comfortable to guide you.

Thank you,

glanke92

unread,
Jan 22, 2020, 8:17:04 PM1/22/20
to YALMIP
Dear Johan,

I have attached the code for your reference.

The problem there is although I change the value of Pdemand by changing the scalar multiplier over there,
I cannot get the expected sum(UpdatedPower) which matches the following the constraint.

Constraints = [Constraints, (sum(P)+ DemandSlack >= Pdemand):'SumPower'];

Actually what I want is sum(P) to be as close as possible to Pdemand while satisfying the other conditions.

That is why I tried adding a slack variable and manipulating it to get the expected outcome.

But it did not work.

Hence I would appreciate if you could give me an idea over here.
error_code.m

glanke92

unread,
Jan 22, 2020, 8:18:25 PM1/22/20
to YALMIP
Hi tulip,

Thanks for your intention to help me with the code.

Can you please have a look at my reply to Johan.

Thanks.

Johan Löfberg

unread,
Jan 23, 2020, 1:57:40 AM1/23/20
to YALMIP
Not sure what you are trying to say. The problem is feasible already without any slack

Then you add a slack, but add no positivity requirement on it, add slack to objective and then naturally (as the problem is easily feasible initially) you find a solution with a negative slack meaning the constraint now is significantly satisfied as you've done the oppositie of relaxing it

glanke92

unread,
Jan 23, 2020, 2:17:52 AM1/23/20
to YALMIP
Hi Johan 

Yeah it is true that the problem is feasible already without any slack.

But the thing is with the constraint


Constraints = [Constraints, (sum(P)<= Pdemand):'SumPower'];

it always gives a result where the sum(P) is less than Pdemand.

But what I want to get is the set of P where the sum(P) is very much close to Pdemand

I hope you got it now ?

Thanks.

Johan Löfberg

unread,
Jan 23, 2020, 2:30:08 AM1/23/20
to YALMIP
Your formulations make no sense.

If you have power generators that are supposed to supply power to cover for a demand, you should have the constraint sum(P)==Pdemand or sum(P)>=Pdemand. If you have a standard setup there is an increasing cost associated to using power and thus with >= the optimal solution will be to produce exactly the demand i.e. the optimal solution will have sum(P)=Pdemand (unless the power is quantized as in your case, and then you will simply get the cheapest solution larger than the required). If you use sum(P)<= Pdemand it will of course lead to a solution where sum(P) is smaller than Pdemand (why generate power which cost money, if someone just is telling you to not produce too much power. Well of course I won't generate power if I don't have to)

glanke92

unread,
Jan 23, 2020, 2:39:00 AM1/23/20
to YALMIP
Dear Johan,

I guess I understood it now.

Thank you.
 

glanke92

unread,
Jan 23, 2020, 7:16:25 PM1/23/20
to YALMIP
Hi Johan,

Still I have a doubt regarding the implementation,

If we consider 

Constraints = [Constraints, (sum(P)>= Pdemand):'SumPower']; and discrete power levels for the generators,

I will get the cheapest solution larger than the required.

But if I want to get the solution which is still cheap but LESS THAN THE REQUIRED (the solution which is closest to the required value but still LESS THAN THE REQUIRED)

what should I do ?

Thank you.

Johan Löfberg

unread,
Jan 24, 2020, 1:47:59 AM1/24/20
to YALMIP
You have already encoded that you want the cheapest solution, since you've added a price on P in the objective. It would never make sense at optimality to use a P which is larger than necessary then.

glanke92

unread,
Feb 9, 2020, 5:33:29 PM2/9/20
to YALMIP
Hi Johan !

I am still struggling with the objective function formulation.

I consider a constraint like the one below.

(sum(P_AC) + sum(P_EWH))*delta T >= total_P *delta T - E_step

Here P_AC and P_EWH can only take discrete levels, Hence MIP. 

delta T and E_step are constants.

In a similar manner to a unit commitment problem, what I am trying to do is to minimize the cost with P_AC and P_EWH.

Actually I am solving an optimization problem every iteration with different values of total_P in each step.

What my intention is to find the 
sum(P_AC) + sum(P_EWH) which is always less than the total_P

But sometimes I end up getting 
sum(P_AC) + sum(P_EWH) > P_total

then it becomes problematic as well.

Can you please give a me an idea here.

Thank you.

Regards
Gayan




Johan Löfberg

unread,
Feb 10, 2020, 1:34:50 AM2/10/20
to YALMIP
If you have added the constraint sum(P_AC) + sum(P_EWH) <= P_total it will be satisfied up to solver tolerances (assuming you actually have solved the problem, i.e. that you aren't looking at the "solution" when the solver has terminated with infeasibility flag etc)
Reply all
Reply to author
Forward
0 new messages