Machine Parts

This model demonstrates the use of stacked interrupts. It is adopted from here.

Each of two machines has three parts, that will be subject to failure. If one or more of these parts has failed, the machine is stopped. Only when all parts are operational, the machine can continue its work (hold).

For a machine to work it needs the resource. If, during the requesting of this resource, one or more parts of that machine break down, the machine stops requesting until all parts are operational.

In this model the interrupt level frequently gets to 2 or 3 (all parts broken down).

Have a close look at the trace output to see what is going on.

////MachineWithParts.kt
import org.kalasim.*
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.minutes

class Part(val machine: Machine, partNo: Int) :
    Component(
        name = machine.name.replace("Machine", "part") + ".${partNo + 1}"
    ) {

    val ttf = uniform(19.hours, 20.hours) // time to failure distribution
    val ttr = uniform(3.hours, 6.hours)  //  time to repair distribution

    override fun process() = sequence {
        while(true) {
            hold(ttf())
            machine.interrupt()
            hold(ttr())
            machine.resume()
        }
    }
}


class Machine : Component() {

    init {
        repeat(3) { Part(this, it) }
    }

    override fun process() = sequence {
        while(true) {
            val r = get<Resource>()
            request(r)
            hold(5.minutes)
            release(r)
        }
    }
}

fun main() {
    createSimulation {
        enableComponentLogger()

        dependency { Resource() }
        repeat(2) { Machine() }

        run(400.hours)
    }
}