如何通过代码在AnyLogic中创建路径空间标记元素

huangapple go评论123阅读模式
英文:

How can i create Path space markup element in Anylogic via Code

问题

PointNode node1 = new PointNode();
node1.setPos(0, 0, 0);
node1.setDrawMode(SHAPE_DRAW_2D3D);
node1.setFillColor(black);
node1.setOwner(this);
node1.setRadius(10);
node1.setVisible(true);

presentation.add(node1);

PointNode node2 = new PointNode();
node2.setPos(100, 0, 0);
node2.setDrawMode(SHAPE_DRAW_2D3D);
node2.setFillColor(black);
node2.setOwner(this);
node2.setRadius(10);
node2.setVisible(true);

presentation.add(node2);

Path path1 = new Path();
path1.setBidirectional(true);
path1.setDrawingType(PATH_LINE);
path1.setDrawMode(SHAPE_DRAW_2D3D);
path1.setLineColor(black);
path1.setLineWidth(10);
path1.setOwner(this);
path1.setSource(node1);
path1.setTarget(node2);
path1.setVisible(true);
path1.toPath3D();
path1.initialize();

presentation.add(path1);

Network net1 = new Network(this, "aa");
net1.setDrawMode(SHAPE_DRAW_2D3D);
net1.setVisible(true);
net1.addAll(node1, node2, path1);
英文:

I'm totally noob in anyloigic, and now I'm trying to make simple network via code; (Network with two pointNode, and path which link those)
Get some problem.

When I run my model, the console show me "using initialize() method", but I already know
initialize method was deprecated in lower version. (I'm using version 8.5.1)

How can i make path via code

Really need your help

Thank you.

PointNode node1 = new PointNode();
node1.setPos(0, 0, 0);
node1.setDrawMode(SHAPE_DRAW_2D3D);
node1.setFillColor(black);
node1.setOwner(this);
node1.setRadius(10);
node1.setVisible(true);

presentation.add(node1);

PointNode node2 = new PointNode();
node2.setPos(100, 0, 0);
node2.setDrawMode(SHAPE_DRAW_2D3D);
node2.setFillColor(black);
node2.setOwner(this);
node2.setRadius(10);
node2.setVisible(true);

presentation.add(node2);

Path path1 = new Path();
path1.setBidirectional(true);
path1.setDrawingType(PATH_LINE);
path1.setDrawMode(SHAPE_DRAW_2D3D);
path1.setLineColor(black);
path1.setLineWidth(10);
path1.setOwner(this);
path1.setSource(node1);
path1.setTarget(node2);
path1.setVisible(true);
path1.toPath3D();
path1.initialize();

presentation.add(path1);

Network net1 = new Network(this,"aa");
net1.setDrawMode(SHAPE_DRAW_2D3D);
net1.setVisible(true);
net1.addAll(node1, node2, path1);

答案1

得分: 3

如您已经注意到的,AnyLogic 8.5 有一种新的方法来实现这一点。主要区别在于新的“级别(level)”系统,您也需要添加它。

以下是 AnyLogic 官方示例,用于在 8.5 版本中通过代码创建节点路径网络:

// 创建矩形节点
rn = new RectangularNode();
rn.setPos(300.0, 350.0, 0.0);
rn.setSize(100.0, 90.0);
rn.addAttractor(new Attractor(25.0, 25.0, 4.7));

// 创建点节点
pn = new PointNode();
pn.setRadius( 5 );
pn.setLineColor( dodgerBlue );
pn.setPos(50.0, 300.0);

// 创建节点之间的路径
Path path = new Path();
path.setBidirectional(true);
path.addSegment(new MarkupSegmentLine(50.0, 300.0, 0.0, 350.0, 300.0, 0.0));
path.addSegment(new MarkupSegmentLine(350.0, 300.0, 0.0, 350.0, 350.0, 0.0));
path.setTarget(rn);
path.setSource(pn);

// 创建带有路径和节点的网络
n = new Network(this, "myNetwork");
n.addAll(rn, pn, path);

// 创建带有网络的级别并初始化级别
Level level = new Level(this, "myLevel", SHAPE_DRAW_2D3D, 0);
level.add(n);
level.initialize(); // 初始化后无法更改!

return level;

您还可以在示例模型中找到这个内容,路径为 帮助/示例模型/通过代码创建传输网络

英文:

As you already noted, AnyLogic 8.5 has a new way of doing this. Main difference is the new level system, which you will have to add as well.

Here is the official example from AnyLogic to create a node-path network from code for 8.5:

// create rectangular node
rn = new RectangularNode();
rn.setPos(300.0, 350.0, 0.0);
rn.setSize(100.0, 90.0);
rn.addAttractor(new Attractor(25.0, 25.0, 4.7));

// create point node
pn = new PointNode();
pn.setRadius( 5 );
pn.setLineColor( dodgerBlue );
pn.setPos(50.0, 300.0);

// create path between nodes
Path path = new Path();
path.setBidirectional(true);
path.addSegment(new MarkupSegmentLine(50.0, 300.0, 0.0, 350.0, 300.0, 0.0));
path.addSegment(new MarkupSegmentLine(350.0, 300.0, 0.0, 350.0, 350.0, 0.0));
path.setTarget(rn);
path.setSource(pn);

// create network with path and nodes
n = new Network(this, "myNetwork");
n.addAll(rn, pn, path);

// create level with the network and initialize the level
Level level = new Level(this, "myLevel", SHAPE_DRAW_2D3D, 0);
level.add(n);
level.initialize(); // cannot be changed after initialization!

return level;

You can find this also in the example models, under Help/Example Models/Create Transporter Network By Code.

huangapple
  • 本文由 发表于 2020年3月4日 10:57:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/60518429.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定