패키지 박스 알고리즘

2670 단어 알고리즘
패키지 컨테이너 단순 알고리즘 임계값 컨테이너 수량 가산 1
/**
* 예상 박스 알고리즘
* @return
*/
  private Tuple2  calculateFareAndNums(List list,PxChannelPrice price){
if(list==null||list.isEmpty()){
Tuple2.of(BigDecimal.ZERO,0);
}
Collections.sort((List) list, new Comparator() {
@Override
public int compare(BigDecimal o1, BigDecimal o2) {
return o2.compareTo(o1);
}
});
BigDecimal taxSum = BigDecimal.ZERO;//
BigDecimal taxLmt = new BigDecimal(50);//
int bagCnt = 0;//
for (int i = 0;i BigDecimal decimal = list.get(i);

if(decimal.compareTo(taxLmt)>-1){
bagCnt++;
}else {
if(taxSum.add(decimal).compareTo(taxLmt)>-1){
bagCnt++;
taxSum = decimal;
}else{
taxSum = taxSum.add(decimal);

}
}
}
if(taxSum.compareTo(BigDecimal.ZERO)==1){
bagCnt++;
}
return Tuple2.of(new BigDecimal(bagCnt).multiply(price.getInitialWeightPrice()),bagCnt);
}


public class Tuple2 {

private final V1 v1;
private final V2 v2;

public Tuple2(V1 t1, V2 t2) {
this.v1 = t1;
this.v2 = t2;
}

public static Tuple2 of(V1 v1, V2 v2) {
return new Tuple2<>(v1, v2);
}

public V1 _1() {
return v1;
}

public V2 _2() {
return v2;
}

@Override
public String toString() {
return "(" + v1 + "," + v2 + ')';
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;

Tuple2, ?> tuple2 = (Tuple2, ?>) o;

if (!v1.equals(tuple2.v1))
return false;
return v2.equals(tuple2.v2);

}

@Override
public int hashCode() {
int result = v1.hashCode();
result = 31 * result + v2.hashCode();
return result;
}
}

좋은 웹페이지 즐겨찾기