Georgios
Georgios

Reputation: 1037

Java Cplex Reduced Optimality and First Feasible Solution

I am working on a LP written in Java and using cplex as a solver. The optimal solution takes some time to be found. It would be sufficient if I had a feasible solution that would be calculated faster or just a solution with reduced optimality.

In the CPLEX User’s Manual I have found the following two parameters:

For optimality: https://www.ibm.com/support/knowledgecenter/SSSA5P_12.7.0/ilog.odms.cplex.help/CPLEX/Parameters/topics/EpOpt.html

cplex.setParam(IloCplex.Param.Simplex.Tolerances.Optimality, 1.0e-1);

For the first feasible solution:

cplex.setParam(IloCplex.Param.MIP.Limits.Solutions, 1);

I have used both of these parameters in my model but the solution of the objective function remains the same as well as the computing time.

Furthermore, I have used them in the following small LP but with no success.

package cplexTest;

import ilog.concert.*;
import ilog.cplex.*;

public class TestC {
    public static void main (String[] args) {
       model1();
}

   public static void model1() {
       try {
           IloCplex cplex = new IloCplex();
           cplex.setParam(IloCplex.Param.Simplex.Tolerances.Optimality, 1.0e-1);
           cplex.setParam(IloCplex.Param.MIP.Limits.Solutions, 100);

           //variables
           IloNumVar x = cplex.numVar(0, Double.MAX_VALUE, "x");
           IloNumVar y = cplex.numVar(0, Double.MAX_VALUE, "y");

           //expressions
           IloLinearNumExpr objective = cplex.linearNumExpr();
           objective.addTerm(0.12, x);
           objective.addTerm(0.15, y);

           // define objective
           cplex.addMinimize(objective);

           //define constraints
           cplex.addGe(cplex.sum(cplex.prod(60, x), cplex.prod(60, y)),300);
           cplex.addGe(cplex.sum(cplex.prod(12, x), cplex.prod(6, y)),36);
           cplex.addGe(cplex.sum(cplex.prod(10, x), cplex.prod(30, y)),90);

           //solve
           if (cplex.solve()) {
               System.out.println("obj = "+cplex.getObjValue());
               System.out.println("x = "+cplex.getValue(x));
               System.out.println("y = "+cplex.getValue(y));
           }
           else {
               System.out.println("Model not solved");
           }
       }
       catch (IloException exc) {
           exc.printStackTrace();
       }
   }
}

Upvotes: 0

Views: 337

Answers (1)

Erwin Kalvelagen
Erwin Kalvelagen

Reputation: 16714

You probably should post the logs to get better answers, but I can make a few points.

  1. LPs in general solve fast. MIPs can be slow.
  2. If your LP is extremely large try the interior point method. For large problems the interior point (barrier) method can be significant faster than the primal or dual simplex method. The interior point solver can also use multiple threads (simplex is serial only).
  3. For very large LPs you may want to watch memory usage (especially when using the concurrent LP method). If you are exceeding your RAM size, the algorithm may start "thrashing" (slowing down because using disk IO through virtual memory). So turn off concurrent LP and use only the best LP algorithm.
  4. In general you should not tinker with the reduced cost tolerance unless you really have a good reason to do so and you know what you are doing. To find just a feasible point, remove your objective. You also may look at making the model sparser.
  5. The solution limit is for MIP models, not for LPs.

Upvotes: 1

Related Questions