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 with AmplExporter.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 <[email protected]>
  • Constructor Details

  • Method Details

    • 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 the ComputationManager 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 CommandExecutions 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 the ComputationManager with the working directory and an execution report as parameters, after the commands defined by the ExecutionHandler.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 the ExecutionReport for errors, and throws a PowsyblException in that case. May be called by actual implementations.

      Specified by:
      after in interface ExecutionHandler<AmplResults>
      Overrides:
      after in class AbstractExecutionHandler<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.