예제 #1
0
  /** Creates an initial marking. */
  private void createMarking() {

    HNSet set = null;

    marking = null;
    marking = new HashMap[size];

    // Building the marking data structure. This structure is an array of
    // hashmaps.
    // For a given hashmap, we have:
    // - Key: Integer = element
    // - Value: HashMap = subsets + the number of tokens associated to them
    // The idea is to keep track of which tasks fired and the number of
    // tokens at their output subsets.
    // Initially, the number of tokens is 0.
    for (int i = 0; i < size; i++) {

      set = hNet.getOutputSet(i);
      HashMap map = new HashMap();
      for (int j = 0; j < set.size(); j++) {
        map.put(set.get(j), new Integer(0));
      }
      marking[i] = map;
    }

    auxMapping = new MappingToSubsets(hNet);
    this.reset();
  }
예제 #2
0
  /**
   * Adds tokens to the output places of a given element
   *
   * @param element element to fire
   */
  private void addTokensOutputPlaces(int element) {

    /*
     * Pseudo-code: 1. Retrieve all elements in the OUT set of 'element' 2.
     * Increase the number of tokens for every output element
     */

    HNSet set = null;

    // update global counter for number of tokens
    // note that OR-situations count as a single token.

    set = hNet.getOutputSet(element);
    if (set.size() == 0) { // element is connected to the end place
      numberTokens++;
      endPlace++;
    } else {
      numberTokens += set.size();
    }

    // update marking...
    for (int iSet = 0; iSet < set.size(); iSet++) {
      increaseNumberTokens(element, set.get(iSet));
    }
  }
예제 #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 void buildMapping(HeuristicsNet hn) {

    HNSet outputSubsets;
    HNSubSet outputSubset;
    int taskInSubset;

    mapping = new HNSet[hn.size()][hn.size()];

    for (int task = 0; task < hn.size(); task++) {
      outputSubsets = hn.getOutputSet(task);
      for (int iOutputSubsets = 0; iOutputSubsets < outputSubsets.size(); iOutputSubsets++) {
        // inserting for every element
        outputSubset = outputSubsets.get(iOutputSubsets);
        for (int iSubset = 0; iSubset < outputSubset.size(); iSubset++) {
          taskInSubset = outputSubset.get(iSubset);
          insertInMapping(taskInSubset, task, outputSubset);
        }
      }
    }
  }