Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using salabim without global variables #13

Closed
jonglezb opened this issue Jan 28, 2019 · 1 comment
Closed

Using salabim without global variables #13

jonglezb opened this issue Jan 28, 2019 · 1 comment

Comments

@jonglezb
Copy link

@jonglezb jonglezb commented Jan 28, 2019

First of all, thank you for this very nice package, it is a real pleasure to write simulations with salabim!

I am only wondering how to avoid using global variables for the simulation state (queues, etc).

All examples from the documentation (along with all the examples I looked at in the git repo) use a pattern like the following:

class MyObject(sim.Component):
    ...
    queue.enter(...)

queue = sim.Queue("myqueue")
obj = MyObject()
env.run()

That is, important state objects are created in the global context, and they are accessed directly by components.

This prevents two usages:

  • setup and run the simulation in a function, so that I could easily run several simulations in a row with different parameters
  • separate the components and the simulation setup in different source files

What would be the best way to make these state objects available to components? Put everything in a big class?

@salabim
Copy link
Owner

@salabim salabim commented Aug 12, 2019

Just attach these variables to env, like env.queue ...

@salabim salabim closed this Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants