Jerald
Jerald

Reputation: 23

SimTalk Plant Sim. Problem finding the duration each station is the bottleneck according to the 'Current longest uninteruppted period' for a station

I am using the codes below to determine which is the station with current longest uninterupted period(Bottleneck). Then find the duration each bottleneck was the one with current longest uninterupted period. The problem is that when the code is going through loop to find the current active period of each station. It always momentarily declares the stations before the current bottleneck station as the one with the current longest uninterupted period. Which makes it impossible to find the real duration each station is the bottlneck for the cluip_table. How can I solve this problem that exists inherently due to the sequence in which the loop checks for the bottleneck?

The first code is called by the event time controller everytime the simtime changes:

-- param attribute: string, oldValue: time
param newValue: time

-- Variables to store the results
var current_longest_active_time, current_second_longest_active_time, begin_time_starv_st, begin_time_block_st, end_time_starv_st, end_time_block_st, Fail_duration : time
var current_BN_station: object
var new_capacity: integer
var BN_station, ShiftingBN_station: object
var current_station: object
var current_duration: time
var duration_of_previousBN: time

-- Initialize variables
/*current_longest_active_time := 0
current_second_longest_active_time := 0*/

for var i := 1 to shifting_table.YdimIndex loop
    current_station := shifting_table["station_object", i]

    if shifting_table["state_inactive", current_station] = true then
        shifting_table["current_inactive_period", current_station] := newValue - shifting_table["end_active_period", current_station]
        shifting_table["current_active_period", current_station] := 0
    elseif shifting_table["state_inactive", current_station] = false then
        shifting_table["current_active_period", current_station] := newValue - shifting_table["start_active_period", current_station]
    end
next

//current_longest_active_time := shifting_table["current_longest_active_time", 7]

        -- Loop through each row in the DataTable to compare values

for var i:=1 to shifting_table.YdimIndex
    current_station := shifting_table["station_object", i]  -- Reading station name
    current_duration := shifting_table["current_active_period", i]  -- Reading active period



    -- Check if the current duration is longer than the stored longest duration
    if current_duration > current_longest_active_time then
        -- Shift the current longest to second longest
        current_second_longest_active_time := current_longest_active_time
        ShiftingBN_station := BN_station
        if ShiftingBN_station = void
        else
            cluip_table["end_cluip", ShiftingBN_station]  := EventController.simtime
        end


        -- Update the longest duration and station
        current_longest_active_time := current_duration
        BN_station := current_station
        cluip_table["start_cluip", BN_station] := EventController.simtime

    elseif current_duration > current_second_longest_active_time then
        -- If the current duration is not the longest but longer than the second longest
        current_second_longest_active_time := current_duration
        ShiftingBN_station := current_station
    end

shifting_table["current_longest_active_time", 7] := current_longest_active_time
shifting_table["current_bn", 7] := BN_station
Drain.CLUIP := shifting_table["current_bn", 7]
shifting_table["current_second_longest_active_time", 7] := current_second_longest_active_time
shifting_table["current_shifting_bn", 7] := ShiftingBN_station

-- Loop through all stations and assign non_bn_wip_limit_tier2 to those that are neither BN_station nor ShiftingBN_station
/*for var k := 1 to shifting_table.YdimIndex
    current_station := shifting_table["station_object", k]
    if shifting_table["current_active_period", current_station] < shifting_table["current_longest_active_time", 8]      -- Skip BN_station and ShiftingBN_station
        if current_station = Station1
        else
            current_station.pred.wip_limit := non_bn_wip_limit_tier2            -- Assign non_bn_wip_limit_tier2 to the buffer before the current station
        end
    end

next

if ShiftingBN_station =void
elseif ShiftingBN_station = Station1
else
    ShiftingBN_station.pred.wip_limit := non_bn_wip_limit_tier1
end

if BN_station =void
elseif BN_station = Station5
    BN_station.pred.wip_limit := bn_wip_limit
elseif BN_station = Station1
    //BN_station.succ.wip_limit := bn_wip_limit
else
    BN_station.pred.wip_limit := bn_wip_limit
    BN_station.succ.wip_limit := bn_wip_limit
end*/


next``


The second code below is the method that updates the values in the cluip_table. It is called everytime the attribute CLUIP changes. Which becuase of the issue caused by the loop, is called much more often than it should. Also correct the formulation of this code because it keeps adding the time for the current longest uninterupted active period to values soo high, that they are even higher than the total simulation time

`param oldValue: object

if oldValue = void
//elseif newValue = void
else
    cluip_table["cluip_duration", oldValue] := cluip_table["cluip_duration", oldvalue] + (cluip_table["end_cluip", oldvalue] - cluip_table["start_cluip", oldvalue])
    //cluip_table["cluip_duration", oldValue] := cluip_table["cluip_duration", oldValue] + (cluip_table["start_cluip", oldValue] - cluip_table["end_cluip", oldValue])
end```


I also created a datatable, called 'cluip_table' that measures how long each station was the one with the current longest active period during the simulation run. Problem is that table keeps updating everytime the even controller is calling the method using change in simtime. Therefore the method keeps adding to the CLUIP duration everytime the attribute I created in the drain called 'CLUIP' that monitors the changes in the station with the current longest uninterupted period. Which leads to it adding huge values. To the CLUIP duration of each station. Precisely because it's being called more often than it should. Becuase the code loops trhough all the stations which leads to the errors. 

I even tried adding a 'confirmation duration' before the cluip actually changes. But nothing I have done soo far has been able to overide the loop and the errors becuase of it

```-- Loop through each row in the DataTable to compare values

for var i:=1 to shifting_table.YdimIndex
    current_station := shifting_table["station_object", i]  -- Reading station name
    current_duration := shifting_table["current_active_period", i]  -- Reading active period

    -- Check if the current duration is longer than the stored longest duration
    if current_duration > current_longest_active_time then
        -- Shift the current longest to second longest
        current_second_longest_active_time := current_longest_active_time
        ShiftingBN_station := BN_station

        -- Update the longest duration and station
        current_longest_active_time := current_duration
        BN_station := current_station
    elseif current_duration > current_second_longest_active_time then
        -- If the current duration is not the longest but longer than the second longest
        current_second_longest_active_time := current_duration
        ShiftingBN_station := current_station
    end

shifting_table["current_longest_active_time", 7] := current_longest_active_time
shifting_table["current_bn", 7] := BN_station
shifting_table["current_longest_active_time", 8] := current_second_longest_active_time
shifting_table["current_bn", 8] := ShiftingBN_station``

Upvotes: 1

Views: 55

Answers (0)

Related Questions