0
votes

I'm developing an Optimization tool for a domestic energy system that also contains a battery. All values are correct and the solution makes sense. The problem is that the solution contains very strong fluctuations. Meaning that the decision variable is often either 0 or the maximum value. In order to avoid that I would like to add a quadratic constraint that penalizes the difference of two values (something like the derivative). Should look something like this:

((x[t] - x[t-1]) / stepsize) ^ 2

Where x is the decision variable of interest. E.g. power_g_h[t].

My objective function (so far) ist definded as follows:

IloLQNumExpr expr = model.lqNumExpr();

        for (int t = 0; t < timesteps; t++) {
            expr.addTerm(problem.getCosts().getElectricityCosts(t), power_g_h[t]);
            expr.addTerm(problem.getCosts().getElectricityCosts(t), power_g_b[t]);
            expr.addTerm(problem.getCosts().getElectricityCosts(t), power_g_bev[t]);
            expr.addTerm(problem.getCosts().getFeedCompensation(), power_pv_g[t]);

        } 

I hope this was somewhat understandable and someone is able to tell whether or not this is even possible in CPLEX.

If this is not possible, I would be very happy about hints on how to "smoothen" a solution in CPLEX.

With kind regards,

L.

1
Yes, you can add quadratic terms to the objective. See the QPex1.java example that is included with CPLEX. Is that what you were asking? You should just try it to see if it gives you the desired smoothing effect. Another idea would be to try using the solution pool to inspect alternative optimal solutions. - rkersh
Thanks for your answer. The solution to the problem was to rewrite (x2-x1)^2 as x2x2 - 2x2x1 + x1x1. But the hint for QPex1.java was also very helpful. - L. Burg
Glad to help. By the way, if you'd like to earn some reputation points, feel free to provide a more detailed answer to this question (it's perfectly legal and encouraged to answer and "accept" your own answers). - rkersh

1 Answers

0
votes

The problem was solved as follows:

It does not seem to be possible to add an expression like x * ((a - b) ^ 2). Instead the solution was to write the above as x*a*a - 2x*a*b + x*b*b. Where x is the penalty factor and a & b are the decision variables. This way it was possible to add the term to the objective function in cplex. In code it looks something like this:

IloCplex model = new IloCplex();
...
IloLQNumExpr expr = model.lqNumExpr();

expr.addTerm(x, a, a);
expr.addTerm(x, b, b);
expr.addTerm(-2 * x, a, b);

In my case a and b was the same variable for two consecutive timestep, s.t. the change over time was kept small.