GithubHelp home page GithubHelp logo

holgerbrandl / kalasim Goto Github PK

View Code? Open in Web Editor NEW
67.0 5.0 10.0 40.68 MB

Discrete Event Simulator

Home Page: https://www.kalasim.org/

License: MIT License

Kotlin 80.52% R 0.28% HTML 17.96% Java 1.23%
simulation discrete-event-simulation process-modeling optimization data-science visulization agent-based-modeling

kalasim's Introduction

kalasim

Discrete Event Simulator

Download Build Status slack github-discussions

kalasim is a discrete event simulator. It provides a statically typed API, dependency injection, modern persistence, structured logging and automation capabilities.

kalasim is designed for simulation practitioners, process analysts and industrial engineers, who need to go beyond the limitations of existing simulation tools to model and optimize their business-critical use-cases.

In contrast to many other simulation tools, kalasim is neither low-code nor no-code. It is code-first to enable change tracking, scaling, refactoring, CI/CD, unit-tests, and the rest of the gang that makes simulation development fun.

Documentation

All docs are hosted under http://www.kalasim.org/

kalasim's People

Contributors

holgerbrandl avatar louiscad avatar pambrose avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

kalasim's Issues

Add support for DurationUnit in distributions

To remove any doubt about what time unit is about to samples we could potentially add more support API using kotlin.time.DurationUnit

val waitingTimeDist = exponential<Seconds>(30)

or similar.

  • Implementation (completed as part of v0.9)
  • Documentation

Find a more concise way to activate a new processes

Currently we need to yield(activate(process = Harvester::harvesting)) which seems too tedious. The average user will struggle is likely to struggle with this part of the API.

We could introduce a new verb such as activate(process) or simply change activate.
`

Add a standard logging library

I have been using https://github.com/MicroUtils/kotlin-logging for years and it works great.

The only thing required to enable it for a given class is to make its companion object inherit from KLogging:

companion object : KLogging()

You then get a local logger value and can add as much logging instrumentation as you want and not worry about overhead because the actions are all lambdas, which are not evaluated if the call level does not warrant it.

Have a look and see what you think.

Allow merging of simulations

It shall support the following API

val env1 = Environment()
val env2 = Environment()

val envMerged = env1 + env2
envMerged.run(10)

This will allow modelling more complex child-parent relations separately. E.g. a department of a store could be modelled and then be bound into a shopping mall model itself.

Note: Unless we can support branching, the original environments will not be functional by themself after merging.

Add component name auto-indexing

Similar to salabim, components should have auto-indexing if the name ends with a comma/dot

  • Create test-coverage
  • Implementation
  • Review contract
  • Update documentation

Provide a more declarative way to implement components

To create a custom component, currently, the user has to

val c = object : Component(){
    override fun process() = sequence { 
        hold(1)
    }
}

But it would be super-cool if she could just do something like

val c = object : Component(){
    hold(1)
}

However, it seems impossible to implement this feature because the underlying building would require multiple receivers (SeqeneceScope and this@Component) for functioning. This is not yet possible with kotlin, so this ticket is blocked by https://youtrack.jetbrains.com/issue/KT-10468.

Improve wait syntax

// current
wait(StateRequest(state) { it!=null })

// better
wait(state){ it!=null }

java.lang.IllegalStateException: KoinApplication has not been started

kalasim 0.6.6

fun main() {
    val devices = Resource(name = "devices", capacity = 1)
}
Exception in thread "main" java.lang.IllegalStateException: KoinApplication has not been started
	at org.koin.core.context.GlobalContext.get(GlobalContext.kt:35)
	at org.kalasim.Resource.<init>(Resource.kt:42)
	at MainKt.main(Main.kt:7)
	at MainKt.main(Main.kt)

How could I start KoinApplication?

collect() has unclear semantics

A common usecase is to filter for just some events of interest. This should be definable at the collector declaration site, but isn't in v0.7.92:

val log = sim.collect<ResourceActivityEvent>().filter{ it.bla}

Optionally disallow use of untyped duration when tick-transform is defined

When a user has defined a tick-transform in a model it should optionally support disallowing untyped use of hold etc.

sim.tickTransform = TickTransform(TimeUnit.MINUTES)
sim.enforceTypedDurations = true
...
hold(3) // should fail because possible incorrect/unintenional use of wrong unit
hold(3.minutes) // should work

In a second iteration, kalasim may also want to enforce a tick-unit when creating a simulation (i.e. val sim = Environment(TimeUnit.MINUTES)). This would make hold(2) impossible: The user would always need to state her intent about the duration by providing a tick-unit.

FYI @MohidQaiser

Component creation order is wrong in clerk queue example

The correct event order when running Bank_1_clerk.kt should be

   30       0.000 main                 current                              
   32                                  customergenerator.0 create           
   32                                  customergenerator.0 activate         scheduled for      0.000 @    6  process=process
   33                                  clerk.0 create                       
   33                                  clerk.0 activate                     scheduled for      0.000 @   21  process=process
   34                                  waitingline create                   
   36                                  main run +50.000    

but instead, we obtain

.00                            main                     DATA        create
.00   main
.00                            CustomerGenerator.1      DATA        create
.00                            CustomerGenerator.1      DATA        activate
.00                            main                     CURRENT     run +50.0
.00   CustomerGenerator.1
.00                                                                 create ComponentQueue.1
.00                            Clerk.1                  DATA        create
.00                            Clerk.1                  DATA        activate

The component queue and the clerk should be created before main is rescheduled.

This problem is caused by InsertKoinIO/koin#801

Allow branching of simulations

To enable different trajectories (with controlled randomization), the user may want to branch simulations at a specific time.

Example

// current API 
val sim  : Environment = createSimulation{ 
// define simulation entities here
}

// run it for 100 ticks
sim.run(100)

// inspect some metric (see https://www.kalasim.org/analysis/)
sim.gatherStatistic()


// Pseudocode/Desired API from here on 
val branches : List<Environment> = sim.branch(100)

val branchStats = branches.forEach { it.run(100) }.map{ it.gatherStatistic() }

To do so we must persist the entire graph including koin, monitors, the environment (including its queue) and process states (which are modelled as kotlin.sequences.Sequence iterators). Naturally - by design of kalasim - user-specific code will also leak into the graph to be persisted.

  • The feature would also provide means to have file-format for saving/loading simulations
  • Such a feature would also prepare for distributed simulation, where simulations are packed and shipped over the network to other compute nodes

Current state
✔️ Framework evaluation -> kryo it is, see evaluation branch https://github.com/holgerbrandl/kalasim/tree/kryoeval
✔️ Persist koin
✔️ Persist main entities and environment
✔️ Deserialize environment including sequence iterators of process definitions (graph looks good and runs up to

val restored = kryo.readClassAndObject(input) as Environment
)
❌ Run deserialized environment--> Fails to run, which boils to sequence iterators being not serializable as of now in https://github.com/holgerbrandl/kryo-kotlin-sam/blob/master/src/main/kotlin/simpleproc/SimpleProc.kt (see Kotlin/kotlinx.coroutines#76 and EsotericSoftware/kryo#867)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.