Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > BotCompany Repo | #1031995 // IProbabilisticScheduler

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (4735L) is out of date.

// Note: Service providers schedule actions.
// Only puzzle runners call step().
// interface for ProbabilisticScheduler (#1031949)
sinterface IProbabilisticScheduler extends Steppable {
  // schedule an action at an absolute probability
  void at(double probability, Runnable action);
  
  // schedule an action at a probability relative to
  // currentProbability()
  default void atRelative aka schedule(double probability, Runnable action) {
    at(currentProbability()*probability, action);
  }
  
  double currentProbability(); // for thread, only while running a step
  long stepCount();
  
  double lastExecutedProbability();
  
  default void run aka schedule aka at(Runnable x) {
    if (x == null) ret;
    initAction(x);
    x.run();
  }
  
  default void scheduleAll(Iterable<WithProbability<? extends Runnable>> l) {
    fOr (var x : l)
      at(x.probability(), x!);
  }

  default void initAction(O action) {  
    if (action cast IProbabilistic)
      action.setScheduler(this);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1031995
Snippet name: IProbabilisticScheduler
Eternal ID of this version: #1031995/19
Text MD5: 0499651dc005842595cf6a56cd4f6172
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-25 03:16:47
Source code size: 1034 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 153 / 327
Version history: 18 change(s)
Referenced in: [show references]