gama-platform / gama.old

Main repository for developing the 1.x versions of GAMA
GNU General Public License v3.0
304 stars 99 forks source link

Continous chart slowing down simulation #3816

Closed NaroaCS closed 1 year ago

NaroaCS commented 1 year ago

Describe the bug I want to have a series chart that runs continuously as part of a demo that is always on. Even if I set memorize: false , it keeps slowing down the simulation.

To Reproduce I reproduced it on one of GAMA's library models so that it is easier to debug:

  1. In GAMA 1.9.1 go to Library models > Toy Models > Traffic > models
  2. Open Simple Traffic Model.gaml
  3. Find the experiment traffic and add:
        display dashboard type: java2D{
            chart "Test Plot" type: series background: #black x_range: 2000 memorize: false {
            data "Data" value:current_date.minute  color: #pink marker: false style: line;
            }
        }
  4. See how the Duration of the cycle increases (slow but steadily)

Expected behavior I would expect it to keep running smoothly

Screenshots Here the duration was 27 ms (top left) while in the beginning it was around 17 ms.

image

If I let it run for a longer time, the duration of the cycle keeps increasing to 40 ms etc (top left).

image

Desktop:

AlexisDrogoul commented 1 year ago

Hi. This is unfortunately to be expected since, even if you use x_range, you have to process more and more points (during all the processing happening before the chart is actually rendered). One possibility could be to build the list of values to draw yourself (always maintaining a constant size, when this size is reached, by removing the first one and adding the new value at the end) and draw only these values using datalist instead of data.

NaroaCS commented 1 year ago

Thank you, Alexis! I really appreciate your help. I've done as you say and it does work better than what I was doing. However, the cycles eventually end up slowing down. This is more noticeable especially with several datasets per plot, but happens even with a very simple model like this one:

global{
    //Initialize list
    list values <- list_with(2000, 0);

    //Reflex update values
    reflex update_values{
        if (cycle > 2000) {
            //Remove last value
            remove first(values) from: values;
        }
        //Add new value 
        add current_date.minute to: values;

    }   
}

experiment test type: gui {

    output {
        display dashboard type: java2D{
            chart "Test Plot" type: series background: #black x_range: 2000 memorize: false {
                data "Data" value:values color: #pink marker: false style: line;
            }
        }
    }
}
AlexisDrogoul commented 1 year ago

@NaroaCS can you test with the fix to #3814 ? It might actually help...

NaroaCS commented 1 year ago

Sorry for the probably very basic question, but how can I download a version of Gama with that commit? I usually download the latest pre-release from here: https://github.com/gama-platform/gama/releases but that doesn't include commit 7839e38

agrignard commented 1 year ago

@NaroaCS you should be able to test it with the last release just recently released here https://github.com/gama-platform/gama/releases/tag/1.9.2

NaroaCS commented 1 year ago

Thanks @agrignard ! 👍 Unfortunately I've just tested it with the simple test code above, and the behavior persists. Let me know if there is anything you need on my side. Thanks for all the help!

AlexisDrogoul commented 1 year ago

Hello - I think I've finally succeeded. But it hasn't been easy ! I have committed a possible fix for this wrong behaviour. Can you please test it in your case study ?

NaroaCS commented 1 year ago

Hi Alexis! Thanks so much, I'll be happy to test this :) I am trying to install the Git version to test it but I get an error in launching Gama from Eclipse, I think I am doing something wrong... Would it be possible to do a new release so that I can download it directly?

lesquoyb commented 1 year ago

Hello @NaroaCS, a new build is available here

NaroaCS commented 1 year ago

Thanks @lesquoyb ! I have been testing it today, and my model run for 6h without the cycles or visualizations slowing down!! I will let you know if I find any issue in the future, but it seems to be working well :) Thanks so much for solving this issue @AlexisDrogoul, I really appreciate your help!