Skip to content

[WIP] Improve filler performance #1299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: idcc/marmot_cucumber
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public abstract class AbstractCoreProblemFiller implements ProblemFiller {
protected final boolean raRangeShrinking;
protected final PstModel pstModel;
protected final OffsetDateTime timestamp;
private final Map<RangeAction<?>, Set<RangeAction<?>>> memoizedSameRangeActions = new HashMap<>();

protected AbstractCoreProblemFiller(OptimizationPerimeter optimizationContext,
RangeActionSetpointResult prePerimeterRangeActionSetpoints,
Expand Down Expand Up @@ -409,6 +410,9 @@ protected static List<Double> getMinAndMaxAbsoluteAndRelativeSetpoints(RangeActi
}

private Set<RangeAction<?>> getAvailableRangeActionsOnSameAction(RangeAction<?> rangeAction) {
if (memoizedSameRangeActions.containsKey(rangeAction)) {
return memoizedSameRangeActions.get(rangeAction);
}
Set<RangeAction<?>> rangeActions = new HashSet<>();
optimizationContext.getRangeActionsPerState().forEach((state, raSet) ->
raSet.forEach(ra -> {
Expand All @@ -417,6 +421,7 @@ private Set<RangeAction<?>> getAvailableRangeActionsOnSameAction(RangeAction<?>
}
})
);
memoizedSameRangeActions.put(rangeAction, rangeActions);
return rangeActions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public class RangeActionActivationResultImpl implements RangeActionActivationRes

private final Map<RangeAction<?>, ElementaryResult> elementaryResultMap = new HashMap<>();

boolean shouldRecomputeSetpointsPerState = true;
boolean shouldRecomputeSetpointsPerState;

private Map<String, Map<State, Double> > setpointPerStatePerPstId;
private Map<State, Optional<State>> memoizedPreviousState = new HashMap<>();

private static class ElementaryResult {
private final double refSetpoint;
Expand Down Expand Up @@ -81,6 +82,7 @@ public RangeActionActivationResultImpl(RangeActionSetpointResult rangeActionSetp
public void putResult(RangeAction<?> rangeAction, State state, double setpoint) {
shouldRecomputeSetpointsPerState = true;
elementaryResultMap.get(rangeAction).put(state, setpoint);
memoizedPreviousState = new HashMap<>();
}

private synchronized void computeSetpointsPerStatePerPst() {
Expand Down Expand Up @@ -202,10 +204,15 @@ public int getTapVariation(PstRangeAction pstRangeAction, State state) {
}

private Optional<State> getPreviousState(State state) {
return elementaryResultMap.values().stream()
if (memoizedPreviousState.containsKey(state)) {
return memoizedPreviousState.get(state);
}
Optional<State> previousState = elementaryResultMap.values().stream()
.flatMap(eR -> eR.getAllStatesWithActivation().stream())
.filter(s -> s.getContingency().equals(state.getContingency()) || s.getContingency().isEmpty())
.filter(s -> s.getInstant().comesBefore(state.getInstant()))
.max(Comparator.comparingInt(s -> s.getInstant().getOrder()));
memoizedPreviousState.put(state, previousState);
return previousState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ public static void loadDataForInterTemporalRao(DataTable arg1) throws IOExceptio
public static void iLaunchMarmot() {
InterTemporalRao.run(interTemporalRaoInput, CommonTestData.getRaoParameters());
}
}
}
Loading