Esempio n. 1
0
 /**
  * Set all variables to their respective value in the solution Throws an exception is this empties
  * a domain (i.e. this domain does not contain the solution value)
  *
  * <p>BEWARE: A restart might be required so that domains contain the solution values
  */
 public void restore(Solver solver) throws ContradictionException {
   if (empty) {
     throw new UnsupportedOperationException("Empty solution. No solution found");
   }
   Variable[] vars = solver.getVars();
   for (int i = 0; i < vars.length; i++) {
     if ((vars[i].getTypeAndKind() & Variable.TYPE) != Variable.CSTE) {
       int kind = vars[i].getTypeAndKind() & Variable.KIND;
       switch (kind) {
         case Variable.INT:
         case Variable.BOOL:
           IntVar v = (IntVar) vars[i];
           int value = intmap.get(v.getId());
           if (value != NO_ENTRY) {
             v.instantiateTo(value, this);
           } // otherwise, this is not a decision variable
           break;
         case Variable.REAL:
           RealVar r = (RealVar) vars[i];
           double[] bounds = realmap.get(r.getId());
           if (bounds != null) {
             r.updateBounds(bounds[0], bounds[1], this);
           } // otherwise, this is not a decision variable
           break;
         case Variable.SET:
           SetVar s = (SetVar) vars[i];
           int[] values = setmap.get(s.getId());
           if (values != null) {
             s.instantiateTo(values, Cause.Null);
           } // otherwise, this is not a decision variable
           break;
       }
     }
   }
 }
Esempio n. 2
0
 public String toString(Solver solver) {
   Variable[] vars = solver.getVars();
   StringBuilder st = new StringBuilder("Solution: ");
   for (int i = 0; i < vars.length; i++) {
     if ((vars[i].getTypeAndKind() & Variable.TYPE) != Variable.CSTE) {
       int kind = vars[i].getTypeAndKind() & Variable.KIND;
       switch (kind) {
         case Variable.INT:
         case Variable.BOOL:
           IntVar v = (IntVar) vars[i];
           st.append(v.getName()).append("=").append(intmap.get(v.getId())).append(", ");
           break;
         case Variable.REAL:
           RealVar r = (RealVar) vars[i];
           double[] bounds = realmap.get(r.getId());
           st.append(r.getName())
               .append("=[")
               .append(bounds[0])
               .append(",")
               .append(bounds[1])
               .append("], ");
           break;
         case Variable.SET:
           SetVar s = (SetVar) vars[i];
           st.append(s.getName())
               .append("=")
               .append(Arrays.toString(setmap.get(s.getId())))
               .append(", ");
           break;
       }
     }
   }
   return st.toString();
 }
  /**
   * Method activate.
   *
   * @param player Player
   * @param item ItemInstance
   */
  public void activate(Player player, ItemInstance item) {
    if ((player == null) || player.isInOlympiadMode()) {
      return;
    }

    CursedWeapon cw = _cursedWeaponsMap.get(item.getId());

    if (cw == null) {
      return;
    }

    if (player.isCursedWeaponEquipped()) {
      if (player.getCursedWeaponEquippedId() != item.getId()) {
        CursedWeapon cw2 = _cursedWeaponsMap.get(player.getCursedWeaponEquippedId());
        cw2.setNbKills(cw2.getStageKills() - 1);
        cw2.increaseKills();
      }

      endOfLife(cw);
      player.getInventory().destroyItem(item, 1);
    } else if (cw.getTimeLeft() > 0) {
      cw.activate(player, item);
      saveData(cw);
      announce(
          new SystemMessage(SystemMessage.THE_OWNER_OF_S2_HAS_APPEARED_IN_THE_S1_REGION)
              .addZoneName(player.getLoc())
              .addString(cw.getName()));
    } else {
      endOfLife(cw);
      player.getInventory().destroyItem(item, 1);
    }
  }
  @Override
  public String onKill(L2Npc npc, L2PcInstance player, boolean isPet) {
    if (player.getClan() == null) {
      return null;
    }

    QuestState st = null;

    if (player.isClanLeader()) {
      st = player.getQuestState(getClass());
    } else {
      L2PcInstance pleader = player.getClan().getLeader().getPlayerInstance();
      if (pleader != null && player.isInsideRadius(pleader, 1500, true, false)) {
        st = pleader.getQuestState(getClass());
      }
    }

    if (st != null && st.isStarted()) {
      int raid = st.getInt("raid");
      if (REWARD_POINTS.containsKey(raid)) {
        if (npc.getNpcId() == REWARD_POINTS.get(raid)[0]
            && !st.hasQuestItems(REWARD_POINTS.get(raid)[1])) {
          st.rewardItems(REWARD_POINTS.get(raid)[1], 1);
          st.playSound(QuestSound.ITEMSOUND_QUEST_ITEMGET);
        }
      }
    }
    return null;
  }
  /** Creates a deep copy of a TIntObjectHashMap<TIntHashSet>. */
  public static TIntObjectHashMap<TIntHashSet> deepClone(TIntObjectHashMap<TIntHashSet> map) {

    TIntObjectHashMap<TIntHashSet> clone = new TIntObjectHashMap<TIntHashSet>();

    for (TIntIterator keyit = map.keySet().iterator(); keyit.hasNext(); ) {
      int key = keyit.next();

      clone.put(key, new TIntHashSet(map.get(key).capacity()));
      clone.get(key).addAll(map.get(key));
    }

    return clone;
  }
  /**
   * Method showUsageTime.
   *
   * @param player Player
   * @param itemId int
   */
  public void showUsageTime(Player player, int itemId) {
    CursedWeapon cw = _cursedWeaponsMap.get(itemId);

    if (cw != null) {
      showUsageTime(player, cw);
    }
  }
Esempio n. 7
0
 public NetworkGameInfo getGame(int id) {
   System.out.println("getGame: " + id);
   readLock.lock();
   NetworkGameInfo info = games.get(id);
   readLock.unlock();
   return info;
 }
 @Override
 public DoubleVector multiplyVectorColumn(DoubleVector v) {
   DoubleVector result = new SparseDoubleVector(this.getColumnCount());
   if (v.isSparse()) {
     Iterator<DoubleVectorElement> vectorNonZero = v.iterateNonZero();
     while (vectorNonZero.hasNext()) {
       DoubleVectorElement featureElement = vectorNonZero.next();
       DoubleVector rowVector = getRowVector(featureElement.getIndex());
       Iterator<DoubleVectorElement> rowNonZero = rowVector.iterateNonZero();
       while (rowNonZero.hasNext()) {
         DoubleVectorElement outcomeElement = rowNonZero.next();
         result.set(
             outcomeElement.getIndex(),
             result.get(outcomeElement.getIndex())
                 + (outcomeElement.getValue() * featureElement.getValue()));
       }
     }
   } else {
     for (int row : rowIndices()) {
       Iterator<DoubleVectorElement> iterateNonZero = matrix.get(row).iterateNonZero();
       while (iterateNonZero.hasNext()) {
         DoubleVectorElement e = iterateNonZero.next();
         result.set(e.getIndex(), (e.getValue() * v.get(row)) + result.get(e.getIndex()));
       }
     }
   }
   return result;
 }
  /**
   * Method increaseKills.
   *
   * @param itemId int
   */
  public void increaseKills(int itemId) {
    CursedWeapon cw = _cursedWeaponsMap.get(itemId);

    if (cw != null) {
      cw.increaseKills();
      saveData(cw);
    }
  }
 @Override
 public void deleteTableById(int tableId) {
   T table = tablesById.get(tableId);
   if (table != null) {
     tablesByIndx.remove(table);
     tablesById.remove(tableId);
   }
 }
Esempio n. 11
0
  public void loadBorderPoints() throws IOException {
    Iterator<Entry<RouteRegion, BinaryMapIndexReader>> it = reverseMap.entrySet().iterator();
    int sleft = Math.min(startX, targetX);
    int sright = Math.max(startX, targetX);
    int stop = Math.min(startY, targetY);
    int sbottom = Math.max(startY, targetY);
    // one tile of 12th zoom around (?)
    int zoomAround = 10;
    int distAround = 1 << (31 - zoomAround);
    leftBorderBoundary = sleft - distAround;
    rightBorderBoundary = sright + distAround;
    SearchRequest<RouteDataBorderLinePoint> req =
        BinaryMapIndexReader.buildSearchRouteBorderRequest(sleft, sright, stop, sbottom);
    while (it.hasNext()) {
      Entry<RouteRegion, BinaryMapIndexReader> entry = it.next();
      entry.getValue().searchBorderPoints(req, entry.getKey());
    }
    TIntObjectHashMap<RouteDataBorderLine> lines =
        new TIntObjectHashMap<RoutingContext.RouteDataBorderLine>();
    for (RouteDataBorderLinePoint p : req.getSearchResults()) {
      if (config.router.acceptLine(p) && p.x > leftBorderBoundary && p.x < rightBorderBoundary) {
        if (!lines.containsKey(p.y)) {
          RouteDataBorderLine line = new RouteDataBorderLine(p.y);
          lines.put(p.y, line);
          RouteDataBorderLinePoint lft = new RouteDataBorderLinePoint(p.region);
          lft.y = p.y;
          lft.id = Long.MIN_VALUE;
          lft.x = leftBorderBoundary;
          line.borderPoints.add(lft);
          RouteDataBorderLinePoint rht = new RouteDataBorderLinePoint(p.region);
          rht.y = p.y;
          rht.id = Long.MIN_VALUE;
          rht.x = rightBorderBoundary;
          line.borderPoints.add(rht);
        }
        lines.get(p.y).borderPoints.add(p);
      }
    }
    borderLines = lines.values(new RouteDataBorderLine[lines.size()]);
    Arrays.sort(borderLines);
    borderLineCoordinates = new int[borderLines.length];
    for (int i = 0; i < borderLineCoordinates.length; i++) {
      borderLineCoordinates[i] = borderLines[i].borderLine;
      // FIXME borders approach
      // not less then 14th zoom
      if (i > 0 && borderLineCoordinates[i - 1] >> 17 == borderLineCoordinates[i] >> 17) {
        throw new IllegalStateException();
      }
      System.out.println(
          "Line "
              + (borderLineCoordinates[i] >> 17)
              + " points "
              + borderLines[i].borderPoints.size() /* + " " +borderLines[i].borderPoints*/);
    }

    updateDistanceForBorderPoints(startX, startY, true);
    updateDistanceForBorderPoints(targetX, targetY, false);
  }
 @Override
 public DoubleMatrix subtract(DoubleVector vec) {
   DoubleMatrix result = new SparseDoubleRowMatrix(this.getRowCount(), this.getColumnCount());
   for (int row : this.matrix.keys()) {
     SparseDoubleVector rowVec = matrix.get(row);
     result.setRowVector(row, rowVec.subtract(vec.get(row)));
   }
   return result;
 }
Esempio n. 13
0
  private String buildKeyhraseHTMLEntry(
      int[] keyphraseTokens, TIntDoubleHashMap matchedKeywords, TIntObjectHashMap<String> id2word) {
    StringBuilder sb = new StringBuilder();
    for (int token : keyphraseTokens) {
      if (matchedKeywords.containsKey(token)) {
        sb.append(
            "<span style='BACKGROUND-COLOR: #FFAA70;'><strong>"
                + id2word.get(token)
                + "</strong> <small>("
                + matchedKeywords.get(token)
                + ")</small></span> ");
      } else {
        sb.append("<strong>" + id2word.get(token) + "</strong> ");
      }
    }

    return sb.toString();
  }
 @Override
 public DoubleVector getRowVector(int row) {
   SparseDoubleVector v = matrix.get(row);
   if (v == null) {
     v = new SparseDoubleVector(getColumnCount());
     matrix.put(row, v);
   }
   return v;
 }
 @Override
 public double get(int row, int col) {
   SparseDoubleVector vector = matrix.get(row);
   if (vector == null) {
     return NOT_FLAGGED;
   } else {
     return vector.get(col);
   }
 }
Esempio n. 16
0
 public String getTitle(LivingEntity entity) {
   if (entity instanceof SpoutPlayer) {
     return ((SpoutPlayer) entity).getTitle();
   }
   if (titles.contains(entity.getEntityId())) {
     return titles.get(entity.getEntityId());
   }
   return null;
 }
Esempio n. 17
0
 @Override
 protected void setupEntities(Entities e) throws SQLException {
   inlinkImportance = new TIntDoubleHashMap();
   TIntObjectHashMap<int[]> neighbors = DataAccess.getInlinkNeighbors(e);
   double collectionSize = (double) DataAccess.getCollectionSize();
   for (int eId : e.getUniqueIds()) {
     double importance = (double) neighbors.get(eId).length / (double) collectionSize;
     inlinkImportance.put(eId, importance);
   }
 }
 @Override
 public void set(int row, int col, double value) {
   if (value != 0.0d) {
     SparseDoubleVector sparseDoubleVector = matrix.get(row);
     if (sparseDoubleVector == null) {
       sparseDoubleVector = new SparseDoubleVector(getColumnCount());
       matrix.put(row, sparseDoubleVector);
     }
     sparseDoubleVector.set(col, value);
   }
 }
Esempio n. 19
0
 @Override
 public void onUpdate(Variable var, EventType evt) {
   if (evt == EventType.INSTANTIATE) {
     int nbp = var.getNbProps();
     for (int p = 0; p < nbp; p++) {
       Propagator prop = var.getPropagator(p);
       int pid = prop.getId();
       pid2ari.get(pid).add(-1);
     }
   }
 }
Esempio n. 20
0
 public boolean containsWord(int word, Mention mention) {
   if (!indexWithoutStopWords.containsKey(word)) return false;
   TIntLinkedList positions = indexIncludingStopWords.get(word);
   int mentionStart = mention.getStartToken();
   int mentionEnd = mention.getEndToken();
   for (TIntIterator itr = positions.iterator(); itr.hasNext(); ) {
     int position = itr.next();
     if (position < mentionStart || position > mentionEnd) return true;
   }
   return false;
 }
Esempio n. 21
0
  public void addToIndex(TIntIntHashMap newIndexEntries) {
    for (int word : newIndexEntries.keys()) {
      int offset = newIndexEntries.get(word);

      TIntLinkedList positions;
      positions = indexIncludingStopWords.get(word);
      if (positions == null) {
        positions = new TIntLinkedList();
        indexIncludingStopWords.put(word, positions);
      }
      positions.add(offset);

      positions = indexWithoutStopWords.get(word);
      if (positions == null) {
        positions = new TIntLinkedList();
        indexWithoutStopWords.put(word, positions);
      }
      positions.add(offset);
    }
  }
 @Override
 public DoubleMatrix divide(double scalar) {
   DoubleMatrix result = new SparseDoubleRowMatrix(this.getRowCount(), this.getColumnCount());
   for (int row : this.matrix.keys()) {
     Iterator<DoubleVectorElement> iterateNonZero = matrix.get(row).iterateNonZero();
     while (iterateNonZero.hasNext()) {
       DoubleVectorElement e = iterateNonZero.next();
       result.set(row, e.getIndex(), e.getValue() / scalar);
     }
   }
   return result;
 }
 @Override
 public boolean setTableName(int tableId, String newName) {
   ODLTableDefinition dfn = TableUtils.findTable(this, newName, true);
   if (dfn != null && dfn.getImmutableId() != tableId) {
     return false;
   }
   ODLTableDefinitionImpl table = (ODLTableDefinitionImpl) tablesById.get(tableId);
   if (table != null) {
     table.setName(newName);
   }
   return true;
 }
 @Override
 public DoubleMatrix multiply(double scalar) {
   DoubleMatrix result = new SparseDoubleRowMatrix(this);
   for (int row : this.matrix.keys()) {
     Iterator<DoubleVectorElement> iterateNonZero = matrix.get(row).iterateNonZero();
     while (iterateNonZero.hasNext()) {
       DoubleVectorElement e = iterateNonZero.next();
       result.set(row, e.getIndex(), get(row, e.getIndex()) * scalar);
     }
   }
   return result;
 }
Esempio n. 25
0
 /**
  * Get the value of variable s in this solution
  *
  * @param s SetVar
  * @return the value of variable s in this solution, or null if the variable is not instantiated
  *     in the solution
  */
 public int[] getSetVal(SetVar s) {
   if (empty) {
     throw new UnsupportedOperationException("Empty solution. No solution found");
   }
   if (setmap.containsKey(s.getId())) {
     return setmap.get(s.getId());
   } else if ((s.getTypeAndKind() & Variable.TYPE) == Variable.CSTE) {
     return s.getValues();
   } else {
     return null;
   }
 }
 @Override
 public DoubleMatrix multiplyElementWise(DoubleMatrix other) {
   DoubleMatrix result = new SparseDoubleRowMatrix(this.getRowCount(), this.getColumnCount());
   for (int row : this.matrix.keys()) {
     Iterator<DoubleVectorElement> iterateNonZero = matrix.get(row).iterateNonZero();
     while (iterateNonZero.hasNext()) {
       DoubleVectorElement e = iterateNonZero.next();
       result.set(row, e.getIndex(), get(row, e.getIndex()) * other.get(row, e.getIndex()));
     }
   }
   return result;
 }
 @Override
 public DoubleMatrix transpose() {
   SparseDoubleRowMatrix m = new SparseDoubleRowMatrix(this.numColumns, this.numRows);
   for (int row : this.matrix.keys()) {
     Iterator<DoubleVectorElement> iterateNonZero = matrix.get(row).iterateNonZero();
     while (iterateNonZero.hasNext()) {
       DoubleVectorElement e = iterateNonZero.next();
       m.set(e.getIndex(), row, e.getValue());
     }
   }
   return m;
 }
 @Override
 public DoubleMatrix subtract(double amount) {
   DoubleMatrix result = new SparseDoubleRowMatrix(this.getRowCount(), this.getColumnCount());
   for (int row : this.matrix.keys()) {
     Iterator<DoubleVectorElement> iterate = matrix.get(row).iterate();
     while (iterate.hasNext()) {
       DoubleVectorElement e = iterate.next();
       result.set(row, e.getIndex(), e.getValue() - amount);
     }
   }
   return result;
 }
 @Override
 public double sum() {
   double res = 0.0d;
   for (int row : this.matrix.keys()) {
     Iterator<DoubleVectorElement> iterateNonZero = matrix.get(row).iterateNonZero();
     while (iterateNonZero.hasNext()) {
       DoubleVectorElement e = iterateNonZero.next();
       res += e.getValue();
     }
   }
   return res;
 }
  @Override
  public String onTalk(L2Npc npc, QuestState st) {
    L2PcInstance player = st.getPlayer();

    L2Clan clan = player.getClan();

    switch (st.getState()) {
      case CREATED:
        return clan == null || !player.isClanLeader() || clan.getLevel() < 6
            ? "31331-0a.htm"
            : "31331-0b.htm";
      case STARTED:
        if (clan == null || !player.isClanLeader()) {
          st.exitQuest(QuestType.REPEATABLE);
          return "31331-6.html";
        }

        int raid = st.getInt("raid");

        if (REWARD_POINTS.containsKey(raid)) {
          if (st.hasQuestItems(REWARD_POINTS.get(raid)[1])) {
            st.playSound(QuestSound.ITEMSOUND_QUEST_FANFARE_1);
            st.takeItems(REWARD_POINTS.get(raid)[1], -1);
            clan.addReputationScore(REWARD_POINTS.get(raid)[2], true);
            player.sendPacket(
                SystemMessage.getSystemMessage(
                        SystemMessageId.CLAN_QUEST_COMPLETED_AND_S1_POINTS_GAINED)
                    .addNumber(REWARD_POINTS.get(raid)[2]));
            clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
            return "31331-" + raid + "b.html";
          } else {
            return "31331-" + raid + "a.html";
          }
        } else {
          return "31331-0.html";
        }
    }
    return null;
  }