Search code examples
anylogic

Anylogic Sensitivity Analysis chart legend


I was able to successfully create a sensitivty analysis, but unfortunately, as can be seen in the picture, the legend has a random arrangement. But I would like to have an ascending order.

Sensitivity Analysis with random legend order

After Simulation Run:

Color color = lerpColor( (getCurrentIteration() - 1) / (double) (getMaximumIterations() - 1), blue, red );
chart0.addDataSet( root.childDS, format( root.childgoal ), color, true, Chart.INTERPOLATION_LINEAR, 1, Chart.POINT_NONE );

The input dataset is in ascending order. I tried it with sortAscending. Unfortunately it did not work.

Thank you very much for suggestions on how I can solve this problem.


Solution

  • Your runs finish quasi-randomly and you simply add datasets when a run is finished.

    To overcome this, either run in sequential mode (turn off "parallel evaluations" in the experiment settings).

    Or do this:

    • add a collection of type LinkedHashMap with key as Integer, value as DataSet, name it myCol
    • in the "After Simulation Run" code, do this after your line to define the color:

    myCol.put(getCurrentIteration(), root.childDS);
    chart0.removeAll(); // maybe use .clearAll(), cant remember
    for (int currIt : myCol.keySet()) {
        chart0.addDataSet(myCol.get(currIt), ...); // add other args as usual
    }
    

    You may need to wiggle with the code itself, just writing from memory here, use the API and help if you get stuck