Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:59:30+00:00 2026-06-07T04:59:30+00:00

Right now in my basic event simulation engine, I simply just resort the list

  • 0

Right now in my basic event simulation engine, I simply just resort the list of event objects to update by their priorities every step of the simulation. I do this because new events can be created during event updates and are appended to the list and when an event expires, I just “swap and pop” it with the last event in the list for performance. Should I just be using two priority queues instead? It seems like the n log n of sorting every step is at least the same if not less costly than dequeing all the events (n log n?) putting each unexpired one in another list that is built into the priority queue for the next update step.

EDIT: I think it would be more apt to refer to the ‘events’ as ‘processes’ instead and the whole thing as more of a process scheduling simulation then. Each object in the queue has it’s state updated in priority order and then only if it has expired (entered some sort of conclusion state) does it get discarded and not reinserted into the queue. This is how having just a single priority queue could be a problem; when an object is reinserted, it will still have the lowest priority and would just be pulled out again. I was considering using a second queue to insert all newly spawned process objects and ones that did not expire into, not considering priority, then I could just build heap and swap it with the active queue before the start of the next update cycle.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:59:31+00:00Added an answer on June 7, 2026 at 4:59 am

    Typically, you should use one event queue in a (sequential) discrete-event simulator. I am not quite sure what you mean with ‘expired’ events, but if these events shall be ignored because they are not valid anymore, a simple solution would be to just discard them instead of processing them, e.g. see this pseudo Java code:

     while (!terminationConditionMet() && !eventQueue.isEmpty()) {
       Event currentEvent = eventQueue.getNextEvent();
       if(currentEvent.isExpired())
         continue;
       List<Event> newEvents = currentEvent.process();
       eventQueue.addEvents(newEvents); 
     }
    

    Generally (for large enough event sets), this should be much faster than re-sorting the event list after each step.

    BTW many event queue implementations achieve a dequeue in O(1), and even though for some operations their worst case performance might not be better than sorting, the actual implementations work much better (i.e. they have smaller constants/better average performance). If you are working with Java, you might want to look at JAMES II, which offers several event queue implementations and is open source (disclaimer: I am one of the devs).

    EDIT (addressing re-formulated question):

    In general, a convenient way of implementing a process-based discrete-event simulation are coroutines, see for example this report for details. If you want to stick to your implementation, however, you could still change the priority to a tuple (timeStep,processPriority) and use an adapted version of the above pseudo-code as follows:

    while (!terminationConditionMet() && !queue.isEmpty()) {
    
     //Read out event
     Tuple minTime = queue.getMinTime();
     ProcessEvent currentEvent = queue.dequeue();
    
     //Execute event
     List<ProcessEvent> newlySpawnedProcesses = processEvent.process();
    
     //Re- and enqueue new events
     int nextTimeStep = minTime.getTime() + 1;
     if(!currentEvent.finalStateReached())
       queue.requeue(currentEvent, new Tuple(nextTimeStep, currentEvent.getPriority())); 
     for(ProcessEvent event : newlySpawnedProcesses)
       queue.enqueue(event, new Tuple(nextTimeStep, event.getPriority()));     
    }
    

    Of course, this assumes that you are using an event queue implementation that is generic enough to allow you to specify your own kind of time/priority ordering, e.g. by specifying a custom comparator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now when I run this it keeps clicking on the same button every
Right now, I've just some code which fetches the picture from the URL directly.
I have a very basic question about populating listviews in android. Right now, if
Let me just first point out to any IE users right now (this is
Right now I have an upload field while uploads files to the server. The
Right now, I have: RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L] to match any username at the
Right now I have a script that will get the last five files in
Right now, the label for my Activity has the name of the current Activity.
Right now I have 3 tables: User, Roles, and User_Roles for the many-to-many association.
Right now I have a function, in a class that is used to listen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.