Use Problem-Based Optimize Live Editor Task Effectively
How the Problem-Based Optimize Live Editor Task Works
The Optimize Live Editor task looks in many ways like a Graphical User Interface for optimization. However, it runs differently than you might expect.
Optimize creates MATLAB® code.
Optimize runs the created code when the Live Editor executes the section containing the task.
The section executes either automatically (when autorun is on, see Leave Autorun On in Define Problem Mode) or when you run the section by Ctrl + Enter or by clicking the blue bar to the left of the section.
To run an optimization, set up the problem in Define problem mode, then switch to Solve problem mode and run the section.
What Does Select task mode Do?
The Select task mode section appears at the bottom of the Live Editor task. The two modes are:
Define problem — Optimize creates MATLAB code representing the problem, but does not include a call to
solve. Therefore, in Define problem mode, the task does not solve the problem.
Solve problem — Optimize includes a call to
solveafter the problem creation code. Therefore, when the task runs in Solve problem mode, MATLAB solves the problem.
If autorun is off, switching the task to Solve problem mode does not run the task, and therefore does not solve the problem.
Leave Autorun On in Define Problem Mode
At the top right section of the task you can find three buttons, as pictured.
To have the task operate most reliably, leave autorun enabled (green) while in Define problem mode. Doing so enables the following behavior:
The list of available solvers stays synchronized with the problem as you change it.
The list of available options stays synchronized with the problem.
With autorun off, the task can be in an internally inconsistent state. In this state, the task creates warning labels: .
When autorun is off, switching the task to Solve problem mode does not run the task, and therefore does not solve the problem. In Solve problem mode, to keep the task from solving the problem every time you change something, set autorun to off. In this case, to solve a problem, run the task by pressing Ctrl + Enter or by clicking the blue bar to the left of the section.