private void newToken(SimplifiedBPMN model, int currentTime) {
   Token token = new Token();
   token.startTime = currentTime;
   tokens.add(token);
   logger.debug("New token " + tokens.size());
   BaseElement firstStartEvent = model.getStartEvents().get(0);
   chooseTokenFlow(firstStartEvent, token);
 }
 public boolean canSimulate() {
   for (Task task : model.getTasks()) {
     ResourceTypeVariant variant = task.getVariant();
     if (variant == null || variant.getInstances().isEmpty()) {
       return false;
     }
   }
   return true;
 }
  public Simulator(SimplifiedBPMN model, int numberOfTokens, int timeBetweenTokens) {
    this.model = model;
    this.numberOfTokens = numberOfTokens;
    this.timeBetweenTokens = timeBetweenTokens;
    timeToNextToken = timeBetweenTokens;

    for (ResourceType resourceType : model.getResourceTypes()) {
      for (ResourceTypeVariant rtv : resourceType.getVariants()) {
        tokensWaiting.put(rtv, new ArrayList<Simulator.Token>());
        for (ResourceInstance resource : rtv.getInstances()) {
          resourceDatas.put(resource, new ResourceInstanceData(resource));
        }
      }
    }

    for (ParallelGateway pGateways : model.getParallelGateways()) {
      arrivedTokens.put(pGateways, new HashMap<Token, Integer>());
    }
  }
 private void startProcessingTokens() {
   for (ResourceType resourceType : model.getResourceTypes()) {
     for (ResourceTypeVariant rtv : resourceType.getVariants()) {
       List<Token> t = tokensWaiting.get(rtv);
       if (!t.isEmpty()) {
         for (ResourceInstance resource : rtv.getInstances()) {
           ResourceInstanceData resourceData = resourceDatas.get(resource);
           if (resourceData.tokenProcessing == null && !t.isEmpty()) {
             Token token = t.remove(0);
             resourceData.tokenProcessing = token;
             resourceData.timeRemaining =
                 (int) Math.round(token.task.getExecutionTime() * rtv.getEfficiency());
             logger.debug(token.task.getName() + " started processing a token.");
           }
         }
       }
     }
   }
 }