Doxygen with Graphviz to document VHDL - doxygen

I don't manage to add a graphviz (#dot) to my doxygen documented VHDL files.
Can somebody provide some example code?
I would like to add fsm graphical representation to my code.
thanks in advance

Just write the dot-file manually:
digraph FSM {
RESET -> IDLE
IDLE -> CALC [label="data_in = '1'"]
CALC -> DONE
DONE -> IDLE
}

comment with --!;
start with #dot and stop with #enddot
Example:
--! #dot
--! digraph finite_state_machine {
--! rankdir=LR;
--! size="8,5"
--! node [shape = circle];
--! S0 -> S1 [ label = "010" ]
--! S1 -> S0 [ label = "000" ]
--! S1 -> S2 [ label = "111" ]
--! S2 -> S0 [ label = "101" ]
--! }
--! #enddot

Related

How to loop in NetLogo?

I have the following problem. I need to loop through the code. However, it doesn't work.
Contextualizing the problem: I have 3 files (in .asc) that represent data referring to 3 ages of the turtles (age 2, age 4 and age 8). I would like if the user puts the value 1 in num-user, it would only do the simulation with only one file (L_2) that would represent [ "2" ] ; if the user puts the value 2 in num-user, he would do the simulation with the files (L_2 and L_4) that would represent [ "2" "4" ] and finally, if the user puts the value 3 in num-use, it would simulate the files (L_2 , L_4 and L_8) that would represent [ "2" "4" "8" ]. The problem is that the loop is not working and gives various errors. Like:
Extension exception: ascii file ./L_8.asc not found or Can't find element 3 of the list [2 4 8], which is only of length 3 or go runs more than 3 simulations.
I was unable to attach the .ascii files here in the question. But if anyone can look at the code and identify the error I would be very grateful. I can't use BehaviouSpace to solve the situation, I need this loop in the code.
Thanks in advance!
extensions [ gis ]
globals [ num turtle-ages num-ages files random-seeds num-user repetitions ]
to setup
ca
set random-seeds 1
random-seed random-seeds
set num 0
set turtle-ages [ "2" "4" "8" ]
set num-ages item num turtle-ages
setup-asc
setup-turtles
reset-ticks
end
to setup-2
clear
random-seed random-seeds
set num-ages item num turtle-ages
setup-asc
setup-turtles
reset-ticks
end
to setup-turtles
ask n-of 5 patches [ sprout 1 ]
end
to clear
set files 0
clear-ticks
clear-turtles
end
to setup-asc
let number1 num-ages
set files gis:load-dataset ( word "./L_" number1 ".asc" ) ;; this loads a one raster file. There are 3 files in the folder with the names: (L_2.asc ; L_4.asc and L_8.asc
end
to go
move
tick
let n count turtles
if n = 0 or ticks = 10
[
set random-seeds random-seeds + 1
set repetitions 1
if random-seeds = repetitions + 1
[
set random-seeds 1
set num num + 1
;; if the user puts the value 1 in num-user, it would only do the simulation with only one file (L_2) that would represent [ "2" ]
;;; if the user puts the value 2 in num-user, he would do the simulation with the files (L_2 and L_4) that would represent [ "2" "4" ]
;;;; and finally, if the user puts the value 3 in num-use, it would simulate the files (L_2 , L_4 and L_8) that would represent [ "2" "4" "8" ]
set num-user 1 ;;
if num = num-user [ stop ]
]
setup-2
]
end
to move
ask turtles [
right random 360
fd 1
if ticks = 5 [ die ]
]
end
Whenever possible, I'd suggest paring down your code to a MRE to a) make sure that users here can run your code (without your files, for example, this is not really viable) and b) to see if reframing your question / goals in simpler terms would help get things working- at least that's what works for me!
I think that you might find foreach useful here as a way to loop through your desired simulations instead of manually tracking the number of iterations. For this example, assuming num-user is a numeric input widget on the interface, the setup below will determine which of the ages to process:
globals [ ages-to-run ]
to base-setup
ca
; Determine how many simulations to run, based on user input into
; 'num-user' numerical input widget on the interface
ifelse num-user < 1 or num-user > 3 [
print "Incorrect number of simulations indicated"
] [
let possible-sims [ "2" "4" "8" ]
set ages-to-run sublist possible-sims 0 num-user
]
reset-ticks
end
After running the above, the ages-to-run variable will contain ["2"], ["2" "4"], or ["2" "4" "8"]. Next, you can iterate over those desired ages to run your simulations (a little more detail in comments):
to run-simulations
if ages-to-run = 0 [
print "Simulation setup not complete"
]
foreach ages-to-run [
; This is the loop proper where each "age" is iterated.
; All of your simulation calls (manual variable resetting,
; etc) should all go within this loop.
current-age ->
print word "Running simulations for age: " current-age
let file-to-load ( word "./L_" current-age ".asc" )
print file-to-load
clear-turtles
ask n-of 5 patches [
sprout 1 [
pd
set color runresult current-age + 55
]
]
repeat 20 [
ask turtles [
rt random 60 - 30
fd 1
]
tick
]
print ( word "Simulations complete for age: " current-age "\n" )
]
end
Running that code above with 3 entered into num-user will run a simulation for each age (different colors indicate different runs):
So to run simulations proper, all your per-age code should go within that foreach loop indicated above- and be careful, as you were in your question, to not reset global variables.

sensitivity analysis (mean of multiple simulations) in netlogo

I have several indexes such as mean and standard deviation of variables.
After 500 ticks, the model stops.
I want to simulate this model, for instance, 100 times and plot the mean and CI of indexes.
Instead of using python or R, is there any way to do this in netlogo?
Yes, you can use BehaviorSpace to run your model 100 times, saving the results you want to a file-system file, then have a different netlogo program ( or proocedure ) read in the data and plot it. Here's a sample writing part that computes mean and standard deviation of a run of numbers and after ten ticks stops.
globals [ delist demean destd fname ]
to setup
clear-all
set fname "myfile.txt"
set delist []
reset-ticks
end
to go
if ( ticks >= 10 ) [
;; show delist
set demean mean delist;
set destd standard-deviation delist;
export-data
;;print (word "mean = " demean " stdev= " destd )
stop
]
set delist lput random 100 delist
tick
end
to export-data
if not (file-exists? fname ) [
file-open fname
file-print ( word "mean stdev" );
file-flush
file-close
]
file-open fname
file-print ( word demean " " destd )
file-flush
file-close
end
to clear-file
if (file-exists? fname ) [
file-delete fname
]
end
here's sample code reading the above myfile.txt in and plotting it.
Assume a plot widget reporting demean and destd
globals [ delist demean destd fname ]
to setup
clear-all
set fname "myfile.txt"
print " This file begins as follows:"
set delist []
ifelse (file-exists? fname ) [
file-open fname
if not file-at-end?
[ let str file-read-line
print str
]
]
[ print " expected file doesn't exits " ]
reset-ticks
end
to go
if file-at-end? [ print "Data has been all read." file-close stop]
set demean file-read
set destd file-read
print (word "mean = " demean " , std-dev = " destd )
tick
end

ITEM expected input to be a string or list but got the number 0 instead error. How would I fix this?

I am trying to make a model in netlogo that can simulate various versions of langton's ant. I have the basic code already (which is not polished up yet, apologies for that). from a chooser in the interface, the user chooses a path that the ant (the turtle) takes, and turns either left or right depending on the color of the patch he is on. to turn the strings in the chooser into a usable code, I am using the following code (only partially included the walk execution, if you want the entire thig
to make-state-sequence
if mychoice = "[own input]"
[
ifelse 2 <= length own-LR-string and length own-LR-string <= 12 and remove "L" remove "R" own-LR-string = ""[
set state-sequence own-LR-string][print "Invalid, can only contain L and R, and must be 2-12 symbols" stop]
] set N length state-sequence
if mychoice = "[Random sequence]"
[
let random-length 2 + random 10
let random-sequence n-values random-length [one-of ["L" "R"]]
set state-sequence random-sequence
]
set N length state-sequence
if table:has-key? instruction-table mychoice [
set state-sequence table:get instruction-table mychoice]
set N length state-sequence
end
to walk
ask turtles [
if bumped? = true [stop]
let direction item [state] of patch-here state-sequence
if direction = "L" [
left 90
]
if direction = "R" [
right 90
]
here, the state-sequence is important; it is the string that is chosen in the chooser used in the interface.
doing this will make the setup button work fine, but using the walk button gives the following error:
ITEM expected input to be a string or list but got the number 0 instead.
I have tried turning the let direction item [state] of patch-here state-sequence portion into an ifelse statement; because if the symbol is not an L, it would automatically be an R. it didn't change the error.
I suspect the state-sequence is not recognised as a string. is there a possible fix for this? I also tried using a to-report in combination with reduce, but we got stuck on that as well.
for good measure, here are some snippets of the widgets in the interface:
the interface
the chooser editor
the info tab, if you would like to see it. has some deeper explanation on how langton's ant works.
As JenB commented above, it seems likely that "state-sequence" for "patch-here" was never initialized or set, so it has defaulted to the number 0.
You could check whether state-sequence was a list or string as the first real step in your ask turtles [ ] section and to throw an informative error if it is not.
Incidentally, your sequence of if-statements in make-state-sequence is a risky coding structure as zero or more than one of the conditions could fire. Possibly in your case zero of them were matched.
;; This structure may fire multiple conditions
;; with later actions possibly overriding earlier actions
;; and has the possibility that none of the conditions are met
;; If TWO conditions are matched, BOTH fire in that order and the SECOND one
;; may overwrite the FIRST one.
( condition1 ) [ action1 ]
( condition2 ) [ action2 ]
;; ...
( conditionn ) [ actionn ]
;; The following structure exits after the first succeessful condition is met.
;; and guarantees that there is always exactly one case matched
;; which might be the default case .
;; if a second condition might have been matched is unknown because the
;; code never gets that far.
;;
;; This is slightly obscurely hidden in the dictionary under "ifelse"
;; and further confused if you believe "choice" is a reserved word or the
;; only way you can test a condition. I tested the following and it works.
(
ifelse
( condition1 ) [ action1 ]
( condition2 ) [ action2 ]
;; ...
( conditionn ) [ actionn ]
;; else
[ default action ]
)
Here's sample code that demonstrates testing what value you have and showing that the zero value resulting from not having set the patches sequence could be detected by the
?is-string and ?is-list tests. It also demonstrates using the CHOICE structure.
patches-own [ x ]
to setup
clear-all
let z n-values 8 [one-of ["L" "R"]]
if is-list? z[ print "it's a list" ]
if is-string? z [ print "it's a string" ]
let a 46
let b 43
let c "dog"
let d "cat"
(
ifelse
( a = 4 ) [ print "a is 4 " ]
( b = 4 ) [ print "b is 4 " ]
( c = "dog" and d = "cat") [ print "strange choice "]
; else
[ print "I fell through to the else condition" ]
)
create-turtles 1
ask turtles [
print ( word "\n x = " x )
print ( word "is x a number? " is-number? x )
print ( word "is x a list? " is-list? x )
print ( word "is x a string? " is-string? x )
]
ask patch 0 0 [ set x n-values 8 [one-of ["L" "R"]]]
ask turtles [
print ( word "\n x = " x )
print ( word "is x a number? " is-number? x )
print ( word "is x a list? " is-list? x )
print ( word "is x a string? " is-string? x )
]
reset-ticks
end

compose and compose/deep for parse rule in red?

How to keep (print text) as it disappears when using compose ?
s: {hello test1 parse test2}
t1: "test1"
t2: "test2"
rule: compose [ thru (t1) mark: copy text to (t2) (print text)]
parse s rule
same question for compose/deep if it's different answer:
s: {hello test1 parse test2. hello second test for test1 parse test2.}
t1: "test1"
t2: "test2"
rule: compose/deep [ any [thru (t1) mark: copy text to (t2) (print text)]]
parse s rule
You aren't limited to what's in the box, so you could make your own COMPOSE-like construct that does other patterns.
For instance, here's a composeII which only substitutes for cases where there are nested parentheses. So it will leave (x) alone but evaluate ((x)).
composeII: function [block /only /deep] [
collect [
foreach item block [
case [
all [
paren? :item
1 = length? item
paren? first item
][
either only [
keep/only do first item
][
keep do first item
]
]
all [
deep
block? :item
][
either only [
keep/only composeII/deep/only item
][
keep/only composeII/deep item
]
]
true [
keep/only :item
]
]
]
]
]
So for your case:
>> t1: "test1"
>> t2: "test2"
>> composeII/deep [
any [thru ((t1)) mark: copy text to ((t2)) (print text)]
]
== [
any [thru "test1" mark: copy text to "test2" (print text)]
]
You can either convert block to paren, or quote paren:
>> compose [something here (to paren! [print text])]
== [something here (print text)]
>> compose [something here (quote (print text))]
== [something here (print text)]
It's the same for compose/deep .
As blocks shield their content from evaluation of compose you can also use
>> rule: compose [ thru (t1) mark: copy text to (t2) (first [(print text)] )]
== [thru "test1" mark: copy text to "test2" (print text)]

Creating and naming links using start and end nodes from .shp file

The attribute table of the .shp file has the following format:
street_name start_node end_node
street_1 A B
street_1 B C
street_2 B D
How could I create links using the start and end nodes and then assign to each link the street name associated with its start and end node. For example, the link with start node A and end node B should get the name "street_1" and the street with start node B and end node D should get the name "street_2".
I used foreach gis:feature-list-of to link the nodes of the dataset but this way I cannot name the links based on their start and end nodes because some of the nodes are shared between street segments.
Many thanks.
Edit:
The columns of the attribute table I am interested in are name1, startNode, and endNode. I have already connected the nodes using the code below and I now have a fully connected road network. I am unsure how I could integrate your code so as the links between the nodes will get the name associated with the combination of nodes that form that link.
foreach gis:feature-list-of roads-dataset [ vector-feature ->
foreach gis:vertex-lists-of vector-feature [ vertex ->
let previous-turtle nobody
foreach vertex [point ->
let location gis:location-of point
if not empty? location
[
let x item 0 location
let y item 1 location
let current-node one-of (turtles-on patch x y) with [ xcor = x and ycor = y ]
if current-node = nobody [
create-nodes 1 [
setxy x y
set size 0.2
set shape "circle"
set color black
set hidden? true
set name gis:property-value vector-feature "name1"
set current-node self
]
]
ask current-node [
if is-turtle? previous-turtle [
create-link-with previous-turtle
]
set previous-turtle self
]
]
]
]
]
Are you saying that your nodes are now correctly named in your model? If that's the case, here's a simplified version of an approach that may work for you. I will note that this is not a very efficient way to go about this as it loops through your links and your attribute table, so if you have many many links it will take a while. To start out with, since I don't have your shapefile, I have made a version of your links example:
extensions [csv]
globals [ whole-file ]
turtles-own [ node ]
links-own [ name ]
to setup
ca
reset-ticks
let names [ "A" "B" "C" "D" ]
let n 0
crt 4 [
setxy random 30 - 15 random 30 - 15
set node item n names
set n n + 1
]
ask turtles with [ node = "A" ] [
create-links-to turtles with [node = "B" ]
]
ask turtles with [ node = "B" ] [
create-links-to turtles with [ node = "C" or node = "D" ]
]
end
That just builds four turtles, with links as indicated in your example shapefile attribute table. I'm using a file called "node_example.csv" that looks like this:
street_name start_node end_node
1 street_1 A B
2 street_1 B C
3 street_2 B D
with four columns, where the first is the observation number.
Essentially, the approach is to iterate through the list and pull out the names of the nodes, from end1 to end2 and vice versa (since both-ends would pull them in a random order), and compare them to each start_node and end_node combination in the table. If they match, assign the street_name from that row to the link with the match:
to link-name
set whole-file csv:from-file "node_example.csv"
foreach sort links [
[ i ] ->
show i
let way-1 list ( [node] of [end1] of i ) ( [node] of [end2] of i )
let way-2 list ( [node] of [end2] of i ) ( [node] of [end1] of i )
foreach whole-file [
[j] ->
if sublist j 2 4 = way-1 or sublist j 2 4 = way-2 [
ask i [
set name item 1 j
]
]
]
]
ask links [
print name
print (word [node] of end1 [node] of end2 )
]
end
Obviously, this is predicated on your nodes being named in your model (in this example, the variable used is node)- if that's not the case this won't work.
Edit 1
Ok, I played around a little using your shapefile. This is not perfect yet, and I can't work on it any more for a while, but maybe it will get you started. Using this setup:
extensions [gis]
breed [ nodes node ]
globals [ roads-dataset ]
turtles-own [ name line-start line-end]
links-own [ lname ]
My idea is to assign the start and end node names to each point along the line feature, so that the links can check against the feature list. More specific notes in comments, but I've basically modified your gis-feature-node code to do that. Play around with it a bit (takes a while to run) and you'll see there are gaps that I haven't quite figured out- maybe you can make progress.
to gis-feature-node
set roads-dataset gis:load-dataset "road_links.shp"
foreach gis:feature-list-of roads-dataset [ vector-feature ->
; First, grab the names of the starting and ending node for the current
; vector feature in order to assign common names to all nodes within
; the feature
let first-vertex gis:property-value vector-feature "startNode"
let last-vertex gis:property-value vector-feature "endNode"
foreach gis:vertex-lists-of vector-feature [ vertex ->
let previous-turtle nobody
foreach vertex [ point ->
let location gis:location-of point
if not empty? location
[
let x item 0 location
let y item 1 location
let current-node one-of (turtles-on patch x y) with [ xcor = x and ycor = y ]
if current-node = nobody [
create-nodes 1 [
setxy x y
set size 0.05
set shape "circle"
set color white
set hidden? false
set name gis:property-value vector-feature "name1"
; Here you assign the first-vertex and last-vertex of the entire line
; to each node
set line-start first-vertex
set line-end last-vertex
set current-node self
]
]
ask current-node [
if is-turtle? previous-turtle [
create-link-with previous-turtle
]
set previous-turtle self
]
]
]
]
]
ask links [
;; Here is a major slowdown- reiterate through the entire roads-dataset
; and, if the names in "startNode" and "endNode" match, assign the
; value from "name1" to the link currently being created.
let way-1 list [line-start] of end1 [line-end] of end2
let way-2 list [line-end] of end1 [line-start] of end2
foreach gis:feature-list-of roads-dataset [ vector-feature-sub ->
let vector-start gis:property-value vector-feature-sub "startNode"
let vector-end gis:property-value vector-feature-sub "endNode"
let start-end list vector-start vector-end
if way-1 = start-end or way-2 = start-end [
set lname gis:property-value vector-feature-sub "name1"
]
]
]
ask links with [ lname = "Hamilton Place" ] [
set color red
set thickness 0.2
]
ask links with [ lname = "Whitcomb Street" ] [
set color yellow
set thickness 0.2
]
end
EDIT 2
The code below is tested and works - problem sorted.
ask links [
set is-road? true
;; Here is a major slowdown- reiterate through the entire roads-dataset
; and, if the names in "startNode" and "endNode" match, assign the
; value from "name1" to the link currently being created.
let way-1 list [line-start] of end1 [line-end] of end2
let way-2 list [line-end] of end1 [line-start] of end2
let way-3 list [ line-start ] of end1 [ line-end ] of end1
let way-4 list [ line-start ] of end2 [ line-end ] of end2
foreach gis:feature-list-of roads-dataset [ vector-feature-sub ->
let vector-start gis:property-value vector-feature-sub "startNode"
let vector-end gis:property-value vector-feature-sub "endNode"
let start-end list vector-start vector-end
let end-start list vector-end vector-start
if way-1 = start-end or way-2 = start-end or way-3 = start-end or way-4 = start-end [
set lname gis:property-value vector-feature-sub "name1"
]
]
]