Beispiel #1
0
########Demonstration of NL4Py#################
#This example demonstrates NetLogo Application Control with GUI through NL4Py
#example usage: python Example3_NetLogoGUIAppControl.py netlogo_home
###############################################

print(
    "\n\n------------ This is a Demonstration of NL4PY --------------------\n")

import nl4py
import sys

print("\n1) Starting the NetLogoControllerServer with: nl4py.startServer()\n")

nl4py.startServer(sys.argv[1])

print('\n2) Starting the model runs... ')

model = "./Fire.nlogo"

print('\n2.1) Starting the NetLogo Application with: n = nl4py.NetLogoApp()')
n = nl4py.NetLogoApp()
print('\n2.2) Opening the model at ' + model +
      ' on the NetLogo application with: n.openModel("model")')
n.openModel(model)

print(
    "\n2.3) Setting the parameters for the model to random values with: n.setParamsRandom()"
)
n.setParamsRandom()

print(
Beispiel #2
0
import nl4py
import sys
import pandas
import numpy

print("\n1) Starting the NetLogoControllerServer with: nl4py.startServer()\n")

netlogo_home = "C://Program Files//NetLogo 6.0.2//"
nl4py.startServer(netlogo_home)

print('\n2) Starting the model runs... ')

model = "C://Users//Mateen Qureshi//Documents//CSCI378//AFM Initial Migration.nlogo"

n = None

print(
    '\n Creating ' + str(n) +
    ' NetLogo HeadlessWorkspaces with: workspace = nl4py.newNetLogoHeadlessWorkspace()\n and clearing any old workspaces with nl4py.deleteAllHeadlessWorkspaces()'
)
print(
    '\n Opening the ' + model +
    ' model on the NetLogo HeadlessWorkspace with: workspace.openModel("model")'
)
nl4py.deleteAllHeadlessWorkspaces()
workspace = nl4py.newNetLogoHeadlessWorkspace()
workspace.openModel(model)

print(
    "\n Setting the parameters to random values with workspace.setParamsRandom()"
)
Beispiel #3
0
def startServer(self):
    nl4py.startServer(
        'E:\Juan\Programs')  # top level directory of your NetLogo installation
########Demonstration of NL4Py#################
#This example schedules reporters for 100 ticks or until stop
# for the Wolf Sheep Predation Sample Model
#example usage: python Example2_ScheduledReporters.py
###############################################

print(
    "\n\n------------ This is a Demonstration of NL4PY --------------------\n")

import nl4py

print("\n1) Starting the NetLogoControllerServer with: nl4py.startServer()\n")

nl4py.startServer()

import sys

print('\n2) Starting the model runs... ')

n = 1

model = "./Wolf Sheep Predation.nlogo"

print(
    '\n2.1) Creating ' + str(n) +
    ' NetLogo HeadlessWorkspaces with: nl4py.netlogoWorkspaceFactory.newNetLogoHeadlessWorkspace()\n and clearing any old workspaces with nl4py.netlogoWorkspaceFactory.deleteAllExistingWorkspaces()'
)
print(
    '\n2.2) Opening the ' + model +
    ' model on the NetLogo HeadlessWorkspace with: nl4py.NetLogoHeadlessWorkspace.openModel("model")'
)
import nl4py, math
import numpy as np

nl4py.startServer("D:/Softwares/NetLogo 6.1.0")
nl = nl4py.NetLogoApp()

nl.openModel("D:/Nikhil/Projects/python_netlogo/Template.nlogo")
nl.command('set-patch-size 2.8')
N = 8
vMax = 2  # m/s
delT = 0.1  # seconds
maxSepTurn = 10
maxAvoidTurn = 10
maxAlignTurn = 20
minSepDist = 5
flockVision = 20
flockAngle = 25


def spawn(Nuavs):
    nl.command('clear-all')
    for i in range(Nuavs):
        nl.command(
            'crt 1[setxy {0} {1} set heading {2} set size 8] ask turtles [set label who]'
            .format(uav_pos[i][0], uav_pos[i][1], float(uav_head[i])))


def relheading(headb, heada):
    """relative heading of b with respect to a"""
    delH = headb - heada
    if abs(delH) >= 180:
Beispiel #6
0
import nl4py

nl4py.startServer('C:/Program Files/NetLogo 6.1.1')

n = nl4py.newNetLogoHeadlessWorkspace()

# open the meta-ABM
n.openModel('COVID-19_Main.nlogo')

# select Massachusetts
region = 'MA'
n.command('set Region "{}"'.format(region))

#### Parameters ####
# a value between 0 and 1 for the moment, which basically removes that fraction of agents from the local ABMs
isolation_intensity = 0.5 
# delay with which isolation is to take place after the first infected individuals are released
isolation_start = 20 
n.command('set isolate-at-intensity {}'.format(isolation_intensity))
n.command('set tick-to-begin-isolation {}'.format(isolation_start))

n.command('setup') # local ABMs are initialized, with the typical number of visitors


#### Objectives ####
measurements = []
# measure the contagion
measurements.append('mean [ count people with [covid-19-symptomatic]] ls:of ls:models')
# measure the economic impact
measurements.append('mean [current-economic-performance] of turtles')