Skip to content

Commit

Permalink
Rename optimizer to simplifier 2
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte committed Dec 13, 2023
1 parent 2ddc03b commit 9f7abd9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public DynaWaltzContext(Network network, String workingVariantId, List<BlackBoxM
this.parameters = Objects.requireNonNull(parameters);
this.dynaWaltzParameters = Objects.requireNonNull(dynaWaltzParameters);

Iterator<ModelsSimplifier> dataOptimizers = dynaWaltzParameters.isUseModelOptimizers() ? ServiceLoader.load(ModelsSimplifier.class).iterator() : Collections.emptyIterator();
this.dynamicModels = runSimplifiers(dataOptimizers,
Iterator<ModelsSimplifier> dataSimplifiers = dynaWaltzParameters.isUseModelSimplifiers() ? ServiceLoader.load(ModelsSimplifier.class).iterator() : Collections.emptyIterator();
this.dynamicModels = runSimplifiers(dataSimplifiers,
Objects.requireNonNull(dynamicModels)
.stream()
.filter(distinctByDynamicId(reporter).and(distinctByStaticId(reporter))),
Expand Down Expand Up @@ -114,8 +114,8 @@ private FrequencySynchronizerModel setupFrequencySynchronizer(Function<List<Freq
.toList());
}

private Stream<BlackBoxModel> runSimplifiers(Iterator<ModelsSimplifier> dataOptimizers, Stream<BlackBoxModel> inputData, Reporter reporter) {
return dataOptimizers.hasNext() ? runSimplifiers(dataOptimizers, dataOptimizers.next().simplifyModels(inputData, dynaWaltzParameters, reporter), reporter) : inputData;
private Stream<BlackBoxModel> runSimplifiers(Iterator<ModelsSimplifier> dataSimplifiers, Stream<BlackBoxModel> inputData, Reporter reporter) {
return dataSimplifiers.hasNext() ? runSimplifiers(dataSimplifiers, dataSimplifiers.next().simplifyModels(inputData, dynaWaltzParameters, reporter), reporter) : inputData;
}

public Network getNetwork() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class DynaWaltzParameters extends AbstractExtension<DynamicSimulationPara
public static final String NETWORK_OUTPUT_PARAMETERS_FILE = "network.par";
public static final String SOLVER_OUTPUT_PARAMETERS_FILE = "solvers.par";
private static final boolean DEFAULT_WRITE_FINAL_STATE = true;
public static final boolean DEFAULT_USE_MODEL_OPTIMIZERS = false;
public static final boolean USE_MODEL_SIMPLIFIERS = false;

public enum SolverType {
SIM,
Expand All @@ -52,7 +52,7 @@ public enum SolverType {
private SolverType solverType;
private boolean mergeLoads;
private boolean writeFinalState = DEFAULT_WRITE_FINAL_STATE;
private boolean useModelOptimizers = DEFAULT_USE_MODEL_OPTIMIZERS;
private boolean useModelSimplifiers = USE_MODEL_SIMPLIFIERS;
private DumpFileParameters dumpFileParameters;

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ public static DynaWaltzParameters load(PlatformConfig platformConfig, FileSystem
// Writes final state IIDM
boolean writeFinalState = config.flatMap(c -> c.getOptionalBooleanProperty("writeFinalState")).orElse(DEFAULT_WRITE_FINAL_STATE);

boolean useModelOptimizers = config.flatMap(c -> c.getOptionalBooleanProperty("useModelOptimizers")).orElse(DEFAULT_USE_MODEL_OPTIMIZERS);
boolean useModelSimplifiers = config.flatMap(c -> c.getOptionalBooleanProperty("useModelSimplifiers")).orElse(USE_MODEL_SIMPLIFIERS);

// Dump file config
boolean exportDumpFile = config.flatMap(c -> c.getOptionalBooleanProperty("dump.export")).orElse(DumpFileParameters.DEFAULT_EXPORT_DUMP);
Expand Down Expand Up @@ -134,7 +134,7 @@ public static DynaWaltzParameters load(PlatformConfig platformConfig, FileSystem
.setSolverType(solverType)
.setMergeLoads(mergeLoads)
.setWriteFinalState(writeFinalState)
.setUseModelOptimizers(useModelOptimizers)
.setUseModelSimplifiers(useModelSimplifiers)
.setDumpFileParameters(dumpFileParameters);
}

Expand Down Expand Up @@ -208,12 +208,12 @@ public boolean isWriteFinalState() {
return writeFinalState;
}

public boolean isUseModelOptimizers() {
return useModelOptimizers;
public boolean isUseModelSimplifiers() {
return useModelSimplifiers;
}

public DynaWaltzParameters setUseModelOptimizers(boolean useModelOptimizers) {
this.useModelOptimizers = useModelOptimizers;
public DynaWaltzParameters setUseModelSimplifiers(boolean useModelSimplifiers) {
this.useModelSimplifiers = useModelSimplifiers;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void checkParameters() throws IOException {
SolverType solverType = SolverType.IDA;
String solverParametersId = "solverParametersId";
boolean mergeLoads = true;
boolean useModelOptimizers = true;
initPlatformConfig(networkParametersId, solverType, solverParametersId, mergeLoads, useModelOptimizers);
boolean useModelSimplifiers = true;
initPlatformConfig(networkParametersId, solverType, solverParametersId, mergeLoads, useModelSimplifiers);

DynaWaltzParameters parameters = DynaWaltzParameters.load(platformConfig, fileSystem);

Expand Down Expand Up @@ -88,7 +88,7 @@ void checkParameters() throws IOException {
assertEquals(ParameterType.DOUBLE, absAccuracy.type());

assertEquals(mergeLoads, parameters.isMergeLoads());
assertEquals(useModelOptimizers, parameters.isUseModelOptimizers());
assertEquals(useModelSimplifiers, parameters.isUseModelSimplifiers());
}

@Test
Expand Down Expand Up @@ -122,7 +122,7 @@ void roundTripParametersSerializing() throws IOException {
JsonDynamicSimulationParameters::read, "/DynaWaltzParameters.json");
}

private void initPlatformConfig(String networkParametersId, SolverType solverType, String solverParametersId, boolean mergeLoads, boolean useModelOptimizers) throws IOException {
private void initPlatformConfig(String networkParametersId, SolverType solverType, String solverParametersId, boolean mergeLoads, boolean useModelSimplifiers) throws IOException {
String parametersFile = USER_HOME + "parametersFile";
String networkParametersFile = USER_HOME + "networkParametersFile";
String solverParametersFile = USER_HOME + "solverParametersFile";
Expand All @@ -135,7 +135,7 @@ private void initPlatformConfig(String networkParametersId, SolverType solverTyp
moduleConfig.setStringProperty("network.parametersId", networkParametersId);
moduleConfig.setStringProperty("solver.type", solverType.toString());
moduleConfig.setStringProperty("solver.parametersId", solverParametersId);
moduleConfig.setStringProperty("useModelOptimizers", String.valueOf(useModelOptimizers));
moduleConfig.setStringProperty("useModelSimplifiers", String.valueOf(useModelSimplifiers));

Files.createDirectories(fileSystem.getPath(USER_HOME));
copyFile("/parametersSet/models.par", parametersFile);
Expand Down Expand Up @@ -182,7 +182,7 @@ void checkDefaultParameters() throws IOException {
assertEquals("1", parameters.getSolverParameters().getId());

assertEquals(DynaWaltzParameters.DEFAULT_MERGE_LOADS, parameters.isMergeLoads());
assertEquals(DynaWaltzParameters.DEFAULT_USE_MODEL_OPTIMIZERS, parameters.isUseModelOptimizers());
assertEquals(DynaWaltzParameters.USE_MODEL_SIMPLIFIERS, parameters.isUseModelSimplifiers());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void loadSimplifiers() {
void simplifyModels() {
Network network = EurostagTutorialExample1Factory.create();
DynamicSimulationParameters parameters = DynamicSimulationParameters.load();
DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load().setUseModelOptimizers(true);
DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load().setUseModelSimplifiers(true);
List<BlackBoxModel> dynamicModels = List.of(
new GeneratorFictitious("BBM_GEN", network.getGenerator("GEN"), "GPV"),
new BaseLoad("BBM_LOAD", network.getLoad("LOAD"), "LOAD", "LoadAlphaBeta"),
Expand Down
2 changes: 1 addition & 1 deletion dynawaltz/src/test/resources/DynaWaltzParameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"solverType" : "IDA",
"mergeLoads" : false,
"writeFinalState" : true,
"useModelOptimizers" : false,
"useModelSimplifiers" : false,
"dumpFileParameters" : {
"exportDumpFile" : false,
"useDumpFile" : false,
Expand Down

0 comments on commit 9f7abd9

Please sign in to comment.