Skip to content

Commit

Permalink
ModelStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
apete committed Nov 25, 2024
1 parent efdbb3e commit da6eec3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Added / Changed / Deprecated / Fixed / Removed / Security
#### org.ojalgo.optimisation

- Refactoring and additions to what's in the `org.ojalgo.optimisation.service` package. They're breaking changes, but most likely no one outside Optimatika used this.
- Minor internal changes to how the `IntegerSolver` works. There's now an equal number of worker threads per worker-strategy.

### Deprecated

Expand Down
27 changes: 22 additions & 5 deletions src/main/java/org/ojalgo/optimisation/integer/IntegerStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@

public interface IntegerStrategy {

/**
* Apart from being able to configure various standard properties, you can also provide your own
* {@link ModelStrategy} factory.
*/
final class ConfigurableStrategy implements IntegerStrategy {

private final BiFunction<ExpressionsBasedModel, IntegerStrategy, ModelStrategy> myFactory;
Expand Down Expand Up @@ -100,11 +104,20 @@ public NumberContext getIntegralityTolerance() {

@Override
public List<Comparator<NodeKey>> getWorkerPriorities() {
int parallelism = myParallelism.getAsInt();
List<Comparator<NodeKey>> retVal = new ArrayList<>(parallelism);
for (int i = 0; i < parallelism; i++) {
retVal.add(myPriorityDefinitions[i % myPriorityDefinitions.length]);

int nbWorkers = myParallelism.getAsInt();
int nbDefinitions = myPriorityDefinitions.length;
int nbRepetions = (nbWorkers + nbDefinitions - 1) / nbDefinitions;

List<Comparator<NodeKey>> retVal = new ArrayList<>(nbRepetions * nbDefinitions);

for (int d = 0; d < nbDefinitions; d++) {
Comparator<NodeKey> prioDef = myPriorityDefinitions[d];
for (int r = 0; r < nbRepetions; r++) {
retVal.add(prioDef);
}
}

return retVal;
}

Expand All @@ -124,6 +137,9 @@ public ConfigurableStrategy withGMICutConfiguration(final GMICutConfiguration ne
return new ConfigurableStrategy(myParallelism, myPriorityDefinitions, myIntegralityTolerance, myGapTolerance, myFactory, newConfiguration);
}

/**
* Create a sub-class of {@link ModelStrategy} and provide a factory method for it here.
*/
public ConfigurableStrategy withModelStrategyFactory(final BiFunction<ExpressionsBasedModel, IntegerStrategy, ModelStrategy> newFactory) {
return new ConfigurableStrategy(myParallelism, myPriorityDefinitions, myIntegralityTolerance, myGapTolerance, newFactory, myGMICutConfiguration);
}
Expand Down Expand Up @@ -198,7 +214,8 @@ static ConfigurableStrategy newConfigurable() {
NumberContext integrality = NumberContext.of(12, 8);
NumberContext gap = NumberContext.of(7, 8);

return new ConfigurableStrategy(Parallelism.CORES.require(4), definitions, integrality, gap, DefaultStrategy::new, new GMICutConfiguration());
return new ConfigurableStrategy(Parallelism.CORES.require(definitions.length), definitions, integrality, gap, DefaultStrategy::new,
new GMICutConfiguration());
}

int countUniqueStrategies();
Expand Down

0 comments on commit da6eec3

Please sign in to comment.