系统工程netlogo
- 格式:docx
- 大小:25.12 KB
- 文档页数:9
netlogo编程语言
NetLogo是一种教育和研究用途的编程语言和集成开发环境。
它主要用于建模和模拟复杂系统,特别是用于代理基础建模。
NetLogo的语法基于Logo语言,它包括了一些特定于代理建模的功能,例如对空间建模的支持。
NetLogo的语言特点包括了易学易用,适合教育和研究使用。
它使用了简单的命令和语法,使得用户可以快速上手。
同时,它也
支持高级编程概念,如条件语句、循环和函数,使得用户可以编写
复杂的模型和模拟。
NetLogo的集成开发环境提供了一个直观的界面,用户可以通
过拖放方式创建代理、设置参数和运行模拟。
它还包括了丰富的可
视化工具,用户可以实时观察模拟结果并进行分析。
除此之外,NetLogo还支持并行计算,可以利用多核处理器来
加速模拟过程。
这使得NetLogo在处理大规模复杂系统时表现出色。
总的来说,NetLogo是一种功能丰富、易学易用的编程语言,
适合用于教育和研究领域,特别是在代理基础建模和复杂系统模拟
方面有着广泛的应用。
希望这些信息能够帮助你更好地了解NetLogo编程语言。
《系统工程》课程实验报告班级:学号:姓名:1) 了解Netlogo编程语言的特点和基本语法。
2) 完成Netlogo基本Model的语句解析和仿真流程分析。
学号尾数为1、6号:Computer Science目录下的Pagerank2、7号:Biology目录下的Heatbugs3、8号:Biology目录下的Virus4、9号:Social Science目录下SugarScape中的Voting5、0号:Biology目录下的Ants实验过程与结果:1) 语句解析:turtles-own[ideal-temp ;; The temperature I want to be atoutput-heat ;; How much heat I emit per time step unhappiness ;; The magnitude of the difference between my ideal;; temperature and the actual current temperature here]基础变量[理想温度;;我想要的温度输出热量;;我每次排放的热量是多少不快乐;;我的理想之间的大小差异;,温度和当前的实际温度]patches-own[temp ;; short for "temperature"]自己的修补程序临时;,简称“温度”to setupclear-allset color-by-unhappiness? false;; creating the bugs the following way ensures that we won't;; wind up with more than one bug on a patchask n-of bug-count patches [sprout 1 [set ideal-temp min-ideal-temp + random (max-ideal-temp -min-ideal-temp)set output-heat min-output-heat + random (max-output-heat - min-output-heat)set unhappiness abs (ideal-temp - temp)color-by-ideal-tempface one-of neighborsset size 2 ;; easier to see]];; plot the initial state of the systemreset-ticksendto color-by-ideal-temp;; when scaling the color of turtles, adjust the value;; range by this amount to avoid turtles being too dark or too light.let range-adjustment ( max-ideal-temp - min-ideal-temp ) / 2set color scale-color lime ideal-temp ( min-ideal-temp - range-adjustment )( max-ideal-temp + range-adjustment )endto color-by-unhappiness [ max-unhappiness ]set color scale-color blue unhappiness max-unhappiness 0 endto goif not any? turtles [ stop ];; diffuse heat through worlddiffuse temp diffusion-rate;; The world retains a percentage of its heat each cycle. ;; (The Swarm and Repast versions have 1.0 meaning no ;; evaporation and 0.0 meaning complete evaporation;;; we reverse the scale to better match the name.)ask patches [ set temp temp * (1 - evaporation-rate) ];; agentsets in NetLogo are always in random order, so ;; "ask turtles" automatically shuffles the order of execution ;; each time.ask turtles [ step ]recolor-turtlesrecolor-patchestickendto recolor-turtlesif color-by-unhappiness?[let max-unhappiness max [unhappiness] of turtlesask turtles [ color-by-unhappiness max-unhappiness ]]endto recolor-patches;; hotter patches will be red verging on white;;; cooler patches will be blackask patches [ set pcolor scale-color red temp 0 150 ]endto step ;; turtle procedure;; my unhappiness is the magnitude or absolute value of the difference ;; between by ideal temperature and the temperature of this patch set unhappiness abs (ideal-temp - temp);; if unhappy and not at the hottest neighbor,;; then move to an open neighborif unhappiness > 0[ ifelse random-float 100 < random-move-chance [ bug-move one-of neighbors ][ bug-move best-patch ] ]set temp temp + output-heatend;; find the hottest or coolest location next to me; also ;; take my current patch into considerationto-report best-patch ;; turtle procedureifelse temp < ideal-temp[ let winner max-one-of neighbors [temp]ifelse [temp] of winner > temp[ report winner ][ report patch-here ] ][ let winner min-one-of neighbors [temp]ifelse [temp] of winner < temp[ report winner ][ report patch-here ] ]endto bug-move [target] ;; turtle procedure;; if we're already there, there's nothing to doif target = patch-here [ stop ];; move to the target patch (if it is not already occupied)if not any? turtles-on target [face targetmove-to targetstop]set target one-of neighbors with [not any? turtles-here]if target != nobody [ move-to target ];; The code above is a bit different from the original Heatbugs ;; model in Swarm. In the NetLogo version, the bug will always ;; find an empty patch if one is available.;; In the Swarm version, the bug picks a random;; nearby patch, checks to see if it is occupied, and if it is,;; picks again. If after 10 tries it hasn't found an empty;; patch, it gives up and stays where it is. Since each try;; is random and independent, even if there is an available;; empty patch the bug will not always find it. Presumably ;; the Swarm version is coded that way because there is no ;; concise equivalent in Swarm/Objective C to NetLogo's;; 'one-of neighbors with [not any? turtles-here]'.;; If you want to match the Swarm version exactly, remove the;; last two lines of code above and replace them with this:; let tries 0; while [tries <= 9]; [ set tries tries + 1; set target one-of neighbors; if not any? turtles-on target [; move-to target; stop; ]; ]end;;; the following procedures support the two extra buttons;;; in the interface;; remove all heat from the worldto deep-freezeask patches [ set temp 0 ]end;; add max-output-heat to all locations in the world, heating it evenly to heat-upask patches [ set temp temp + max-output-heat ]end; Copyright 2004 Uri Wilensky.; See Info tab for full copyright and license.设置清除所有设置color-by-unhappiness ?假创建bug;,以下方式确保我们不会;,风与不止一个bug补丁问n[错误数补丁发芽1(设置ideal-temp min-ideal-temp +随机(max-ideal-temp - min-ideal-temp)设置输出温度min-output-heat +随机(max-output-heat - min-output-heat)设置不满abs(ideal-temp - temp)color-by-ideal-temp脸便是邻居设置大小2;;更容易看到]];,画出系统的初始状态reset-ticks结束对color-by-ideal-temp;,当缩放海龟的颜色,调整值海龟;,范围的数量,以避免太暗或太轻。
课内实验报告课程名:系统工程任课教师:巩永华专业:学号:姓名:二○二○至二○二一年度第 1 学期南京邮电大学管理学院《系统工程》课程实验报告实验内容及基本要求:实验项目名称:基于Netlogo的狼吃羊生态系统仿真实验类型:设计每组人数: 1实验内容及要求:1) 了解Netlogo编程语言的特点和基本语法。
2) 用系统动力学建模工具完成狼吃羊生态系统模型的仿真和仿真流程分析。
羊群和狼群的初始数值设置分别为:学号尾数为1、6号:50, 152、7号:80,203、8号:60, 204、9号:90,305、0号:100,30实验过程与结果:(1)系统动力学建模一、建立羊群繁殖模型1.建立羊群模型并编辑其数值2.NetLogo集成3.建立完整狼羊模型wolves 的初值为30,wolf-deaths的表达式为 wolves * wolf-death-rate ,wolf-death-rate 是 0.15,predator-efficiency 是 .8,wolf-births的表达式是 wolves * predator-efficiency * predation-rate * sheep, predation-rate 是 3.0E-4,sheep-deaths 的表达式是 sheep * predation-rate * wolves.4.设置绘图、按钮、监视器、画笔等set-current-plot-pen "sheep"plotxy ticks sheep]if plot-pen-exists? "wolves" [set-current-plot-pen "wolves"plotxy ticks wolves]end(3)仿真结果(4)实验总结在本次实验中我学习了简单的NetLogo建模方法,在过程中遇到了程序错误、无狼的曲线图等问题,通过检查与询问老师,最后了解了自己的问题(连接线错误、缺少指令等)与解决办法,最后成功做出了实验。
《系统工程》课程实验报告班级:学号:姓名:1) 了解Netlogo编程语言的特点和基本语法。
2) 完成Netlogo基本Model的语句解析和仿真流程分析。
学号尾数为1、6号:Computer Science目录下的Pagerank2、7号:Biology目录下的Heatbugs3、8号:Biology目录下的Virus4、9号:Social Science目录下SugarScape中的V oting5、0号:Biology目录下的Ants实验过程与结果:1) 语句解析:turtles-own[ideal-temp ;; The temperature I want to be atoutput-heat ;; How much heat I emit per time stepunhappiness ;; The magnitude of the difference between my ideal;; temperature and the actual current temperature here]基础变量[理想温度;;我想要的温度输出热量;;我每次排放的热量是多少不快乐;;我的理想之间的大小差异;,温度和当前的实际温度]patches-own[temp ;; short for "temperature"]自己的修补程序临时;,简称“温度”to setupclear-allset color-by-unhappiness? false;; creating the bugs the following way ensures that we won't;; wind up with more than one bug on a patchask n-of bug-count patches [sprout 1 [set ideal-temp min-ideal-temp + random (max-ideal-temp - min-ideal-temp) set output-heat min-output-heat + random (max-output-heat - min-output-heat) set unhappiness abs (ideal-temp - temp)color-by-ideal-tempface one-of neighborsset size 2 ;; easier to see]];; plot the initial state of the systemreset-ticksendto color-by-ideal-temp;; when scaling the color of turtles, adjust the value;; range by this amount to avoid turtles being too dark or too light.let range-adjustment ( max-ideal-temp - min-ideal-temp ) / 2set color scale-color lime ideal-temp ( min-ideal-temp - range-adjustment )( max-ideal-temp + range-adjustment )endto color-by-unhappiness [ max-unhappiness ]set color scale-color blue unhappiness max-unhappiness 0endto goif not any? turtles [ stop ];; diffuse heat through worlddiffuse temp diffusion-rate;; The world retains a percentage of its heat each cycle.;; (The Swarm and Repast versions have 1.0 meaning no;; evaporation and 0.0 meaning complete evaporation;;; we reverse the scale to better match the name.)ask patches [ set temp temp * (1 - evaporation-rate) ];;agentsets in NetLogo are always in random order, so;; "ask turtles" automatically shuffles the order of execution;; each time.ask turtles [ step ]recolor-turtlesrecolor-patchestickendto recolor-turtlesif color-by-unhappiness?[let max-unhappiness max [unhappiness] of turtlesask turtles [ color-by-unhappiness max-unhappiness ]]endto recolor-patches;; hotter patches will be red verging on white;;; cooler patches will be blackask patches [ set pcolor scale-color red temp 0 150 ]endto step ;; turtle procedure;; my unhappiness is the magnitude or absolute value of the difference ;; between by ideal temperature and the temperature of this patchset unhappiness abs (ideal-temp - temp);; if unhappy and not at the hottest neighbor,;; then move to an open neighborif unhappiness > 0[ ifelse random-float 100 < random-move-chance[ bug-move one-of neighbors ][ bug-move best-patch ] ]set temp temp + output-heatend;; find the hottest or coolest location next to me; also;; take my current patch into considerationto-report best-patch ;; turtle procedureifelse temp < ideal-temp[ let winner max-one-of neighbors [temp]ifelse [temp] of winner > temp[ report winner ][ report patch-here ] ][ let winner min-one-of neighbors [temp]ifelse [temp] of winner < temp[ report winner ][ report patch-here ] ]endto bug-move [target] ;; turtle procedure;; if we're already there, there's nothing to doif target = patch-here [ stop ];; move to the target patch (if it is not already occupied)if not any? turtles-on target [face targetmove-to targetstop]set target one-of neighbors with [not any? turtles-here]if target != nobody [ move-to target ];; The code above is a bit different from the original Heatbugs ;; model in Swarm. In the NetLogo version, the bug will always ;; find an empty patch if one is available.;; In the Swarm version, the bug picks a random;; nearby patch, checks to see if it is occupied, and if it is,;; picks again. If after 10 tries it hasn't found an empty;; patch, it gives up and stays where it is. Since each try;; is random and independent, even if there is an available;; empty patch the bug will not always find it. Presumably;; the Swarm version is coded that way because there is no;; concise equivalent in Swarm/Objective C to NetLogo's;; 'one-of neighbors with [not any? turtles-here]'.;; If you want to match the Swarm version exactly, remove the ;; last two lines of code above and replace them with this:; let tries 0; while [tries <= 9]; [ set tries tries + 1; set target one-of neighbors; if not any? turtles-on target [; move-to target; stop; ]; ]end;;; the following procedures support the two extra buttons;;; in the interface;; remove all heat from the worldto deep-freezeask patches [ set temp 0 ]end;; add max-output-heat to all locations in the world, heating it evenlyto heat-upask patches [ set temp temp + max-output-heat ]end; Copyright 2004 Uri Wilensky.; See Info tab for full copyright and license.设置清除所有设置color-by-unhappiness ?假创建bug;,以下方式确保我们不会;,风与不止一个bug补丁问n[错误数补丁发芽1(设置ideal-temp min-ideal-temp +随机(max-ideal-temp - min-ideal-temp) 设置输出温度min-output-heat +随机(max-output-heat - min-output-heat) 设置不满abs(ideal-temp - temp)color-by-ideal-temp脸便是邻居设置大小2;;更容易看到]];,画出系统的初始状态reset-ticks结束对color-by-ideal-temp;,当缩放海龟的颜色,调整值海龟;,范围的数量,以避免太暗或太轻。