【仿真建模-anylogic】Path代码解析

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);
}

  • 10
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值