Frequently Asked Questions

The basics

What is ojAlgo?

An open source Java library for mathematical optimisation (optimization), linear algebra and related maths. It contains LP, QP and MIP solvers, a modelling API for them (ExpressionsBasedModel), fast dense and sparse linear algebra, and array, statistics and time series tools. It is developed and maintained by Optimatika, and has been in continuous development since 2003.

Is ojAlgo pure Java?

Yes. No native code, no JNI, no platform-specific binaries, and zero dependencies: ojAlgo itself depends on no other library. It runs anywhere a JVM runs, which is what makes it a fit for locked-down containers, regulated environments and build pipelines where native libraries are a problem.

How do I add it to a project?

One Maven dependency, org.ojalgo:ojalgo; the current version is 57.4.0. It requires Java 11 or later, and works from Kotlin, Scala or any other JVM language.

What does it cost, and what is the licence?

Nothing. ojAlgo is MIT licensed: free to use, modify and embed in commercial products. Paid support is available separately, see below.

Is ojAlgo only for finance?

No. Its first use was in finance, and there is a finance package with portfolio optimisation, but the library is general maths: optimisation and linear algebra for any domain.

Is it maintained?

Yes, actively. New versions are released several times a year; the release notes are in the CHANGELOG.

Optimisation

Which problem types can ojAlgo solve?

Linear programming (LP), quadratic programming (QP) with a convex quadratic objective, and mixed-integer programming (MIP) — integer and binary variables in either. All three are built in and pure Java. Java LP, QP and MIP Solvers has a complete example.

How do I define the objective?

Through weights. weight(...) on a variable or on an expression puts it in the objective, with that weight as its coefficient; then call minimise() or maximise(). There is no separate objective object to build. Constraints are bounds: lower(...), upper(...) or level(...) on a variable or an expression.

Does ojAlgo really do MIP?

Yes. Mark a variable integer() or binary() and the model becomes a MIP; ojAlgo's own solver uses branch-and-bound with cut generation. MIP is also where the difference to the best native solvers is largest, so for big or structurally difficult MIP models a native solver may be needed — see the next sections.

How large a model can it handle?

There is no single limit; structure matters more than size. LP and convex QP models with thousands of variables and constraints are routine. For MIP, a small model can be much harder than a large one. The practical approach is to try: write the model once with ExpressionsBasedModel, and if ojAlgo's own solver turns out to be too slow, run the same model on a stronger solver without changing it.

Can I use Gurobi, CPLEX, HiGHS or another solver with the same model?

Yes. ExpressionsBasedModel does not encode which solver runs it. Integration modules connect it to COPT, CPLEX, Gurobi, MOSEK, Xpress, HiGHS, SCIP, Clarabel, CP-SAT, OR-Tools, Choco and others; one line of code registers a solver, and your models run on it. The modules are on Maven Central — see Solver Integrations. You need the solver itself installed and, for commercial solvers, licensed.

If you want the stronger open source native solvers without dealing with native code in your application, the Optimisation Service packages a combination of the best open source solvers in a container you deploy yourself; your ojAlgo models use it as a remote solver.

Can ojAlgo read and write MPS and LP files?

Yes. ExpressionsBasedModel.parse(file) reads MPS and CPLEX LP files, and model.writeTo(path) writes them; the format follows the file name. See Optimisation Model File Formats.

Where do I start writing a model?

In the Optimisation Cookbook: complete, runnable models for production planning, blending, knapsack, assignment, bin packing, set covering, shift scheduling, facility location and portfolio optimisation, plus the rules every model should follow. More complete programs, for optimisation and everything else, are under Code Examples.

Why does my model return INFEASIBLE, or a variable's value null?

Always check result.getState() before reading values; after an infeasible or unbounded result the variables have no values. Infeasibility usually comes from a sign, a unit or an equality that should have been an inequality. Writing the model to an LP file (model.writeTo(Path.of("model.lp"))) shows exactly what you built. The cookbook's rules cover the common mistakes.

My old ojAlgo code no longer compiles. What changed?

Many classes and methods were renamed over the years — PrimitiveMatrix is now MatrixR064, Variable.make is now model.newVariable, and so on. Updating Old ojAlgo Code lists the old names and their replacements.

Compared with other tools

ojAlgo or Google OR-Tools?

OR-Tools is a C++ library with a Java wrapper: it needs platform-specific native libraries and JNI. It is very strong, and it also covers constraint programming and vehicle routing, which ojAlgo does not. It is not either-or, though: there are ojAlgo integrations for both OR-Tools and its CP-SAT solver, so a model written with ExpressionsBasedModel can run on ojAlgo's own solvers or on CP-SAT, and you switch with one line of code. Use OR-Tools directly when you need its routing library or constraint programming beyond linear models.

ojAlgo or Apache Commons Math, Hipparchus or JAMA?

JAMA is linear algebra only, with no optimisation, and has not been updated in many years; parts of it live on, extended and improved, inside ojAlgo. Commons Math covers a broad range of maths, but its optimisation and linear algebra are limited by comparison, and it has had no releases for years; most of its developers moved on to the Hipparchus fork. Hipparchus has LP and QP solvers but no MIP, and fails on many standard LP test models that ojAlgo solves. For linear algebra, ojAlgo is the fastest pure Java library in the independent Java Matrix Benchmark.

ojAlgo or Timefold, OptaPlanner or Choco?

Different techniques for different problems. Timefold (and its predecessor OptaPlanner) uses local search heuristics, and Choco uses constraint programming; both are strong for scheduling and rostering with many complex rules. ojAlgo is mathematical programming: models stated as linear or quadratic objectives and constraints, solved to proven optimality. Many problems can be stated either way; if yours is naturally a set of linear constraints with an objective, ojAlgo is a direct fit. Choco is also available as a solver integration, so an integer model written with ExpressionsBasedModel can be run on Choco as well.

Can I use ojAlgo from Python, R or other languages?

ojAlgo is a JVM library, so directly only from Java, Kotlin, Scala and other JVM languages. The Optimisation Service has a REST API that any language can use to solve models in MPS or LP format.

Linear algebra

What linear algebra does ojAlgo offer?

Dense and sparse matrices, and the standard decompositions — LU, QR, Cholesky, LDL, singular value and eigenvalue — with equation solvers, least squares, inverses and determinants on top. See Linear Algebra.

Which matrix class should I use?

R064Store is the main dense matrix type: mutable, so you create it with its factory, fill it in place and reuse memory — there is no need to go through double[][]. SparseStore is for large matrices that are mostly zeros. Declare variables with the interfaces MatrixStore (read) and PhysicalStore (mutable), and use the classes only to create instances; the decompositions (LU, QR, Cholesky, SVD, eigenvalue) accept any MatrixStore. There is also an immutable MatrixR064, convenient for small amounts of code. Linear Algebra Introduction explains the layers.

Does ojAlgo support sparse matrices?

Yes. SparseStore holds large, mostly-zero matrices, and there are sparse decompositions (sparse LU, LDL) and iterative equation solvers such as conjugate gradient. Sparse support has been extended considerably in recent versions; Sparse and Special Structure Matrices shows the basics and how to exploit special structure.

Can I control multi-threading?

ojAlgo decides on its own when parallel execution pays off, and works well without any tuning. When you need to limit or direct it, for example in a server with many concurrent requests, see Controlling Concurrency.

Help and support

Where do I ask questions or report bugs?

Questions in GitHub Discussions, bugs as GitHub issues. See Support & Community.

Is commercial support available?

Yes, from Optimatika, the company behind ojAlgo, through the Optimatika Subscription. It also covers the solver integrations and the Optimisation Service.

Does ojAlgo work well with AI coding assistants?

There are agent skills that teach assistants such as Claude and Codex to write correct ojAlgo code; in Claude they are listed in the plugin directory as ojAlgo. For other tools, llms.txt is a structured index of this site.