Re: Tasks and actions

Hi Hadi

 

You should check the examples/Advanced/ServiceApi example for an example on how to call the default solver (OPL).

The part that is doing the job is:

        IloExecutionScope scope = processingService.newScope(scenario);

          IloSolveTaskController solveTask = (IloSolveTaskController) processingService.newTask(
              processingService.getConfiguration().getDefaultTask(), scope);

….

        // Submit the solve operation. Notice that this call is the same whether the

        // solve is performed on the optimization server or locally: this is only a deployment
        // decision, transparent for the API.
        processingService.submitTask(solveTask);

 

To call a custom task from an action, you would write something like:

 

  public void execute(String taskName) {
    final IloScenarioLink currentScenario = getODMApplication().getScenarioSelectionInteractor().getCurrentScenario();
    final IloScenarioProcessingService processingService = getODMApplication().getService(
        IloScenarioProcessingService.class);

    final Window activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();

    // get the task description
    final IloTaskConfig taskConfig = processingService.getConfiguration().getTaskByName(taskName);
    if (taskConfig == null) {
      JOptionPane.showMessageDialog(activeWindow, “Error creating a task”,
          NLS.bind(“Task “{0}” not found”, taskName), JOptionPane.ERROR_MESSAGE);
      return;
    }

    // create the controller
    IloExecutionScope scope = processingService.newScope(currentScenario.getScenario());
    IloTaskController controller = processingService.newTask(taskConfig, scope);
    if (!initializeController(controller, activeWindow)) return;

    // submitting the task if the scenario is not saved will fail. So save it anyway.
    try {
      currentScenario.getScenario().save();
    } catch (IloDataException e1) {
      JOptionPane.showMessageDialog(activeWindow, “Error saving the scenario”, e1.getMessage(),
          JOptionPane.ERROR_MESSAGE);
      return;
    }

    // submit the task
    try {
      processingService.submitTask(controller);
    } catch (Exception e) {
      JOptionPane.showMessageDialog(activeWindow, “Error submitting a task”, e.getLocalizedMessage(),
          JOptionPane.ERROR_MESSAGE);
    }

  }

 

Hope this helps

Regards

Michel

 

 

 

Source: Re: Tasks and actions