Skip to content

Instantly share code, notes, and snippets.

@galonsky
Created April 13, 2016 22:17
Show Gist options
  • Save galonsky/a81bf13028e8f25cf8d85fc56128ab7b to your computer and use it in GitHub Desktop.
Save galonsky/a81bf13028e8f25cf8d85fc56128ab7b to your computer and use it in GitHub Desktop.
cbc test
package com.betterment.linearprogramming.google;
import org.junit.Test;
import com.google.ortools.linearsolver.MPConstraint;
import com.google.ortools.linearsolver.MPObjective;
import com.google.ortools.linearsolver.MPSolver;
import com.google.ortools.linearsolver.MPVariable;
public class SimpleGoogleSolverTest {
static {
System.loadLibrary("jniortools");
}
@Test
public void breakit() {
for (int i = 0; i < 50000; i++) {
solveLP();
}
}
private void solveLP() {
MPSolver solver = new MPSolver("test", MPSolver.OptimizationProblemType.CBC_MIXED_INTEGER_PROGRAMMING);
MPVariable x = solver.makeNumVar(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, "x");
final MPObjective objective = solver.objective();
objective.setMaximization();
objective.setCoefficient(x, 1);
MPConstraint constraint = solver.makeConstraint(0, 5);
constraint.setCoefficient(x, 1);
solver.solve();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment