Search code examples
simulationanylogic

Is there any option of running an Anylogic simulator without opening any UI window?


I'm in a project in which I have to run an Anylogic simulator multiple times. I made an script to modify the input data, run the simulator and then store the output data just before the next simulation run.

The idea is to externally run the simulation (from a python file). The problem is that, when the simulation ends, the simulation window doesn't close automatically so the python file won't continue executing.

I´ve tried to run the simulator without showing the animation of the simulation but still opens a window so it doesn´t work for my purpose.

I don´t know if there is an option in Anylogic to export a model that automatically closes the window once the simulation is completed or if there is any way of creating a simulator that runs without opening any window.

Thank you.


Solution

  • Unfortunately there is no such solution. Even if you can run without UI in Linux, it will not automatically close once the run is complete. I use a workaround: It is a Python script that scans the outputs folder every 5 seconds and if there are changes in the files, it closes the AnyLogic file. Use this as an inspiration::

    from time import sleep
    
    from utils.data.fileSystem import FileSystem
    
    
    def sync_polling_folder(path, predicate, delay_sec):
    
        print('checking under ' + path + ' folder')
    
        beginning = FileSystem.stat(path)
        old = beginning
        new = beginning
    
        def two_files_are_different():
            return not predicate(str(old), str(new))
    
        def the_process_has_not_begun():
            return str(new) == str(beginning) or str(old) == str(beginning)
    
        # if two folders are the same, quit (means no-changes = finished)
        # but if they are equal because process never started, keep going
        while two_files_are_different() or the_process_has_not_begun():
            print('[sleeping] because files are not written yet.')
            sleep(delay_sec)  # main thread waiting
            old = new
            new = FileSystem.stat(path)
    
        print('[anylogic] ready to be killed')
    
        return True