@@ -7,18 +7,20 @@ import 'package:simdart/src/event.dart';
77import 'package:simdart/src/execution_priority.dart' ;
88import 'package:simdart/src/internal/event_action.dart' ;
99import 'package:simdart/src/internal/event_scheduler_interface.dart' ;
10+ import 'package:simdart/src/internal/now_interface.dart' ;
1011import 'package:simdart/src/internal/repeat_event_action.dart' ;
1112import 'package:simdart/src/internal/resource.dart' ;
1213import 'package:simdart/src/internal/time_action.dart' ;
1314import 'package:simdart/src/internal/time_loop.dart' ;
14- import 'package:simdart/src/internal/time_loop_interface .dart' ;
15+ import 'package:simdart/src/internal/sim_configuration_interface .dart' ;
1516import 'package:simdart/src/interval.dart' ;
1617import 'package:simdart/src/resource_configurator.dart' ;
18+ import 'package:simdart/src/sim_result.dart' ;
1719import 'package:simdart/src/simulation_track.dart' ;
1820import 'package:simdart/src/start_time_handling.dart' ;
1921
2022/// Represents a discrete-event simulation engine.
21- class SimDart implements TimeLoopInterface , EventSchedulerInterface {
23+ class SimDart implements SimConfigurationInterface , EventSchedulerInterface , NowInterface {
2224 /// Creates a simulation instance.
2325 ///
2426 /// - [now] : The starting time of the simulation. Defaults to `0` if null.
@@ -27,8 +29,7 @@ class SimDart implements TimeLoopInterface, EventSchedulerInterface {
2729 /// - [startTimeHandling] : Determines how to handle events scheduled with a start
2830 /// time in the past. The default behavior is [StartTimeHandling.throwErrorIfPast] .
2931 ///
30- /// - [onTrack] : The optional callback function that can be used to track the progress
31- /// of the simulation.
32+ /// - [includeTracks] : Determines whether simulation tracks should be included in the simulation result.
3233 ///
3334 /// - [seed] : The optional parameter used to initialize the random number generator
3435 /// for deterministic behavior in the simulation. If provided, it ensures that the
@@ -40,22 +41,25 @@ class SimDart implements TimeLoopInterface, EventSchedulerInterface {
4041 /// - [executionPriority] : Defines the priority of task execution in the simulation.
4142 SimDart (
4243 {StartTimeHandling startTimeHandling = StartTimeHandling .throwErrorIfPast,
43- OnTrack ? onTrack,
4444 int ? now,
4545 this .secondarySortByName = false ,
46+ this .includeTracks= false ,
4647 ExecutionPriority executionPriority = ExecutionPriority .high,
4748 int ? seed})
48- : _onTrack = onTrack,
49- random = Random (seed) {
49+ : random = Random (seed) {
5050 _loop = TimeLoop (
5151 now: now,
52+ includeTracks: includeTracks,
5253 beforeRun: _beforeRun,
5354 executionPriority: executionPriority,
5455 startTimeHandling: startTimeHandling);
5556 }
5657
5758 late final TimeLoop _loop;
5859
60+ @override
61+ final bool includeTracks;
62+
5963 /// Determines whether events with the same start time are sorted by their event name.
6064 ///
6165 /// The primary sorting criterion is always the simulated start time (`start` ). If
@@ -77,11 +81,6 @@ class SimDart implements TimeLoopInterface, EventSchedulerInterface {
7781 /// instantiate a new `Random` object for each event.
7882 late final Random random;
7983
80- /// A callback function used to track the progress of the simulation.
81- /// If provided, this function will be called with each [SimulationTrack] generated
82- /// during the simulation. This is useful for debugging or logging purposes.
83- final OnTrack ? _onTrack;
84-
8584 /// A queue that holds event actions that are waiting for a resource to become available.
8685 ///
8786 /// These events were initially denied the resource and are placed in this queue
@@ -101,7 +100,7 @@ class SimDart implements TimeLoopInterface, EventSchedulerInterface {
101100 ///
102101 /// - [until] : The time at which execution should stop. Execution will include events
103102 /// scheduled at this time (inclusive). If null, execution will continue indefinitely.
104- Future <void > run ({int ? until}) async {
103+ Future <SimResult > run ({int ? until}) async {
105104 return _loop.run (until: until);
106105 }
107106
@@ -190,7 +189,6 @@ class SimDart implements TimeLoopInterface, EventSchedulerInterface {
190189 } else {
191190 _loop.addAction (EventAction (
192191 sim: this ,
193- onTrack: _onTrack,
194192 start: start,
195193 eventName: name,
196194 event: event,
@@ -200,25 +198,17 @@ class SimDart implements TimeLoopInterface, EventSchedulerInterface {
200198 }
201199 }
202200
203- @override
204- int ? get duration => _loop.duration;
205-
206201 @override
207202 ExecutionPriority get executionPriority => _loop.executionPriority;
208203
209204 @override
210205 int get now => _loop.now;
211206
212- @override
213- int ? get startTime => _loop.startTime;
214207
215208 @override
216209 StartTimeHandling get startTimeHandling => _loop.startTimeHandling;
217210}
218211
219- /// A function signature for tracking the progress of a simulation.
220- typedef OnTrack = void Function (SimulationTrack track);
221-
222212/// Defines the behavior of the interval after a newly created event has been rejected.
223213enum RejectedEventPolicy {
224214 /// Continues the repetition of the event at the specified intervals, even after the event was rejected.
@@ -275,18 +265,18 @@ class SimDartHelper {
275265 return sim._resources[resourceId];
276266 }
277267
278- static SimulationTrack buildSimulationTrack (
268+ static void addSimulationTrack (
279269 {required SimDart sim,
280270 required String eventName,
281271 required Status status}) {
282272 Map <String , int > resourceUsage = {};
283273 for (Resource resource in sim._resources.values) {
284274 resourceUsage[resource.id] = resource.queue.length;
285275 }
286- return SimulationTrack (
276+ sim._loop. addTrack ( SimulationTrack (
287277 status: status,
288278 name: eventName,
289279 time: sim.now,
290- resourceUsage: resourceUsage);
280+ resourceUsage: resourceUsage)) ;
291281 }
292282}
0 commit comments