to chuc quy hoach
DESCRIPTION
aaaaaaaaaaTRANSCRIPT
public class Node implements INode, Comparable {
protected int nodeID; //Tn ca nt protected int nodeWeight; //Trng s ca nt protected int nodeParentID = -1;//Tn nt cha, khi cha c nt cha = -1 protected int nodeX; //Honh ca nt thc t protected int nodeY; //Tung ca nt thc t protected double distanceFromCenter = Double.MAX_VALUE; //Khong cch n nt trung tm CenterNode protected boolean connected = false; //Trng thi kt ni ti nt no khc cha: //NOT_CONNECTED = false, CONNECTED = true
public Node(); public Node(int initID); public Node(int initID, int initWeight); public Node(int initID, int initWeight, int initX, int initY); public Node(IBackboneNode backboneNode); public Node(ICenterNode centerNode); public int getNodeID(); public void setNodeID(int nodeID;
public int getNodeWeight(); public void setNodeWeight(int nodeWeight);
public int getNodeParentID(); public void setNodeParentID(int nodeParentID);
public int getNodeX(); public void setNodeX(int nodeX);
public int getNodeY() public void setNodeY(int nodeY);
public double getDistanceFromCenter(); public void setDistanceFromCenter(double distanceFromCenter);
public boolean isConnected(); public void setConnected(boolean connected);
public int compareTo(Node node) { if (this.nodeID > node.getNodeID()) { return 1; } else if (this.nodeID < node.getNodeID()) { return -1; } else { return 0; } }
public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Node other = (Node) obj; if (this.nodeID != other.nodeID) { return false; } if (this.nodeWeight != other.nodeWeight) { return false; } return true; }
/** * Phng thc sp xp cc nt tng dn theo trng s (weight) */ public static Comparator weightComparator = new Comparator() { @Override public int compare(INode node1, INode node2) { if (node1.getNodeWeight() > node2.getNodeWeight()) { return 1; } else if (node1.getNodeWeight() < node2.getNodeWeight()) { return -1; } else { return 0; } } };
/** * Phng thc sp xp cc nt tng dn theo khong cch n nt trung tm */ public static Comparator distanceFromCenterComparator = new Comparator() { @Override public int compare(INode node1, INode node2) { if (node1.getDistanceFromCenter() > node2.getDistanceFromCenter()) { return 1; } else if (node1.getDistanceFromCenter() < node2.getDistanceFromCenter()) { return -1; } else { return 0; } } };
/** * Ly tp cc nt c lin kt ti nt ang xt trong th - l cc nt * nm trong th v tn ti cnh kt ni n n (cnh c gi khc 0) * * @param graph * @return */ @Override public ArrayList getConnectableNodes(Graph graph) { ArrayList connectableNodes = new ArrayList(); for (INode node : graph.getNodeList()) { if (graph.getLine(this.nodeID, node.getNodeID()).getLineCost() != 0) { connectableNodes.add(node); } } return connectableNodes; } /** * Kim tra xem nt c thuc vng trn ph sng ca nt ng trc hay khng * T nt ng trc quay vng trn bn knh R, nu khong cch t nt ti * nt ng trc nh hn R th tr v true * * @param center * @param radius * @return */ public boolean isInBackboneCircle(IBackboneNode center, int radius) { int xl = Math.abs(center.getNodeX() - this.nodeX); int yl = Math.abs(center.getNodeY() - this.nodeY); int distance = (int) (Math.sqrt(xl * xl + yl * yl)); if (distance < 1) { distance = 1; } if (distance < radius) { return true; } else { return false; } }
}
public class Line implements ILine, Comparable {
private INode lineSrcNode; //Nt bt u ca cnh private INode lineDestNode; //Nt cui ca cnh private int lineCost = 0; //Gi ca cnh private int lineTraffic = 0; //Lu lng ca cnh private int lineType = 0; //Trng thi ca cnh: 0-connectable, 1-access network, 2-backbone network private boolean inThePath = false; //C nm trn ng i ngn nht gia 2 nt hay khng
public Line() {
}
public Line(INode srcNode, INode destNode) { this.lineSrcNode = srcNode; this.lineDestNode = destNode; }
public Line(INode srcNode, INode destNode, int initCost, int initTraffic) { this.lineSrcNode = srcNode; this.lineDestNode = destNode; this.lineCost = initCost; this.lineTraffic = initTraffic; }
/** * * @return */ @Override public INode getLineSrcNode() { return lineSrcNode; }
public void setLineSrcNode(INode lineSrcNode) { this.lineSrcNode = lineSrcNode; }
/** * * @return */ @Override public INode getLineDestNode() { return lineDestNode; }
public void setLineDestNode(INode lineDestNode) { this.lineDestNode = lineDestNode; }
public int getLineCost() { return lineCost; }
public void setLineCost(int lineCost) { this.lineCost = lineCost; }
public int getLineTraffic() { return lineTraffic; }
public void setLineTraffic(int lineTraffic) { this.lineTraffic = lineTraffic; }
public int getLineType() { return lineType; }
public void setLineType(int lineType) { this.lineType = lineType; }
public boolean isInThePath() { return inThePath; }
public void setInThePath(boolean inThePath) { this.inThePath = inThePath; }
@Override public int compareTo(Line line) { if (this.lineCost > line.getLineCost()) { return 1; } else if (this.lineCost < line.getLineCost()) { return -1; } else { return 0; } }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Line other = (Line) obj; if ((!Objects.equals(this.lineSrcNode, other.lineSrcNode)) && (!Objects.equals(this.lineSrcNode, other.lineDestNode))) { return false; } if ((!Objects.equals(this.lineDestNode, other.lineDestNode)) && (!Objects.equals(this.lineDestNode, other.lineSrcNode))) { return false; } return true; } /** * Phng thc sp xp cc cnh tng dn theo gi */ public static Comparator costComparator = new Comparator() { @Override public int compare(ILine line1, ILine line2) { if (line1.getLineCost() > line2.getLineCost()) { return 1; } else if (line1.getLineCost() < line2.getLineCost()) { return -1; } else { return 0; } } };
}