Assembly Line Scheduling

package dynamicProgramming

import kotlin.math.min


/*
 * This is a dynamic programming implementation of assembly line scheduling.
 * @Params n- number of stations, a- service time at each station, t- line switch time from each station, e- entry time, x- exit time
 * @Return minimum time to cross n stations
 * */
fun AssemblyLineScheduling(n:Int,a:Array<IntArray>,t:Array<IntArray>,e:IntArray,x:IntArray):Int {

    var L1:IntArray =  IntArray(n);
    var L2:IntArray = IntArray(n) ;
    var i=0;

    L1[0] = e[0] + a[0][0];

    L2[0] = e[1] + a[1][0];

    for(i in 1..n-1)
    {
        L1[i] = min(L1[i - 1] + a[0][i],
                L2[i - 1] + t[1][i] + a[0][i]);
        L2[i] = min(L2[i - 1] + a[1][i],
                L1[i - 1] + t[0][i] + a[1][i]);
    }

    return min(L1[n-1] + x[0],
            L2[n-1] + x[1]);


}
Algerlogo

Β© Alger 2022

About us

We are a group of programmers helping each other build new things, whether it be writing complex encryption programs, or simple ciphers. Our goal is to work together to document and model beautiful, helpful and interesting algorithms using code. We are an open-source community - anyone can contribute. We check each other's work, communicate and collaborate to solve problems. We strive to be welcoming, respectful, yet make sure that our code follows the latest programming guidelines.