Class AmplModelExecutionHandler
- java.lang.Object
-
- com.powsybl.computation.AbstractExecutionHandler<AmplResults>
-
- com.powsybl.ampl.executor.AmplModelExecutionHandler
-
- All Implemented Interfaces:
ExecutionHandler<AmplResults>
public class AmplModelExecutionHandler extends AbstractExecutionHandler<AmplResults>
This executionHandler will run an ampl model on a network.It copies every file given by
AmplModel.getAmplRunFiles()
in the working directory. It exports the Network withAmplExporter.export(com.powsybl.iidm.network.Network, java.util.Properties, com.powsybl.commons.datasource.DataSource)
.Then it runs the ampl model, and
AmplReadableElement.readElement(com.powsybl.ampl.converter.AmplNetworkReader)
is used to apply modifications on the network.The majority of the configuration is made by the
AmplModel
interface.- Author:
- Nicolas Pierre
-
-
Constructor Summary
Constructors Constructor Description AmplModelExecutionHandler(AmplModel model, Network network, String networkVariant, AmplConfig config, AmplParameters parameters)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AmplResults
after(Path workingDir, ExecutionReport report)
Method called by theComputationManager
with the working directory and an execution report as parameters, after the commands defined by theExecutionHandler.before(java.nio.file.Path)
method have been executed: it is in charge of any postprocessing and of providing the actual computation result.List<CommandExecution>
before(Path workingDir)
Method called by theComputationManager
with the working directory as parameter, before the commands are actually executed: it is in charge of any preprocessing of providing the list of commands to be executed.protected static CommandExecution
createAmplRunCommand(AmplConfig config, AmplModel model)
protected static String
getAmplBinPath(AmplConfig cfg)
-
Methods inherited from class com.powsybl.computation.AbstractExecutionHandler
onExecutionCompletion, onExecutionStart
-
-
-
-
Constructor Detail
-
AmplModelExecutionHandler
public AmplModelExecutionHandler(AmplModel model, Network network, String networkVariant, AmplConfig config, AmplParameters parameters)
-
-
Method Detail
-
createAmplRunCommand
protected static CommandExecution createAmplRunCommand(AmplConfig config, AmplModel model)
-
getAmplBinPath
protected static String getAmplBinPath(AmplConfig cfg)
-
before
public List<CommandExecution> before(Path workingDir) throws IOException
Description copied from interface:ExecutionHandler
Method called by theComputationManager
with the working directory as parameter, before the commands are actually executed: it is in charge of any preprocessing of providing the list of commands to be executed. Typically, it will copy input data to the specified working directory, and create the command to be executed with those inputs.If the call throws an exception, no command will be executed.
- Parameters:
workingDir
- the working directory used for this computation. Input data may be written to it.- Returns:
- the list of
CommandExecution
s to be executed. - Throws:
IOException
- when an error occurs while wirting to working directory.
-
after
public AmplResults after(Path workingDir, ExecutionReport report) throws IOException
Description copied from class:AbstractExecutionHandler
Method called by theComputationManager
with the working directory and an execution report as parameters, after the commands defined by theExecutionHandler.before(java.nio.file.Path)
method have been executed: it is in charge of any postprocessing and of providing the actual computation result. Typically, it will check that the execution was correctly performed, then read command results from the specified working directory and translate it to a business object.That method will not be called in case the call to
ExecutionHandler.before(java.nio.file.Path)
throws an exception, or if the execution is cancelled. That implementation checks theExecutionReport
for errors, and throws aPowsyblException
in that case. May be called by actual implementations.- Specified by:
after
in interfaceExecutionHandler<AmplResults>
- Overrides:
after
in classAbstractExecutionHandler<AmplResults>
- Parameters:
workingDir
- the working directory used for this computation. Results may be read from it.report
- the execution report, in particular reporting command execution errors.- Returns:
- the actual result of the processing.
- Throws:
IOException
- if and error occurs while reading results from the working directory.
-
-