Author:赵志乾
Date:2024-06-24
Declaration:All Right Reserved!!!
1. 类图
2. 代码解析
//**************************核心字段**************************
// Path起点
private Node source;
// Path终点
private Node target;
// Path各段描述
private final CircularCurve circularCurve;
// Path是否为双向
private boolean bidirectional;
// 限速和最大速度
private boolean limitSpeed;
private double maxSpeed;
// Path是否限制运输设备数量
private boolean limitNumberOfTransporters;
// Path上最大运输设备数量
private int maxNumberOfTransporters;
// Path的descriptor,Anylogic用于代码桥接
private IPathDescriptor<Agent> descriptor;
//*************************构造函数****************************
// 构造函数,指定Path的owner,即空间坐标基准;并设置默认最大速度10m/s,最大运输设备数量10个;
public Path(Agent owner) {
super(owner);
this.limitSpeed = false;
this.maxSpeed = 10.0;
this.limitNumberOfTransporters = false;
this.maxNumberOfTransporters = 10;
this.descriptor = (IPathDescriptor)IMaterialLibraryDescriptorFactory.create(IPathDescriptor.class, true);
}
//***********************Path上实时运输设备********************************
// 获取当前运输设备数量
public int getNumberOfTransporters() {
return this.descriptor.getNumberOfTransporters();
}
// 获取第index个运输设备
public Agent getTransporter(int index) {
return this.descriptor.getTransporter(index);
}
//***********************Path起止点****************************************
// 设置起始点
public void setSource(Node source) {
// Path只有一个起始点,重新设置时会将原有设置清除
if (this.source != source) {
if (this.source != null) {
// 解除原有起始点与Path的关系
this.source.removeConnection(this);
}
// 重新设置Path起始点,且Path的起点、终点不能为同一点
this.source = source;
if (this.source != null) {
if (this.source == this.target) {
error("source is the same as target");
}
// 从Node角度建立与Path的关系
this.source.addConnection(this, PathEndType.BEGIN);
}
}
}
// 设置终止点
public void setTarget(Node target) {
// Path只有一个终止点,重新设置时会将原有设置清除
if (this.target != target) {
if (this.target != null) {
this.target.removeConnection(this);
}
// 重新设置Path终止点,且Path的起点、终点不能为同一点
this.target = target;
if (this.target != null) {
if (this.target == this.source) {
error("source is the same as target");
}
this.target.addConnection(this, PathEndType.END);
}
}
}
// 获取Path的起点
public Point getStartPoint() {
Point startPoint = this.circularCurve.getStartPoint();
this.refreshZ(startPoint);
return startPoint;
}
// 获取Path的终点
public Point getEndPoint() {
Point endPoint = this.circularCurve.getEndPoint();
this.refreshZ(endPoint);
return endPoint;
}
//*******************************定义Path各段******************************
// 设定Path的起点
public void startDrawing(double x, double y, double z) {
this.circularCurve.startDrawing(x, y, z);
}
// 从Path最后一点直线连至新点
public void lineTo(double x, double y, double z) {
this.circularCurve.lineTo(x, y, z);
}
// 添加Segment至Path
public void addSegment(MarkupSegment segment) {
this.circularCurve.addSegment(segment);
}
// 获取Path的Segment数量
public int getSegmentCount() {
return this.circularCurve.getSegmentCount();
}
// 获取Paht的第index条Segment
public MarkupSegment getSegment(int index) {
return (MarkupSegment)this.circularCurve.getSegment(index);
}
//****************************Path长度***************************************
// 获取Path的长度
public final double length(LengthUnits units) {
// 需要Path已有owner才能进行长度单位的换算
return this.getSpace().toLengthUnits(this.circularCurve.length(), units);
}
标签:circularCurve,target,建模,private,anylogic,source,Path,public
From: https://blog.csdn.net/zhaoyaxuan001/article/details/139882299