Exemple #1
1
  public void moveToShape(Collection<ShapeInArea> des, Class<? extends MoveType> type)
      throws SOSActionException {

    if (!(me.me() instanceof Human)) {
      log().warn("can't use move in Center Agent " + me + "\n");
      return;
    }
    try {
      checkTraffic(); // TODO uncomment
      MoveType mt = moves.get(type.hashCode());
      if (mt != null) {
        Path path = mt.getPathToShape(des);
        log().debug("MOVE " + type.getSimpleName() + "\nTO : " + path + "\n");
        move(path);
      } else log().error(new Error("in move can not found type=" + type.getSimpleName()));

    } catch (SOSActionException e) {
      throw e;
    } catch (Exception er) {
      log().error(er);
      log().warn("using bfs for finding path");
      ArrayList<Area> goals = new ArrayList<Area>();

      for (ShapeInArea shapeInArea : des) {
        goals.add(shapeInArea.getArea(me.model()));
      }
      move(bfs.breadthFirstSearch((Area) me.location(), goals));
    }
    log().error("in move can not found type=" + type.getSimpleName());
    me.problemRest("in move can not found type=" + type.getSimpleName());
  }
Exemple #2
0
 private void createHashCode() {
   int result = annotation != null ? annotation.hashCode() : 0;
   result = 31 * result + (provider ? 1 : 0);
   result = 31 * result + (name != null ? name.hashCode() : 0);
   result = 31 * result + (serviceDefinition != null ? serviceDefinition.hashCode() : 0);
   hashCode = result;
 }
Exemple #3
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((classFrom == null) ? 0 : classFrom.hashCode());
   result = prime * result + ((classTo == null) ? 0 : classTo.hashCode());
   return result;
 }
Exemple #4
0
 /** {@inheritDoc} */
 @Override
 public int hashCode() {
   int result = -1845873496;
   result += mClass.hashCode();
   if (mName != null) {
     result += mName.hashCode();
   }
   if (mAnnotation != null) {
     result += mAnnotation.hashCode();
   }
   return result;
 }
 public int hashCode() {
   if (j == 0) {
     j = b.hashCode();
     j = (j * 31 + g.hashCode());
     j = (j * 31 + c);
     j = (j * 31 + d);
     j = (j * 31 + h.hashCode());
     j = (j * 31 + e.hashCode());
     j = (j * 31 + f.hashCode());
     j = (j * 31 + i.hashCode());
   }
   return j;
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((annotated == null) ? 0 : annotated.hashCode());
   return result;
 }
 public static int methodKey(Method m) {
   int key = ShaDigest.shortDigest(m.getName());
   for (Class c : m.getParameterTypes()) {
     key += c.hashCode();
   }
   return key;
 }
  /*
   * findDescriptorFor a Class.  This looks in the cache for a
   * mapping from Class -> ObjectStreamClass mappings.  The hashCode
   * of the Class is used for the lookup since the Class is the key.
   * The entries are extended from java.lang.ref.SoftReference so the
   * gc will be able to free them if needed.
   */
  private static ObjectStreamClass_1_3_1 findDescriptorFor(Class cl) {

    int hash = cl.hashCode();
    int index = (hash & 0x7FFFFFFF) % descriptorFor.length;
    ObjectStreamClassEntry e;
    ObjectStreamClassEntry prev;

    /* Free any initial entries whose refs have been cleared */
    while ((e = descriptorFor[index]) != null && e.get() == null) {
      descriptorFor[index] = e.next;
    }

    /* Traverse the chain looking for a descriptor with ofClass == cl.
     * unlink entries that are unresolved.
     */
    prev = e;
    while (e != null) {
      ObjectStreamClass_1_3_1 desc = (ObjectStreamClass_1_3_1) (e.get());
      if (desc == null) {
        // This entry has been cleared,  unlink it
        prev.next = e.next;
      } else {
        if (desc.ofClass == cl) return desc;
        prev = e;
      }
      e = e.next;
    }
    return null;
  }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + (type == null ? 0 : type.hashCode());
   return result;
 }
 public int hashCode() {
   int hash = itemType.hashCode() << 7;
   if (itemFieldName != null) {
     hash += itemFieldName.hashCode();
   }
   return hash;
 }
Exemple #11
0
 public void moveXY(
     Collection<Pair<? extends Area, Point2D>> destinations, Class<? extends MoveType> type)
     throws SOSActionException {
   if (!(me.me() instanceof Human)) {
     log().warn("can't use move in Center Agent " + me + "\n");
     return;
   }
   try {
     checkTraffic();
     MoveType mt = moves.get(type.hashCode());
     if (mt != null) {
       Path path = mt.getPathToPoints(destinations);
       log().debug("MOVE XY" + type.getSimpleName() + "\nTO : " + path + "\n");
       move(path);
     } else log().error(new Error("in move can not found type=" + type.getSimpleName()));
   } catch (SOSActionException e) {
     throw e;
   } catch (Exception er) {
     log().error(er);
     log().warn("using bfs for finding path");
     move(bfs.breadthFirstSearchXY((Area) me.location(), destinations));
   }
   log().error("in move can not found type=" + type.getSimpleName());
   me.problemRest("in move can not found type=" + type.getSimpleName());
 }
Exemple #12
0
 @Override
 public int hashCode() {
   int hash = 7;
   hash = 29 * hash + (klass != null ? klass.hashCode() : 0);
   hash = 29 * hash + (id != null ? id.hashCode() : 0);
   return hash;
 }
 @Override
 public int hashCode() {
   int result = 17;
   result = 31 * result + targetClass.hashCode();
   result = 31 * result + numberClass.hashCode();
   return result;
 }
  public Object getConfiguredModelFactory(String sModelFactoryClassName)
      throws ClassNotFoundException, InvocationTargetException, ParameterProviderException,
          ConstructorNotFoundException, InstantiationException, IllegalAccessException {
    // first load the class (the class loader caches)
    Class oModelFactoryClass = _oClassLoader.loadClass(sModelFactoryClassName);

    // see if we have a cached instance of the factory class
    Object oModelFactory = _oConfiguredModelFactoryMap.get(oModelFactoryClass.getName());

    if (oModelFactory == null) {
      // no cached instance, create a new factory class instance and cache
      oModelFactory = createConfiguredModelFactory(oModelFactoryClass);

      _oConfiguredModelFactoryMap.put(oModelFactoryClass.getName(), oModelFactory);
    } else {
      if (oModelFactory.getClass().hashCode() != oModelFactoryClass.hashCode()) {
        ObjectFactory.destroyObject(oModelFactory);

        // to be safe remove and add instead of overwrite to prevent leaving
        // an invalid obect in the cache in case creating the new instance
        // fails
        _oConfiguredModelFactoryMap.remove(oModelFactoryClass.getName());

        // create a new factory class instance and cache
        oModelFactory = createConfiguredModelFactory(oModelFactoryClass);

        _oConfiguredModelFactoryMap.put(oModelFactoryClass.getName(), oModelFactory);
      }
    }

    return oModelFactory;
  }
Exemple #15
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + proxyType.hashCode();
   return result;
 }
 /* (non-Javadoc)
  * @see java.lang.Object#hashCode()
  */
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((basePackage == null) ? 0 : basePackage.hashCode());
   result = prime * result + ((markerAnnotation == null) ? 0 : markerAnnotation.hashCode());
   return result;
 }
 /** @see java.lang.Object#hashCode() */
 @Override
 public int hashCode() {
   int hashcode = beanType.hashCode();
   if (beanName != null) {
     hashcode = hashcode + (127 * beanName.hashCode());
   }
   return hashcode;
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((declaringClass == null) ? 0 : declaringClass.hashCode());
   result = prime * result + ((signature == null) ? 0 : signature.hashCode());
   return result;
 }
 /** {@inheritDoc} */
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + keyType.hashCode();
   result = prime * result + valueType.hashCode();
   result =
       prime * result + ((listenerConfigurations == null) ? 0 : listenerConfigurations.hashCode());
   result = prime * result + ((cacheLoaderFactory == null) ? 0 : cacheLoaderFactory.hashCode());
   result = prime * result + ((cacheWriterFactory == null) ? 0 : cacheWriterFactory.hashCode());
   result = prime * result + ((expiryPolicyFactory == null) ? 0 : expiryPolicyFactory.hashCode());
   result = prime * result + (isReadThrough ? 1231 : 1237);
   result = prime * result + (isStatisticsEnabled ? 1231 : 1237);
   result = prime * result + (isStoreByValue ? 1231 : 1237);
   result = prime * result + (isWriteThrough ? 1231 : 1237);
   return result;
 }
  @Override
  public int hashCode() {
    if (generics == null) return super.hashCode();

    int result = dataTypeIn.hashCode();
    result = 31 * result + generics.hashCode();
    return result;
  }
Exemple #21
0
  public final Entry getMethods(Class cls, String name) {
    int h = hash(31 * cls.hashCode() + name.hashCode());
    Entry e = table[h & (table.length - 1)];
    for (; e != null; e = e.nextHashEntry)
      if (e.hash == h && cls == e.cls && (e.name == name || e.name.equals(name))) return e;

    return null;
  }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((cls == null) ? 0 : cls.hashCode());
   result = prime * result + distance;
   return result;
 }
 @Override
 public final int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((id == null) ? 0 : id.hashCode());
   result = prime * result + ((keyClass == null) ? 0 : keyClass.hashCode());
   return result;
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((_name == null) ? 0 : _name.hashCode());
   result = prime * result + ((_type == null) ? 0 : _type.hashCode());
   result = prime * result + ((augmentation == null) ? 0 : augmentation.hashCode());
   return result;
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((beanType == null) ? 0 : beanType.hashCode());
   result = prime * result + ((entityId == null) ? 0 : entityId.hashCode());
   result = prime * result + ((beanTypeId == null) ? 0 : beanTypeId.hashCode());
   return result;
 }
Exemple #26
0
    /* !(cycleinfo2.getAct() instanceof MoveAction) || */ !(cycleinfo2.getAct()
        instanceof StockMoveAction)) return;
    if (!(cycleinfo3.getAct() instanceof MoveAction)
        || cycleinfo3.getAct() instanceof StockMoveAction) return;

    log()
        .debug(
            "cycleinfo1:"
                + cycleinfo1.getPositionPair()
                + "cycleinfo2:"
                + cycleinfo2.getPositionPair()
                + " cycleinfo3:"
                + cycleinfo3.getPositionPair());
    if (SOSGeometryTools.getDistance(
                cycleinfo1.getPositionPair().second(), cycleinfo2.getPositionPair().second())
            < MoveConstants.TRAFFIC_CHECKING_DISTANCE
        && SOSGeometryTools.getDistance(
                cycleinfo1.getPositionPair().second(), cycleinfo3.getPositionPair().second())
            < MoveConstants.TRAFFIC_CHECKING_DISTANCE) {
      Path randomPath = bfs.getDummyRandomWalkPath();

      me.send(
          new AKMove(
              me.getID(),
              me.time(),
              randomPath.getIds(),
              randomPath.getDestination().second().getIntX(),
              randomPath.getDestination().second().getIntY()));
      sendStockMessage(path);
      me.informationStacker.addInfo(me.model(), new StockMoveAction(randomPath));
      throw new SOSActionException("Move Stock Random Walk(" + randomPath + ")");
    }
  }

  private void sendStockMessage(Path path) {
    if (me instanceof PoliceForceAgent) return;

    if (!(me.me() instanceof Human)) return;

    if (me.time() < 50) return;

    Human meEntity = (Human) me.me();

    if (meEntity.isBuriednessDefined() && meEntity.getBuriedness() > 0) return;

    if (meEntity.getImReachableToEdges().isEmpty()) return;

    if (me.isTimeToActFinished()) return;

    if (me.lastException != null) return;

    try {
      //			if (me.getMyClusterData().isCoverer())
      //				return;

      if (me.me().getAreaPosition().isBlockadesDefined()
          && me.me().getAreaPosition().getBlockadesID().isEmpty()) {
        boolean haveBlock = false;
        for (Area neighbour : me.me().getAreaPosition().getNeighbours()) {
          if (neighbour.isBlockadesDefined() && !neighbour.getBlockadesID().isEmpty())
            haveBlock = true;
        }
        if (!haveBlock) return;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    log().debug("Sending Stock Message");
    me.messageBlock = new MessageBlock(MessageXmlConstant.HEADER_AGENT_STOCK);
    me.messageBlock.addData(
        MessageXmlConstant.DATA_AREA_INDEX, me.me().getAreaPosition().getAreaIndex());
    me.messages.add(me.messageBlock);
    me.lowCommunicationMessages.add(me.messageBlock);
  }

  private void checkEarlyStock(Path path) throws SOSActionException {
    Area source = me.me().getAreaPosition();
    if (me.informationStacker.getInformations(1).getAct() instanceof MoveAction
        && me.informationStacker.getInformations(1).getPositionPair().first() instanceof Building) {
      log()
          .debug(
              "last act is move and current position is in building ==> don't check early stock");
      return;
    }
    if (me.informationStacker.getInformations(1).getAct() instanceof StockMoveAction) {
      log().debug("last act is stock move ==> don't check early stock");
      return;
    }

    if (source instanceof Building) {
      log().debug("early stock detected!!! agent is in " + source);
      ArrayList<EntityID> entityPath = new ArrayList<EntityID>();
      entityPath.add(source.getID());
      Area second = null;
      Area third = null;

      if (path.getIds().size() > 0 && !path.getIds().get(0).equals(source.getID())) {
        second = (Area) me.model().getEntity(path.getIds().get(0));
        if (path.getIds().size() > 1) third = (Area) me.model().getEntity(path.getIds().get(1));
      } else if (path.getIds().size() > 1 && path.getIds().get(0).equals(source.getID())) {
        second = (Area) me.model().getEntity(path.getIds().get(1));
        if (path.getIds().size() > 2) third = (Area) me.model().getEntity(path.getIds().get(2));
      } else {
        log().warn("move path size is 0 can't checkEarlyStock!!!");
        return;
      }
      if (second == null) {
        log().warn("second is null can't checkEarlyStock!!!");
        return;
      } else {
        ArrayList<Edge> edges = second.getEdgesTo(source);
        int minDistance = Integer.MAX_VALUE;
        for (Edge edge : edges) {
          minDistance =
              (int)
                  Math.min(
                      minDistance, SOSGeometryTools.distance(edge, me.me().getPositionPoint()));
        }
        //				Edge fedge = second.getEdgeTo(source);
        //				if (SOSGeometryTools.distance(fedge, me.me().getPositionPoint()) <
        // MoveConstants.ENTRACE_DISTANCE_MM+1000)
        //					return;
        if (minDistance < MoveConstants.ENTRACE_DISTANCE_MM + 1000) {
          log().debug("I'm too neat to edge in building... no need to check early stock");
          return;
        }
        entityPath.add(second.getID());
      }
      if (third == null) {
        log().debug("Move path is too small!!! no need to early stock handle");
        return;
      } else {
        Edge ed = second.getEdgeTo(third);
        Point2D destXYAPointNearEdge;
        if (ed != null) {
          Line2D wallLine =
              ed
                  .getLine(); // new Line2D(edge.getStartX(), edge.getStartY(), edge.getEndX() -
                              // edge.getStartX(), edge.getEndY() - edge.getStartY());
          // ppp.add(new ShapeDebugFrame.Line2DShapeInfo(wallLine, "edge", Color.white.darker(),
          // false, false));
          Vector2D offset;
          if (AliGeometryTools.havecorrectDirection(second)) {
            offset = wallLine.getDirection().getNormal().normalised().scale(15);
          } else {
            offset = wallLine.getDirection().getNormal().normalised().scale(-15);
          }
          destXYAPointNearEdge = ed.getMidPoint().plus(offset);
        } else {
          log().error("[Move]edge is null!!!!!some problem!!!!");
          destXYAPointNearEdge = second.getPositionPair().second();
        }
        log()
            .debug(
                "source:"
                    + source
                    + " dest area for stock:"
                    + second
                    + " dst point:"
                    + destXYAPointNearEdge);
        me.send(
            new AKMove(
                me.getID(),
                me.time(),
                entityPath,
                (int) destXYAPointNearEdge.getX(),
                (int) destXYAPointNearEdge.getY()));
        path =
            new Path(
                null,
                null,
                entityPath,
                me.me().getPositionPair(),
                new Pair<Area, Point2D>(second, destXYAPointNearEdge),
                false);
        me.informationStacker.addInfo(me.model(), new StockMoveAction(path));
        throw new SOSActionException(
            "Move Stock(" + source + "," + second + " " + destXYAPointNearEdge + ")");
      }
    }
  }

  private void check2CycleStock() throws SOSActionException {
    CycleInformations cycleinfo1 = me.informationStacker.getInformations(1);
    CycleInformations cycleinfo2 = me.informationStacker.getInformations(2);
    if (!(cycleinfo1.getAct() instanceof MoveAction)
        || cycleinfo1.getAct() instanceof StockMoveAction) return;
    if (!(cycleinfo2.getAct() instanceof MoveAction)
        || cycleinfo1.getAct() instanceof StockMoveAction) return;

    Path path1 = ((MoveAction) cycleinfo1.getAct()).getPath();
    //			Path path2 = ((MoveAction) cycleinfo2.getAct()).getPath();
    log().info("Two(2) cycle move ....");
    log().debug("current position:" + me.me().getAreaPosition());
    log().debug("1 cycle ago position:" + cycleinfo1.getPositionPair());
    log().debug("2 cycle ago position:" + cycleinfo2.getPositionPair());
    if (!cycleinfo1.getPositionPair().first().equals(cycleinfo2.getPositionPair().first())) return;
    if (!cycleinfo1.getPositionPair().first().equals(me.me().getAreaPosition())) return;
    if (SOSGeometryTools.getDistance(
            cycleinfo1.getPositionPair().second(), cycleinfo2.getPositionPair().second())
        > MoveConstants.TRAFFIC_CHECKING_DISTANCE) return;

    //////////////// Stock Occured
    log().debug("2 cycle stock occured!!!!!!!");

    ArrayList<EntityID> entityPath = new ArrayList<EntityID>();
    Area area = me.me().getAreaPosition();
    log().debug("Current Position:" + area);
    entityPath.add(area.getID());
    Edge ed;
    Area ne;
    if (path1.getIds().size() > 0 && !path1.getIds().get(0).equals(area.getID())) {
      ne = (Area) me.model().getEntity(path1.getIds().get(0));
      ed = area.getEdgeTo(ne);
    } else if (path1.getIds().size() > 1 && path1.getIds().get(0).equals(area.getID())) {
      ne = (Area) me.model().getEntity(path1.getIds().get(1));
      ed = area.getEdgeTo(ne);
    } else {
      ne = area.getNeighbours().get(0);
      ed = area.getEdgeTo(ne);
    }
    log().debug("ne:" + ne + " ed:" + ed + " last move path:" + path1);
    if (ed == null) {
      log().error("[Move]edge is null!!!!!some problem!!!!");
      ne = area.getNeighbours().get(0);
      ed = area.getEdgeTo(ne);
      log().debug("changed!!!! ne:" + ne + " ed:" + ed + " last move path:" + path1);
    }
    Point2D destXYAPointNearEdge;
    if (ed != null) {
      //			if (area instanceof Road) {
      Pair<Point2D, Point2D> points = getAPointInReachblePartEdges(area, ed);
      destXYAPointNearEdge = points.second();
      //			} else {
      //				Line2D wallLine = ed.getLine();// new Line2D(edge.getStartX(), edge.getStartY(),
      // edge.getEndX() - edge.getStartX(), edge.getEndY() - edge.getStartY());
      //				// ppp.add(new ShapeDebugFrame.Line2DShapeInfo(wallLine, "edge", Color.white.darker(),
      // false, false));
      //				Vector2D offset;
      //				if (lastStockTime < me.time() - 4) {
      //					if (AliGeometryTools.havecorrectDirection(area)) {
      //						offset = wallLine.getDirection().getNormal().normalised().scale(1500);
      //					} else {
      //						offset = wallLine.getDirection().getNormal().normalised().scale(-1500);
      //					}
      //				} else {
      //					if (!AliGeometryTools.havecorrectDirection(area)) {
      //						offset = wallLine.getDirection().getNormal().normalised().scale(1500);
      //					} else {
      //						offset = wallLine.getDirection().getNormal().normalised().scale(-1500);
      //					}
      //				}
      //				destXYAPointNearEdge = ed.getMidPoint().plus(offset);
      //			}
    } else {
      log().error("[Move]edge is null!!!!!some problem!!!!");
      destXYAPointNearEdge = area.getPositionPair().second();
    }
    log().debug("dest area for stock:" + area + " dst point:" + destXYAPointNearEdge);
    me.send(
        new AKMove(
            me.getID(),
            me.time(),
            entityPath,
            (int) destXYAPointNearEdge.getX(),
            (int) destXYAPointNearEdge.getY()));
    Path path =
        new Path(
            null,
            null,
            entityPath,
            me.me().getPositionPair(),
            new Pair<Area, Point2D>(area, destXYAPointNearEdge),
            false);
    me.informationStacker.addInfo(me.model(), new StockMoveAction(path));
    //		log().warn("Traffic Handeling should be change due to server doesn't support AKMotion");
    lastStockTime = me.time();
    throw new SOSActionException("Move Stock(" + area + " " + destXYAPointNearEdge + ")");
  }

  private Pair<Point2D, Point2D> getAPointInReachblePartEdges(Area area, Edge relatedEdge) {
    Point2D point = null;
    Edge rEdge = null;
    if (area instanceof Road) {
      Road road = (Road) area;
      FOR:
      for (SOSArea reachablePart : road.getReachableParts()) {
        for (Edge edge : reachablePart.getEdges()) {
          if (edge.getReachablityIndex() >= 0
              && area.getEdges().get(edge.getReachablityIndex()).equals(relatedEdge)) {
            point = edge.getMidPoint();
            rEdge = edge;
            break FOR;
          }
        }
      }
    }
    if (point == null) {
      point = relatedEdge.getMidPoint();
      rEdge = relatedEdge;
    }
    ArrayList<Point2D> twoPointForCheckContain =
        Utility.get2PointsAroundAPointOutOfLine(rEdge.getStart(), rEdge.getEnd(), point, 10);
    ArrayList<Point2D> twoPoint =
        Utility.get2PointsAroundAPointOutOfLine(rEdge.getStart(), rEdge.getEnd(), point, 3000);
    if (area.getShape().contains(twoPointForCheckContain.get(0).toGeomPoint()))
      return new Pair<Point2D, Point2D>(twoPoint.get(0), twoPoint.get(1));
    else return new Pair<Point2D, Point2D>(twoPoint.get(1), twoPoint.get(0));
  }

  @SuppressWarnings("unused")
  private void check4CycleStock() throws SOSActionException {
    CycleInformations cycleinfo1 = me.informationStacker.getInformations(1);
    CycleInformations cycleinfo2 = me.informationStacker.getInformations(2);
    CycleInformations cycleinfo3 = me.informationStacker.getInformations(3);
    CycleInformations cycleinfo4 = me.informationStacker.getInformations(4);
    if (cycleinfo2.getAct() instanceof StockMoveAction) return;
    if (cycleinfo1.getAct() instanceof MoveAction
        && cycleinfo2.getAct() instanceof MoveAction
        && cycleinfo3.getAct() instanceof MoveAction
        && cycleinfo4.getAct() instanceof MoveAction) {
      //			Path path1 = ((MoveAction) cycleinfo1.getAct()).getPath();
      //			Path path2 = ((MoveAction) cycleinfo2.getAct()).getPath();
      //			Path path3 = ((MoveAction) cycleinfo3.getAct()).getPath();
      //			Path path4 = ((MoveAction) cycleinfo4.getAct()).getPath();
      log().debug("Four(4) cycle move ....");
      log().debug("1 cycle ago position:" + cycleinfo1.getPositionPair());
      log().debug("2 cycle ago position:" + cycleinfo2.getPositionPair());
      log().debug("3 cycle ago position:" + cycleinfo3.getPositionPair());
      log().debug("4 cycle ago position:" + cycleinfo4.getPositionPair());
      if (cycleinfo1.getPositionPair().first().equals(cycleinfo2.getPositionPair().first())
          && cycleinfo1.getPositionPair().first().equals(cycleinfo3.getPositionPair().first())
          && cycleinfo1.getPositionPair().first().equals(cycleinfo4.getPositionPair().first())) {
        if (SOSGeometryTools.getDistance(
                    cycleinfo1.getPositionPair().second(), cycleinfo2.getPositionPair().second())
                < MoveConstants.TRAFFIC_CHECKING_DISTANCE
            && SOSGeometryTools.getDistance(
                    cycleinfo1.getPositionPair().second(), cycleinfo3.getPositionPair().second())
                < MoveConstants.TRAFFIC_CHECKING_DISTANCE
            && SOSGeometryTools.getDistance(
                    cycleinfo1.getPositionPair().second(), cycleinfo4.getPositionPair().second())
                < MoveConstants.TRAFFIC_CHECKING_DISTANCE) {
          //////////////////// DO TRAFFIC/////////////////////////////
          log().warn("4 cycle stock!--> do random walk");
          move(bfs.getDummyRandomWalkPath(), false);
        }
      }
    }
  }

  // **---------------------------------------------INTERFACE
  // SEGMENT----------------------------------------------**//
  // ********* STANDARD MOVE INTERFACE *********//
  public void moveStandard(Area destination) throws SOSActionException {
    move(destination, StandardMove.class);
  }

  public void moveStandard(Collection<? extends Area> destination) throws SOSActionException {
    move(destination, StandardMove.class);
  }

  public void moveStandardXY(Area destination, int x, int y) throws SOSActionException {
    moveXY(destination, x, y, StandardMove.class);
  }

  public void moveStandardXY(Collection<Pair<? extends Area, Point2D>> destinations)
      throws SOSActionException {
    moveXY(destinations, StandardMove.class);
  }

  // ********* POLICE MOVE INTERFACE *********//
  public void movePolice(Area destination) throws SOSActionException {
    move(destination, PoliceMove.class);
  }

  public void movePolice(Collection<? extends Area> destination) throws SOSActionException {
    move(destination, PoliceMove.class);
  }

  public void movePoliceXY(Area destination, int x, int y) throws SOSActionException {
    moveXY(destination, x, y, PoliceMove.class);
  }

  public void movePoliceXY(Collection<Pair<? extends Area, Point2D>> destinations)
      throws SOSActionException {
    moveXY(destinations, PoliceMove.class);
  }

  public void moveToShape(Collection<ShapeInArea> des, Class<? extends MoveType> type)
      throws SOSActionException {

    if (!(me.me() instanceof Human)) {
      log().warn("can't use move in Center Agent " + me + "\n");
      return;
    }
    try {
      checkTraffic(); // TODO uncomment
      MoveType mt = moves.get(type.hashCode());
      if (mt != null) {
        Path path = mt.getPathToShape(des);
        log().debug("MOVE " + type.getSimpleName() + "\nTO : " + path + "\n");
        move(path);
      } else log().error(new Error("in move can not found type=" + type.getSimpleName()));

    } catch (SOSActionException e) {
      throw e;
    } catch (Exception er) {
      log().error(er);
      log().warn("using bfs for finding path");
      ArrayList<Area> goals = new ArrayList<Area>();

      for (ShapeInArea shapeInArea : des) {
        goals.add(shapeInArea.getArea(me.model()));
      }
      move(bfs.breadthFirstSearch((Area) me.location(), goals));
    }
    log().error("in move can not found type=" + type.getSimpleName());
    me.problemRest("in move can not found type=" + type.getSimpleName());
  }

  // ********* GENERAL MOVE INTERFACE *********//
  public void move(Area destination, Class<? extends MoveType> type) throws SOSActionException {
    move(Collections.singleton(destination), type);
  }

  public void move(Collection<? extends Area> goals, Class<? extends MoveType> type)
      throws SOSActionException {
    if (!(me.me() instanceof Human)) {
      log().warn("can't use move in Center Agent " + me + "\n");
      return;
    }
    try {
      checkTraffic(); // TODO uncomment
      MoveType mt = moves.get(type.hashCode());

      if (mt != null) {
        Path path = mt.getPathTo(goals);
        log().debug("MOVE " + type.getSimpleName() + "\nTO : " + path + "\n");
        move(path);
      } else log().error(new Error("in move can not found type=" + type.getSimpleName()));
    } catch (SOSActionException ec) {
      throw ec;
    } catch (Exception er) {
      log().error(er);
      log().warn("using bfs for finding path");
      move(bfs.breadthFirstSearch((Area) me.location(), goals));
    }
    log().error("in move can not found type=" + type.getSimpleName());
    me.problemRest("in move can not found type=" + type.getSimpleName());
  }

  public void moveXY(Area destination, int x, int y, Class<? extends MoveType> type)
      throws SOSActionException {
    Pair<? extends Area, Point2D> pair = new Pair<Area, Point2D>(destination, new Point2D(x, y));
    ArrayList<Pair<? extends Area, Point2D>> arr = new ArrayList<Pair<? extends Area, Point2D>>();
    arr.add(pair);
    moveXY(arr, type);
  }

  public void moveXY(
      Collection<Pair<? extends Area, Point2D>> destinations, Class<? extends MoveType> type)
      throws SOSActionException {
    if (!(me.me() instanceof Human)) {
      log().warn("can't use move in Center Agent " + me + "\n");
      return;
    }
    try {
      checkTraffic();
      MoveType mt = moves.get(type.hashCode());
      if (mt != null) {
        Path path = mt.getPathToPoints(destinations);
        log().debug("MOVE XY" + type.getSimpleName() + "\nTO : " + path + "\n");
        move(path);
      } else log().error(new Error("in move can not found type=" + type.getSimpleName()));
    } catch (SOSActionException e) {
      throw e;
    } catch (Exception er) {
      log().error(er);
      log().warn("using bfs for finding path");
      move(bfs.breadthFirstSearchXY((Area) me.location(), destinations));
    }
    log().error("in move can not found type=" + type.getSimpleName());
    me.problemRest("in move can not found type=" + type.getSimpleName());
  }

  public void move(Path path, Class<? extends MoveType> type) throws SOSActionException {
    if (!(me.me() instanceof Human)) {
      log().warn("can't use move in Center Agent " + me + "\n");
      return;
    }
    MoveType mt = moves.get(type.hashCode());
    if (mt != null) {
      log().debug("MOVE " + type.getSimpleName() + "\nTO : " + path + "\n");
      move(path);
    } else log().error(new Error("in move can not found type=" + type.getSimpleName()));

    log().error("in move can not found type=" + type.getSimpleName());
    me.problemRest("in move can not found type=" + type.getSimpleName());
  }

  public void move(Path path) throws SOSActionException {
    move(path, true);
  }

  public void move(Path path, boolean checkStock) throws SOSActionException {
    if (!(me.me() instanceof Human)) {
      log().warn("can't use move in Center Agent " + me + "\n");
      return;
    }
    if (path == null) {
      log().error("move to null??....doing random walk");
      ((PlatoonAgent<?>) me).randomWalk(true);
    }

    log().debug("MOVE TO : " + path + "\n");
    if (checkStock) checkStock(path);
    Point2D xy = path.getDestination().second();

    me.informationStacker.addInfo(me.model(), new MoveAction(path));
    me.send(
        new AKMove(me.getID(), me.model().time(), path.getIds(), (int) xy.getX(), (int) xy.getY()));
    throw new SOSActionException("MoveXY(" + path + ", " + xy + ")");
  }

  // *************************************** GET PATH
  // *************************************************/
  public Path getPathTo(Collection<? extends Area> destinations, Class<? extends MoveType> type) {
    MoveType mt = moves.get(type.hashCode());
    if (mt != null) {
      Path path = mt.getPathTo(destinations);
      log().debug("Move.getPathTo " + type.getSimpleName() + "\nTO : " + path + "\n");
      return path;
    } else log().error(new Error("in Move.getPathTo can not found type=" + type.getSimpleName()));
    return null;
  }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((name == null) ? 0 : name.hashCode());
   result = prime * result + ((parameters == null) ? 0 : parameters.hashCode());
   result = prime * result + ((type == null) ? 0 : type.hashCode());
   return result;
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((operation == null) ? 0 : operation.hashCode());
   result = prime * result + ((proxyClass == null) ? 0 : proxyClass.hashCode());
   result = prime * result + ((proxyId == null) ? 0 : proxyId.hashCode());
   return result;
 }
Exemple #29
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((clazz == null) ? 0 : clazz.hashCode());
   result = prime * result + ((fieldNames == null) ? 0 : fieldNames.hashCode());
   result = prime * result + ((fields == null) ? 0 : fields.hashCode());
   result = prime * result + ((style == null) ? 0 : style.hashCode());
   return result;
 }
 @Override
 public int hashCode() {
   int result = name != null ? name.hashCode() : 0;
   result = 31 * result + (prettyname != null ? prettyname.hashCode() : 0);
   result = 31 * result + (isDateBased ? 1 : 0);
   result = 31 * result + value;
   result = 31 * result + (isImageType ? 1 : 0);
   result = 31 * result + (facetClass != null ? facetClass.hashCode() : 0);
   return result;
 }