google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
11.25k stars 2.13k forks source link

process crash by CBC_MIXED_INTEGER_PROGRAMMING solver #1571

Closed zhengdi1992 closed 5 years ago

zhengdi1992 commented 5 years ago

i find the process will crash in java example SimpleMipProgram.java i have install or-tools successfully by make java and make java_test

after create a java project and add lib com.google.ortools.jar and protobuf.jar and also add dylib libjniortools.dylib libortools.dylib and also all *.dylib where in the dependencies/install/lib

only output

Number of variables = 2
Number of constraints = 2

Process finished with exit code 132 (interrupted by signal 4: SIGILL)

any help for it?

zhengdi1992 commented 5 years ago

lpsolve is ok

boolean printModel = false;
    String solverType = "CLP_LINEAR_PROGRAMMING";
    MPSolver solver = createSolver(solverType);
    if (solver == null) {
      System.out.println("Could not create solver " + solverType);
      return;
    }
    double infinity = Double.POSITIVE_INFINITY;
    // x1, x2 and x3 are continuous non-negative variables.
    MPVariable x1 = solver.makeNumVar(0.0, infinity, "x1");
    MPVariable x2 = solver.makeNumVar(0.0, infinity, "x2");
    MPVariable x3 = solver.makeNumVar(0.0, infinity, "x3");

    // Maximize 10 * x1 + 6 * x2 + 4 * x3.
    MPObjective objective = solver.objective();
    objective.setCoefficient(x1, 10);
    objective.setCoefficient(x2, 6);
    objective.setCoefficient(x3, 4);
    objective.setMaximization();

    // x1 + x2 + x3 <= 100.
    MPConstraint c0 = solver.makeConstraint(-infinity, 100.0);
    c0.setCoefficient(x1, 1);
    c0.setCoefficient(x2, 1);
    c0.setCoefficient(x3, 1);

    // 10 * x1 + 4 * x2 + 5 * x3 <= 600.
    MPConstraint c1 = solver.makeConstraint(-infinity, 600.0);
    c1.setCoefficient(x1, 10);
    c1.setCoefficient(x2, 4);
    c1.setCoefficient(x3, 5);

    // 2 * x1 + 2 * x2 + 6 * x3 <= 300.
    MPConstraint c2 = solver.makeConstraint(-infinity, 300.0);
    c2.setCoefficient(x1, 2);
    c2.setCoefficient(x2, 2);
    c2.setCoefficient(x3, 6);

    System.out.println("Number of variables = " + solver.numVariables());
    System.out.println("Number of constraints = " + solver.numConstraints());

    if (printModel) {
      String model = solver.exportModelAsLpFormat();
      System.out.println(model);
    }

    final MPSolver.ResultStatus resultStatus = solver.solve();

    // Check that the problem has an optimal solution.
    if (resultStatus != MPSolver.ResultStatus.OPTIMAL) {
      System.err.println("The problem does not have an optimal solution!");
      return;
    }

    // Verify that the solution satisfies all constraints (when using solvers
    // others than GLOP_LINEAR_PROGRAMMING, this is highly recommended!).
    if (!solver.verifySolution(/*tolerance=*/1e-7, /* log_errors= */ true)) {
      System.err.println("The solution returned by the solver violated the"
          + " problem constraints by at least 1e-7");
      return;
    }

    System.out.println("Problem solved in " + solver.wallTime() + " milliseconds");

    // The objective value of the solution.
    System.out.println("Optimal objective value = " + solver.objective().value());

    // The value of each variable in the solution.
    System.out.println("x1 = " + x1.solutionValue());
    System.out.println("x2 = " + x2.solutionValue());
    System.out.println("x3 = " + x3.solutionValue());

    final double[] activities = solver.computeConstraintActivities();

    System.out.println("Advanced usage:");
    System.out.println("Problem solved in " + solver.iterations() + " iterations");
    System.out.println("x1: reduced cost = " + x1.reducedCost());
    System.out.println("x2: reduced cost = " + x2.reducedCost());
    System.out.println("x3: reduced cost = " + x3.reducedCost());
    System.out.println("c0: dual value = " + c0.dualValue());
    System.out.println("    activity = " + activities[c0.index()]);
    System.out.println("c1: dual value = " + c1.dualValue());
    System.out.println("    activity = " + activities[c1.index()]);
    System.out.println("c2: dual value = " + c2.dualValue());
    System.out.println("    activity = " + activities[c2.index()]);

maybe some problems in my cbc install?

lperron commented 5 years ago

Can you use GLOP instead of CLP ? Laurent Perron | Operations Research | lperron@google.com | (33) 1 42 68 53 00

Le mer. 11 sept. 2019 à 13:27, Alardear notifications@github.com a écrit :

lpsolve is ok

boolean printModel = false; String solverType = "CLP_LINEAR_PROGRAMMING"; MPSolver solver = createSolver(solverType); if (solver == null) { System.out.println("Could not create solver " + solverType); return; } double infinity = Double.POSITIVE_INFINITY; // x1, x2 and x3 are continuous non-negative variables. MPVariable x1 = solver.makeNumVar(0.0, infinity, "x1"); MPVariable x2 = solver.makeNumVar(0.0, infinity, "x2"); MPVariable x3 = solver.makeNumVar(0.0, infinity, "x3");

// Maximize 10 * x1 + 6 * x2 + 4 * x3.
MPObjective objective = solver.objective();
objective.setCoefficient(x1, 10);
objective.setCoefficient(x2, 6);
objective.setCoefficient(x3, 4);
objective.setMaximization();

// x1 + x2 + x3 <= 100.
MPConstraint c0 = solver.makeConstraint(-infinity, 100.0);
c0.setCoefficient(x1, 1);
c0.setCoefficient(x2, 1);
c0.setCoefficient(x3, 1);

// 10 * x1 + 4 * x2 + 5 * x3 <= 600.
MPConstraint c1 = solver.makeConstraint(-infinity, 600.0);
c1.setCoefficient(x1, 10);
c1.setCoefficient(x2, 4);
c1.setCoefficient(x3, 5);

// 2 * x1 + 2 * x2 + 6 * x3 <= 300.
MPConstraint c2 = solver.makeConstraint(-infinity, 300.0);
c2.setCoefficient(x1, 2);
c2.setCoefficient(x2, 2);
c2.setCoefficient(x3, 6);

System.out.println("Number of variables = " + solver.numVariables());
System.out.println("Number of constraints = " + solver.numConstraints());

if (printModel) {
  String model = solver.exportModelAsLpFormat();
  System.out.println(model);
}

final MPSolver.ResultStatus resultStatus = solver.solve();

// Check that the problem has an optimal solution.
if (resultStatus != MPSolver.ResultStatus.OPTIMAL) {
  System.err.println("The problem does not have an optimal solution!");
  return;
}

// Verify that the solution satisfies all constraints (when using solvers
// others than GLOP_LINEAR_PROGRAMMING, this is highly recommended!).
if (!solver.verifySolution(/*tolerance=*/1e-7, /* log_errors= */ true)) {
  System.err.println("The solution returned by the solver violated the"
      + " problem constraints by at least 1e-7");
  return;
}

System.out.println("Problem solved in " + solver.wallTime() + " milliseconds");

// The objective value of the solution.
System.out.println("Optimal objective value = " + solver.objective().value());

// The value of each variable in the solution.
System.out.println("x1 = " + x1.solutionValue());
System.out.println("x2 = " + x2.solutionValue());
System.out.println("x3 = " + x3.solutionValue());

final double[] activities = solver.computeConstraintActivities();

System.out.println("Advanced usage:");
System.out.println("Problem solved in " + solver.iterations() + " iterations");
System.out.println("x1: reduced cost = " + x1.reducedCost());
System.out.println("x2: reduced cost = " + x2.reducedCost());
System.out.println("x3: reduced cost = " + x3.reducedCost());
System.out.println("c0: dual value = " + c0.dualValue());
System.out.println("    activity = " + activities[c0.index()]);
System.out.println("c1: dual value = " + c1.dualValue());
System.out.println("    activity = " + activities[c1.index()]);
System.out.println("c2: dual value = " + c2.dualValue());
System.out.println("    activity = " + activities[c2.index()]);

maybe some problems in my cbc install?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/or-tools/issues/1571?email_source=notifications&email_token=ACUPL3PT6QKFLZU34G3HCXTQJDI3NA5CNFSM4IVSXTBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6OFIPA#issuecomment-530338876, or mute the thread https://github.com/notifications/unsubscribe-auth/ACUPL3MYUVIUTZO4WFB53BLQJDI3NANCNFSM4IVSXTBA .

zhengdi1992 commented 5 years ago

yep, in the mip case only change OptimizationProblemType.CBC_MIXED_INTEGER_PROGRAMMING to OptimizationProblemType.GLOP_LINEAR_PROGRAMMING than it will work ok...

but, why not works well in CBC_MIXED_INTEGER_PROGRAMMING model? it means that mip problem can not use coin-or/cbc

lperron commented 5 years ago

Please be precise.

Your code use CLP, which is an LP solver, not a MIP solver. GLOP is our internal version of an LP solver, so you can replace it.

CBC is a MIP solver, and it is known to be problematic, especially with very small models, where simplification tends to be over-agressive.

What you can do is to export the model as a MPS file, and to check wether the clp binary crashes on it. If it does, please send the bug report to the Coin team.

If it does not, then we start investigating.

Laurent Perron | Operations Research | lperron@google.com | (33) 1 42 68 53 00

Le mer. 11 sept. 2019 à 13:40, Alardear notifications@github.com a écrit :

yep, in the mip case only change OptimizationProblemType.CBC_MIXED_INTEGER_PROGRAMMING to OptimizationProblemType.GLOP_LINEAR_PROGRAMMING than it will work ok...

but, why not works well in CBC_MIXED_INTEGER_PROGRAMMING model? it means that mip problem can not use coin-or/cbc

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/google/or-tools/issues/1571?email_source=notifications&email_token=ACUPL3OXDUHSJSODE3JO7KDQJDKJFA5CNFSM4IVSXTBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6OGDHI#issuecomment-530342301, or mute the thread https://github.com/notifications/unsubscribe-auth/ACUPL3JRSKUYGKZVTSJO6NLQJDKJFANCNFSM4IVSXTBA .

zhengdi1992 commented 5 years ago

the wrong code was in the class SimpleMipProgram.java

// [START solver]
    // Create the linear solver with the CBC backend.
    MPSolver solver = new MPSolver(
        "SimpleMipProgram", MPSolver.OptimizationProblemType.CBC_MIXED_INTEGER_PROGRAMMING);
    // [END solver]

    // [START variables]
    double infinity = java.lang.Double.POSITIVE_INFINITY;
    // x and y are integer non-negative variables.
    MPVariable x = solver.makeIntVar(0.0, infinity, "x");
    MPVariable y = solver.makeIntVar(0.0, infinity, "y");

    System.out.println("Number of variables = " + solver.numVariables());
    // [END variables]

    // [START constraints]
    // x + 7 * y <= 17.5.
    MPConstraint c0 = solver.makeConstraint(-infinity, 17.5, "c0");
    c0.setCoefficient(x, 1);
    c0.setCoefficient(y, 7);

    // x <= 3.5.
    MPConstraint c1 = solver.makeConstraint(-infinity, 3.5, "c1");
    c1.setCoefficient(x, 1);
    c1.setCoefficient(y, 0);

    System.out.println("Number of constraints = " + solver.numConstraints());
    // [END constraints]

    // [START objective]
    // Maximize x + 10 * y.
    MPObjective objective = solver.objective();
    objective.setCoefficient(x, 1);
    objective.setCoefficient(y, 10);
    objective.setMaximization();
    // [END objective]

    // [START solve]
    final MPSolver.ResultStatus resultStatus = solver.solve();
    // Check that the problem has an optimal solution.
    if (resultStatus != MPSolver.ResultStatus.OPTIMAL) {
      System.err.println("The problem does not have an optimal solution!");
      return;
    }
    // Verify that the solution satisfies all constraints (when using solvers
    // others than GLOP_LINEAR_PROGRAMMING, this is highly recommended!).
    if (!solver.verifySolution(/*tolerance=*/1e-7, /*log_errors=*/true)) {
      System.err.println("The solution returned by the solver violated the"
          + " problem constraints by at least 1e-7");
      return;
    }
    // [END solve]

    // [START print_solution]
    System.out.println("Solution:");
    System.out.println("Objective value = " + objective.value());
    System.out.println("x = " + x.solutionValue());
    System.out.println("y = " + y.solutionValue());
    // [END print_solution]

    // [START advanced]
    System.out.println("\nAdvanced usage:");
    System.out.println("Problem solved in " + solver.wallTime() + " milliseconds");
    System.out.println("Problem solved in " + solver.iterations() + " iterations");
    System.out.println("Problem solved in " + solver.nodes() + " branch-and-bound nodes");

it's a mip problem..

and it's almost a bug for the new version coin-or/cbc which run in macos platform.

others, in ortools, any better chose for solve mip problem?

lperron commented 5 years ago

If everything is integral, you can use CP-SAT. The API is slightly different, but very close.

I tested your code on my machine (mac) and it worked fine (with CLP and CBC).

Good luck debugging your installation.

zhengdi1992 commented 5 years ago

After see test_java log...i find the real reason... -Xss2048k other than default jvm param can work it out..

lperron commented 5 years ago

Ok.

Le jeu. 12 sept. 2019 à 06:02, Alardear notifications@github.com a écrit :

After see test_java log...i find the real reason... -Xss2048k other than default jvm param can work it out..

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/google/or-tools/issues/1571?email_source=notifications&email_token=ACUPL3N2JX6MNVIWIYVFX3TQJG5L3A5CNFSM4IVSXTBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6QSNLI#issuecomment-530654893, or mute the thread https://github.com/notifications/unsubscribe-auth/ACUPL3PS7MOZJJBX4JSNUT3QJG5L3ANCNFSM4IVSXTBA .

haohoang commented 4 years ago

@zhengdi1992, I also get the bug like you. How did you fix that?