NetLogo: Model gets stuck w no error message - runtime-error

I try to make a bunch of turtles (Movers) to go trough a gate and avoid the wall which is white. Somehow the model freezes after a few runs. Go button stays black and blue circle turns for ever. No error MSG given. It must get stuck in some calculation within the "move-movers" function but I can't determine why.
I added a simplified version of my code which still produces the crash. Copy & paste to run. Disable world wrap. Include a slider for "num-movers" Variable.
breed [ movers mover ]
movers-own [ steps ] ; Steps will be used to determine if an agent has moved.
to setup
clear-all
reset-ticks
ask patches [ set pcolor green ]
basic-pattern
end
to basic-pattern ; sets up gate and wall
let wallXCor 16 ; sets a white line to determine the inside & outside of the gate
repeat 33 [
ask patch wallXCor 0 [ set pcolor white ]
set wallXCor wallXCor - 1
]
ask patches with [ pycor > 0 ] [ set pcolor lime ] ; sets the outside of the gate to another color (lime)
; changes color of the center to lime to create a passable opening
ask patch 0 0 [ set pcolor lime ]
ask patch 1 0 [ set pcolor lime ]
ask patch -1 0 [ set pcolor lime ]
end
to distribute-agents ; Distributes the Movers outside the gate based on the patch color lime. The number needs to be set via slider "num-movers"
repeat num-movers [
ask one-of patches with [ pcolor = lime and pycor > 2 and any? turtles-here = false ] [
sprout-movers 1 [ set color red set shape "circle" facexy 0 -12 ] set num-movers num-movers- 1 ]
] end
to go
move-movers
tick
end
to move-movers ; reset the steps variable and facing
ask movers [ set steps steps + 1 ]
ask movers [ facexy 0 -3 ]
; following lines checks if next patch to be steped upon is "legal".
while [ any? movers with [ steps > 0 ] ] [
ask movers with [ steps > 0 ] [
ifelse is-patch? patch-ahead 1
and not any? turtles-on patch-ahead 1
and [ not member? pcolor [ white brown ] ] of patch-ahead 1
[
fd 1
set steps steps - 1
] [ dirchange ]
]
]
end
to dirchange ;If not able to move to next patch change direction to allow a step backwards.
if ( pxcor <= 0 and ycor >= 0 ) [ facexy 1 3 ] ;fd 1 set steps steps - 1]
if ( pxcor >= 0 and ycor >= 0 ) [ facexy -1 3 ] ;fd 1 set steps steps - 1]
end

You're not getting an error message, because there is no actual error. The code just gets stuck in your while loop.
Did you mean to comment out the fd 1 set steps steps - 1 in your dirchange? My guess is that you have a bunch of turtles that face the same patch (either 1,3 or -1, 3) and get stuck because none of them can move because another turtle is in front of them. And because you only subtract from their steps if they actually move, some of them never get to 0 steps.
While is in general a bad primitive to use for this reason, especially when you have this many conditionals in your move code, making it hard to know what is causing your while loop to not end. is it because your turtles are facing a wall, or because they are at the boundary of the world, or because someone else is blocking their path? You just don't know, and because the code is stuck in a loop, your model view doesn't update so you can't see what is going on.
If you insist on keeping the while, I would at least put in a safeguard: write a turtle reporter that checks if your turtles are able to move and break your while if they can't, or give them a finite number of attempts at moving, rather requiring them to have actually moved.

Related

How to estimate current cost for logging?

Brand new to DataDog. I'm disappointed that my "usage" console doesn't give any indication of how much money I'm spending. So, I'm trying to create a dashboard. Right now I'm trying to simply show how much we are paying for logs this month.
I have the "sum of logs in bytes" (I think) but I'm having trouble converting that to $. This is due to my weakness in math as well as my lack of understanding of the DataDog interface. Below is my current effort. I'm dividing by 1024 three times to convert GB, then dividing by 10 (because you can't multiply by .10) to adjust for the 10 cents per gigabyte and hopefully end up with price per byte. The result is 2.05e-3 and I obviously have zero confidence that this is right.
{
"viz": "query_value",
"requests": [
{
"formulas": [
{
"formula": "(query1 / 1024 / 1024 / 1024) / 10"
}
],
"response_format": "scalar",
"queries": [
{
"data_source": "metrics",
"name": "query1",
"query": "sum:datadog.estimated_usage.logs.ingested_bytes{*}.as_count()",
"aggregator": "sum"
}
]
}
],
"autoscale": true,
"precision": 2,
"timeseries_background": {
"type": "bars"
}
}
So I did some simple math in my head.
if 1GB = 10 cents then 100MB = 1 cent and 10MB = .1 cent.
So the 21MB of logs I have should be costing .21 cents.
Working backwards from the answer, I came up with this formula:
"clamp_min((query1 / 1024 / 1024 / 1024) * 10, 0.1)"
Which results in something that looks right to me:
Note I also used clamp_min to keep it from showing scientific notation when we are very low at the beginning of the month.

Change the length of ContextPre and ContextPost in Quanteda KWIC

Is there a way to increase the number of words appearing before and after the keyword in Quanteda kwic function?
I've tried by changing the numeric value in:
options(width = 200)
but it didn't work.
#KenBenoit
options(width) affects the number of text columns displayed by the R interpreter. You want the window argument to kwic():
> kwic(data_corpus_inaugural, "war against")
contextPre keyword contextPost
[1857-Buchanan, 2933:2934] advantage of the fortune of [ war against ] a sister republic, we
[1901-McKinley, 2284:2285] . We are not waging [ war against ] the inhabitants of the Philippine
[1901-McKinley, 2299:2300] portion of them are making [ war against ] the United States. By
[1901-McKinley, 2413:2414] used when those who make [ war against ] us shall make it no
[1933-Roosevelt, 1851:1852] Executive power to wage a [ war against ] the emergency, as great
> kwic(data_corpus_inaugural, "war against", window=7)
contextPre keyword contextPost
[1857-Buchanan, 2933:2934] to take advantage of the fortune of [ war against ] a sister republic, we purchased these
[1901-McKinley, 2284:2285] be deceived. We are not waging [ war against ] the inhabitants of the Philippine Islands.
[1901-McKinley, 2299:2300] . A portion of them are making [ war against ] the United States. By far the
[1901-McKinley, 2413:2414] needed or used when those who make [ war against ] us shall make it no more.
[1933-Roosevelt, 1851:1852] - broad Executive power to wage a [ war against ] the emergency, as great as the

unix commands in Informatica command task - what am I missing?

I tried a simple
if [ 1 == 1 ]; then echo "Hi"; fi >>/projects/ods/Chk.txt
included in the command task but it fails with error code 512....
what am I missing here?
An if/fi block cannot redirect output.
use
if [ 1 == 1 ]; then echo "Hi">>/projects/ods/Chk.txt; fi
As you indicate this is a simple test case, if you need output from a larger block of if/the/else/fi or other logic, you can wrap it all in a process group and redirect that output..
{
if [ 1 == 1 ]; then
echo "Hi"
else
echo "nope"
fi
} >>/projects/ods/Chk.txt
Also, it's likely that using == is a problem. Typically you'd use 1 -eq 1 or other constructs like if true ; then, or if you really want good math comparisons, use if (( 1 == 1 )) ; then ..., but older shells may or may not support the (( ... )) test.
IHTH
Found this while searching for some my queries.
you should use create mode instead of append mode. >> does not work, same happened with me. try this , if u are still facing this and needed an answer. :)

Issue using If statments in Unix

I'm new to shell scripting and need some help. I am trying to write a script to bounce some servers and I am having a few issues with my if statements. The First and Second one below is giving me a too many arguments error.
For the first one, I am the variable $jmsProcess is a ps -ef | grep command and I only want to go into the if-statement, if this returns some results. This is the same issue for the second one.
In the Third if-statement I want it to check if either of those variables have the value true but this gives me a
if[ [ false || false ] == true ]: command not found
Error.
#Check the JMS process has been killed
if [ $jmsProcess != null ] # SHOULD THIS BE NULL???
then
echo "JMS Process is still running"
$jmsRunning = "true"
fi
#Check the Bone process has been killed
if [ $boneProcess != null ] # SHOULD THIS BE NULL???
then
echo "B-One Process is still Running"
$boneRunning = "true"
fi
if[ [ $jmsRunning || $boneRunning ] == true ] # CHECK THIS FOR QUOTES
then
# $killProcess
fi
null is not a Bash keyword. If you want to check whether a variable is defined, you can do the following:
if [ "${var+defined}" = defined ]
To check whether it's empty or undefined:
if [ -z "${var-}" ]
We don't know how you're setting any of the variable values, (jmsProcess, boneProcess).
Try surrounding all var values like "$var" (with dbl-quotes) and see if the error messages change.
Also there are numerous syntax issues in code visible above. Hard to tell if it is an artifact of posting here, (The code block feature is pretty robust), so I'm going to comment on what I see wrong.
if[ [ false || false ] == true ]: command not found
There are a lot of issues here: false is an shell command. Try typing it on the command line and then do echo $?. you should see 1. true; echo $? will return 0. But the if statements continue or fall-over to the else block based on the last return code (with some special case exceptions).
Also, I'm guessing you're trying to make some sort of reg exp with [ false || false ] == true. Won't work. see below.
You can set status variables to have the value of false (or true) which will be evaluated correctly by the shell.
Also, if[ will give the 'command not found' msg. So by using vars that have the value false, you can do
Try
jmsRunning=false ; boneRunning=true
if [[ ${jmsRunning} || ${boneRunning} ]] ; then
echo both NOT running
else
echo at least 1 is running
fi
Change both to false to see the message change.
Also, null is just a string in a shell script, you probably mean "".
Finally, var assignments cannot have spaces surrounding the '=' sign AND do not use the '$' char at the front when it is on the left hand side of the statment, i.e.
boneRunning=true
I hope this helps.

Why Rebol engage doesn't work?

I have added keyboard event but none is detected why ?
plot: [
pen green line 5x404 5x440 pen gold fill-pen 0.255.0 box 3x424 7x418 line 10x396 10x422 pen gold fill-pen 0.255.0 box 8x418 12x402 line 15x397 15x436 pen gold fill-pen 255.0.0 box 13x401 17x435 line 20x429 20x447 pen gold fill-pen 255.0.0 box 18x434 22x446 line 25x441 25x464 pen gold fill-pen 255.0.0 box 23x446 27x463 line 30x445 30x493 pen gold fill-pen 255.0.0 box 28x461 32x482 line 35x470 35x504 pen gold fill-pen 255.0.0 box 33x481 37x492 line 40x466 40x498 pen gold fill-pen 0.255.0 box 38x491 42x477
]
grid: [1100 600]
step-grid: 5
max-n-points: (grid/1 / step-grid) - 1
x-axis-border: 20
Y-margin: 10
X0: 5
grid-color: coal
main: layout [
origin 20x0
space 1x1
panel1: box 1100x580 black effect reduce [
'line-pattern 4 4
'grid 30x30 0x0 (grid-color)
'draw plot
] feel [
engage: func [face action event] [
if action = 'down [drag-start: event/offset]
if action = 'up [drag-end: event/offset
scroll-size: to-integer abs ((pick (drag-start - drag-end) 1) / 5)
]
if action = 'key [
probe event/key
either word? event/key [
probe event/key
if (event/key = 'left) [
probe event/key
]
if (event/key = 'right) [
probe event/key
]
][
]
]
]
]
panel2: box 1100x0 black
panel3: box 1100x20 black
]
view main
focus panel1
A: simple, the engage feel only triggers for key events when the face is the focal-face.
here is a partial rewrite of your app (faster and more readable too) which uses a global event handler and 'SWITCHes instead of 'IFs.
The input handler is fed ALL events of ALL windows, and can be used to do global tricks like hotkeys.
obviously, you can improve the event-handler to detect per window, and detect where the mouse is located to only enable keys when appropriate. you could also build an alternate focus tracking that works outside of the usual handling and which doesn't enter the text edit mode.
I added a field above, just so you can experiment with the effect of having a focused face active and how to detect it in your event-handler.
rebol []
plot: []
data: reduce [ ]
refresh: func [/local clr delta prev-pos pos] [
clear plot
prev-pos: 0x300
foreach [clr delta] data [
pos: prev-pos + (delta * 0x1) + 7x0
append plot compose [
pen (clr) line (prev-pos) (pos) fill-pen (clr) pen none circle dot-size (pos)
]
prev-pos: pos
]
show panel1
]
add-data: func [i][loop i [append data reduce [(random white * .85) + (white * .15) (-20 + random 40)]] refresh]
grid: [800 600]
step-grid: 5
max-n-points: (grid/1 / step-grid) - 1
x-axis-border: 20
Y-margin: 10
X0: 5
grid-color: coal
dot-size: 1
; open up console before vid window
prin "!"
main: layout [
origin 20x0
space 1x1
field 800
panel1: box 800x580 black effect [
line-pattern 4 4
grid 30x30 0x0 grid-color
draw plot
] feel [
engage: func [face action event] [
switch action [
down [
drag-start: event/offset
]
up [
drag-end: event/offset
scroll-size: to-integer abs ((pick (drag-start - drag-end) 1) / 5)
]
]
]
]
panel2: box 800x0 black
panel3: box 800x20 black
]
insert-event-func [
either all [
event/type = 'key
none? system/view/focal-face
][
print ["shortcut: " event/key]
switch event/key [
; escape
#"^[" [quit]
; enter/return
#"^M" [print "resampling data" clear data add-data 100]
up [dot-size: dot-size + 1 show panel1]
down [dot-size: dot-size - 1 show panel1]
left [clear skip tail plot -12 clear skip tail data -2 show panel1]
right [add-data 2]
]
none
][
event
]
]
add-data 100
refresh
view main
focus panel1
Note that there is no need to reduce your code block when you use words within. VID automatically resolves word references for you, its a lot easier (and dramatically faster) to make dynamic GUIs once you know this. as a proof, hold down the up or down arrow key, and you'll see the dots resize quite smoothly, even on a full graph.
Also note the return value of event-handler func is the event, if you want view to continue handling the event, or none, if your handler "consumes" the event.
HTH!
I tried insert-event-func with dummy func and my own example above I fail to see why it doesn't work:
plot: [
pen green line 5x404 5x440 pen gold fill-pen 0.255.0 box 3x424 7x418 line 10x396 10x422 pen gold fill-pen 0.255.0 box 8x418 12x402 line 15x397 15x436 pen gold fill-pen 255.0.0 box 13x401 17x435 line 20x429 20x447 pen gold fill-pen 255.0.0 box 18x434 22x446 line 25x441 25x464 pen gold fill-pen 255.0.0 box 23x446 27x463 line 30x445 30x493 pen gold fill-pen 255.0.0 box 28x461 32x482 line 35x470 35x504 pen gold fill-pen 255.0.0 box 33x481 37x492 line 40x466 40x498 pen gold fill-pen 0.255.0 box 38x491 42x477
]
grid: [1100 600]
step-grid: 5
max-n-points: (grid/1 / step-grid) - 1
x-axis-border: 20
Y-margin: 10
X0: 5
grid-color: coal
main: layout [
origin 20x0
space 1x1
panel1: box 1100x580 black effect reduce [
'line-pattern 4 4
'grid 30x30 0x0 (grid-color)
'draw plot
] feel [
engage: func [face action event] [
if action = 'down [drag-start: event/offset]
if action = 'up [drag-end: event/offset
scroll-size: to-integer abs ((pick (drag-start - drag-end) 1) / 5)
]
]
]
panel2: box 1100x0 black
panel3: box 1100x20 black
]
insert-event-func [
either all [
event/type = 'key
none? system/view/focal-face
][
print ["shortcut: " event/key]
switch event/key [
; escape
#"^[" [quit]
; enter/return
#"^M" [print "resampling data" clear data add-data 100]
up [print "up"]
down [print "down"]
left [print "left"]
right [print "right"]
]
none
][
event
]
]
view main
focus panel1

Resources