Search code examples
functioncplexlogarithm

Can cplex solve problems with logarithmic objective fucntions?


can CPLEX, e.g., in python API, solve a problem like max( Sum(log(x)) )? Basically i have a problem with logarithmic ( as simple as log(x) ) objective and linear constraints.

best, Pavlos


Solution

  • then you could use CPOptimizer:

    In OPL the following code works fine

    using CP;
    
    dvar int x in 0..100000;
    dvar int y in 0..100000;
    
    dexpr float ax=1+x/1000;
    dexpr float ay=1+y/1000;
    
    minimize log(ax-ay);
    subject to
    {
      abs(ax-ay)>=1;
    }
    

    and with python docplex you can write

    from docplex.cp.model import CpoModel
    
    mdl = CpoModel(name='buses')
    x = mdl.integer_var(0,100000,name='x')
    y = mdl.integer_var(0,100000,name='y')
    mdl.add(mdl.abs(x/1000-y/1000)>=1);
    mdl.minimize(mdl.log(mdl.abs(x/1000-y/1000)))
    
    msol=mdl.solve()
    
    print("x=",msol[x])
    print("y=",msol[y])