本文介绍了如何通过代码在 Anylogic 中创建路径空间标记元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对任何逻辑完全是菜鸟,现在我正在尝试通过代码制作简单的网络;(具有两个 pointNode 的网络,以及连接它们的路径)遇到一些问题.

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.

当我运行模型时,控制台显示使用 initialize() 方法",但我已经知道初始化方法在较低版本中被弃用.(我使用的是 8.5.1 版)

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)

如何通过代码创建路径

真的需要你的帮助

谢谢.

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

推荐答案

正如您已经注意到的,AnyLogic 8.5 有一种新的方法来做到这一点.主要区别在于新的级别系统,您也必须添加该系统.

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.

以下是 AnyLogic 的官方示例,用于从 8.5 的代码创建节点路径网络:

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.

这篇关于如何通过代码在 Anylogic 中创建路径空间标记元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 16:05