Пример #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;
       }
     }
   }
 }
Пример #2
0
 public void renderText(
     final BinaryMapDataObject obj,
     final RenderingRuleSearchRequest render,
     final RenderingContext rc,
     final TagValuePair pair,
     final float xMid,
     final float yMid,
     final Path path,
     final PointF[] points) {
   TIntObjectHashMap<String> map = obj.getObjectNames();
   if (map != null) {
     map.forEachEntry(
         new TIntObjectProcedure<String>() {
           @Override
           public boolean execute(int tag, String name) {
             if (name != null && name.trim().length() > 0) {
               createTextDrawInfo(
                   obj,
                   render,
                   rc,
                   pair,
                   xMid,
                   yMid,
                   path,
                   points,
                   name,
                   tag == obj.getMapIndex().nameEncodingType
                       ? ""
                       : obj.getMapIndex().decodeType(tag).tag);
             }
             return true;
           }
         });
   }
 }
  @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;
  }
 static {
   REWARD_POINTS.put(1, new int[] {25290, 8489, 1378}); // Daimon The White-Eyed
   REWARD_POINTS.put(
       2, new int[] {25293, 8490, 1378}); // Hestia, Guardian Deity Of The Hot Springs
   REWARD_POINTS.put(3, new int[] {25523, 8491, 1070}); // Plague Golem
   REWARD_POINTS.put(4, new int[] {25322, 8492, 782}); // Demon's Agent Falston
 }
  /**
   * 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);
    }
  }
Пример #6
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();
 }
Пример #7
0
 /** Turnoff and cleanup the plugin. sets shutdown flag Signs all users out of IRC */
 @Override
 public void onDisable() {
   // disconnect all agents
   TIntObjectProcedure<IrcAgent> shutdown = new ShutdownProcedure();
   bots.forEachEntry(shutdown);
   bots.clear();
   LOG.log(Level.INFO, this.getDescription().getFullName() + " is disabled");
 }
 @Override
 public void deleteTableById(int tableId) {
   T table = tablesById.get(tableId);
   if (table != null) {
     tablesByIndx.remove(table);
     tablesById.remove(tableId);
   }
 }
 @Override
 public DoubleVector getRowVector(int row) {
   SparseDoubleVector v = matrix.get(row);
   if (v == null) {
     v = new SparseDoubleVector(getColumnCount());
     matrix.put(row, v);
   }
   return v;
 }
Пример #10
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;
 }
Пример #11
0
 public static TIntObjectHashMap<String> getAllWordIds() {
   TObjectIntHashMap<String> wordIds = DataAccess.getAllWordIds();
   TIntObjectHashMap<String> idWords = new TIntObjectHashMap<String>(wordIds.size());
   for (TObjectIntIterator<String> itr = wordIds.iterator(); itr.hasNext(); ) {
     itr.advance();
     idWords.put(itr.value(), itr.key());
   }
   return idWords;
 }
Пример #12
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);
   }
 }
Пример #14
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;
 }
Пример #15
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;
   }
 }
    private Facility binFacility(final Facility fromFacility) {
      final int cellX = (int) (fromFacility.getCoord().getX() / cellSize_m);
      final int cellY = (int) (fromFacility.getCoord().getY() / cellSize_m);

      TIntObjectHashMap<Facility> atX;
      synchronized (binnedFacilities) {
        atX = binnedFacilities.get(cellX);
        if (atX == null) {
          atX = new TIntObjectHashMap<>();
          binnedFacilities.put(cellX, atX);
        }
      }

      Facility f;
      synchronized (atX) {
        f = atX.get(cellY);
        if (f == null) {
          f =
              new Facility() {
                private Coord coord =
                    new Coord(
                        cellX * cellSize_m + cellSize_m / 2, cellY * cellSize_m + cellSize_m / 2);
                private Id<Link> linkId =
                    NetworkUtils.getNearestLinkExactly(network, coord).getId();

                @Override
                public Id<Link> getLinkId() {
                  return linkId;
                }

                @Override
                public Coord getCoord() {
                  return coord;
                }

                @Override
                public Map<String, Object> getCustomAttributes() {
                  throw new UnsupportedOperationException();
                }

                @Override
                public Id getId() {
                  throw new UnsupportedOperationException();
                }
              };
          atX.put(cellY, f);
        }
      }

      return f;
    }
 @Override
 public DoubleVector multiplyVectorRow(DoubleVector v) {
   DoubleVector result = new SparseDoubleVector(this.getRowCount());
   for (int row : matrix.keys()) {
     Iterator<DoubleVectorElement> iterateNonZero = matrix.get(row).iterateNonZero();
     double sum = 0.0d;
     while (iterateNonZero.hasNext()) {
       DoubleVectorElement e = iterateNonZero.next();
       sum += (e.getValue() * v.get(e.getIndex()));
     }
     result.set(row, sum);
   }
   return result;
 }
Пример #18
0
 /**
  * Get the bounds of r in this solution
  *
  * @param r RealVar
  * @return the bounds of r in this solution, or null if the variable is not instantiated in the
  *     solution
  */
 public double[] getRealBounds(RealVar r) {
   if (empty) {
     throw new UnsupportedOperationException("Empty solution. No solution found");
   }
   if (realmap.containsKey(r.getId())) {
     return realmap.get(r.getId());
   } else {
     if ((r.getTypeAndKind() & Variable.TYPE) == Variable.CSTE) {
       return new double[] {r.getLB(), r.getUB()};
     } else {
       return null;
     }
   }
 }
Пример #19
0
  /*
   * (non-Javadoc)
   *
   * @see org.jmangos.commons.dataholder.DataLoadService#reload()
   */
  @Override
  public void reload() {

    // Don't replace directly becouse the players can't query quest while
    // it's loading!
    logger.info("Loading quest templates to temoary store.");
    final List<QuestPrototype> questPrototypeList =
        this.questPrototypeService.readQuestPrototypes();
    TIntObjectHashMap<QuestPrototype> tempQuestMap = new TIntObjectHashMap<QuestPrototype>();
    for (final QuestPrototype quest : questPrototypeList) {
      tempQuestMap.put(quest.getEntry(), quest);
    }
    logger.info("Loaded " + tempQuestMap.size() + " quests. Replacing new old Quests with newer");
    this.questMap = tempQuestMap;
    tempQuestMap = null;
  }
Пример #20
0
  /*
   * (non-Javadoc)
   *
   * @see org.jmangos.commons.dataholder.DataLoadService#load()
   */
  @Override
  public TIntObjectHashMap<QuestPrototype> load() {

    final List<QuestPrototype> questPrototypeList =
        this.questPrototypeService.readQuestPrototypes();

    // Quest map by id
    final TIntObjectHashMap<QuestPrototype> map = new TIntObjectHashMap<QuestPrototype>();

    for (final QuestPrototype quest : questPrototypeList) {
      map.put(quest.getEntry(), quest);
    }

    this.questMap = map;
    return this.questMap;
  }
Пример #21
0
  /**
   * 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);
    }
  }
Пример #22
0
 void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
   for (SkillPanel panel : templates) {
     skillPanels.put(panel.getPanelId(), panel);
   }
   templates.clear();
   templates = null;
 }
Пример #23
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;
 }
Пример #25
0
  /**
   * The URLs are a bit ugly and so we need to find out which area name a certain lat,lon coordinate
   * has.
   */
  private SRTMProvider init() {
    try {
      String strs[] = {
        "Africa", "Australia", "Eurasia", "Islands", "North_America", "South_America"
      };
      for (String str : strs) {
        InputStream is = getClass().getResourceAsStream(str + "_names.txt.zip");
        ZipInputStream zis = new ZipInputStream(is);
        zis.getNextEntry();
        for (String line : Helper.readFile(new InputStreamReader(zis, "UTF-8"))) {
          int lat = Integer.parseInt(line.substring(1, 3));
          if (line.substring(0, 1).charAt(0) == 'S') lat = -lat;

          int lon = Integer.parseInt(line.substring(4, 7));
          if (line.substring(3, 4).charAt(0) == 'W') lon = -lon;

          int intKey = calcIntKey(lat, lon);
          String key = areas.put(intKey, str);
          if (key != null)
            throw new IllegalStateException(
                "do not overwrite existing! key " + intKey + " " + key + " vs. " + str);
        }
      }
      return this;
    } catch (Exception ex) {
      throw new IllegalStateException("Cannot load area names from classpath", ex);
    }
  }
Пример #26
0
  private void removeStaleClients() {
    final TIntArrayList staleIDs = new TIntArrayList();

    clients.forEachEntry(
        new TIntObjectProcedure<ClientInfo>() {
          @Override
          public boolean execute(int id, ClientInfo client) {
            if (client.checkIfStale()) staleIDs.add(id);
            return true;
          }
        });

    if (staleIDs.size() == 0) return;

    staleIDs.forEach(
        new TIntProcedure() {
          @Override
          public boolean execute(int id) {
            // System.out.println("Removing stale ID: " + id);
            clients.remove(id);
            games.remove(id);
            return true;
          }
        });
  }
Пример #27
0
  @Override
  public void release() {
    cacheData.clear();

    // for memory mapped type we create temporary unpacked files which should be removed
    if (dir != null) dir.clear();
  }
Пример #28
0
 /**
  * Records the current solution of the solver clears all previous recordings
  *
  * @param solver a solver
  */
 public void record(Solver solver) {
   if (empty) {
     Variable[] _dvars = solver.getStrategy().getVariables();
     for (int i = 0; i < _dvars.length; i++) {
       dvars.add(_dvars[i].getId());
     }
     empty = false;
   }
   boolean warn = false;
   intmap.clear();
   realmap.clear();
   setmap.clear();
   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;
       if (!vars[i].isInstantiated()) {
         if (dvars.contains(vars[i].getId())) {
           throw new SolverException(vars[i] + " is not instantiated when recording a solution.");
         } else {
           warn = true;
         }
       } else {
         switch (kind) {
           case Variable.INT:
           case Variable.BOOL:
             IntVar v = (IntVar) vars[i];
             intmap.put(v.getId(), v.getValue());
             break;
           case Variable.REAL:
             RealVar r = (RealVar) vars[i];
             realmap.put(r.getId(), new double[] {r.getLB(), r.getUB()});
             break;
           case Variable.SET:
             SetVar s = (SetVar) vars[i];
             setmap.put(s.getId(), s.getValues());
             break;
         }
       }
     }
   }
   if (warn && solver.getSettings().warnUser()) {
     Chatterbox.err.printf(
         "Some non decision variables are not instantiated in the current solution.");
   }
 }
  /**
   * Generates a matrix out of a vector list. it treats the entries as rows and the vector itself
   * contains the values of the columns.
   *
   * @param vectorArray the list of vectors.
   */
  public SparseDoubleRowMatrix(List<DoubleVector> vec) {
    this(vec.size(), vec.get(0).getDimension());

    int key = 0;
    for (DoubleVector value : vec) {
      matrix.put(key++, new SparseDoubleVector(value));
    }
  }
Пример #30
0
 private ShuttleWayEvent getNextFloor() {
   int floors = _floors.size() - 1;
   if (!_moveBack) {
     _currentWay++;
     if (_currentWay > floors) {
       _currentWay = floors - 1;
       _moveBack = true;
     }
   } else {
     _currentWay--;
     if (_currentWay < 0) {
       _currentWay = 1;
       _moveBack = false;
     }
   }
   return _floors.get(_currentWay);
 }