Question

In: Computer Science

In a discrete event simulation, a physical system, such as a galaxy or solar system, is...

In a discrete event simulation, a physical system, such as a galaxy or solar system, is modeled as it changes over time based on simulated forces. The objects being modeled define events that are scheduled to occur in the future. Each event, e, is associated with a time, te,in the future. To move the simulation forward,the event,e,that has smallest time,te,in the future needs to be processed. To process such an event, e is removed from the set of pending events, and a set of physical forces are calculated for this event, which can optionally create a constant number of new events for the future, each with its own event time. Describe a way to support event processing in a discrete event simulation in O(logn) time, where n is the number of events in the system.

Solutions

Expert Solution

Given Scenario :

Here, we have a set of events for their future times 'te'. In each step, we need to extract the event with minimum 'te' and proceed with that event and also add other finite numbers of events associated with our extracted event.

One possible approach to do this may be to find the minimum 'te' event in each step. But it will be an O(n) operation in each step.

The optimal solution is to use priority queues. Let us make a min-priority queue of our event 'te' times. A min priority queue is a queue in which the minimum element is at the front of the queue. In this way, we have to just extract the first element of the queue in each step and we are done.

Let us analyze the complexity of the solution:

In a priority queue:

Insertion -> log(n)

So, when a new element is added to the queue, it will take log(n) time to insert it.

Accessing the front element -> O(1).

it just need to access the first element of the queue which is O(1).

So, it maintain a min-priority queue. In each step, access the first element of the queue. Add the new elements in the priority queue.

Minimum priority queues can be easily implemented using minimum heap.

Pseudo Code:

#Function called by min-heap function to buold the heap.

def min_heapify (Arr[ ] , i, N)

left  = 2*i;
right = 2*i+1;
smallest;
if left <= N and Arr[left] < Arr[ i ] 
     smallest = left
else
    smallest = i
END If

if right <= N and Arr[right] < Arr[smallest] 
    smallest = right
END If
if smallest != i

    swap (Arr[ i ], Arr[ smallest ])
    min_heapify (Arr, smallest,N)
END If 

End

#function to build min-heap

def min-heap(Arr[], N)

i = N/2
for i : N/2 to 1 in steps of 1 
    min_heapify (Arr, i);

End

# function to extract minimum time

def min_extract( A[ ] )

return A [ 0 ]

END

#functions to insert new elements

def insertion (Arr[ ], value)

    length = length + 1
    Arr[ length ] = -1 
    value_increase (Arr, length, val)
END

def value_increase(Arr [ ], length, val)

if val < Arr[ i ]
        return
    END If
    Arr[ i ] = val;
    while i > 1 and Arr[ i/2 ] < Arr[ i ]
    
        swap|(Arr[ i/2 ], Arr[ i ]);
        i = i/2;
    END While

END


Related Solutions

As the galaxy is moving and the solar system orbiting the galaxy and the Earth orbiting...
As the galaxy is moving and the solar system orbiting the galaxy and the Earth orbiting the sun. So how fast is each object moving and what is the fastest we move at? Do we even know how fast the galaxy is moving that is not relative to another galaxy (although I guess velocity has to be measured relative to something).
Explain briefly. In Simulation Modelling. How is a random number the engine of discrete event simulation?
Explain briefly. In Simulation Modelling. How is a random number the engine of discrete event simulation?
write a program in matlab to produce a discrete event simulation of a switching element with...
write a program in matlab to produce a discrete event simulation of a switching element with 10 inputs and 3 outputs. Time is slotted on all inputs and outputs. Each input packet follows a Bernoulli process. In a given slot, the independent probability that a packet arrives in a slot is p and the probability that a slot is empty is (1– p). One packet fills one slot. For a switching element if 3 or less packets arrives to some...
Is every galaxy in the universe rotating in the same way as our solar system?
Is every galaxy in the universe rotating in the same way as our solar system?
The galaxy that contains our solar system, the milky way, is approximately a uniform disc of...
The galaxy that contains our solar system, the milky way, is approximately a uniform disc of mass 10^12Msun and diameter 175×10^3 light years. Assuming that the center of mass of the galaxy is at rest, estimate the time that it takes the sun to complete one orbit around the galaxy center. A few useful numbers: the mass of the sun Msun = 2 × 10^30kg, 1 light year = 9.46 × 10^15m, and the distance between the sun and the...
In which region of the Milky Way galaxy does the solar system reside? Give three properties...
In which region of the Milky Way galaxy does the solar system reside? Give three properties of this region.
Discuss the formation of the solar system. List the planets of the solar system, discussing their...
Discuss the formation of the solar system. List the planets of the solar system, discussing their properties, attributes, and missions that explored them.
is the solar system isolated
is the solar system isolated
On the basis of a physical examination, a doctor determines the probability of no tumour   (event...
On the basis of a physical examination, a doctor determines the probability of no tumour   (event labelled C for ‘clear’), a benign tumour (B) or a malignant tumour (M) as 0.7, 0.2 and 0.1 respectively. A further, in depth, test is conducted on the patient which can yield either a negative (N) result or positive (P). The test gives a negative result with probability 0.9 if no tumour is present (i.e. P(N|C) = 0.9). The test gives a negative result...
The Ivanpah Solar Electric Generating System is the largest solar thermal power- tower facility in the...
The Ivanpah Solar Electric Generating System is the largest solar thermal power- tower facility in the world. It collects 1321 MW of solar thermal energy to heat special collectors to 566 °C. The thermal energy is then used to make steam to operate an electric generator. (a) What is the maximum efficiency of the power plant, taking the cold reservoir to be the surrounding environment at 12 °C. (b) How much mechanical work (electricity) could the facility generate if it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT