Search code examples
anylogic

Model is duplicating output of 1 time instead of the 3 required


In the model, there are 2 types of agents (FollowUp and NewConsult) that I would like to collect time for upon entering a seize block and upon seizing the resource in order to understand the time waiting in that block while running a parameters variation experiment. Each patient type has their respective variable of timeEnterClerk and the time is added to their respective waitClerkTime statistic. As seen in the output, each agent type is being given a single time, regardless of its the morning (time < 150), afternoon (time > 150), or entire day. I am confused as this is not the case when outputting the average for all agent types as seen in waitClerkTime.add(time() - agent.timeEnterClerk );, waitClerkTimeMorn.add(time() - agent.timeEnterClerk );, and waitClerkTimeAft.add(time() - agent.timeEnterClerk );.

// On Enter

agent.timeEnterClerk = time();  

if (agent instanceof FollowUp)
    ((FollowUp)agent).timeEnterClerkFollowUp = time();

if (agent instanceof NewConsult)
    ((NewConsult)agent).timeEnterClerkNewConsult = time();

// On Seize

waitClerkTime.add(time() - agent.timeEnterClerk );

if (agent instanceof FollowUp)
    waitClerkTimeFollowUp.add(time() - ((FollowUp)agent).timeEnterClerkFollowUp );
if (agent instanceof NewConsult)
    waitClerkTimeNewConsult.add(time() - ((NewConsult)agent).timeEnterClerkNewConsult );

if (time() < 150)
    
    waitClerkTimeMorn.add(time() - agent.timeEnterClerk );

    if (agent instanceof FollowUp)
        waitClerkTimeMornFollowUp.add(time() - ((FollowUp)agent).timeEnterClerkFollowUp );
    if (agent instanceof NewConsult)
        waitClerkTimeMornNewConsult.add(time() - ((NewConsult)agent).timeEnterClerkNewConsult); 

        
if (time() > 150)
    
    waitClerkTimeAft.add(time() - agent.timeEnterClerk );

    if (agent instanceof FollowUp)
        waitClerkTimeAftFollowUp.add(time() - ((FollowUp)agent).timeEnterClerkFollowUp );
    if (agent instanceof NewConsult)
        waitClerkTimeAftNewConsult.add(time() - ((NewConsult)agent).timeEnterClerkNewConsult);

Parameters variation in After Simulation Run:

KneeClinicDataExport.setCellValue(root.waitClerkTime.mean(), 1, row + 1, 1); 
KneeClinicDataExport.setCellValue(root.waitClerkTimeMorn.mean(), 1, row + 1, 2); 
KneeClinicDataExport.setCellValue(root.waitClerkTimeAft.mean(), 1, row + 1, 3);

KneeClinicDataExport.setCellValue(root.waitClerkTimeFollowUp.mean(), 1, row + 1, 4); 
KneeClinicDataExport.setCellValue(root.waitClerkTimeMornFollowUp.mean(), 1, row + 1, 5); 
KneeClinicDataExport.setCellValue(root.waitClerkTimeAftFollowUp.mean(), 1, row + 1, 6);

KneeClinicDataExport.setCellValue(root.waitClerkTimeNewConsult.mean(), 1, row + 1, 7); 
KneeClinicDataExport.setCellValue(root.waitClerkTimeMornNewConsult.mean(), 1, row + 1, 8); 
KneeClinicDataExport.setCellValue(root.waitClerkTimeAftNewConsult.mean(), 1, row + 1, 9);

KneeClinicDataExport.setCellValue(root.waitClerkTimeRevision.mean(), 1, row + 1, 10); 
KneeClinicDataExport.setCellValue(root.waitClerkTimeMornRevision.mean(), 1, row + 1, 11); 
KneeClinicDataExport.setCellValue(root.waitClerkTimeAftRevision.mean(), 1, row + 1, 12);

row++;

enter image description here


Solution

  • the reason you have this problem is that you are not using brackets for your if statements

    In the following case, both statements are executed when the condition is true

    if(conditions){
        statementA;
        statementB;
    }
    

    In the following example, only statementA is executed when the condition is true, but statementB is executed always

    if(conditions)
    statementA;
    statementB;