Showing Progress of Long Running Algorithms

Most users can be re-assured that a long running algorithm is working by showing the progress that is being made. There are various ways of doing this. This article gives a brief overview and a detailed example of showing progress in data for the WebUI.

WinUI

  1. Showing a progress bar using DialogProgress()

  2. During the running of the algorithm, call PageRefreshAll()

WebUI

  1. Showing progress message in the busy icon see SetProgressMessage

  2. Regularly scheduling the next portion of the algorithm using ScheduleAt. This requires rewriting the algorithm, which is illustrated in the next section.

WinUI and WebUI Showing Progress

WinUI Example Showing Progress

Showing the progress of an algorithm in WinUI is achieved by adding PageRefreshAll calls to the code, see line 6 below:

 1Procedure pr_simulatingWinUI {
 2    Body: {
 3        bp_stop := 0 ;
 4        while not bp_stop do
 5            pr_iteration();
 6            pageRefreshAll();
 7            delay(1);
 8        endwhile ;
 9    }
10}

To enable interruption of the algorithm by running another procedure, you will need to activate the actual algorithm in the background; this can be done in the properties of the button activating the actual algorithm:

../../_images/winui-alg-runs-in-background.png

WebUI Example Showing Progress

There is no equivalent to PageRefreshAll in the WebUI. To create an equivalent procedure, the algorithm is broken in separate procedures:

First the start of an algorithm:

1Procedure pr_startSimulating {
2    Body: {
3        bp_stop := 0 ;
4        pr_nextIteration();
5    }
6}

In an iteration, we do it; and when the stopping condition is not yet satisfied, another iteration is started in a second:

 1Procedure pr_nextIteration {
 2    Body: {
 3        pr_iteration();
 4        if not bp_stop then
 5            pr_scheduleOver(
 6                p_in_noSecs   :  1[s],
 7                ep_in_payLoad :  'pr_nextIteration');
 8        endif ;
 9    }
10}

Here pr_scheduleOver is a small wrapper around ScheduleAt, that schedules in the given number of seconds.

For the details see this AIMMS 4.91 project download

A screenshot of this app:

../../_images/MovingColumnBars.png

This app makes an arbitrary change in the levels by -1 or by +1 every second.

See also