|
@@ -166,31 +166,31 @@ public class TabuSearch {
|
|
|
break;
|
|
|
} else {
|
|
|
Square square = squareList.remove(maxIndex);
|
|
|
- double l = square.getL();
|
|
|
- double w = square.getW();
|
|
|
+ double l = square.getLength();
|
|
|
+ double w = square.getWidth();
|
|
|
if (isRotate > 0) {
|
|
|
// 表示进行了旋转
|
|
|
- square.setL(w);
|
|
|
- square.setW(l);
|
|
|
+ square.setLength(w);
|
|
|
+ square.setWidth(l);
|
|
|
}
|
|
|
// 移除当前角点
|
|
|
placePointList.remove(i);
|
|
|
//新增已放置的square
|
|
|
- placeSquareList.add(new PlaceSquare(square.getId(), placePoint.getX(), placePoint.getY(), square.getL(), square.getW()));
|
|
|
+ placeSquareList.add(new PlaceSquare(square.getId(), placePoint.getX(), placePoint.getY(), square.getLength(), square.getWidth()));
|
|
|
// 新增两个可行角点
|
|
|
- double surplus = placePoint.getLength() - square.getL(); // 剩余长度
|
|
|
+ double surplus = placePoint.getLength() - square.getLength(); // 剩余长度
|
|
|
if (surplus > 0) {
|
|
|
- placePointList.add(new PlacePoint(placePoint.getX() + square.getL(), placePoint.getY(), surplus));
|
|
|
+ placePointList.add(new PlacePoint(placePoint.getX() + square.getLength(), placePoint.getY(), surplus));
|
|
|
}
|
|
|
- placePointList.add(new PlacePoint(placePoint.getX(), placePoint.getY() + square.getW(), square.getL()));
|
|
|
+ placePointList.add(new PlacePoint(placePoint.getX(), placePoint.getY() + square.getWidth(), square.getLength()));
|
|
|
// 重新排序
|
|
|
Collections.sort(placePointList);
|
|
|
i = 0;
|
|
|
// 还原矩形
|
|
|
if (isRotate > 0) {
|
|
|
// 表示进行了旋转
|
|
|
- square.setL(l);
|
|
|
- square.setW(w);
|
|
|
+ square.setLength(l);
|
|
|
+ square.setWidth(w);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -200,7 +200,7 @@ public class TabuSearch {
|
|
|
double rate;
|
|
|
double s = 0.0f;
|
|
|
for (PlaceSquare placeSquare : placeSquareList) {
|
|
|
- s += (placeSquare.getL() * placeSquare.getW());
|
|
|
+ s += (placeSquare.getLength() * placeSquare.getWidth());
|
|
|
}
|
|
|
rate = s / (length * width);
|
|
|
solution.setRate(rate);
|
|
@@ -211,18 +211,18 @@ public class TabuSearch {
|
|
|
private double[] getMarks(PlacePoint placePoint, Square square, List<PlaceSquare> placeSquareList) {
|
|
|
// 返回{是否旋转,分数}
|
|
|
double delta, mark1, mark2;
|
|
|
- PlaceSquare placeSquare = new PlaceSquare(square.getId(), placePoint.getX(), placePoint.getY(), square.getL(), square.getW());
|
|
|
+ PlaceSquare placeSquare = new PlaceSquare(square.getId(), placePoint.getX(), placePoint.getY(), square.getLength(), square.getWidth());
|
|
|
if (isOverlap(placeSquareList, placeSquare)) {
|
|
|
mark1 = -1.0d;
|
|
|
} else {
|
|
|
- delta = Math.abs(placePoint.getLength() - square.getL());
|
|
|
+ delta = Math.abs(placePoint.getLength() - square.getLength());
|
|
|
mark1 = 1 - delta / placePoint.getLength();
|
|
|
}
|
|
|
mark2 = -1.0d;
|
|
|
if (instance.isRotateEnable()) {
|
|
|
- placeSquare = new PlaceSquare(square.getId(), placePoint.getX(), placePoint.getY(), square.getW(), square.getL());
|
|
|
+ placeSquare = new PlaceSquare(square.getId(), placePoint.getX(), placePoint.getY(), square.getWidth(), square.getLength());
|
|
|
if (!isOverlap(placeSquareList, placeSquare)) {
|
|
|
- delta = Math.abs(placePoint.getLength() - square.getW());
|
|
|
+ delta = Math.abs(placePoint.getLength() - square.getWidth());
|
|
|
mark2 = 1 - delta / placePoint.getLength();
|
|
|
}
|
|
|
}
|
|
@@ -235,11 +235,11 @@ public class TabuSearch {
|
|
|
// 判断放置在该位置是否超出边界或者和其他矩形重叠
|
|
|
public boolean isOverlap(List<PlaceSquare> placeSquareList, PlaceSquare tempPlaceSquare) {
|
|
|
// 出界
|
|
|
- if (tempPlaceSquare.getL() > length || tempPlaceSquare.getW() > width) {
|
|
|
+ if (tempPlaceSquare.getLength() > length || tempPlaceSquare.getWidth() > width) {
|
|
|
return true;
|
|
|
}
|
|
|
// 出界
|
|
|
- if (tempPlaceSquare.getX() + tempPlaceSquare.getL() > length || tempPlaceSquare.getY() + tempPlaceSquare.getW() > width) {
|
|
|
+ if (tempPlaceSquare.getX() + tempPlaceSquare.getLength() > length || tempPlaceSquare.getY() + tempPlaceSquare.getWidth() > width) {
|
|
|
return true;
|
|
|
}
|
|
|
for (PlaceSquare placeSquare : placeSquareList) {
|
|
@@ -260,8 +260,8 @@ public class TabuSearch {
|
|
|
public boolean isOverlap2(PlaceSquare placeSquare, PlaceSquare tempPlaceSquare) {
|
|
|
double x1 = Math.max(placeSquare.getX(), tempPlaceSquare.getX());
|
|
|
double y1 = Math.max(placeSquare.getY(), tempPlaceSquare.getY());
|
|
|
- double x2 = Math.min(placeSquare.getX() + placeSquare.getL(), tempPlaceSquare.getX() + tempPlaceSquare.getL());
|
|
|
- double y2 = Math.min(placeSquare.getY() + placeSquare.getW(), tempPlaceSquare.getY() + tempPlaceSquare.getW());
|
|
|
+ double x2 = Math.min(placeSquare.getX() + placeSquare.getLength(), tempPlaceSquare.getX() + tempPlaceSquare.getLength());
|
|
|
+ double y2 = Math.min(placeSquare.getY() + placeSquare.getWidth(), tempPlaceSquare.getY() + tempPlaceSquare.getWidth());
|
|
|
return !(x1 >= x2) && !(y1 >= y2);
|
|
|
}
|
|
|
|