- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在获取 NetLogo 模型中补丁环境(彩色区域)中簇的大小(补丁数量)列表时遇到了时间问题。对于小网格值(NetLogo 中的世界大小)如 50 x 50、100 x 100 甚至 150 x 150,BFS 的标准 DFS 变得高效,但随着阶数的增加,这些过程变得不可行。我的任务是计算相同的结果,但网格的 block 数至少为 10000 x 10000 或更高。
我尝试使用 Hoshen-Kopelman 算法进行并查找,但我的实际 NetLogo 实现花费了大约 5 小时来处理 500 x 500 阶的补丁网格。
有人知道有什么算法可以为至少 1000 x 1000 个补丁的世界计算或标记集群吗?
如果我改用 C/C++ 或其他编程语言而不是使用补丁和 Netlogo,我可以获得一些改进吗?
有什么建议吗?
提前致谢,美好的一天
最佳答案
我的代码基本上就是这个模型Clusters with Recursion .
当集群大小适中时,模型可以很好地找到集群,但是如果您的设置过程生成大型集群,则递归会说“递归太深”并且不报告结果,现在我最初的问题可以改写,如何避免这个带有 netlogo 的“递归太深”?
Netlogo 代码:
globals [npixel caux final-participante1 final-participante2 r i j intera2 clist1 clist2 nc1 nc2]
patches-own
[
partido influencia votoduro
cluster
]
to find-clusters
loop [
let seed one-of patches with [cluster = nobody]
if seed = nobody
[ contarclusvar
stop ]
ask seed
[ set cluster self
grow-cluster ]
]
display
end
to setup1
__clear-all-and-reset-ticks
ask patches [set partido 0 set influencia 0 set cluster nobody]
set npixel[]
set final-participante1 0
set final-participante2 0
set r (L + 1)
set-patch-size ps
resize-world 0 L 0 L
set participante2 (L + 1) * (L + 1) - participante1
set i 0
set j 0
repeat r
[
repeat r
[
set npixel sentence npixel patch i j
set j j + 1
]
set i i + 1
set j 0
]
set Caux npixel
let N r * r
repeat participante1
[
let z random N
ask item z npixel [set pcolor white set partido 1 set influencia 1 set votoduro 1]
set npixel replace-item z npixel item (N - 1 ) npixel
set N N - 1
]
repeat participante2
[
let z random N
ask item z npixel [set pcolor gray set partido 2 set influencia 1 set votoduro 1]
set npixel replace-item z npixel item (N - 1 ) npixel
set N N - 1
]
;------------------- Procedure
set clist1 []
set clist2 []
let ciclos 0
let intera 0
let aux 0
let nulo 0
if participante1 + participante2 > r * r
[stop]
let C1 participante1
let C2 participante2
repeat 75
[
set i 0
set j 0
set npixel Caux
set N r * r
set intera 0
set aux 0
let aux2 (((ciclos - 1) * r * r) + intera2)
repeat (r * r)
[
let z random N
ask item z npixel
[
let sum-inf1 sum ([influencia] of neighbors4 with [partido = 1])
let sum-inf2 sum ([influencia] of neighbors4 with [partido = 2])
if (sum-inf2 = sum-inf1) and (partido = 1) [ask item z npixel [set pcolor black set partido 0 set influencia 0 ] set Nulo Nulo + 1 set C1 C1 - 1 set aux aux + 1 set intera2 intera]
if (sum-inf2 = sum-inf1) and (partido = 2) [ask item z npixel [set pcolor black set partido 0 set influencia 0 ] set Nulo Nulo + 1 set C2 C2 - 1 set aux aux + 1 set intera2 intera]
if ((sum-inf1 > sum-inf2) and ((partido = 2) or (partido = 0))) [
set pcolor white set partido 1 set influencia 1
set C1 C1 + 1 set C2 C2 - 1 set aux aux + 1 set intera2 intera
]
if ((sum-inf2 > sum-inf1) and ((partido = 1) or (partido = 0))) [
set pcolor gray set partido 2 set influencia 1
set C2 C2 + 1 set C1 C1 - 1 set aux aux + 1 set intera2 intera
]
set npixel replace-item z npixel item (N - 1 ) npixel
set N N - 1
set intera intera + 1
]
if (intera - aux) > (r * r) - 1 [
stop
]
]
]
end
to contarclusvar
let comp []
set comp ([cluster] of patches with [pcolor = white])
set comp remove-duplicates comp
set nc1 length comp
foreach comp [ set clist1 sentence clist1 count patches with [cluster = ? and pcolor = white]
]
set comp []
set comp ([cluster] of patches with [pcolor = gray])
set comp remove-duplicates comp
set nc2 length comp
foreach comp [ set clist2 sentence clist2 count patches with [cluster = ? and pcolor = gray]
]
end
to grow-cluster
ask neighbors4 with [(cluster = nobody) and (pcolor = [pcolor] of myself)]
[ set cluster [cluster] of myself
grow-cluster ]
end
to show-clusters
let counter 0
loop [
let p one-of patches with [plabel = ""]
if p = nobody
[ stop ]
ask p
[ ask patches with [cluster = [cluster] of myself]
[ set plabel counter ] ]
set counter counter + 1
]
end
关于c++ - 测量大型方形网格中的簇有哪些好的替代方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38211432/
性能优化的重要性不言而喻,Google 的 研究表明 ,当网站达到核心 Web 指标(Core Web Vitals)阈值时,用户放弃加载网页的可能性会降低 24%。 如何
我正在创建一个横幅设计创建器(这样人们就可以使用自己的文本、背景、图像、形状等来制作自己的设计)。我的产品有各种尺寸,例如:800x2000 mm、A4(210 x 297mm)、3300x2200m
我不确定如何使用测量来获取单位的全名。例如“公里”而不是“公里”。 let measurement = Measurement(value: 50, unit: UnitLength.meters)
我有一个自定义 ViewGroup,它有一个子 ViewPager。 ViewPager 由 PagerAdapter 提供,该 LinearLayout 向 ViewPager 提供 LayoutP
我想测量一个大型软件项目在 Linux (make) 中构建过程中的内存消耗是多少内存。理想情况下,消耗会按操作(即编译、链接)拆分,但一开始绘制随时间变化的图表可能就足够了。 我有哪些选择? 最佳答
我正在运行一个 SSIS 包来从一个平面文件加载一百万行,它使用一个脚本任务进行复杂的转换和一个 SQL Server 表目标。我试图找出在数据流处理期间将行数(可能是 1000 的倍数以提高效率)写
我正在尝试检查 Keras 模型不同层的执行速度(使用来自 tensorflow 2.3.0 v 的 keras) 我从这个 repo 中获取了代码并修改它,使用 timer() from from
我有一个旧的应用程序,一个 JAR 文件,它经过了一些增强。基本上必须修改代码的某些部分以及修改一些逻辑。 将旧版本与新版本进行比较,新版本比旧版本慢约 2 倍。 我试图缩小导致速度变慢的原因,但我发
我正在尝试测量不同 Silverlight 图表库(例如 Silverlight Control Toolkit、Visifire、Telerik)在屏幕上加载所需的时间。 我的问题是我只能测量加载控
由于 TTFB 会因每个请求而异,因此我想对其进行统计并获取平均值。有谁知道我如何通过 PHP 进行测量?bytecheck.com 网站能够分析这些数据:这是 example.com 的示例:htt
我正在使用 .NET 4.0 C# 编写应用程序。我将对象放在 .net httpruntime 缓存中,并希望在其上生成一些统计信息。我想知道对象在放入缓存之前的大小以及它在缓存中的大小。我该如何衡
我正在寻找某种方法来测量应用程序的启动时间。从点击应用程序图标的那一刻到用户可以看到例如登录页面的那一刻。 最佳答案 跑 flutter run --trace-startup --profile 跟
我正在优化 iPhone 应用程序以实现非常短的加载时间,我想知道: 是否有一种方法可以测量 iPhone 应用程序从用户点击图标到应用程序可用(或至少 –viewDidLoad 被调用)的加载时间?
我无法理解 中的一件事谷歌分析 .我的应用中需要一个功能,例如 一个 用户将我的应用转至 乙用户然后他得到了一些奖励,但我想跟踪 一个 时通过链接的用户 ID乙用户点击该链接然后我可以得到一个 中的用
有没有办法用 DUnit 来衡量代码覆盖率?或者有没有免费的工具可以实现这一点?你用它做什么?您通常追求什么代码覆盖率? Jim McKeeth:感谢您的详细回答。我谈论的是 TDD 方法意义上的单元
当我执行Makefile时,是否可以递归地回荡在make all的每个目标中花费的(系统,用户,实际)时间? 我想以比time make all更细粒度的方式对项目的编译进行基准测试。理想情况下,它将
R 中有衡量函数执行时间的标准化方法吗? 显然我可以在执行之前和之后获取system.time,然后取它们的差异,但我想知道是否有一些标准化的方法或功能(不想发明轮)。 我似乎记得我曾经使用过如下的东
我最近为了好玩而开始学习 Fortran,我想知道是否有任何简单的方法来显示执行我的代码所花费的时间。这只是一个数到一百万的简单循环,我想看看完成这个需要多长时间。 如果有帮助,这是我正在使用的代码:
我正在开发一个 Shiny 的应用程序。 我对计算执行某些代码块(例如 ggplot 等)所需的时间很感兴趣。 出于某种原因,使用通常的时钟方法似乎在响应式(Reactive)调用中不起作用,例如:
我想测量 jpeg 的白色/黄色量(在可调整的容差范围内)。 我正在尝试开发一种质量控制工具来测量杏仁的缺陷。缺陷是棕色杏仁皮上的划痕(见下图)。由于这些缺陷是白色/黄色的,我想要一种简单地将图像加载
我是一名优秀的程序员,十分优秀!