Skip to content

Commit

Permalink
Merge branch 'master' into temporary_limit_value
Browse files Browse the repository at this point in the history
  • Loading branch information
geofjamg authored Nov 28, 2016
2 parents 10575a6 + 4f12cba commit ca40c12
Show file tree
Hide file tree
Showing 9 changed files with 774 additions and 558 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
package eu.itesla_project.eurostag;

import com.google.common.base.Strings;
import eu.itesla_project.iidm.eurostag.export.EurostagDictionary;
import eu.itesla_project.iidm.network.*;
import eu.itesla_project.contingency.Contingency;
import eu.itesla_project.contingency.ContingencyElement;
import eu.itesla_project.iidm.eurostag.export.EurostagDictionary;
import eu.itesla_project.iidm.network.*;
import eu.itesla_project.simulation.SimulationParameters;
import org.jboss.shrinkwrap.api.Domain;
import org.jboss.shrinkwrap.api.GenericArchive;
Expand Down Expand Up @@ -136,8 +136,7 @@ public void writeFaultSeq(BufferedWriter writer, Contingency contingency, Networ
writer.newLine();
for (ContingencyElement element : contingency.getElements()) {
switch (element.getType()) {
case LINE:
{
case LINE: {
Line l = network.getLine(element.getId());
if (l == null) {
throw new RuntimeException("Line '" + element.getId() + "' not found");
Expand Down Expand Up @@ -194,8 +193,7 @@ public void writeFaultSeq(BufferedWriter writer, Contingency contingency, Networ
}
break;

case GENERATOR:
{
case GENERATOR: {
Generator g = network.getGenerator(element.getId());
if (g == null) {
throw new RuntimeException("Generator '" + element.getId() + "' not found");
Expand Down Expand Up @@ -252,6 +250,9 @@ public GenericArchive writeFaultSeqArchive(List<Contingency> contingencies, Netw
}

public GenericArchive writeFaultSeqArchive(Domain domain, List<Contingency> contingencies, Network network, EurostagDictionary dictionary, Function<Integer, String> seqFileNameFct) throws IOException {
if ((contingencies == null) || (contingencies.isEmpty())) {
throw new RuntimeException("contingencies list is empty, cannot write .seq scenario files");
}
GenericArchive archive = domain.getArchiveFactory().create(GenericArchive.class);
try (FileSystem fileSystem = ShrinkWrapFileSystems.newFileSystem(archive)) {
Path rootDir = fileSystem.getPath("/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
*/
package eu.itesla_project.modules.online;

import java.io.Serializable;
import java.util.*;

import eu.itesla_project.cases.CaseType;
import eu.itesla_project.commons.config.ModuleConfig;
import eu.itesla_project.commons.config.PlatformConfig;
import eu.itesla_project.iidm.network.Country;
import eu.itesla_project.cases.CaseType;
import eu.itesla_project.simulation.securityindexes.SecurityIndexType;

import org.joda.time.DateTime;
import org.joda.time.Interval;

import java.io.Serializable;
import java.util.Objects;
import java.util.Set;

/**
*
* @author Quinary <[email protected]>
*/
public class OnlineWorkflowParameters implements Serializable {
Expand Down Expand Up @@ -48,10 +47,11 @@ public class OnlineWorkflowParameters implements Serializable {
private float limitReduction;
private boolean handleViolationsInN;
private float constraintMargin;
private String caseFile;

public static OnlineWorkflowParameters loadDefault() {
ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("online-default-parameters");
DateTime baseCaseDate = DateTime.parse(config.getStringProperty("baseCaseDate"));

int states = config.getIntProperty("states");
String offlineWorkflowId = config.getStringProperty("offlineWorkflowId", null);
TimeHorizon timeHorizon = TimeHorizon.fromName(config.getStringProperty("timeHorizon").trim());
Expand All @@ -62,43 +62,61 @@ public static OnlineWorkflowParameters loadDefault() {
boolean analyseBasecase = config.getBooleanProperty("analyseBasecase", true);
boolean validation = config.getBooleanProperty("validation", false);
Set<SecurityIndexType> securityIndexes = config.getEnumSetProperty("securityIndexes", SecurityIndexType.class, null);
CaseType caseType = config.getEnumProperty("caseType", CaseType.class);
Set<Country> countries = config.getEnumSetProperty("countries", Country.class);
boolean mergeOptimized = config.getBooleanProperty("mergeOptimized", DEFAULT_MERGE_OPTIMIZED);
float limitReduction = config.getFloatProperty("limitReduction", DEFAULT_LIMIT_REDUCTION);
boolean handleViolationsInN = config.getBooleanProperty("handleViolationsInN", DEFAULT_HANDLE_VIOLATIONS_IN_N);
float constraintMargin = config.getFloatProperty("constraintMargin", DEFAULT_CONSTRAINT_MARGIN);

return new OnlineWorkflowParameters(baseCaseDate,
states,
histoInterval,
offlineWorkflowId,
timeHorizon,
feAnalysisId,
rulesPurityThreshold,
storeStates,
analyseBasecase,
String caseFile = config.getStringProperty("caseFile", null);
if (caseFile != null) {
if ((config.getStringProperty("baseCaseDate", null) != null)
|| (config.getStringProperty("caseType", null) != null)
|| (config.getStringProperty("countries", null) != null))
throw new RuntimeException("caseFile and ( baseCaseDate, caseType, countries ) are mutually exclusive options");
return new OnlineWorkflowParameters(states,
histoInterval,
offlineWorkflowId,
timeHorizon,
feAnalysisId,
rulesPurityThreshold,
storeStates,
analyseBasecase,
validation,
securityIndexes,
mergeOptimized,
limitReduction,
handleViolationsInN,
constraintMargin,
caseFile);
}
DateTime baseCaseDate = DateTime.parse(config.getStringProperty("baseCaseDate"));
CaseType caseType = config.getEnumProperty("caseType", CaseType.class);
Set<Country> countries = config.getEnumSetProperty("countries", Country.class);
return new OnlineWorkflowParameters(baseCaseDate,
states,
histoInterval,
offlineWorkflowId,
timeHorizon,
feAnalysisId,
rulesPurityThreshold,
storeStates,
analyseBasecase,
validation,
securityIndexes,
caseType,
countries,
mergeOptimized,
limitReduction,
handleViolationsInN,
constraintMargin
);
}

public OnlineWorkflowParameters(DateTime baseCaseDate, int states, Interval histoInterval, String offlineWorkflowId, TimeHorizon timeHorizon,
String feAnalysisId, double rulesPurityThreshold, boolean storeStates, boolean analyseBasecase, boolean validation,
Set<SecurityIndexType> securityIndexes, CaseType caseType, Set<Country> countries, boolean mergeOptimized,
float limitReduction, boolean handleViolationsInN, float constraintMargin) {
Objects.requireNonNull(baseCaseDate);
Objects.requireNonNull(histoInterval);
Objects.requireNonNull(countries);
Objects.requireNonNull(caseType);
constraintMargin);
}

private OnlineWorkflowParameters(DateTime baseCaseDate, int states, Interval histoInterval, String offlineWorkflowId, TimeHorizon timeHorizon,
String feAnalysisId, double rulesPurityThreshold, boolean storeStates, boolean analyseBasecase, boolean validation,
Set<SecurityIndexType> securityIndexes, CaseType caseType, Set<Country> countries, boolean mergeOptimized,
float limitReduction, boolean handleViolationsInN, float constraintMargin, String caseFile) {
this.baseCaseDate = baseCaseDate;
this.states=states;
this.states = states;
this.histoInterval = histoInterval;
this.offlineWorkflowId = offlineWorkflowId;
this.timeHorizon = timeHorizon;
Expand All @@ -114,6 +132,62 @@ public OnlineWorkflowParameters(DateTime baseCaseDate, int states, Interval hist
this.limitReduction = limitReduction;
this.handleViolationsInN = handleViolationsInN;
this.constraintMargin = constraintMargin;
this.caseFile = caseFile;
}


public OnlineWorkflowParameters(DateTime baseCaseDate, int states, Interval histoInterval, String offlineWorkflowId, TimeHorizon timeHorizon,
String feAnalysisId, double rulesPurityThreshold, boolean storeStates, boolean analyseBasecase, boolean validation,
Set<SecurityIndexType> securityIndexes, CaseType caseType, Set<Country> countries, boolean mergeOptimized,
float limitReduction, boolean handleViolationsInN, float constraintMargin) {
this(baseCaseDate,
states,
histoInterval,
offlineWorkflowId,
timeHorizon,
feAnalysisId,
rulesPurityThreshold,
storeStates,
analyseBasecase,
validation,
securityIndexes,
caseType,
countries,
mergeOptimized,
limitReduction,
handleViolationsInN,
constraintMargin,
null);
Objects.requireNonNull(this.baseCaseDate);
Objects.requireNonNull(this.countries);
Objects.requireNonNull(this.caseType);
Objects.requireNonNull(this.histoInterval);
}

public OnlineWorkflowParameters(int states, Interval histoInterval, String offlineWorkflowId, TimeHorizon timeHorizon,
String feAnalysisId, double rulesPurityThreshold, boolean storeStates, boolean analyseBasecase, boolean validation,
Set<SecurityIndexType> securityIndexes, boolean mergeOptimized,
float limitReduction, boolean handleViolationsInN, float constraintMargin, String caseFile) {
this(null,
states,
histoInterval,
offlineWorkflowId,
timeHorizon,
feAnalysisId,
rulesPurityThreshold,
storeStates,
analyseBasecase,
validation,
securityIndexes,
null,
null,
mergeOptimized,
limitReduction,
handleViolationsInN,
constraintMargin,
caseFile);
Objects.requireNonNull(this.caseFile);
Objects.requireNonNull(this.histoInterval);
}

public DateTime getBaseCaseDate() {
Expand All @@ -124,20 +198,20 @@ public Interval getHistoInterval() {
return histoInterval;
}

public int getStates() {
return states;
public int getStates() {
return states;
}

public String getOfflineWorkflowId() {
return offlineWorkflowId;
public String getOfflineWorkflowId() {
return offlineWorkflowId;
}

public TimeHorizon getTimeHorizon() {
return timeHorizon;
public TimeHorizon getTimeHorizon() {
return timeHorizon;
}

public String getFeAnalysisId() {
return feAnalysisId;
public String getFeAnalysisId() {
return feAnalysisId;
}

public double getRulesPurityThreshold() {
Expand Down Expand Up @@ -184,6 +258,10 @@ public float getConstraintMargin() {
return constraintMargin;
}

public String getCaseFile() {
return caseFile;
}

@Override
public String toString() {
return "{baseCaseDate=" + baseCaseDate
Expand All @@ -196,13 +274,14 @@ public String toString() {
+ ", storeStates=" + storeStates
+ ", analyseBasecase=" + analyseBasecase
+ ", validation=" + validation
+ ", securityIndexes=" + securityIndexes
+ ", securityIndexes=" + securityIndexes
+ ", caseType=" + caseType
+ ", countries=" + countries
+ ", mergeOptimized=" + mergeOptimized
+ ", limitReduction=" + limitReduction
+ ", handleViolationsInN=" + handleViolationsInN
+ ", constraintMargin=" + constraintMargin
+ ", caseFile=" + caseFile
+ "}";
}

Expand Down Expand Up @@ -274,4 +353,8 @@ public void setConstraintMargin(float constraintMargin) {
this.constraintMargin = constraintMargin;
}

public void setCaseFile(String caseFile) {
this.caseFile = caseFile;
}

}
Loading

0 comments on commit ca40c12

Please sign in to comment.