Esempio n. 1
0
  private void chooseRoadMessages() { // TODO choose to spread it over time
    if (!(agent instanceof SOSAgent<?>)) return;

    PriorityQueue<Road> roads =
        new PriorityQueue<Road>(
            agent.model().roads().size(),
            new Comparator<Road>() {

              @Override
              public int compare(Road o1, Road o2) {
                return o2.updatedtime() - o1.updatedtime();
              }
            });
    FOR:
    for (Road road : agent.model().roads()) {
      if (road.updatedtime() <= 1) continue;
      boolean haveAnOpenEdge = false;
      for (int j = 0; j < road.getGraphEdges().length; j++) {
        GraphEdge ge = model().graphEdges().get(road.getGraphEdges()[j]);
        //				if (ge.getState() == GraphEdgeState.FoggyBlock ||
        //						ge.getState() == GraphEdgeState.FoggyOpen)
        //					continue FOR;
        if (ge.getState() == GraphEdgeState.Open) haveAnOpenEdge = true;
      }
      if (haveAnOpenEdge) roads.add(road);
    }
    int priority = 6;
    int count = 0;
    SOSAgent<?> agent = (SOSAgent<?>) this.agent;
    for (Road rd : roads) {

      count++;
      if (priority > 0 && count % 10 == 0) priority--;
      boolean isAllOpen = true;
      for (Short ind : rd.getGraphEdges()) {
        GraphEdge ge = agent.model().graphEdges().get(ind);
        if (ge instanceof WorldGraphEdge && ge.getState() != GraphEdgeState.Open) {
          isAllOpen = false;
          break;
        }
      }
      if (isAllOpen) {
        MessageBlock messageBlock = new MessageBlock(HEADER_OPEN_ROAD);
        messageBlock.addData(DATA_ROAD_INDEX, rd.getRoadIndex());
        sayMessages.add(messageBlock);
      } else {
        SOSBitArray states = new SOSBitArray(rd.getWorldGraphEdgesSize());
        for (int i = 0; i < rd.getWorldGraphEdgesSize(); i++) {
          states.set(
              i,
              agent.model().graphEdges().get(rd.getGraphEdges()[i]).getState()
                  != GraphEdgeState.Open);
        }
        MessageBlock messageBlock = new DynamicSizeMessageBlock(HEADER_ROAD_STATE, states);
        messageBlock.addData(DATA_ROAD_INDEX, rd.getRoadIndex());
        sayMessages.add(messageBlock);
      }
    }
  }
Esempio n. 2
0
  public SOSBitArray toBitArray(ChannelSystemType channelType) {
    if (messageBitArray != null) {
      if (lastChannelType == channelType) return messageBitArray;

      SOSAgent.currentAgent()
          .sosLogger
          .messageContent
          .debug(
              "lastchanneltype is different!!!!!"
                  + lastChannelType
                  + " new chaneltype"
                  + channelType);
    }

    lastChannelType = channelType;
    MessageGroup messageGroup = ReadXml.getValidChannelMessages(channelType);

    messageBitArray = new SOSBitArray(getBitSize(channelType));
    int tempBitPosition = 0;

    messageBitArray.set(
        tempBitPosition,
        SOSBitArray.makeBit(messageGroup.headerToIndex(header), messageGroup.bitSize()));
    tempBitPosition += messageGroup.bitSize();

    DataArrayList xmlData = ReadXml.blocks.get(header).data();

    for (int i = 0; i < xmlData.size(); i++) {
      if (xmlData.getValue(i) < 0) {
        new Error("value is negetive!!!!!!!!!!!![TO BIT ARRAY]").printStackTrace();
        messageBitArray.set(tempBitPosition, SOSBitArray.makeBit(0, xmlData.getValue(i)));
      } else
        messageBitArray.set(
            tempBitPosition, SOSBitArray.makeBit(getData(xmlData.getKey(i)), xmlData.getValue(i)));
      tempBitPosition += xmlData.getValue(i);
    }
    return messageBitArray;
  }