Skip to content

Commit b00ed84

Browse files
AdminAdmin
authored andcommitted
Backup before adding instrumentation interfaces
1 parent f5eb69d commit b00ed84

File tree

6 files changed

+56
-14
lines changed

6 files changed

+56
-14
lines changed

JSimpleSim/src/org/simplesim/core/scheduling/MultiLevelEventQueue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class MultiLevelEventQueue<E> implements EventQueue<E> {
4848

4949
private final static int TIER2_DEFAULT_CHUNK_SIZE=128;
5050

51-
private Queue<EventQueueEntry<E>> tier1=new PriorityQueue<>(); // current events, sorted
51+
private final Queue<EventQueueEntry<E>> tier1=new PriorityQueue<>(TIER2_DEFAULT_CHUNK_SIZE); // current events, sorted
5252
private final List<Collection<EventQueueEntry<E>>> tier2=new ArrayList<>();// near future events, partly sorted
5353
private final Collection<EventQueueEntry<E>> tier3=new ArrayList<>(); // far future events, unsorted
5454

@@ -187,7 +187,7 @@ public Time getTime(E event) {
187187

188188
private void refillTier1() {
189189
if (indexTier2>=maxIndexTier2) refillTier2();
190-
tier1=new PriorityQueue<>(tier2.get(indexTier2)); // heapify() only called once when init with a collection.
190+
tier1.addAll(tier2.get(indexTier2));
191191
tier2.get(indexTier2).clear();
192192
indexTier2++;
193193
actTimeTier2+=bucketWidth;

JSimpleSim/src/org/simplesim/examples/elevator/DynamicMain.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.simplesim.examples.elevator.dyn.Floor;
1414
import org.simplesim.examples.elevator.shared.Limits;
1515
import org.simplesim.examples.elevator.shared.View;
16+
import org.simplesim.model.InstrumentationDecorator;
1617
import org.simplesim.model.MessageForwardingStrategy;
1718
import org.simplesim.model.RoutedMessageForwarding;
1819
import org.simplesim.simulator.ConcurrentDESimulator;
@@ -25,21 +26,23 @@
2526
* <p>
2627
* To illustrate differences of a static and a dynamic modeling approach, both
2728
* are used with the same simulation problem: the steering strategy of an
28-
* elevator. Common data structure, the steering algorithm and the graphical
29-
* representation are shared, so the focus lies on the differences of both
30-
* approaches:
29+
* elevator. Steering algorithm, graphical representation and common data structures are shared,
30+
* so the focus lies on the differences of both approaches:
3131
* <p>
3232
* <u>Static model:</u>
3333
* <ul>
34-
* <li>Visitors store their current floor in their state.
34+
* <li>There are no model changes.
35+
* <li>Visitors store their current floor as part of their state.
3536
* <li>Ports of elevator and visitor are connected directly.
36-
* <li>
37+
* <li>Direct message forwarding is used.
38+
* </ul>
39+
* <u>Dynamic model:</u>
40+
* <ul>
41+
* <li>Each floor is represented by a submodel containing its visitors.
42+
* <li>Change of the floor is implemented as moving to an other submodel, the model is changed repeatedly during simulation run.
43+
* <li>The model hierarchy Building-->Floor-->Visitor represents the real world situation comprehensibly.
44+
* <li>Messaging is done by a routing mechanism.
3745
* </ul>
38-
*
39-
*
40-
* (no model changes) (model is changed during the simulation run) nThis is the
41-
* dynamic variant of the elevator simulation example to illustrate differences
42-
* from the static apporach.
4346
*/
4447
public class DynamicMain {
4548

@@ -56,6 +59,7 @@ public static void main(String[] args) {
5659
model.addEntity(elevator);
5760
final Floor lobby=new Floor(Limits.LOBBY);
5861
model.addEntity(lobby);
62+
lobby.addEntity(new InstrumentationDecorator(new DynamicVisitor(model)));
5963
for (int i=0; i<Limits.VISITORS; i++) lobby.addEntity(new DynamicVisitor(model));
6064
for (int floor=1; floor<=Limits.MAX_FLOOR; floor++) model.addEntity(new Floor(floor));
6165

JSimpleSim/src/org/simplesim/examples/elevator/StaticMain.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@
1717
import org.simplesim.simulator.ConcurrentDESimulator;
1818
import org.simplesim.simulator.Simulator;
1919

20+
/**
21+
* Example of a multi-domain agent system with routed messaging and dynamic
22+
* model changes
23+
* <p>
24+
* To illustrate differences of a static and a dynamic modeling approach, both
25+
* are used with the same simulation problem: the steering strategy of an
26+
* elevator. Steering algorithm, graphical representation and common data structures are shared,
27+
* so the focus lies on the differences of both approaches:
28+
* <p>
29+
* <u>Static model:</u>
30+
* <ul>
31+
* <li>There are no model changes.
32+
* <li>Visitors store their current floor as part of their state.
33+
* <li>Ports of elevator and visitor are connected directly.
34+
* <li>Direct message forwarding is used.
35+
* </ul>
36+
* <u>Dynamic model:</u>
37+
* <ul>
38+
* <li>Each floor is represented by a submodel containing its visitors.
39+
* <li>Change of the floor is implemented as moving to an other submodel, the model is changed repeatedly during simulation run.
40+
* <li>The model hierarchy Building-->Floor-->Visitor represents the real world situation comprehensibly.
41+
* <li>Messaging is done by a routing mechanism.
42+
* </ul>
43+
*/
2044
public class StaticMain {
2145

2246
/**

JSimpleSim/src/org/simplesim/examples/gameoflife/Main.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import org.simplesim.core.scheduling.Time;
99
import org.simplesim.model.DirectMessageForwarding;
10-
import org.simplesim.simulator.ConcurrentTSSimulator;
1110
import org.simplesim.simulator.SequentialTSSimulator;
1211
import org.simplesim.simulator.Simulator;
1312

JSimpleSim/src/org/simplesim/model/InstrumentationDecorator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
public class InstrumentationDecorator implements Agent {
3131

32-
/* the encapsulated simulator */
32+
/* the encapsulated agent */
3333
private final Agent agent;
3434

3535
// listeners to notify BEFORE agent is called
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* JSimpleSim is a framework to build multi-agent systems in a quick and easy way. This software is published as open
3+
* source and licensed under the terms of GNU GPLv3.
4+
*
5+
* Contributors: - Rene Kuhlemann - development and initial implementation
6+
*/
7+
package org.simplesim.model;
8+
9+
/**
10+
*
11+
*
12+
*/
13+
public interface ModelEntity {
14+
15+
}

0 commit comments

Comments
 (0)