예제 #1
0
 public static boolean couldPutHere(Item it, Posi_tion position, VehicleType ve) {
   if (position.getX() + it.get_width() > ve.get_width()) {
     return false;
   }
   if (position.getY() + it.get_length() > ve.get_length()) {
     return false;
   }
   return true;
 }
예제 #2
0
  public static int getLB(Item it, Posi_tion p, VehicleType ve) {
    // Can't be placed in vehicle
    if ((p.getY() + it.get_length() > ve.get_length())
        || (p.getX() + it.get_width() > ve.get_width())) return 0;
    /*
     * int index = ve.unpacked.indexOf(it); ve.unpacked.remove(index);
     * ve.packed.add(it);
     */

    int y1 = it.get_length() + p.getY();
    int x1 = it.get_width() + p.getX();
    int itArea = it.get_length() * it.get_width();

    // Situation 1
    if (ve.pos.size() == 1) {
      return remainArea - itArea;
    }

    // Situation 2
    if (p.getX() == 0) {
      if (x1 < ve.pos.get(1).getX()) {
        return remainArea - itArea;
      } else {
        return remainArea
            - itArea
            - (x1 - ve.pos.get(1).getX()) * (ve.pos.get(0).getY() - ve.pos.get(1).getY());
      }
    }
    // Situation 3
    if (p.getY() == 0) {
      if (y1 < ve.pos.get(ve.pos.size() - 1).getY()) return remainArea - itArea;
      else
        return remainArea
            - itArea
            - (p.getX() - ve.pos.get(ve.pos.size() - 2).getX())
                * (y1 - ve.pos.get(ve.pos.size() - 2).getY());
    }
    // Situation 4
    int ip = ve.pos.indexOf(p);
    if (x1 < ve.pos.get(ip + 1).getX() && y1 < ve.pos.get(ip - 1).getY())
      return remainArea - itArea;
    else if (y1 >= ve.pos.get(ip - 1).getY())
      return remainArea
          - itArea
          - (p.getX() - ve.pos.get(ip - 1).getX()) * (y1 - ve.pos.get(ip - 1).getY());
    else if (x1 > ve.pos.get(ip + 1).getX())
      return remainArea
          - itArea
          - (x1 - ve.pos.get(ip + 1).getX()) * (p.getY() - ve.pos.get(ip + 1).getY());
    else return 0;
  }