コード例 #1
0
 private void reactivateTokenSets() {
   for (TokenSet tokenSet : tokenSets) {
     if (tokenSet.isComplete()
         && (!tokenSet.getActiveArcTokens(engine).isEmpty()
             || !tokenSet.getActiveNodeTokens(engine).isEmpty())) {
       tokenSet.reactivateForBacktrack(engine);
     }
   }
 }
コード例 #2
0
 private void shareTokenSets(final ArcToken newToken, final ArcToken origToken) {
   for (ArcTokenSetMember setMember : origToken.getTokenSetMemberships()) {
     TokenSet tokenSet = setMember.getTokenSet();
     ArcTokenSetMember newSetMember =
         engine.getFactory().newArcTokenSetMember(tokenSet, newToken, setMember.getMemberIndex());
     newToken.getTokenSetMemberships().add(newSetMember);
     tokenSet.getActiveArcTokens(engine).add(newToken);
     tokenSets.add(tokenSet);
   }
 }
コード例 #3
0
ファイル: BaseEngine.java プロジェクト: balaknathan/sarasvati
  private ArcToken generateArcToken(
      final GraphProcess process, final Arc arc, final NodeToken token) {
    ArcToken arcToken = getFactory().newArcToken(process, arc, ExecutionType.Forward, token);
    token.getChildTokens().add(arcToken);

    for (NodeTokenSetMember setMember : token.getTokenSetMemberships()) {
      TokenSet tokenSet = setMember.getTokenSet();
      if (!tokenSet.isComplete()) {
        ArcTokenSetMember newSetMember =
            getFactory().newArcTokenSetMember(tokenSet, arcToken, setMember.getMemberIndex());
        tokenSet.getActiveArcTokens(this).add(arcToken);
        arcToken.getTokenSetMemberships().add(newSetMember);
      }
    }

    return arcToken;
  }
コード例 #4
0
ファイル: BaseEngine.java プロジェクト: balaknathan/sarasvati
  public void completeWithNewTokenSet(
      final NodeToken token,
      final String arcName,
      final String tokenSetName,
      final int numberOfTokens,
      final boolean asynchronous,
      final Env initialEnv,
      final Map<String, List<?>> initialMemberEnv) {
    GraphProcess process = token.getProcess();

    if (!process.isExecuting() || token.isComplete()) {
      return;
    }

    completeNodeToken(process, token, arcName);

    List<? extends Arc> outArcs = process.getGraph().getOutputArcs(token.getNode(), arcName);

    if (!outArcs.isEmpty()) {
      TokenSet tokenSet = getFactory().newTokenSet(process, tokenSetName, numberOfTokens);

      if (initialEnv != null) {
        tokenSet.getEnv().importEnv(initialEnv);
      }

      if (initialMemberEnv != null) {
        TokenSetMemberEnv memberEnv = tokenSet.getMemberEnv();
        for (Map.Entry<String, List<?>> entry : initialMemberEnv.entrySet()) {
          memberEnv.setAttribute(entry.getKey(), entry.getValue());
        }
      }

      for (int memberIndex = 0; memberIndex < numberOfTokens; memberIndex++) {
        for (Arc arc : outArcs) {
          ArcToken arcToken = generateArcToken(process, arc, token);

          ArcTokenSetMember setMember =
              getFactory().newArcTokenSetMember(tokenSet, arcToken, memberIndex);
          tokenSet.getActiveArcTokens(this).add(arcToken);
          arcToken.getTokenSetMemberships().add(setMember);

          finishNewArcTokenProcessing(process, arcToken, asynchronous);
        }
      }
    }
  }