Skip to content

Commit

Permalink
Update ExpressionsBasedModel.java
Browse files Browse the repository at this point in the history
  • Loading branch information
apete committed Feb 2, 2025
1 parent 381eee7 commit 4995536
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions src/main/java/org/ojalgo/optimisation/ExpressionsBasedModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public String toString() {
* {@link ExpressionsBasedModel.Integration#toModelState(org.ojalgo.optimisation.Optimisation.Result, ExpressionsBasedModel)}.
* </ol>
*/
public static interface EntityMap extends ProblemStructure {
public interface EntityMap extends ProblemStructure {

/**
* The number of variables, in the solver, that directly correspond to a model variable. (Not slack or
Expand Down Expand Up @@ -346,7 +346,7 @@ protected final void setSwitch(final ExpressionsBasedModel model, final Integrat
* @see ExpressionsBasedModel.Integration#setSwitch(ExpressionsBasedModel, IntegrationProperty, boolean)
* @see ExpressionsBasedModel.Integration#isSwitch(ExpressionsBasedModel, IntegrationProperty)
*/
public static enum IntegrationProperty {
public enum IntegrationProperty {

/**
* Any integration that can switch between Java and native code solvers.
Expand Down Expand Up @@ -482,6 +482,37 @@ static final class DefaultIntermediate extends IntermediateSolver {

}

static final class IntegrationWrapper extends ExpressionsBasedModel.Integration<Optimisation.Solver> {

private final Optimisation.Integration<ExpressionsBasedModel, ?> myDelegate;

IntegrationWrapper(final Optimisation.Integration<ExpressionsBasedModel, ?> delegate) {
super();
myDelegate = delegate;
}

@Override
public Solver build(final ExpressionsBasedModel model) {
return myDelegate.build(model);
}

@Override
public boolean isCapable(final ExpressionsBasedModel model) {
return myDelegate.isCapable(model);
}

@Override
public Result toModelState(final Result solverState, final ExpressionsBasedModel model) {
return myDelegate.toModelState(solverState, model);
}

@Override
public Result toSolverState(final Result modelState, final ExpressionsBasedModel model) {
return myDelegate.toSolverState(modelState, model);
}

}

static abstract class Simplifier<ME extends ModelEntity<?>, S extends Simplifier<?, ?>> implements Comparable<S> {

private final int myExecutionOrder;
Expand Down Expand Up @@ -699,8 +730,12 @@ void update(final ArrayList<Variable> variables) {
/**
* Add an integration for a solver that will be used rather than the built-in solvers
*/
public static boolean addIntegration(final Integration<?> integration) {
return INTEGRATIONS.add(integration);
public static boolean addIntegration(final Optimisation.Integration<ExpressionsBasedModel, ?> integration) {
if (integration instanceof ExpressionsBasedModel.Integration<?>) {
return INTEGRATIONS.add((ExpressionsBasedModel.Integration<?>) integration);
} else {
return INTEGRATIONS.add(new IntegrationWrapper(integration));
}
}

public static boolean addPresolver(final Presolver presolver) {
Expand Down

0 comments on commit 4995536

Please sign in to comment.