How to avoid nobody run time error in netlogo? - runtime

I'm checking the interaction among the properties of three types of patches by using 'one-of neighbors' command. Problem occurs when the two patches are not neighboring to each other in some cases and entity NOBODY emerges. Is there any way to avoid this. It is necessary for me to use 'one-of neighbors' command. Can I give a command stating that if Nobody is detected then the value of the property of that patch be 0.1. In my code give below the problem occurs in the interaction b/w yellow patch and red patch as in some places red is not a neighbor of yellow.
I tried writing a Nobody command it was not correct.I appreciate your advice.
globals [ k ] ; interaction constant
patches-own [ a b c d' e' eeep deep ] ; state variables of properties
; a is the Proportion and variety of Blend of land
use
; b is the Land uses with supportiveness for
complimentary activities
; c is the Vehicular and Pedestrian Intensity
; d is the Intensity of Nodes in urban web
; e' is the Frequency of Enforced Vigilance
to setup
clear-all
set k initial-k
setup-patches
reset-ticks
end
to setup-patches
ask patches [ set pcolor yellow ] ; defines the patches as built up in an area
; to define yellow patches without a and b
ask patches [ if (pycor > 1) and (pycor < 8) and (pxcor = -3 ) [ set pcolor 46 ] ]
ask patches [ if (pycor > 1) and (pycor < 8) and (pxcor = -2 ) [ set pcolor 46 ] ]
ask patches [ if (pycor < -1) and (pxcor = -10 ) [ set pcolor 46 ] ]
ask patches [ if (pycor < -1) and (pxcor = -9 ) [ set pcolor 46 ] ]
ask patches [ if (pycor < -1) and (pxcor = -5 ) [ set pcolor 46 ] ]
ask patches [ if (pycor < -1) and (pxcor = 2 ) [ set pcolor 46 ] ]
ask patches [ if (pycor < -2) and (pxcor = 6 ) [ set pcolor 46 ] ]
ask patches [ if (pycor > 1) and (pycor < 8) and (pxcor = 2 ) [ set pcolor 46 ] ]
ask patches [ if (pycor = 2) and (pxcor > 8 ) [ set pcolor 46 ] ]
ask patches [ if (pycor = -2) and (pxcor > 2 ) [ set pcolor 46 ] ]
ask patches [ if (pycor = -3) and (pxcor > 6 ) [ set pcolor 46 ] ]
ask patches [ if (pycor = -4) and (pxcor > 6 ) [ set pcolor 46 ] ]
ask patches [ if (pycor = -8) and (pxcor > 6 ) [ set pcolor 46 ] ]
ask patches [ if (pycor = -9) and (pxcor > 6 ) [ set pcolor 46 ] ]
ask patches [ if (pycor = 7) and (pxcor > 8 ) [ set pcolor 46 ] ]
ask patches [ if (pycor = 6) and (pxcor > 8 ) [ set pcolor 46 ] ]
ask patches [ if (pycor = 2) and (pxcor > 2 ) and (pxcor < 6) [ set pcolor 46 ] ]
; to define road patches (horizontal)
ask patches [ if pycor = 0 [ set pcolor grey ] ]
ask patches [ if pxcor = 0 [ set pcolor grey ] ]
ask patches [if pycor = 9 [ set pcolor grey ] ]
ask patches [ if (pycor = 6) and (pxcor < -4 )[ set pcolor grey ] ]
ask patches [ if (pycor = 3) and (pxcor < -4 ) [ set pcolor grey ] ]
ask patches [ if (pycor = 4) and (pxcor > 3 ) [ set pcolor grey ] ]
ask patches [ if (pycor = -6) and (pxcor > 7 ) [ set pcolor grey ] ]
; to define road patches (vertical)
ask patches [ if (pycor > 0) and (pxcor = -10 ) [ set pcolor grey ] ]
ask patches [ if (pycor > 0) and (pxcor = -5 ) [ set pcolor grey ] ]
ask patches [ if (pycor < 0) and (pxcor = -7 ) [ set pcolor grey ] ]
ask patches [ if (pycor < 0) and (pxcor = -3 ) [ set pcolor grey ] ]
ask patches [ if (pycor < -3) and (pxcor = 4 ) [ set pcolor grey ] ]
ask patches [ if (pycor > 3) and (pxcor = 4 ) [ set pcolor grey ] ]
ask patches [ if (pycor > 0) and (pxcor = 7 ) [ set pcolor grey ] ]
; to define nodes as patches
ask patches [ if pxcor = 0 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = 7 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = -3 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = -5 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = -7 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = -10 and pycor = 0 [ set pcolor red ] ]
ask patches [ if pxcor = 4 and pycor = 4 [ set pcolor red ] ]
ask patches [ if pxcor = 7 and pycor = 4 [ set pcolor red ] ]
ask patches [ if pxcor = 7 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = 4 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = 0 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = -5 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = -10 and pycor = 9 [ set pcolor red ] ]
ask patches [ if pxcor = -10 and pycor = 6 [ set pcolor red ] ]
ask patches [ if pxcor = -10 and pycor = 3 [ set pcolor red ] ]
ask patches [ if pxcor = -5 and pycor = 6 [ set pcolor red ] ]
ask patches [ if pxcor = -5 and pycor = 3 [ set pcolor red ] ]
; to set intial values of properties for patches
ask patches with [pcolor = yellow] [ set a random-float 0.9] ; initial a
ask patches with [pcolor = yellow] [ set b random-float 0.9] ; initial b
ask patches with [pcolor = grey] [ set c random-float 0.9] ; initial c
ask patches with [pcolor = red] [ set d' random-float 0.9] ; initial d'
ask patches with [pcolor = grey] [ set e' random-float 0.9] ; initial e'
end
to go
tick
if ticks >= 52 [ stop ]
ask patches with [pcolor = yellow]
[
let fc [c] of one-of neighbors with [pcolor = grey] ; reports c of any
one grey patch of neighbours
let fe' [e'] of one-of neighbors with [pcolor = grey] ; reports e' of any one grey patch of neighbours
let fd' [d'] of one-of neighbors with [pcolor = red]; reports d' of any one red patch of neighbours
if a < 0.1 [ set a 0.1
if a > 0.9 [ set a 0.9 ] ]
if b < 0.9 [ set b b + (k * a) + (k * fc) + (k * fd')
if b > 0.9 [ set b 0.9 ] ]
if b > 0.1 [ set b b - (k * fe')
if b < 0.1 [ set b 0.1 ] ]
]
end

I am guessing that the part of the code throwing the error is (for future reference, it is helpful if you try to focus on the part of the code that is causing the problem):
ask patches with [pcolor = yellow]
[ let fc [c] of one-of neighbors with [pcolor = grey]
let fe' [e'] of one-of neighbors with [pcolor = grey]
let fd' [d'] of one-of neighbors with [pcolor = red]
...
]
end
The primitive you want is any?. So you could rewrite:
let fc [c] of one-of neighbors with [pcolor = grey]
as
let greys neighbors with [pcolor = grey]
let fc 0.1
if any? greys
[ set fc [c] of one-of greys ]
Alternatively
let greys neighbors with [pcolor = grey]
let fc ifelse-value any? greys
[ [c] of one-of greys ]
[ 0.1 ]
Note that neither of these pieces of code is tested.

Related

Graphviz dot-file crazy edge positioning

I have a problem with the positions of the edges in my dot-file.
In the dot-file I used contrainsts=false to exclude the edges m and l from the ranking and gave it some headport and tailport (with pygraphviz: headport='e', tailport='e'.
They got a crazy shape. I want to have them on the right side of the nodes.
This is the dot-file:
strict digraph "" {
graph [bb="0,0,717.03,767.02",
edges="{'arrowsize': '4.0'}",
rankdir=LR,
size="100,100",
];
cen0
[height=0.5,
label=a,
rank=0,
];
3 [
label=b,
rank=1,
];
cen0 -> 3
[label=z,
pos=e];
0
[label=c,
rank=1,
];
cen0 -> 0
[label=z,
pos=e];
cor22
[label=d,
rank=2,
];
3 -> cor22
[label=2,
pos=e];
con23
[label=e,
rank=2,
];
3 -> con23
[label=1,
];
cor2
[label=g,
rank=2,
];
0 -> cor2
[label=4];
con4
[label=h,
rank=2,
];
0 -> con4
[label=3];
1
[label="Why I can't delete the attribute 'width'
from this node?:
Warning: Unable to reclaim box space in spline
routing for edge \"con4\" ->\"con23\". Something is
probably seriously wrong.
",
rank=2,
width=2.5731];
0 -> 1
[label=k];
cor2:e -> cor22:e
[constraint=false,
rank=3
label=l];
con4:e -> con23:e
[constraint=false,
rank=3
label="Why this way?"];
}
I also wondered about why there comes that warning, when I delete the one last "width"-attribute.
How could I get my edges in the way, I expected?
This is probably an automatically generated product with a lot of "noise" - I have taken the liberty to almost completely re-write the code, to make it easier for me to work and test, and to concentrate on the essentials. You will add what is important for you back in and find out whether or not some of that breaks it.
With a good amount of trial and error, I found four major changes necessary:
The four third level nodes need to be in the same rank (rank = 3 does not help)
They need to be connected in the desired order by invisible edges
The edges between these nodes need to maintain the right hierarchical level, with the arrow pointing backwards
xlabels rather than labels need to be used for the edges
So here my largely edited code
digraph so
{
rankdir = LR;
// edge[ arrowsize = 4 ]; // you don't want that
cen0[ label = "a" ];
3 [ label = "b" ];
0 [ label = "c" ];
cen0 -> { 3 0 }[ label = "z" ];
cor22[ label = "d" ];
con23[ label = "e" ];
3 -> cor22[ label = "2" ];
3 -> con23[ label = "1" ];
cor2[ label = "g" ];
con4[ label = "h" ];
1 [ label = "Why I can't delete the attribute 'width' from this node?:\nWarning: Unable to reclaim box space in spline routing for edge \"con4\" ->\"con23\".\nSomething is probably seriously wrong.\n--- Width attribute not present here! ---" ];
0 -> cor2[ label = "4"];
0 -> con4[ label = "3" ];
0 -> 1[ label = "k" ];
{rank = same; cor22 con23 cor2 con4 1 }
cor22 -> con23 -> cor2 -> con4[ style = invis ]
cor22:e -> cor2:e[ dir = back, xlabel = " l" ];
con23:e -> con4:e[ dir = back, xlabel = " Is this better?" ];
}
and here is the result:
The missing attribute is splines=curved, added to my graphviz code gives:

Collect puzzle from curve fragments

I have a data, which consists of a number of chunks. I now that they come from some continuous curve, but later were shifted in the y-direction. Now I want to shift them back to estimate original curve. Some parts are not shifted, but just absent. To clarify the situation dummy code to generate something similar is below (Matlab):
%% generate some dummy data
knots = rand(10,2);
% fix starting and stop points
knots = [[0,rand()];knots;[1,rand()]];
% sort knots
knots=unique(knots,'rows');
% generate dummy curve
dummyX = linspace(0,1,10^4);
dummyY = interp1(knots(:,1),knots(:,2),dummyX,'spline');
figure()
subplot(2,1,1)
plot(dummyX,dummyY)
%% Add offset and wipe some parts
% get borders of chunks
borders = [1;randi([1,numel(dummyX)],20,1);numel(dummyX)];
borders = unique(borders);
borders = [borders(1:end-1)+1,borders(2:end)];
borders(1) = 1;
% add ofsets or nans
offset = (rand(size(borders,1),1)-0.5)*5;
offset(randperm(numel(offset),floor(size(borders,1)/3)))=nan;
for iBorder = 1:size(borders,1)
idx = borders(iBorder,1): borders(iBorder,2);
dummyY(idx)=dummyY(idx)+offset(iBorder);
dummyY(idx([1,end]))=nan;
end
subplot(2,1,2)
plot(dummyX,dummyY)
Original curve is on top, shifted on the bottom. I try to shift chunks pairwise, minimizing the length of the cubic spline, but it did not work for me. I understand, that it is impossible to obtain absolutely same curve (I may lose some peaks).
Could You help me to find the best shifts?
I had several ideas for this and played with overall curvature, arc length, etc. as well as mixed combinations. Turned out that a simple chi**2 works best. So it goes as simple as this:
Get some knots to fit every chunk with a given precision by splines
join everything
reduce knots to avoid very close knots in touching sets, those can result in large curvature.
use leastsq fit on entire set with splines on joined and reduced set of knots to find shifts.
In theory one could play with / modify:
spline order
min knot density
max knot density
how adjacent sets are dealt with
adding a knot to a large gap
etc.
(Note: In some random data the splrev produced error messages. As those are mostly not very helpful, I can only say that this code is not 100% robust.)
Code is as follows
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import interp1d, splrep, splev
from scipy.optimize import fmin, leastsq
def reduce_knots( inList, dist ):
outList=[]
addList=[]
for i in inList:
try:
if abs( i - addList[ -1 ] ) < dist:
addList += [ i ]
else:
outList += [ addList ]
addList = [ i ]
except IndexError:### basically the first
addList = [ i]
outList += [ addList ]
return [ sum( x ) / len( x ) for x in outList ]
def adaptive_knots( inX, inY, thresh=.005 ):
ll = len( inX )
sup = ll - 4
assert sup > 3
nN = 3
test = True
while test:
testknots = np.linspace( 1, len( inX ) - 2, nN, dtype=np.int )
testknots = [ inX[ x ] for x in testknots ]
myTCK= splrep( inX , inY, t=testknots )
newY = splev( inX , myTCK )
chi2 = np.sum( ( newY - inY )**2 ) / ll
if chi2 > thresh:
nN += 1
if nN > sup:
test = False
else:
test = False
return testknots
def global_residuals( shiftList, xBlocks, yBlocks, allTheKnots ):# everything shifted (1 is redundant by global offset) Blocks must be ordered an np.arrays
localYBlocks = [ s + yList for s, yList in zip( shiftList, yBlocks ) ]
allTheX = np.concatenate( xBlocks )
allTheY = np.concatenate( localYBlocks )
tck = splrep( allTheX, allTheY, t=allTheKnots )
yList = splev( allTheX, tck )
diff = yList - allTheY
return diff
#~ np.random.seed( 28561 )
np.random.seed( 5561 )
#~ np.random.seed( 733437 )
### python way for test data
knots = np.random.rand( 8, 2 )
knots = np.array( sorted( [ [ 0, np.random.rand() ] ] + list( knots ) + [ [ 1, np.random.rand() ] ], key=lambda x: x[ 0 ] ) )
dummyX = np.linspace( 0, 1, 3e4 )
f = interp1d( knots[ :, 0 ], knots[ :, 1 ], 'cubic' )
dummyY = np.fromiter( ( f( x ) for x in dummyX ), np.float )
chunk = np.append( [ 0 ], np.append( np.sort( np.random.randint( 7, high=len( dummyX ) - 10 , size= 10, dtype=np.int ) ), len( dummyX ) ) )
xDataDict = dict()
yDataDict = dict()
allX = np.array( [] )
allY = np.array( [] )
allK = np.array( [] )
allS = []
for i, val in enumerate(chunk[ : -1 ] ):
if np.random.rand() < .75: ## 25% of not appearing
xDataDict[ i ] = dummyX[ val:chunk[ i + 1 ] ]
realShift = 1.5 * ( 1 - 2 * np.random.rand() )
allS += [ realShift ]
yDataDict[ i ] = dummyY[ val:chunk[ i + 1 ] ] + realShift
yDataDict[ i ] = np.fromiter( ( np.random.normal( scale=.05, loc=y ) for y in yDataDict[ i ] ), np.float )
allX = np.append( allX, xDataDict[ i ] )
allY = np.append( allY, yDataDict[ i ] )
### Plotting
fig = plt.figure()
ax = fig.add_subplot( 3, 1, 1 )
ax.plot( knots[ :, 0 ],knots[ :, 1 ], ls='', c='r', marker='o')
ax.plot( dummyX , dummyY, '--' )
for key in xDataDict.keys():
ax.plot(xDataDict[ key ], yDataDict[ key ] )
myKnots = adaptive_knots( xDataDict[ key ], yDataDict[ key ] )
allK = np.append( allK, myKnots )
myTCK = splrep( xDataDict[ key ], yDataDict[ key ], t=myKnots )
ax.plot( xDataDict[ key ], splev( xDataDict[ key ] , myTCK ) )
myTCK = splrep( allX, allY, t=allK )
ax.plot( allX, splev( allX, myTCK ) )
for x in allK:
ax.axvline( x=x, linestyle=':', color='#AAAAAA', linewidth=1 )
### now fitting
myXBlockList = []
myYBlockList = []
for key in sorted( xDataDict.keys() ):
myXBlockList += [ xDataDict[ key ] ]
myYBlockList += [ yDataDict[ key ] ]
#start values
s = [ 0 ]
for i,y in enumerate( myYBlockList[ :-1 ] ):
ds = myYBlockList[ i + 1 ][ 0 ] - y[ -1 ]
s += [ -ds ]
startShift = np.cumsum( s )
allK = reduce_knots( allK, .01 )
sol, ierr = leastsq( global_residuals, x0=startShift, args=( myXBlockList, myYBlockList, allK ), maxfev=10000 )
sol = np.array(sol) - sol[ 0 ]
print "solution: ", -sol
print "real: ", np.array( allS ) - allS[ 0 ]
### Plotting solutions
bx = fig.add_subplot( 3, 1, 3, sharex=ax )
for x, y, s in zip( myXBlockList, myYBlockList, sol ):
bx.plot( x, y + s )
localYBlocks = [ s + yList for s,yList in zip( sol, myYBlockList ) ]
allTheX = np.concatenate( myXBlockList )
allTheY = np.concatenate( localYBlocks )
tck = splrep( allTheX, allTheY, t=allK )
dx = allTheX[ 1 ] - allTheX[ 0 ]
testX = np.arange( allTheX[ 0 ], allTheX[ -1 ], dx )
finalyList = splev( testX, tck)
bx.plot( testX, finalyList , 'k--' )
mean = sum( dummyY ) / len( dummyY ) - sum( finalyList ) / len( finalyList )
bx.plot( dummyX, dummyY - mean, '--' )
for x in allK:
bx.axvline( x=x, linestyle=':', color='#AAAAAA', linewidth=1 )
cx = fig.add_subplot( 3, 1, 2, sharex=ax )
for x, y, s in zip( myXBlockList, myYBlockList, startShift ):
cx.plot( x, y + s )
plt.show()
For small gaps this works nicely on the test data
The upper graph shows the original spline and its knots as red dots. This generated the data. Moreover, it shows the noisy shifted chunks, the initial fitting knots as vertical lines and an according spline fit.
Mid graph shows the chunks shifted by the pre-calculated start values - aligned ends.
Lower graph shows original spline, fitted spline, reduced knot positions, and chunks shifted according to the fit solution.
Naturally, the larger the gaps the more the solution deviates from the original
...but still quite good.

Make multiple turtles move all at the same time

What is the idea of the program: We have watchdogs, sheep, wolves. My sheep are in a ford, the wolves are coming from outside, when entering the ford, watchdogs start moving. Wolves eat sheep, sheep eat grass, watchdogs should scare wolves (not yet implemented).
My problem: All the turtles are moving one at a time.
What I want: I want them to move all at once for every tick.
Code:
breed [sheeps sheep]
breed [wolves wolf]
breed [watchdogs watchdog]
turtles-own [attacked?]
globals [counter
attack
sheep-energy
wolf-energy
grass-counter
lifespan
age
num-attacks
death-countdown]
to set-variables-shapes
set lifespan 365 * 10
set-default-shape sheeps "sheep"
set-default-shape watchdogs "dog"
set-default-shape wolves "wolf"
set sheep-energy 200
set wolf-energy 400
set death-countdown 60
end
to setup
clear-all
set-variables-shapes
create-fold
spawn-animals
reset-ticks
end
to go
ask turtles [
move
]
respawn-grass
ask sheeps [
if ( pcolor != green or pcolor != brown) [
move-to one-of patches with [ pcolor = green or pcolor = brown] ;; If i change this with turn-around (procedure), all sheeps die at once.
]
eat-grass
reproduce
sheep-status
death
show sheep-energy
]
ask wolves [
attack-sheep
if (xcor < 5 and xcor > -14 and ycor < 15 and ycor > -5 ) [
ask watchdogs [
move
if ( pcolor != green or pcolor != brown ) [
move-to one-of patches with [ pcolor = green]
]
]
]
]
tick
end
to create-fold
ask patches [
if (pxcor < 6 and pxcor > -15 and pycor < 16 and pycor > -6)[
set pcolor grey]
if (pxcor < 5 and pxcor > -14 and pycor < 15 and pycor > -5) [
set pcolor green]
]
end
to sheep-status
if (pcolor = brown) [
set sheep-energy sheep-energy - (life-from-food / 2)]
if attacked?
[set color red]
end
to attack-sheep
ask other sheeps in-radius (size)[
set attacked? true
set color red
]
end
to reproduce
if (age = lifespan / 10) [
hatch-sheeps 40 [
hatch-options
]
]
end
to eat-grass
if (pcolor = green)[
set pcolor brown
set sheep-energy sheep-energy + life-from-food
]
end
to respawn-grass
ask patches [
if pcolor = brown [
ifelse grass-counter = 0 [
set pcolor green
set grass-counter grass-respawn-timer
]
[ set grass-counter grass-counter - 1]
]
]
end
to death
sheep-death-timer
if (sheep-energy <= 0)
[die]
;;if (age >= lifespan) [die]
sheep-explode
end
to sheep-death-timer
if (attacked?)[
set death-countdown death-countdown - 1
if (death-countdown <= 30)
[set color black]
if (death-countdown <= 0)
[die]
]
end
to sheep-explode
if (sheep-energy >= 10000)[
hatch-sheeps 20 [
hatch-options]
die
]
end
to hatch-options
set sheep-energy 200
set age 1
set attacked? false
end
to move
fd 1
rt random 90
lt random 90
end
to spawn-animals
create-wolves number-of-wolves [
set color red
setxy 10 -10
set size 1.3
ask patch 10 -10[
Set plabel "Wolves"]
]
create-sheeps number-of-sheeps [
if (pxcor < 5 and pxcor > -14 and pycor < 15 and pycor > -5 )[
setxy -4.5 5]
ask patch -4.5 15 [
Set plabel "Sheeps"]
set color white
set attacked? false
]
create-watchdogs number-of-dogs [
if (pxcor < 5 and pxcor > -14 and pycor < 15 and pycor > -5 )[
setxy -4.5 5
set size 1.3]
set color blue
]
end
to turn-around
fd -1
rt 180
end
There is no such thing as "at the same time" in NetLogo. NetLogo is single-threaded and doesn't support parallel processing.
If all the agents move during the same tick, you can think of that as "at the same time", since it all happened during the course of a tick.
But within a single tick, there is literally no way for agents to move other than one at a time.
You can use
ask-concurrent sheeps [move ]
to make each sheep agent all move at the same time, but it shouldn't matter and they actually don't recommend you use it.

netlogo, ticks is slower if setting a variable

NORMAL TICKS SPEED:
ask turtles with [seated? = 0] [
fd speed
if (pxcor > -5 and pxcor < 10) and (pycor > 5 and pycor < 10) [facexy (87 + random 4) (6 + random 4) fd speed]
if (pxcor > 25 and pxcor < 28) and (pycor > 5 and pycor < 12) [
let choice random 2
fd speed
if choice = 0 [leftbench]
if choice = 1 [facexy 75 (6 + random 5)]
]
if (pxcor > 73 and pxcor < 79) and (pycor > 5 and pycor < 15) [rightbench fd speed]
if pcolor = brown and not any? other turtles-here
[ move-to patch-here
set seated? true
set pcolor orange
]
]
SLOW TICKS SPEED:
ask turtles with [seated? = 0] [
let gate patches with [(pxcor >= 88 and pxcor <= 90) and (pycor >= 5)]
fd speed
if (pxcor > -5 and pxcor < 10) and (pycor > 5 and pycor < 10) [face one-of gate fd speed]
if (pxcor > 25 and pxcor < 28) and (pycor > 5 and pycor < 12) [
let choice random 2
fd speed
if choice = 0 [leftbench]
if choice = 1 [facexy 75 (6 + random 5)]
]
if (pxcor > 73 and pxcor < 79) and (pycor > 5 and pycor < 15) [rightbench fd speed]
if pcolor = brown and not any? other turtles-here
[ move-to patch-here
set seated? true
set pcolor orange
]
]
the problem is, I want to make the speed normal every time I set a variable to make coding a lot easier and more organized.. please help
If you have a chunk of code you want to use twice, put it in a procedure.
Then whenever you need that chunk of code, you don't have to repeat it using copy-and-paste; you just call the procedure.
If the procedure needs to be able to behave a little differently, depending on where it's being used, you might have the procedure take inputs, and then have it inspect those inputs to decide what to do.
See http://ccl.northwestern.edu/netlogo/docs/programming.html#procedures .
I hope this helps? I'm not entirely sure I'm addressing your question, but if I'm not, maybe you can clarify what it is you're trying to do.

How can I get dot to draw connected subgraphs side by side?

This is what the generated graph looks currently:
And here is the code for this:
digraph {
rankdir=TB;
subgraph cluster01 {
label="1.fázis"
aSTART;
node [shape = doublecircle]; a001;
node [shape = ellipse];
aSTART -> a0 [ penwidth = 3 label = "0" ];
a0 -> a00 [ penwidth = 3 label = "0" ];
a00 -> a001 [ penwidth = 3 label = "1" ];
a0 -> aSTART [ label = "1" ];
a00 -> a00 [ label = "0" ];
a001 -> a0 [ label = "0"];
a001 -> aSTART [ label = "1"];
aSTART -> aSTART [ label = "1"];
}
subgraph cluster02
{
label="2.fázis"
bSTART; b1; b11;
node [shape = doublecircle]; b111;
node [shape = ellipse];
bSTART -> b1 [ penwidth = 3 label = "1" ];
b1 -> b11 [ penwidth = 3 label = "1" ];
b11 -> b111 [ penwidth = 3 label = "1" ];
b1 -> bSTART [ label = "0" ];
b11 -> bSTART [ label = "0" ];
b111 -> bSTART [ label = "0"];
bSTART -> bSTART [ label = "0"];
b111 -> b111 [label = "1"];
}
subgraph cluster03
{
label="3.fázis";
cSTART; c0; c1; c01; c10;
node [shape = doublecircle]; c010; c100;
node [shape = ellipse];
cSTART -> c0 [ penwidth = 3 label = "0" ];
c0 -> c01 [ label = "1" ];
c01 -> c010 [ penwidth = 3 label = "0" ];
cSTART -> c1 [ label = "1" ];
c1 -> c10 [ penwidth = 3 label = "0" ];
c10 -> c100 [ label = "0" ];
c0 -> c1 [ penwidth = 3 label = "1" ];
c01 -> c1 [ label = "1" ];
c1 -> c1 [label = "1"];
c10 -> c01 [ penwidth = 3 label = "1"];
c010 -> c100 [penwidth = 3 label = "0"];
c010 -> c01 [label = "1"];
c100 -> c01 [label = "1"];
c100 -> c0 [label = "0"];
}
a001 -> b1 [color = "red" style = "dashed"];
b111 -> c1 [color = "red" style = "dashed"];
}
If I remove the 2 red lines, then it lines up the way I want it to:
How could I make it line up like this and have the two red lines at the same time?
You can add
{
rank=same;
aSTART;
bSTART
cSTART;
}
After your subgraph cluster03. Dot will yield you a warning but draw the way yo want:
D:\Code\funfunfun>dot -Tpng -oso1.png -Gcharset=latin1 so1.dot
Warning: aSTART was already in a rankset, ignored in cluster _anonymous_0
Warning: bSTART was already in a rankset, ignored in cluster _anonymous_0
Warning: cSTART was already in a rankset, ignored in cluster _anonymous_0
Patched graph available here
You should use the constraint=false attribute on the two red edges.
If false, the edge is not used in ranking the nodes.

Resources