Beispiel #1
0
 /**
  * Main pick function. If table size is greater then or equal to 16, it will use heuristic
  * algorithm.
  *
  * @param limit maximum value of combinations
  * @param items object value table
  * @return solution
  */
 public static <T> Pack<T> pick(Long limit, AbstractMap<T, Long> items) {
   if (items.size() < 26) {
     return Pack.binarySearch(limit, items);
   } else {
     return Pack.geneticAlgorithm(limit, items);
   }
 }
Beispiel #2
0
 /** Gets a copy of this variable. */
 Term copy(AbstractMap vMap, AbstractMap substMap) {
   Var v;
   Object temp = vMap.get(this);
   if (temp == null) {
     v =
         new Var(
             null,
             Var.PROGRESSIVE,
             vMap.size(),
             timestamp); // name,Var.PROGRESSIVE,vMap.size(),timestamp);
     vMap.put(this, v);
   } else {
     v = (Var) temp;
   }
   Term t = getTerm();
   if (t instanceof Var) {
     Object tt = substMap.get(t);
     if (tt == null) {
       substMap.put(t, v);
       v.link = null;
     } else {
       v.link = (tt != v) ? (Var) tt : null;
     }
   }
   if (t instanceof Struct) {
     v.link = t.copy(vMap, substMap);
   }
   if (t instanceof Number) v.link = t;
   return v;
 }
Beispiel #3
0
    public GeneticAlgorithm(Long limit, AbstractMap<T, Long> items) {
      this.limit_ = limit;
      this.table_ = items;

      this.population_ = new ArrayList<Cell<T>>();
      for (int i = 0; i < items.size(); ++i) {
        this.population_.add(this.generatePopulation());
      }
      Collections.sort(this.population_);
    }