Updating Old ojAlgo Code
ojAlgo has been developed since 2003, and a lot of the code written for it — in old articles, forum answers, and whatever an AI coding assistant learned from — uses names that have since been renamed or removed. If something that looks like reasonable ojAlgo code fails with cannot find symbol, it is probably on this page.
Everything in the Now column compiles with the current release, 57.3.1. If your build still names version 47, 51 or 53, update that first: org.ojalgo:ojalgo, as shown under get started.
Optimisation
| Old | Now |
|---|---|
Variable.make("x") or new Variable("x"), then model.addVariable(x) |
Variable x = model.newVariable("x") |
Variable.makeBinary("x"), Variable.makeInteger("x") |
model.newVariable("x").binary(), model.newVariable("x").integer() |
model.addExpression("c") |
model.newExpression("c") |
expression.setLinearFactor(x, 2) |
expression.set(x, 2) |
expression.setQuadraticFactor(x, y, 2) |
expression.set(x, y, 2) |
model.options.mip_gap = 0.001 |
model.options.integer(IntegerStrategy.DEFAULT.withGapTolerance(NumberContext.of(3))) |
NumberContext.getGeneral(8) |
NumberContext.of(8) |
org.ojalgo.optimisation.service.* |
the Optimisation Service client |
Variables and expressions are always created by the model they belong to. A model written the current way:
ExpressionsBasedModel model = new ExpressionsBasedModel();
Variable x = model.newVariable("x").lower(0).weight(3);
Variable y = model.newVariable("y").lower(0).integer().weight(2);
model.newExpression("limit").upper(10.5).set(x, 1).set(y, 2);
Optimisation.Result result = model.maximise();
if (result.getState().isOptimal()) {
double xValue = x.getValue().doubleValue();
long yValue = Math.round(y.getValue().doubleValue());
}
For complete programs, start from the Optimisation Cookbook.
Linear algebra and arrays
The classes were renamed to state the element type: R064 is a real 64-bit number (double), R032 is float, C128 complex, Q128 rational, H256 quaternion, R128 quadruple precision.
| Old | Now |
|---|---|
PrimitiveMatrix, Primitive64Matrix |
MatrixR064 |
Primitive32Matrix |
MatrixR032 |
ComplexMatrix |
MatrixC128 |
RationalMatrix |
MatrixQ128 |
QuaternionMatrix |
MatrixH256 |
PrimitiveDenseStore, Primitive64Store |
R064Store |
Primitive32Store |
R032Store |
ComplexDenseStore, GenericStore.COMPLEX |
GenericStore.C128 |
Primitive64Array |
ArrayR064 |
Primitive32Array |
ArrayR032 |
The factories kept their shape: MatrixR064.FACTORY, R064Store.FACTORY. See Linear Algebra Introduction for which class to use when.
Packages that moved
| Old | Now |
|---|---|
org.ojalgo.constant |
org.ojalgo.function.constant |
org.ojalgo.access |
org.ojalgo.structure |
org.ojalgo.finance |
org.ojalgo.data.domain.finance |
So org.ojalgo.finance.portfolio.MarkowitzModel is now org.ojalgo.data.domain.finance.portfolio.MarkowitzModel.
If it is not listed here
The changelog records every rename and removal, by version. The example code is kept current with each release, so it is always safe to copy from.