JuliaDynamics / DiscreteEvents.jl

Discrete event generation and simulation in Julia
MIT License
56 stars 10 forks source link

Conditioning to finish events #44

Closed ga72kud closed 2 years ago

ga72kud commented 2 years ago

Is there any possibility to finish all events by a condition?

For example, I have a variable TMAX to finish all events after, let's say, 5 seconds. But if an agent completes the task in my simulation, the simulation should stop before TMAX has ended.

@event call_initial_plot(c,sc) DiscreteEvents.every myParameters.param().Ts
@event call_linearized_vehicle_mpc(c, obj_veh, targ_veh, sc) DiscreteEvents.every myParameters.param().Ts
#@event call_reach(c) DiscreteEvents.every myParameters.param().Ts

@run! c myParameters.param().TMAX
hdavid16 commented 2 years ago

@ga72kud please provide a minimum working example code for what you are doing so as to best help.

ga72kud commented 2 years ago

@hdavid16, thank you for answering. I try a fictive example that might not work or make no sense to clarify the issue.

The idea of following a minimal example is that I have a simulation where the simulation will run 5 seconds and an event to call a function sample_number every Ts (sample time).

The question is if there is a possibility to reduce 5 seconds of simulation when in sample_number some condition is fulfilled? For example, in my simulations, I simulate an autonomous vehicle, which might take 50 seconds, but when there is a collision, the simulation should stop. I am not sure if the package DiscreteEvents is providing something. I know that there are possibilities from JuliaLang.

@event sample_number(c) DiscreteEvents.every Ts
@run! c 5s (running 5 seconds)

If it is not available, this might be a feature request...

hdavid16 commented 2 years ago

So it sounds like you want to interrupt events. In your example, if a collision event occurs, then interrupt the main event. Right?

https://pbayer.github.io/DiscreteEventsCompanion.jl/dev/examples/queue_mmc_srv_fail/

The link above might help setting up an interruption (failure)

ga72kud commented 2 years ago

Yes

I currently had no time to read the example, but I guess this will work