Skip to content

Commit

Permalink
Merge branch 'master' into case-projector
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Biasuzzi committed Jun 23, 2017
2 parents cdcfd26 + 53858b3 commit 326b0c3
Show file tree
Hide file tree
Showing 78 changed files with 636 additions and 588 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import eu.itesla_project.commons.config.ComponentDefaultConfig;
import eu.itesla_project.commons.tools.Command;
import eu.itesla_project.commons.tools.Tool;
import eu.itesla_project.commons.tools.ToolRunningContext;
import eu.itesla_project.contingency.ContingenciesProvider;
import eu.itesla_project.contingency.ContingenciesProviderFactory;
import eu.itesla_project.eurostag.network.EsgGeneralParameters;
Expand Down Expand Up @@ -50,7 +51,7 @@ public Command getCommand() {
}

@Override
public void run(CommandLine line) throws Exception {
public void run(CommandLine line, ToolRunningContext context) throws Exception {
ComponentDefaultConfig defaultConfig = ComponentDefaultConfig.load();
EurostagConfig eurostagConfig = EurostagConfig.load();
Path caseFile = Paths.get(line.getOptionValue("case-file"));
Expand All @@ -60,15 +61,15 @@ public void run(CommandLine line) throws Exception {
}
DynamicDatabaseClient ddbClient = defaultConfig.newFactoryImpl(DynamicDatabaseClientFactory.class).create(eurostagConfig.isDdbCaching());

System.out.println("loading case...");
context.getOutputStream().println("loading case...");
// load network
Network network = Importers.loadNetwork(caseFile);
if (network == null) {
throw new RuntimeException("Case '" + caseFile + "' not found");
}
network.getStateManager().allowStateMultiThreadAccess(true);

System.out.println("exporting ech...");
context.getOutputStream().println("exporting ech...");
// export .ech and dictionary
EurostagEchExportConfig exportConfig = new EurostagEchExportConfig();
BranchParallelIndexes parallelIndexes = BranchParallelIndexes.build(network, exportConfig);
Expand All @@ -84,12 +85,12 @@ public void run(CommandLine line) throws Exception {
new EsgWriter(networkEch, parameters).write(writer, network.getId() + "/" + network.getStateManager().getWorkingStateId());
}
dictionary.dump(outputDir.resolve("dict.csv"));
System.out.println("exporting dta...");
context.getOutputStream().println("exporting dta...");

// export .dta
ddbClient.dumpDtaFile(outputDir, "sim.dta", network, parallelIndexes.toMap(), EurostagUtil.VERSION, dictionary.toMap());

System.out.println("exporting seq...");
context.getOutputStream().println("exporting seq...");

// export .seq
EurostagScenario scenario = new EurostagScenario(SimulationParameters.load(), eurostagConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
package eu.itesla_project.fpf_integration;

import com.google.auto.service.AutoService;
import eu.itesla_project.cases.CaseRepository;
import eu.itesla_project.cases.CaseType;
import eu.itesla_project.commons.tools.Command;
import eu.itesla_project.commons.tools.Tool;
import eu.itesla_project.computation.ComputationManager;
import eu.itesla_project.computation.local.LocalComputationManager;
import eu.itesla_project.commons.tools.ToolRunningContext;
import eu.itesla_project.contingency.Contingency;
import eu.itesla_project.fpf_integration.executor.FPFAnalysis;
import eu.itesla_project.iidm.network.Country;
import eu.itesla_project.iidm.network.Network;
import eu.itesla_project.mcla.ForecastErrorsDataStorageImpl;
import eu.itesla_project.cases.CaseRepository;
import eu.itesla_project.cases.CaseType;
import eu.itesla_project.modules.contingencies.ContingenciesAndActionsDatabaseClient;
import eu.itesla_project.contingency.Contingency;
import eu.itesla_project.modules.online.OnlineConfig;
import eu.itesla_project.modules.online.OnlineWorkflowParameters;
import eu.itesla_project.modules.online.TimeHorizon;
Expand Down Expand Up @@ -96,7 +95,7 @@ public Command getCommand() {
}

@Override
public void run(CommandLine line) throws Exception {
public void run(CommandLine line, ToolRunningContext context) throws Exception {

OnlineWorkflowParameters parameters=OnlineWorkflowParameters.loadDefault();
OnlineConfig onlineConfig=OnlineConfig.load();
Expand All @@ -113,23 +112,22 @@ public void run(CommandLine line) throws Exception {

String outputDir = line.getOptionValue("output-dir");

ComputationManager computationManager = new LocalComputationManager();
ForecastErrorsDataStorageImpl feDataStorage = new ForecastErrorsDataStorageImpl();
CaseRepository caseRepository = onlineConfig.getCaseRepositoryFactoryClass().newInstance().create(computationManager);
CaseRepository caseRepository = onlineConfig.getCaseRepositoryFactoryClass().newInstance().create(context.getComputationManager());

List<Network> networks = caseRepository.load(baseCaseDate, CaseType.FO, Country.FR);
if (networks.isEmpty()) {
throw new RuntimeException("Base case not found");
}
Network network = networks.get(0);
System.out.println("- Network id: " + network.getId());
System.out.println("- Network name: " + network.getName());
context.getOutputStream().println("- Network id: " + network.getId());
context.getOutputStream().println("- Network name: " + network.getName());

ContingenciesAndActionsDatabaseClient contingenciesDb = onlineConfig.getContingencyDbClientFactoryClass().newInstance().create();
List<Contingency> contingencyList=contingenciesDb.getContingencies(network);

FPFAnalysis fpfce=new FPFAnalysis();
fpfce.init(network,computationManager,feDataStorage);
fpfce.init(network,context.getComputationManager(),feDataStorage);
fpfce.run(analysisId, timeHorizon, contingencyList, Paths.get(outputDir));
}
}
4 changes: 4 additions & 0 deletions iidm-ddb/iidm-ddb-eurostag-import-export/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<groupId>eu.itesla_project</groupId>
<artifactId>iidm-api</artifactId>
</dependency>
<dependency>
<groupId>eu.itesla_project</groupId>
<artifactId>tools</artifactId>
</dependency>

<!-- We depend on the EJB remote interfaces of this application -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;

import eu.itesla_project.commons.tools.ToolRunningContext;
import org.apache.commons.cli.CommandLine;

import com.google.auto.service.AutoService;
Expand All @@ -31,7 +32,7 @@ public Command getCommand() {
}

@Override
public void run(CommandLine line) throws Exception {
public void run(CommandLine line, ToolRunningContext context) throws Exception {
String dataDir = line.getOptionValue(DdbLoaderCommand.DATA_DIR);
String jbossHost = line.getOptionValue(DdbLoaderCommand.HOST);
String jbossPort = line.getOptionValue(DdbLoaderCommand.PORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package eu.itesla_project.iidm.ddb.eurostag_imp_exp.tools;

import eu.itesla_project.commons.tools.ToolRunningContext;
import org.apache.commons.cli.CommandLine;

import com.google.auto.service.AutoService;
Expand All @@ -28,7 +29,7 @@ public Command getCommand() {
}

@Override
public void run(CommandLine line) throws Exception {
public void run(CommandLine line, ToolRunningContext context) throws Exception {
String jbossHost = line.getOptionValue(DdbLoaderCommand.HOST);
String jbossPort = line.getOptionValue(DdbLoaderCommand.PORT);
String jbossUser = line.getOptionValue(DdbLoaderCommand.USER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.auto.service.AutoService;
import eu.itesla_project.commons.tools.Command;
import eu.itesla_project.commons.tools.Tool;
import eu.itesla_project.commons.tools.ToolRunningContext;
import eu.itesla_project.iidm.ddb.eurostag_imp_exp.DdbConfig;
import eu.itesla_project.iidm.ddb.eurostag_imp_exp.DdbDtaImpExp;
import org.apache.commons.cli.CommandLine;
Expand Down Expand Up @@ -121,7 +122,7 @@ public Command getCommand() {
}

@Override
public void run(CommandLine line) throws Exception {
public void run(CommandLine line, ToolRunningContext context) throws Exception {
String dataDir = line.getOptionValue(DATA_DIR);
String ddFile = line.getOptionValue(DD_FILE);
String jbossHost = line.getOptionValue(HOST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;

import eu.itesla_project.commons.tools.ToolRunningContext;
import eu.itesla_project.iidm.ddb.psse_imp_exp.DdbDyrLoader;
import org.apache.commons.cli.CommandLine;

Expand All @@ -31,7 +32,7 @@ public Command getCommand() {
}

@Override
public void run(CommandLine line) throws Exception {
public void run(CommandLine line, ToolRunningContext context) throws Exception {
String dyrPathS = line.getOptionValue(DdbLoaderCommand.PSSE_DYRFILEPATH);
String mappingPathS = line.getOptionValue(DdbLoaderCommand.PSSE_MAPPINGFILEPATH);
String jbossHost = line.getOptionValue(DdbLoaderCommand.HOST);
Expand Down
4 changes: 2 additions & 2 deletions iidm-ddb/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ MYSQL iidm-ddb schema creation
----------------------------------------
execute the following 3-lines DDL script:


CREATE DATABASE itesladdb CHARACTER SET utf8 COLLATE utf8_general_ci;
DROP DATABASE IF EXISTS itesladdb;
CREATE DATABASE IF NOT EXISTS itesladdb CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL ON itesladdb.* TO 'itesla'@'localhost' IDENTIFIED BY 'itesla';
GRANT ALL ON itesladdb.* TO 'itesla'@'%' IDENTIFIED BY 'itesla';

Expand Down
63 changes: 30 additions & 33 deletions modules/src/main/java/eu/itesla_project/modules/OptimizerTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
import com.google.auto.service.AutoService;
import eu.itesla_project.commons.tools.Command;
import eu.itesla_project.commons.tools.Tool;
import eu.itesla_project.computation.ComputationManager;
import eu.itesla_project.computation.local.LocalComputationManager;
import eu.itesla_project.commons.tools.ToolRunningContext;
import eu.itesla_project.iidm.import_.Importers;
import eu.itesla_project.iidm.network.Network;
import eu.itesla_project.loadflow.api.LoadFlow;
import eu.itesla_project.loadflow.api.LoadFlowResult;
import eu.itesla_project.modules.histo.HistoDbClient;
import eu.itesla_project.modules.offline.OfflineConfig;
import eu.itesla_project.modules.sampling.SampleCharacteritics;
import eu.itesla_project.security.Security;
import eu.itesla_project.modules.topo.TopologyContext;
import eu.itesla_project.modules.topo.TopologyMiner;
import eu.itesla_project.security.Security;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
Expand Down Expand Up @@ -105,7 +104,7 @@ public Command getCommand() {
}

@Override
public void run(CommandLine line) throws Exception {
public void run(CommandLine line, ToolRunningContext context) throws Exception {
Path caseFile = Paths.get(line.getOptionValue("case-file"));
Interval histoInterval = Interval.parse(line.getOptionValue("history-interval"));
boolean checkConstraints = line.hasOption("check-constraints");
Expand All @@ -114,48 +113,46 @@ public void run(CommandLine line) throws Exception {
boolean generationSampled = line.hasOption("generation-sampled");
boolean boundariesSampled = line.hasOption("boundaries-sampled");

try (ComputationManager computationManager = new LocalComputationManager()) {
System.out.println("loading case...");
// load the network
Network network = Importers.loadNetwork(caseFile);
if (network == null) {
throw new RuntimeException("Case '" + caseFile + "' not found");
}
network.getStateManager().allowStateMultiThreadAccess(true);
context.getOutputStream().println("loading case...");
// load the network
Network network = Importers.loadNetwork(caseFile);
if (network == null) {
throw new RuntimeException("Case '" + caseFile + "' not found");
}
network.getStateManager().allowStateMultiThreadAccess(true);

System.out.println("sample characteristics: " + SampleCharacteritics.fromNetwork(network, generationSampled, boundariesSampled));
context.getOutputStream().println("sample characteristics: " + SampleCharacteritics.fromNetwork(network, generationSampled, boundariesSampled));

OfflineConfig config = OfflineConfig.load();
try (HistoDbClient histoDbClient = config.getHistoDbClientFactoryClass().newInstance().create();
TopologyMiner topologyMiner = config.getTopologyMinerFactoryClass().newInstance().create()) {
OfflineConfig config = OfflineConfig.load();
try (HistoDbClient histoDbClient = config.getHistoDbClientFactoryClass().newInstance().create();
TopologyMiner topologyMiner = config.getTopologyMinerFactoryClass().newInstance().create()) {

Optimizer optimizer = config.getOptimizerFactoryClass().newInstance().create(network, computationManager, 0, histoDbClient, topologyMiner);
LoadFlow loadFlow = config.getLoadFlowFactoryClass().newInstance().create(network, computationManager, 0);
Optimizer optimizer = config.getOptimizerFactoryClass().newInstance().create(network, context.getComputationManager(), 0, histoDbClient, topologyMiner);
LoadFlow loadFlow = config.getLoadFlowFactoryClass().newInstance().create(network, context.getComputationManager(), 0);

System.out.println("initializing optimizer...");
context.getOutputStream().println("initializing optimizer...");

TopologyContext topologyContext = TopologyContext.create(network, topologyMiner, histoDbClient, computationManager, histoInterval, correlationThreshold, probabilityThreshold);
TopologyContext topologyContext = TopologyContext.create(network, topologyMiner, histoDbClient, context.getComputationManager(), histoInterval, correlationThreshold, probabilityThreshold);

optimizer.init(new OptimizerParameters(histoInterval), topologyContext);
optimizer.init(new OptimizerParameters(histoInterval), topologyContext);

System.out.println("running optimizer...");
context.getOutputStream().println("running optimizer...");

OptimizerResult result = optimizer.run();
OptimizerResult result = optimizer.run();

System.out.println("optimizer status is " + (result.isFeasible() ? "feasible" : "unfeasible") + " (" + result.getMetrics() + ")");
context.getOutputStream().println("optimizer status is " + (result.isFeasible() ? "feasible" : "unfeasible") + " (" + result.getMetrics() + ")");

if (result.isFeasible()) {
System.out.println("running loadflow...");
if (result.isFeasible()) {
context.getOutputStream().println("running loadflow...");

LoadFlowResult result2 = loadFlow.run();
LoadFlowResult result2 = loadFlow.run();

System.out.println("loadflow status is " + (result2.isOk() ? "ok" : "nok") + " (" + result2.getMetrics() + ")");
context.getOutputStream().println("loadflow status is " + (result2.isOk() ? "ok" : "nok") + " (" + result2.getMetrics() + ")");

if (result2.isOk() && checkConstraints) {
String report = Security.printLimitsViolations(network);
if (report != null) {
System.out.println(report);
}
if (result2.isOk() && checkConstraints) {
String report = Security.printLimitsViolations(network);
if (report != null) {
context.getOutputStream().println(report);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.auto.service.AutoService;
import eu.itesla_project.commons.tools.Command;
import eu.itesla_project.commons.tools.Tool;
import eu.itesla_project.commons.tools.ToolRunningContext;
import eu.itesla_project.modules.histo.HistoDbClient;
import eu.itesla_project.modules.offline.OfflineConfig;
import org.apache.commons.cli.CommandLine;
Expand Down Expand Up @@ -59,13 +60,13 @@ public String getUsageFooter() {
}

@Override
public void run(CommandLine line) throws Exception {
public void run(CommandLine line, ToolRunningContext context) throws Exception {
OfflineConfig config = OfflineConfig.load();
String dbName = null;
if (line.hasOption("db-name")) {
dbName = line.getOptionValue("db-name");
}
System.out.println("clear " + dbName + "...");
context.getOutputStream().println("clear " + dbName + "...");
try (HistoDbClient histoDbClient = config.getHistoDbClientFactoryClass().newInstance().create(false)) {
if (dbName == null) {
histoDbClient.clearDb();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.auto.service.AutoService;
import eu.itesla_project.commons.tools.Command;
import eu.itesla_project.commons.tools.Tool;
import eu.itesla_project.commons.tools.ToolRunningContext;
import eu.itesla_project.modules.histo.*;
import eu.itesla_project.modules.offline.OfflineConfig;
import org.apache.commons.cli.CommandLine;
Expand Down Expand Up @@ -69,7 +70,7 @@ public String getUsageFooter() {
}

@Override
public void run(CommandLine line) throws Exception {
public void run(CommandLine line, ToolRunningContext context) throws Exception {
Interval interval = Interval.parse(line.getOptionValue("interval"));
HistoDbHorizon horizon = HistoDbHorizon.SN;
if (line.hasOption("horizon")) {
Expand All @@ -80,7 +81,7 @@ public void run(CommandLine line) throws Exception {
Set<HistoDbAttributeId> attributeIds = new LinkedHashSet<>(histoDbClient.listAttributes());
HistoDbStats stats = histoDbClient.queryStats(attributeIds, interval, horizon, true);
for (HistoDbAttributeId attributeId : attributeIds) {
System.out.println(attributeId + ";" + (int) stats.getValue(HistoDbStatsType.COUNT, attributeId, -1));
context.getOutputStream().println(attributeId + ";" + (int) stats.getValue(HistoDbStatsType.COUNT, attributeId, -1));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.auto.service.AutoService;
import eu.itesla_project.commons.tools.Command;
import eu.itesla_project.commons.tools.Tool;
import eu.itesla_project.commons.tools.ToolRunningContext;
import eu.itesla_project.modules.histo.HistoDbAttr;
import eu.itesla_project.modules.histo.HistoDbAttributeId;
import eu.itesla_project.modules.histo.HistoDbClient;
Expand Down Expand Up @@ -67,7 +68,7 @@ public String getUsageFooter() {
}

@Override
public void run(CommandLine line) throws Exception {
public void run(CommandLine line, ToolRunningContext context) throws Exception {
OfflineConfig config = OfflineConfig.load();
Set<HistoDbAttr> types = null;
if (line.hasOption("attribute-types")) {
Expand All @@ -81,7 +82,7 @@ public void run(CommandLine line) throws Exception {
if (types == null
|| (attributeId instanceof HistoDbNetworkAttributeId
&& types.contains(((HistoDbNetworkAttributeId) attributeId).getAttributeType()))) {
System.out.println(attributeId);
context.getOutputStream().println(attributeId);
}
}
}
Expand Down

0 comments on commit 326b0c3

Please sign in to comment.