package com.zy.acs.manager.core.service.astart;
|
|
import lombok.Data;
|
|
import java.io.Serializable;
|
import java.util.Objects;
|
import java.util.Optional;
|
|
@Data
|
public class RetreatNavigateNode implements Comparable<RetreatNavigateNode>, Cloneable, Serializable {
|
|
private static final long serialVersionUID = 1L;
|
|
protected int x; //坐标x
|
protected int y; //坐标y
|
protected int z; //坐标z(高度)
|
|
protected int F; //综合花费的步数
|
protected int G; //已经花费的步数
|
protected int H; //将要花费的步数
|
|
protected RetreatNavigateNode parent; //父节点
|
protected Boolean turningPoint; //是否为拐点
|
protected String direction; //行走方向
|
protected Integer lastDistance; // 距离上个节点距离
|
protected Integer moveDistance; // 总行走距离
|
|
protected String codeData;
|
|
protected int weight;
|
|
public RetreatNavigateNode(int x, int y) {
|
this.x = x;
|
this.y = y;
|
}
|
|
public RetreatNavigateNode(int x, int y, String codeData) {
|
this.x = x;
|
this.y = y;
|
this.codeData = codeData;
|
}
|
|
public void initNode(RetreatNavigateNode father, int weight) {
|
this.parent = father;
|
if (this.parent != null) {
|
this.G = father.G + Optional.ofNullable(this.lastDistance).orElse(0);
|
this.H = father.H + weight;
|
} else {
|
this.G = 0;
|
this.H = weight;
|
}
|
|
this.F = this.G + this.H;
|
}
|
|
@Override
|
public int compareTo(RetreatNavigateNode o) {
|
// asc
|
return Integer.compare(this.F, o.F);
|
}
|
|
@Override
|
public RetreatNavigateNode clone() {
|
try {
|
return (RetreatNavigateNode) super.clone();
|
} catch (CloneNotSupportedException e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
@Override
|
public boolean equals(Object obj) {
|
if (this == obj) return true;
|
if (!(obj instanceof RetreatNavigateNode)) return false;
|
RetreatNavigateNode that = (RetreatNavigateNode) obj;
|
return this.x == that.x && this.y == that.y;
|
}
|
|
@Override
|
public int hashCode() {
|
return Objects.hash(x, y);
|
}
|
|
}
|