# Decision Optimization

View Only

## Can CPLEX solve a problem with a logarithm in the objective function (e.g. optimize entropy) #### Patrick KreitzberThu November 05, 2020 10:11 AM #### ALEX FLEISCHERThu November 05, 2020 10:33 AM #### Philippe CouronneThu November 05, 2020 11:43 AM #### Farahanim MisniThu November 19, 2020 08:37 AM • #### 1.  Can CPLEX solve a problem with a logarithm in the objective function (e.g. optimize entropy)

Posted Thu November 05, 2020 10:11 AM
Hi,

I am trying to optimize for the Shannon entropy of a system. This would mean the objective function is (summing over i) Σxi*log(xi).  The problem is linearly constrained.

I am not sure if there is anyway to get CPLEX to solve for this directly? Preferably using the C API as that is what I have a decent amount of experience using. Any help would be appreciated!

------------------------------
Patrick
------------------------------

• #### 2.  RE: Can CPLEX solve a problem with a logarithm in the objective function (e.g. optimize entropy)

Posted Thu November 05, 2020 10:33 AM
Hi,

you can either use CPO

using CP;

int scale=1000;

dvar int scalex in 1..1000000;
dexpr float x=scalex/scale;

maximize x;

subject to
{
log(x)<=2.5;
}

execute
{
writeln("x=",x);
}

works fine and you can do that in C++ too

or you can linearize and then use CPLEX MIP

------------------------------
ALEX FLEISCHER
------------------------------

• #### 3.  RE: Can CPLEX solve a problem with a logarithm in the objective function (e.g. optimize entropy)

Posted Thu November 05, 2020 11:43 AM
Edited by Philippe Couronne Thu November 05, 2020 12:05 PM

You could linearize the function x -> xlog(x), that is approximate it with a piecewise linear function F.
then you define new variables yj == F(xj) and minimize the sum of yj.
As Alex mentioned, this will introduce binary variables and change the nature of your problem to MILP.

------------------------------
Philippe Couronne
------------------------------

• #### 4.  RE: Can CPLEX solve a problem with a logarithm in the objective function (e.g. optimize entropy)

Posted Thu November 19, 2020 08:37 AM
May I know, why the constraint become log(x)<=2.5?

------------------------------
Farahanim Misni
------------------------------

• #### 5.  RE: Can CPLEX solve a problem with a logarithm in the objective function (e.g. optimize entropy)

Posted Thu November 19, 2020 08:43 AM
Hi,

what do you mean ? With CPOptimizer within CPLEX you can use log and as an example I wrote

``log(x)<=2.5;​``

------------------------------
[Alex] [Fleischer]
[EMEA CPLEX Optimization Technical Sales]
[IBM]
------------------------------