A Simple Discrete-Event Simulation: Part 6

Now that I’m sure the basics are working the way I’d like I want to see if I can streamline things some more.

The first thing to do is recognize that the next item being pulled off the future events queue can always be referred to the same way. If we make the item a global variable then we can always have code refer to it by a known name without having to pass the reference around all over the place. This cleans things up quite a bit.

We’ll start by creating a variable called feqCurrent, which is intended to hold a futureEventItem object.

Next, we’ll copy the insertExistingItem method in the futureEventsQueue object so it eliminates the need to pass in a reference to an feqItem, because it refers to the global variable instead.

We’ll follow that up by streamlining the advance function in the same way.

Then we’ll do the same to the activate function in the entity object.

Finally, we’ll do the same thing to the main event processing loop.

The output remains the same as before, so we assume we haven’t broken anything.

Posted in Simulation | Tagged , | Leave a comment

A Simple Discrete-Event Simulation: Part 5

Adding a second entity works correctly.


104 minutes

entity 1 created at time 0
entity 2 created at time 0
entity 1 updated at time 11
entity 2 updated at time 13
entity 1 updated at time 21
entity 2 updated at time 26
entity 1 updated at time 31
entity 2 updated at time 39
entity 1 updated at time 41
entity 1 updated at time 51
entity 2 updated at time 52
entity 1 updated at time 61
entity 2 updated at time 65
entity 1 updated at time 71
entity 2 updated at time 78
entity 1 updated at time 81
entity 2 updated at time 91
entity 1 updated at time 91
entity 1 terminated at time 101
entity 2 terminated at time 104

Posted in Simulation | Tagged , | Leave a comment

A Simple Discrete-Event Simulation: Part 4

Here is code that actually runs. It creates a single entity, then updates it in a loop until the ending time is exceeded. The next steps will be to see how it works with multiple entities of the same kind and then with entities of different kinds.

This example is quite trivial so far. It doesn’t do a thing that’s meaningful but we can see the underlying mechanisms building up. It should get interesting quickly enough.

I also had to modify the getFirstItem method in the futureEventsQueue object. It has to test whether the returned array is of zero length, which indicates that the future events queue is empty.

Here’s the browser output, now that I’ve started to build something the user can see via HTML. The first line is a clock that gets updated with each event. The remainder is a block that logs all the events, which in this case involve only a single entity.


101 minutes

entity 1 created at time 0
entity 1 updated at time 11
entity 1 updated at time 21
entity 1 updated at time 31
entity 1 updated at time 41
entity 1 updated at time 51
entity 1 updated at time 61
entity 1 updated at time 71
entity 1 updated at time 81
entity 1 updated at time 91
entity 1 terminated at time 101

Posted in Simulation | Tagged , | Leave a comment

A Simple Discrete-Event Simulation: Part 3

Here is an entity object that knows how to be created and activated from external calls. It updates itself and puts itself back into the future events queue is appropriate. This is in keeping with my original concept of how an entity would work. The key, of course, is to keep rewriting and simplifying this thing until more and more of the mechanics are hidden from the coder. Languages like SLX do this implicitly, but if we’re building a framework from scratch, given the limitations imposed by JavaScript, there’s only so far we’re going to be able to go with that. Still, it’ll be fun to see how far we get.

In the meantime the forms here mean I’ll have to streamline some of the existing code. Since the state information is all kept within the entity itself it no longer has to be kept with the future events queue elements (since those elements contain a reference to the entity), so those data structures and calls will be pruned.

I’ll make this all run tomorrow, but here’s the rough code for now:

Posted in Simulation | Tagged , | Leave a comment

A Simple Discrete-Event Simulation: Part 2

Today I’ve added the ability to retrieve the first item from the future events queue, which is the next item to process and that with the lowest activation time. In this case I just update the item’s time when it’s retrieved, then insert it back into the future events queue wherever it belongs. In the example it goes to the end of the queue with a time of 55.

Note that I’ve updated that state values, though I haven’t defined how they’re going to work yet.

I added an update function to the futureEventItem object. I added the functions getFirstItem and insertExistingItem to the futureEventsQueue object. Finally, I added some calls to exercise the new capabilities down at the bottom.

The console output again indicates that things are working as expected.

Number of events in queue: 0
Array size: 1
reportItemInfo: element: [object Object] index: 0 arr: [object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
Number of events in queue: 1
Array size: 2
reportItemInfo: element: [object Object] index: 0 arr: [object Object],[object Object]
Time: 30 ID: 444 Prev: prev2 Next: next2
reportItemInfo: element: [object Object] index: 1 arr: [object Object],[object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
Number of events in queue: 2
Array size: 3
reportItemInfo: element: [object Object] index: 0 arr: [object Object],[object Object],[object Object]
Time: 30 ID: 444 Prev: prev2 Next: next2
reportItemInfo: element: [object Object] index: 1 arr: [object Object],[object Object],[object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
reportItemInfo: element: [object Object] index: 2 arr: [object Object],[object Object],[object Object]
Time: 50 ID: 555 Prev: prev3 Next: next3
Number of events in queue: 3
reportItemInfo: element: [object Object] index: 0 arr: [object Object],[object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
reportItemInfo: element: [object Object] index: 1 arr: [object Object],[object Object]
Time: 50 ID: 555 Prev: prev3 Next: next3
Number of events in queue: 2
Array size: 3
reportItemInfo: element: [object Object] index: 0 arr: [object Object],[object Object],[object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
reportItemInfo: element: [object Object] index: 1 arr: [object Object],[object Object],[object Object]
Time: 50 ID: 555 Prev: prev3 Next: next3
reportItemInfo: element: [object Object] index: 2 arr: [object Object],[object Object],[object Object]
Time: 55 ID: 444 Prev: prev1a Next: next1a
Number of events in queue: 3

Posted in Simulation | Tagged , | Leave a comment

A Simple Discrete-Event Simulation: Part 1

Some months ago I discussed some internal features of a discrete-event simulation. My next series of exercises and ruminations will proceed toward building one in JavaScript, using the simple pseudo-construct I outlined in the linked post.

I’ll start with the creation of a future events queue. Since the point is to get something running in a reasonably brief series of posts I’ll keep it simple. There are many ways to make a future events queue more efficient, but for our purposes we’ll create one with a straightforward insert/pull structure. That is, it’ll be a single list of items, sorted by time (we’ll assume items occurring at the exact same time are processed in the order in which they were added to the queue, in one dimension.

Here’s a rough bit of code I worked out a while ago.

This code generates the following output to the console, which indicates that the basic insertion mechanism is working.

Number of events in queue: 0
Array size: 1
reportItemInfo: element: [object Object] index: 0 arr: [object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
Number of events in queue: 1
Array size: 2
reportItemInfo: element: [object Object] index: 0 arr: [object Object],[object Object]
Time: 30 ID: 444 Prev: prev2 Next: next2
reportItemInfo: element: [object Object] index: 1 arr: [object Object],[object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
Number of events in queue: 2
Array size: 3
reportItemInfo: element: [object Object] index: 0 arr: [object Object],[object Object],[object Object]
Time: 30 ID: 444 Prev: prev2 Next: next2
reportItemInfo: element: [object Object] index: 1 arr: [object Object],[object Object],[object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
reportItemInfo: element: [object Object] index: 2 arr: [object Object],[object Object],[object Object]
Time: 50 ID: 555 Prev: prev3 Next: next3
Number of events in queue: 3

Posted in Software | Tagged , | Leave a comment

My Favorite Player in the NFL Hall of Fame

My first football hero, Larry Brown, Jr., is still my favorite player. He didn’t stay healthy enough to actually be elected to the NFL Hall of Fame, but if they’d had the medical technology they do now he might have been able to come back from having his knee torn up all the time. He wasn’t the biggest guy or the fastest guy, and I didn’t appreciate what he was doing at the time, but video of his playing days shows that he ran with as much heart and disregard for personal safety as anyone ever has. George Allen was a defensive coach so he tended to play it close to the vest on offense. That meant handing the ball to Brown about a million times a game and letting him hurl his body into the opposition. Everybody in the stadium knew it was coming, but on balance it was more effective than it had a right to be.

This was not a smart way to treat such a valuable asset; by his fourth year in the league you can see he’s practically running on one leg.

Even so, he was only the second player in league history to run for 5,000 yards in his first five seasons (a feat O.J. Simpson matched the same year with his 2,000-yard season). He didn’t get much farther than that, and he isn’t remembered as much as he should be (in my opinion), but I was happy to see him included in this picture when I pulled into Canton, OH.

Granted, the picture is of his efforts being largely thwarted as the Dolphins defeated the Redskins in Super Bowl VII to complete their perfect season, but it made this fan happy to see him remembered at all. Brown was the NFL’s Offensive Player of the Year that year, despite missing the final two regular season games to injury. I think about him sometimes when things get tough.

Posted in Life | Tagged , , | Leave a comment

A New Record! For This Trip, Anyway.

Today I didn’t have anything to do but drive, drive, and drive some more. I took it easy, sat back, drove a bit slower, listened to some XM radio and audio books, and let the miles roll by–over 800 of them. I ended the day near Dayton, OH, home of the Wright Brothers and the always impressive Air Force Museum. I’d been there a few times before and was in a hurry to get home, so I didn’t visit, but if you ever get the chance it’s something well worth seeing at least once. Allow plenty of time if you do go–it’s big!

Posted in Life | Tagged | Leave a comment

And Now For Something Completely Less Serious!

Wednesday saw the turn home really pick up steam, but it wasn’t without frivolity. I hit the UFO Museum in Roswell, NM first thing in the morning. The best thing I saw there was patrons wearing tinfoil hats, which you could apparently get at one of the other gift shops in town.

I picked up some spray paint on the way out of town so I could help my mascot let everyone know he’d been to the Cadillac Ranch in Amarillo, TX. This, boys and girls, is as cheesy (and All-American-ly wonderful) as it gets!

Posted in Life | Tagged , | Leave a comment

Biosphere 2 and a Small Bonus!

I had pre-positioned in Tucson where, after a brief deluge that was almost the only rain I’d seen, I finally got to visit Biosphere 2, which I’d wanted to see since it was built. I’d been in the area a few times doing discovery and collecting data for border crossings, but had never taken the time to stop in. Along with the perpetual sunset as I pulled into Yellowknife at midnight, it was probably the highlight of the trip.


The view as you walk in from the parking lot. I’m a sucker for space frames, metal and glass, and futuristic architecture, so it had me at “Hello!”


Here’s how the interior was laid out, with the five biomes, the agricultural section, and the living quarters. (Picture borrowed from this TED talk.)


The agriculture sections have been converted to experimental bays. The movement and behavior of moisture is under investigation in this one.


A river runs through the savanna biome, toward the desert in the background. I’m guessing this was more densely planted during the initial missions.


Here’s the beach end of the ocean biome.


The marsh biome was at the far end of the ocean. I never got a decent picture of it from inside.


You don’t really get a feel for the space in the rather large rainforest biome, though this picture suggests that it goes on for a bit in the background. There’s a waterfall in there somewhere.


The fog desert biome looked rather different in every direction. This was my favorite angle.


This was my favorite interior shot, which gives you a feel for the space, and has lots of that lovely metal and glass and space frame-y stuff.


The desire may have been to create a stable interior environment where the sections interact and maintain themselves naturally, but the extant reality means that some help was needed. The tanks, pipes, valves, pumps, filters, and control hardware reminded me of all the time I spent in paper and steel mills. I was right at home down there!


One of the most interesting features of the complex was the “lung”, a huge diaphragm that allowed the interior volume to vary so the interior pressure could equalize with the exterior pressure. Without this feature the glass window sections would be blown in or out. The diaphragm (or perhaps the entire lung enclosure) is about 180 feet across. The metal disk in the center is heavy at 16 tons and moves up and down by tens of feet. The diaphragm itself is four tons or rubber.


Opening the door allows huge volumes of air to escape the lung interior. You can see the disc lower significantly.


Here’s the back side of the complex and the exterior of one of the lungs. A second lung is available as a backup, but it has apparently never been used.


Another view along the outside. The rainforest is in the foreground and the desert in the distance.


The ocean can been seen from the outside through a window. We were told that the goal is not to run an aquarium but a more natural system, thus the cloudiness of the water. Interestingly, some scuba divers were practicing for certification in the ocean during the tour.


I really enjoyed the faux New Mexican adobe look of the complex of service buildings on the site. They really added to the ambiance of the place.


After imbibing all of Biosphere 2 I headed west to Roswell. This took me through my old stomping grounds in Alamogordo, NM. I stayed with my Army test platoon at Holloman Air Force Base on and off for several months and trained and participated in tests up north. We’d often stop at this Sonic in the evenings and I relived happy memories of chili cheese coneys and root beer floats. (I chose to pass on the onion rings…)

Posted in Life | Tagged , , | Leave a comment