跳到主要内容

全局方法

仿真控制类

// 重置
sim.reset()

// 启动仿真模型(返回动画)
sim.start()

// 全速模式启动仿真模型(不含动画)
sim.startFullSpeed()

// 获取动画:返回当前的动画格式
sim.getAnimation()

// 倍速
sim.Speed = 10

// 结束
sim.stop()

// 暂停
sim.pause()

// 仿真结束时间,可读可写
sim.EndTime = 100000

// 仿真统计时间,可读可写
sim.StartStat = 1000

// 当前仿真时间(绝对数值),只读
sim.SimTime

// 当前仿真时间(DateTime格式),只读
sim.SimTimeFormatted

// 动画模式,false表示为均匀时间动画模式
sim.EventSim = false

// 获取事件列表
sim.getEventList(最大事件数:integer)

模型创建类

// 继承性创建非移动类对象
Station1.originate()

// 复制创建非移动类对象
Station1.duplicate()

// 删除固定类对象
Station1.deleteObject

// 创建移动类对象
item1.create(Station1)

// 删除移动类对象
item1.delete()

// 连接s1和s2对象
connect(s1, s2)

打印类

// 将信息打印到日志控制台
print("错误信息XXX,请检查YYY")

// 弹窗日志,级别:info/warn/error
showinfo("这是弹窗日志!", "level")

// 弹窗日志(带标题),级别:info/warn/error
showinfo("这是标题", "这是弹窗日志!", "level")

匿名指代符

@  // 移动单元,在脚本中表示触发当前脚本的移动单元
? // 调用当前脚本的对象

数学运算类

基于 java.lang.Math

// 求绝对值
Math.abs(-10)

// 求平方根
Math.sqrt(25)

// 求幂
Math.pow(2, 3) // = 8

// 求最大值
Math.max(10, 20)

// 求最小值
Math.min(10, 20)

// 四舍五入为1位整数
Math.round(1.2345)

// 四舍五入为指定的小数位数
v = Math.round(value * Math.pow(10, scale)) / Math.pow(10, scale)

// 向上取整
Math.ceil(1.2)

// 向下取整
Math.floor(1.8)

// 生成随机数,生成[0,1)之间的随机数
double randomValue = Math.random()

// 其它
Math.sin()
Math.cos()
Math.tan()
Math.log()

字符串

String.format(String format, Object... args)

  • format:包含格式化占位符的字符串模板。
  • args:用于替换格式化占位符的参数列表。

常用格式化符号:

// %s:格式化字符串
String name = "Alice"
String message = String.format("Hello, %s!", name)
print(message) // 输出: Hello, Alice!
// %d:格式化整数
int number = 42
String formatted = String.format("The number is: %d", number)
print(formatted) // 输出: The number is: 42
// %f:格式化浮点数
double price = 23.4567
String formattedPrice = String.format("The price is: %.2f", price)
print(formattedPrice) // 输出: The price is: 23.46
// %t:格式化日期时间
import java.util.Date
String formattedDate = String.format("Today's date: %tF", new Date())
print(formattedDate) // 输出: Today's date: 2025-12-05 (根据实际日期)

分布函数

使用方法:sim.uniform(1, 2)

支持的分布函数如下:

// 均匀分布 (Uniform Distribution)
public double uniform(double lowerBound, double upperBound)

// 正态分布 (Normal Distribution)
public double normal(double mu, double sigma)

// 二项分布 (Binomial Distribution)
public int binomial(int n, double p)

// 泊松分布 (Poisson Distribution)
public int poisson(double lambda)

// 指数分布 (Exponential Distribution)
public double exponential(double beta)

// 伽马分布 (Gamma Distribution)
public double gamma(double alpha, double beta)

// 三角分布 (Triangular Distribution)
public double triangular(double a, double b, double c)

// 韦伯分布 (Weibull Distribution)
public double weibull(double alpha, double beta)