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

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

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

问题

  1. PointNode node1 = new PointNode();
  2. node1.setPos(0, 0, 0);
  3. node1.setDrawMode(SHAPE_DRAW_2D3D);
  4. node1.setFillColor(black);
  5. node1.setOwner(this);
  6. node1.setRadius(10);
  7. node1.setVisible(true);
  8. presentation.add(node1);
  9. PointNode node2 = new PointNode();
  10. node2.setPos(100, 0, 0);
  11. node2.setDrawMode(SHAPE_DRAW_2D3D);
  12. node2.setFillColor(black);
  13. node2.setOwner(this);
  14. node2.setRadius(10);
  15. node2.setVisible(true);
  16. presentation.add(node2);
  17. Path path1 = new Path();
  18. path1.setBidirectional(true);
  19. path1.setDrawingType(PATH_LINE);
  20. path1.setDrawMode(SHAPE_DRAW_2D3D);
  21. path1.setLineColor(black);
  22. path1.setLineWidth(10);
  23. path1.setOwner(this);
  24. path1.setSource(node1);
  25. path1.setTarget(node2);
  26. path1.setVisible(true);
  27. path1.toPath3D();
  28. path1.initialize();
  29. presentation.add(path1);
  30. Network net1 = new Network(this, "aa");
  31. net1.setDrawMode(SHAPE_DRAW_2D3D);
  32. net1.setVisible(true);
  33. 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.

  1. PointNode node1 = new PointNode();
  2. node1.setPos(0, 0, 0);
  3. node1.setDrawMode(SHAPE_DRAW_2D3D);
  4. node1.setFillColor(black);
  5. node1.setOwner(this);
  6. node1.setRadius(10);
  7. node1.setVisible(true);
  8. presentation.add(node1);
  9. PointNode node2 = new PointNode();
  10. node2.setPos(100, 0, 0);
  11. node2.setDrawMode(SHAPE_DRAW_2D3D);
  12. node2.setFillColor(black);
  13. node2.setOwner(this);
  14. node2.setRadius(10);
  15. node2.setVisible(true);
  16. presentation.add(node2);
  17. Path path1 = new Path();
  18. path1.setBidirectional(true);
  19. path1.setDrawingType(PATH_LINE);
  20. path1.setDrawMode(SHAPE_DRAW_2D3D);
  21. path1.setLineColor(black);
  22. path1.setLineWidth(10);
  23. path1.setOwner(this);
  24. path1.setSource(node1);
  25. path1.setTarget(node2);
  26. path1.setVisible(true);
  27. path1.toPath3D();
  28. path1.initialize();
  29. presentation.add(path1);
  30. Network net1 = new Network(this,"aa");
  31. net1.setDrawMode(SHAPE_DRAW_2D3D);
  32. net1.setVisible(true);
  33. net1.addAll(node1, node2, path1);

答案1

得分: 3

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

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

  1. // 创建矩形节点
  2. rn = new RectangularNode();
  3. rn.setPos(300.0, 350.0, 0.0);
  4. rn.setSize(100.0, 90.0);
  5. rn.addAttractor(new Attractor(25.0, 25.0, 4.7));
  6. // 创建点节点
  7. pn = new PointNode();
  8. pn.setRadius( 5 );
  9. pn.setLineColor( dodgerBlue );
  10. pn.setPos(50.0, 300.0);
  11. // 创建节点之间的路径
  12. Path path = new Path();
  13. path.setBidirectional(true);
  14. path.addSegment(new MarkupSegmentLine(50.0, 300.0, 0.0, 350.0, 300.0, 0.0));
  15. path.addSegment(new MarkupSegmentLine(350.0, 300.0, 0.0, 350.0, 350.0, 0.0));
  16. path.setTarget(rn);
  17. path.setSource(pn);
  18. // 创建带有路径和节点的网络
  19. n = new Network(this, "myNetwork");
  20. n.addAll(rn, pn, path);
  21. // 创建带有网络的级别并初始化级别
  22. Level level = new Level(this, "myLevel", SHAPE_DRAW_2D3D, 0);
  23. level.add(n);
  24. level.initialize(); // 初始化后无法更改!
  25. 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:

  1. // create rectangular node
  2. rn = new RectangularNode();
  3. rn.setPos(300.0, 350.0, 0.0);
  4. rn.setSize(100.0, 90.0);
  5. rn.addAttractor(new Attractor(25.0, 25.0, 4.7));
  6. // create point node
  7. pn = new PointNode();
  8. pn.setRadius( 5 );
  9. pn.setLineColor( dodgerBlue );
  10. pn.setPos(50.0, 300.0);
  11. // create path between nodes
  12. Path path = new Path();
  13. path.setBidirectional(true);
  14. path.addSegment(new MarkupSegmentLine(50.0, 300.0, 0.0, 350.0, 300.0, 0.0));
  15. path.addSegment(new MarkupSegmentLine(350.0, 300.0, 0.0, 350.0, 350.0, 0.0));
  16. path.setTarget(rn);
  17. path.setSource(pn);
  18. // create network with path and nodes
  19. n = new Network(this, "myNetwork");
  20. n.addAll(rn, pn, path);
  21. // create level with the network and initialize the level
  22. Level level = new Level(this, "myLevel", SHAPE_DRAW_2D3D, 0);
  23. level.add(n);
  24. level.initialize(); // cannot be changed after initialization!
  25. 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:

确定