Пример #1
0
  /**
   * Removes one token from the marked output places (subsets) of the tasks in <i>tasks</i> that
   * contain <i>element</i>.
   *
   * @param element element to fire
   * @param tasks whose output places point to element
   */
  private void removeTokensOutputPlaces(int element, HNSubSet tasks) {

    HNSubSet subset = null;
    HNSet subsets = null;

    Integer tokens = null;
    int taskToFire;
    int task;

    // Checking if element is a start element
    if (hNet.getInputSet(element).size() == 0) {
      if (startPlace > 0) {
        startPlace--;
        numberTokens--;
      }
    } else {
      taskToFire = element;
      for (int iTasks = 0; iTasks < tasks.size(); iTasks++) {
        task = tasks.get(iTasks);
        subsets = auxMapping.getRelatedSubsets(taskToFire, task);
        if (subsets != null) {
          for (int iSubsets = 0; iSubsets < subsets.size(); iSubsets++) {
            subset = subsets.get(iSubsets);
            tokens = getNumberTokens(task, subset);
            if (tokens.intValue() > 0) {
              decreaseNumberTokens(task, subset);
              numberTokens--;
            }
          }
        }
      }
    }
  }
Пример #2
0
  /*
   * Checks if a element is enabled at the current marking. <p> <b>Note:</b>
   * The element MUST be in the Element.
   *
   * @param element element/transition to check
   *
   * @return true if the element is enabled at the current marking. false
   * otherwise.
   */
  public boolean isEnabled(int element) {
    if (hNet.getInputSet(element) == null) {
      return false;
    }

    if (hNet.getInputSet(element).size() == 0) {
      if (startPlace < 1) {
        return false;
      }
    } else {
      bestCombination = findBestSetTasks(element);
      if (bestCombination.getNumberMissingTokens() > 0) {
        return false;
      }
    }

    return true;
  }
Пример #3
0
  /**
   * Build an initial marking for a given heuristics net.
   *
   * @param net an enhanced heuristics net to which the initial marking must be built.
   * @throws java.lang.NullPointerException whenever the net has disconnected elements. An element
   *     is disconnected when its INPUT or OUTPUT set is null.
   */
  public MarkingHeuristicsNet(HeuristicsNet net, Random generator) throws NullPointerException {

    this.generator = generator;
    size = net.size();
    hNet = net;
    // checking if all input and output sets are DIFFERENT from null...
    for (int i = 0; i < size; i++) {
      if (hNet.getInputSet(i) == null || hNet.getOutputSet(i) == null) {
        throw new NullPointerException("Net has disconnected elements!!");
      }
    }
    createMarking();
  }
Пример #4
0
  private CombinationTasksToFire findBestSetTasks(int element) {
    CombinationTasksToFire bCombination = null;
    CombinationTasksToFire combination = null;
    HNSubSet noTokensFromTasks = null;
    HNSubSet treatedTasks = null;
    HNSet inputSet = null;
    HNSet temp_inputSet = null;

    HNSubSet subset = null;

    int numberMissingTokens = 0;
    int rootTask = ROOT_TASK_ID;

    bCombination = new CombinationTasksToFire();

    inputSet = hNet.getInputSet(element);

    if (inputSet.size() == 0) {
      if (startPlace <= 0) {
        numberMissingTokens++; // one token is missing
      }
    } else {
      // inputSubset is not empty. Search for tasks that "have tokens" to
      // element

      noTokensFromTasks = getTasksWithEmptyOutputPlaces(element);

      // >>>>>>>>>>>>>>>>>> Hint!!! I think that's why I don't run into
      // problems...
      // /// Idea -> shrink the subsets without using a temp variable, get
      // / the size before shrinking, shrink them, reorder the set and
      // /remove the empty set (do this via a method in the class
      // /HNSet, get the new size. This is the number of missing tokens.

      // make a copy to avoid destroying the original net
      inputSet = inputSet.deepCopy();
      temp_inputSet = new HNSet();
      // removing the tasks whose output subsets that contain element are
      // empty
      for (int iInputSubsets = 0; iInputSubsets < inputSet.size(); iInputSubsets++) {
        subset = inputSet.get(iInputSubsets);
        subset.removeAll(noTokensFromTasks);
        if (subset.size() == 0) {
          numberMissingTokens += 1;
        } else {
          temp_inputSet.add(subset);
        }
      }
      inputSet = temp_inputSet;
      // retrieving the best combination of tasks that can fire to enable
      // element

      if (inputSet.size() > 0) {
        combination = new CombinationTasksToFire();
        treatedTasks = new HNSubSet();
        bCombination =
            findBestCombination(bCombination, inputSet, rootTask, combination, treatedTasks);
      }
    }

    bCombination.setElementToFire(element);
    bCombination.setTokens(bCombination.getNumberMissingTokens() + numberMissingTokens);

    return bCombination;
  }