Skip to content

Commit

Permalink
reconditions wca_reduction_matrix.txt before executing domains/clusters
Browse files Browse the repository at this point in the history
 - only if wca/reconditionCorrelationMatrix config is true (default is false)
  • Loading branch information
CBiasuzzi committed Feb 23, 2018
1 parent d70c261 commit b2c86b4
Show file tree
Hide file tree
Showing 5 changed files with 333 additions and 16 deletions.
13 changes: 11 additions & 2 deletions wca-integration/src/main/java/eu/itesla_project/wca/WCAConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class WCAConfig {
public static final boolean DEFAULT_FILTER_PREVENTIVE_ACTIONS = true;
public static final boolean DEFAULT_FILTER_CURATIVE_ACTIONS = true;
public static final boolean DEFAULT_LOOOSEN_CONSTRAINTS = false;
public static final boolean DEFAULT_RECONDITION_CORRELATION_MATRIX = false;

private final Path xpressHome;
private final float reducedVariableRatio;
Expand All @@ -56,6 +57,7 @@ public class WCAConfig {
private final boolean filterPreventiveActions;
private final boolean filterCurativeActions;
private final boolean loosenConstraints;
private final boolean reconditionCorrelationMatrix;

public static WCAConfig load() {
return load(PlatformConfig.defaultConfig());
Expand All @@ -80,16 +82,17 @@ public static WCAConfig load(PlatformConfig platformConfig) {
boolean filterPreventiveActions = config.getBooleanProperty("filterPreventiveActions", DEFAULT_FILTER_PREVENTIVE_ACTIONS);
boolean filterCurativeActions = config.getBooleanProperty("filterCurativeActions", DEFAULT_FILTER_CURATIVE_ACTIONS);
boolean loosenConstraints = config.getBooleanProperty("loosenConstraints", DEFAULT_LOOOSEN_CONSTRAINTS);
boolean reconditionCorrelationMatrix = config.getBooleanProperty("reconditionCorrelationMatrix", DEFAULT_RECONDITION_CORRELATION_MATRIX);
return new WCAConfig(xpressHome, reducedVariableRatio, debug, exportStates, restrictingThresholdLevels, margin, ignoreVoltageConstraints,
activateFiltering, preventiveActionsFilter, preventiveActionsOptimizer, applyPreventiveActions, curativeActionsOptimizer,
voltageLevelConstraintFilter, countryConstraintFilter, filterPreventiveActions, filterCurativeActions, loosenConstraints);
voltageLevelConstraintFilter, countryConstraintFilter, filterPreventiveActions, filterCurativeActions, loosenConstraints, reconditionCorrelationMatrix);
}

public WCAConfig(Path xpressHome, float reducedVariableRatio, boolean debug, boolean exportStates, Set<WCARestrictingThresholdLevel> restrictingThresholdLevels,
float margin, boolean ignoreVoltageConstraints, boolean activateFiltering, WCAPreventiveActionsFilter preventiveActionsFilter,
WCAPreventiveActionsOptimizer preventiveActionsOptimizer, boolean applyPreventiveActions, WCACurativeActionsOptimizer curativeActionsOptimizer,
float voltageLevelConstraintFilter, Set<Country> countryConstraintFilter, boolean filterPreventiveActions, boolean filterCurativeActions,
boolean loosenConstraints) {
boolean loosenConstraints, boolean reconditionCorrelationMatrix) {
this.xpressHome = Objects.requireNonNull(xpressHome);
this.reducedVariableRatio = reducedVariableRatio;
this.debug = debug;
Expand All @@ -107,6 +110,7 @@ public WCAConfig(Path xpressHome, float reducedVariableRatio, boolean debug, boo
this.filterPreventiveActions = filterPreventiveActions;
this.filterCurativeActions = filterCurativeActions;
this.loosenConstraints = loosenConstraints;
this.reconditionCorrelationMatrix = reconditionCorrelationMatrix;
}

public Path getXpressHome() {
Expand Down Expand Up @@ -177,6 +181,10 @@ public boolean loosenConstraints() {
return loosenConstraints;
}

public boolean isReconditionCorrelationMatrix() {
return reconditionCorrelationMatrix;
}

@Override
public String toString() {
return getClass().getSimpleName() + " [xpressHome=" + xpressHome +
Expand All @@ -196,6 +204,7 @@ public String toString() {
", filterPreventiveActions=" + filterPreventiveActions +
", filterCurativeActions=" + filterCurativeActions +
", loosenConstraints=" + loosenConstraints +
", reconditionCorrelationMatrix=" + reconditionCorrelationMatrix +
"]";
}
}
39 changes: 33 additions & 6 deletions wca-integration/src/main/java/eu/itesla_project/wca/WCAImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public class WCAImpl implements WCA, WCAConstants {
private static final String WCA_SENSIBILITIES_FILE = "wca_sensibilities.txt";
private static final String WCA_INFLUENCE_PST_FILE = "wca_influence_pst.txt";

private static final String R_RECONDITION_MATRIX_SCRIPT = "recondition_reduction_matrix.R";

private final Network network;

private final ComputationManager computationManager;
Expand Down Expand Up @@ -215,6 +217,13 @@ private static void copyRequired(Path workingDir) throws IOException {
Files.copy(WCAImpl.class.getResourceAsStream("/" + REQUIRED_FILE_NAME), workingDir.resolve(REQUIRED_FILE_NAME));
}

private static void copyOptional(Path workingDir, WCAConfig config) throws IOException {
if (config.isReconditionCorrelationMatrix()) {
Files.copy(WCAImpl.class.getResourceAsStream("/R/" + R_RECONDITION_MATRIX_SCRIPT), workingDir.resolve(R_RECONDITION_MATRIX_SCRIPT));
}
}


private CompletableFuture<WCAClustersResult> createClustersTask(Contingency contingency,
List<String> curativeActionIds,
String baseStateId,
Expand All @@ -235,6 +244,8 @@ public List<CommandExecution> before(Path workingDir) throws IOException {

copyRequired(workingDir);

copyOptional(workingDir, config);

DataSource commonDataSource = new FileDataSource(workingDir, COMMONE_FILE_PREFIX);

// write uncertainies
Expand Down Expand Up @@ -289,10 +300,17 @@ public List<CommandExecution> before(Path workingDir) throws IOException {
// write curatives action description associated to the contingency
WCAUtils.writeActions(curativeActionIds, dataSource, mapper, "Curative actions", AmplSubset.CURATIVE_ACTION);

Command cmd = new SimpleCommandBuilder()
GroupCommandBuilder cmdBuilder = new GroupCommandBuilder()
.id(CLUSTERS_CMD_ID)
.inputFiles(inputFiles(dataSetNum));
if (config.isReconditionCorrelationMatrix()) {
cmdBuilder = cmdBuilder.subCommand()
.program("R")
.args("--no-save", "-f", R_RECONDITION_MATRIX_SCRIPT)
.add();
}
cmdBuilder = cmdBuilder.subCommand()
.program("clusters")
.inputFiles(inputFiles(dataSetNum))
.args(COMMONE_FILE_PREFIX,
FILE_PREFIX + dataSetNum,
REQUIRED_FILE_NAME,
Expand All @@ -307,7 +325,8 @@ public List<CommandExecution> before(Path workingDir) throws IOException {
WCA_UNDEFINED_PST_FILE,
WCA_SENSIBILITIES_FILE,
WCA_INFLUENCE_PST_FILE)
.build();
.add();
Command cmd = cmdBuilder.build();
return Arrays.asList(new CommandExecution(cmd, 1));
}

Expand Down Expand Up @@ -385,10 +404,17 @@ public List<CommandExecution> before(Path workingDir) throws IOException {
// write security rules corresponding to the contingency
new WCASecurityRulesWriter(network, securityRuleExpressions, dataSource, mapper, false, activateFiltering).write();

Command cmd = new SimpleCommandBuilder()
GroupCommandBuilder cmdBuilder = new GroupCommandBuilder()
.id(DOMAINS_CMD_ID)
.inputFiles(inputFiles(dataSetNum));
if (config.isReconditionCorrelationMatrix()) {
cmdBuilder = cmdBuilder.subCommand()
.program("R")
.args("--no-save", "-f", R_RECONDITION_MATRIX_SCRIPT)
.add();
}
cmdBuilder = cmdBuilder.subCommand()
.program("domains")
.inputFiles(inputFiles(dataSetNum))
.args(COMMONE_FILE_PREFIX,
FILE_PREFIX + dataSetNum,
REQUIRED_FILE_NAME,
Expand All @@ -404,7 +430,8 @@ public List<CommandExecution> before(Path workingDir) throws IOException {
WCA_UNDEFINED_PST_FILE,
WCA_SENSIBILITIES_FILE,
WCA_INFLUENCE_PST_FILE)
.build();
.add();
Command cmd = cmdBuilder.build();
return Arrays.asList(new CommandExecution(cmd, 1));
}

Expand Down

0 comments on commit b2c86b4

Please sign in to comment.