I have a *.shp file that I've upload and i'm using as part of my model (calculating shortest paths). This is quite a big shape file with thousands of road links and intersections and bridges represented by nodes. I was hoping to speed up the running of behavior space by not loading this map every time, and so created a separate procedure for loading the map and defining link weights etc. In this procedure I have clear-all - reset ticks so everything is effectively wiped if i load a new map. In the setup i define turtle attributes for each run. Between each run I use clear-all-plots and clear-output, and reset-ticks. When i run this model behavior space starts to run slowly after a few setups, even with a table output. However, if i combine the load-map and setup-files together i.e. the map is load for every new behavior space run, then the speed is maintained throughout.
Example - runs slow, but the maps is not reloaded everytime
to-load-map
Clear-all
... code for loading map
reset-ticks
end
to-setup-model
clear-all-plots
clear-outputs
... code for setting up turtle variables
reset-ticks
end
Example (maintains speed - but has to load map)
To-setup
clear-all
...code for loading map
...code for setting up turtle variables
reset-ticks
end
My question: am i missing something that would help to speed things up while not having to reload the map?
Not knowing anything else about your model, I wonder if you essentially have a "memory leak" with lots of information accumulating in global variables that are not getting purged every time by the to-setup-model procedure. Are there perhaps other global variables you can explicitly reinitialize in to-setup-model that might help free up some of this space? For instance, do you have large tables hanging around between runs that only gain more key-value pairs and never get trimmed back down? Just a thought.
I almost always define a clear-most procedure that clears everything out except the big data I don't want to load/compute every time. Unfortunately, that means I must list the variables to initialize out in detail, but I like to free as much as possible between runs to keep things speedy.
-- Glenn
Related
I'm new to Anylogic and created a simple traffic model. Only use 'carSource', 'CarMoveTo', 'Car Dispose' blocks to set the car routes. But After I ran the model, it worked for a while, then all the cars froze without any error occurring. ’Events‘ panel also stopped. How to solve it?
Most likely your model is running into an infinite loop somewhere in the logic. The first place to check would be all your loops that might become infinite,e.g Do loops, Do-while loops, iterator for loops where you perhaps change the counter variable manually...
If you have the professional version of AnyLogic the best option is to run the model in debug mode until you get this to the point where it freezes and then press pause. You will then see where in the code the model is getting stuck.
If this does not work you might need to start putting traceln in major functions and see ing you can spot the last traceln that gets printed and keep on adding more and more until you can find the point between two traceln where the model freezes
I had the same problem, that after a certain time, all cars froze and there wasn't a signle error.
The problem on my side was that the stop line was too close to the intersection, so I moved it a little bit farther.
I switched gears from yesterday and now have a workable solution to the pairs problem I posted. However, now I am being defeated by the simplest of issues. I keep getting a mixture of errors. 1)Maketerrain is the first module that runs on setup. It errors saying I can't use maketerrain in an observer context because it patch/turtle only. I've never had a module give such an error, and I use modular code-writing routinely. So this is completely flummoxing me. 2)Wherever I put "tick" (end of go, start of go, middle of go, in some other procedure) further breaks the code, with the same error--"tick is observer and thus will not run because this is X context." I have checked brackets and parentheses more than a dozen times--taking a break and coming back at it fresh to see if I missed something. No errors there that I have been able to find. I am using Netlogo 6.1.1. I am now dizzyingly confused.
Rather than post another lengthy set of code at this juncture, I want to take another few cracks at it myself. So I am asking, can anyone possibly offer a principle or two I can use to try to debug this? Like, what establishes context? What can I do to make the context be what I want and not what gets "implied" by earlier commands? How can I use a module in which patches and turtles do something to set themselves up and still have it run on setup? (Note--moving stuff to the interface did not solve the problem.) What sets the "go" procedure context, what should it be to run, and what can someone do to make it be what it needs to be? What do I do to place tick--a command I have never had problems with before--correctly?
I have scoured stackoverflow, netlogo manual pages and programming guide, books I have, and still cannot debug what seems to be a very very very simple issue.
Have a look at the first few lines of the Maketerrain procedure. NetLogo interprets the context from the primitives used. If the first line is something like:
set color red
then NetLogo 'knows' that this is a procedure to be run by turtles (that is, it is turtle context) because only turtles can set color because color is a turtle variable. If, however, it starts:
ask turtles
[ set color red
then it is observer context because the external 'observer' instructs turtles to do things (roughly).
Context is actually an incredibly important concept in NetLogo programming - as you do something like the following, you are constantly changing context:
to demo
ask patches
[ ask one-of turtles-here
[ set color red
]
]
end
It starts in the observer context, then iterates through the patches doing something. In a sense, it is thinking like a patch (and is in patch context). Then you open the next code block with [ and switch to the turtle context so that 'I' (a randomly selected turtle on the current patch) can change colour. Then each ] to end a code block backs out of the layers of context.
My goal is to build a 5x5 grid of images. In the following code, row, col and rowcol were created as variables local to the sprite, and newcol, newrow and cats are global. (By the way, is it possible to tell which variables are local and which are global? It's easy to forget or make mistakes.)
The result is a 5x1 grid only, as seen here.
I am unclear as to the order of execution of these statements. Does when I start as a clone get called before or after add_cat gets called the second time? My tentative conclusion is that it gets called afterwards, yet the clone's global variables seem to contain their values from beforehand instead.
When I attempted to debug it with ask and say and wait commands, the results varied wildly. Adding such pauses in some places fixed the problem completely, resulting in a 5x5 grid. In other places, they caused a 1x5 grid.
The main question is: How to fix this so that it produces a 5x5 grid?
Explanation
Unfortunately, the execution order in Scratch is a little bizarre. Whenever you edit a script (by adding or removing blocks, editing inputs, or dragging the entire script to a new location in the editor), it gets placed at the bottom of the list (so it runs last).
A good way to test this out is to create a blank project with the following scripts:
When you click the green flag, the sprite will either say "script one" or "script two", depending on which runs first. Try clicking and dragging one of the when green flag clicked blocks. The next time you click the green flag, the sprite will say whichever message corresponds to the script you just dragged.
This crazy order can make execution incredibly unpredictable, especially when using clones.
The solution
The only real solution is to write code that has a definite execution order built-in (rather than relying on the whims of the editor). For simpler scripts, this generally means utilizing the broadcast and wait block to run particular events in the necessary order.
For your specific project, I see two main solutions:
Procedural Solution
This is the most straightforward script, and it's probably what I would choose to go with:
(row and col are both sprite-only variables)
Because clones inherit all sprite-only variable values when they are created, each clone will be guaranteed to have the correct row and col when it is created.
Recursive Solution
This solution is a bit harder to understand than the first, so I would probably avoid it unless you're just looking for the novelty:
.nlogo file
I am getting this error while running iterations using behavior space
The tick counter has not been started yet. Use RESET-TICKS.
error while observer running TICKS
called by procedure __EVALUATOR
I am not sure why this is happening. I have included reset-ticks in the "set" routine.
In addition in the behavior space dialog wizard, i also included reset-ticks as the final command to be executed. Yet i am getting this error.
Below is my setup and go code:
to setup
clear-all
setup-citizens
setup-parties
update-support
reset-ticks
end
to go
ask parties [ adapt set my-old-size my-size ]
update-support
election
plot-voter-turnout
plot-volatility
if (Turnout-100%? = false) [plot-citizen-comparison]
tick
end
You are using ticks in your BehaviorSpace experiment's "stop condition", so I think it's nearly certain that's where the "error while observer running TICKS" error must be coming from, given that the stack trace doesn't refer to a procedure name.
Here's my best guess at what's going on here: under some conditions, your setup procedure fails, and therefore never reaches the call to reset-ticks at the end of setup. Then BehaviorSpace tries to run your stop condition, resulting in the error you see.
This guess has some problems:
Why BehaviorSpace would only be showing you the eventual ticks error, and not the error causing setup to fail, I don't know.
I have no idea why your setup procedure would be failing.
Nonetheless, that's the best I can offer you without doing a more in-depth investigation.
I was facing the same issue not too long ago. I'm pretty sure that the issue goes back to how Netlogo shares the global variables/states among the threads. I suspect that one thread starts the go procedure while another thread hasn't called the reset-ticks yet.
A temporary fix to this is to call reset-ticks if it hasn't been called already at the beginning of your go procedure.
carefully [let t ticks][reset-ticks]
For those people who found this question by searching for the error "The tick counter has not been started yet. Use RESET-TICKS." but are not actually using BehaviorSpace - the question (and therefore the accepted answer) does not apply to your situation. Instead, you have almost certainly forgotten to initialise the model before trying to run it, probably by hitting the go button without first hitting the setup button.
The reset-ticks command starts the tick counter (makes the internal clock available) so that the tick command can advance the clock. By convention, a procedure named setup has all the commands to initialise the model, including reset-ticks, creating turtles etc. Similarly, a procedure called go contains all the commands to actually run the model like moving turtles around, including tick. Also by convention, these procedures are run by pressing buttons named setup and go respectively.
I've written some code that has an RTC component in it. It's a bit difficult to do proper emulation of the code because the clock speed is set to 50MHz so to see any 'real time' events take place would take forever. I did try to do simulation for 2 seconds in modelsim but it ended up crashing.
What would be a better way to do it if I don't have an evaluation board to burn and test using scope?
If you could provide a little more specific example of exactly what you're trying to test and what is chewing up your simulation cycles that would be helpful.
In general, if you have a lot of code that you need to test in simulation, it's helpful if you can create testbenches of the sub-modules and test them first. Often, if you simulate at the top (chip) level and try to stimulate sub-modules that are buried deep in the hierarchy of a design, it takes many clock ticks just to get data into and out of the sub-module. If you simulate the sub-module directly you have direct access to the modules I/O and can test the things you want to test in that module in fewer cycles than if you try to get to it from the top level.
If you are trying to test logic that has very deep fifos that you are trying to fill or a specific count of a large counter you're trying to hit, you can either add logic to your code to help create those conditions in fewer cycles (like a load instruction on the counter) or you can force the values of internal signals of your design from the testbench itself.
These are just a couple of general ideas. Again, if you provide more detail about what it is you're simulating there are probably people on this forum that can provide help that is more specific to your problem.
As already mentioned by Ciano, if you provided more information about your design we would be able to give more accurate answer. However, there are several tips that hardware designers should follow, specially for complex system simulation. Some of them (that I mostly use) are listed below:
Hierarchical simulation (as Ciano, already posted): instead of simulating the entire system, try to simulate smaller set of modules.
Selective configuration: most systems require some initialization processes such as reset initialization time, external chips register initialization, etc... Usually for simulation purposes a few of them are not require and you may use a global constant to jump these stages when simulating, like:
constant SIMULATION_ENABLE : STD_LOGIC := '1';
...;
-- in reset condition:
if SIMULATION_ENABLE = '1' then
currentState <= state_executeSystem; -- jump the initialization procedures
else
currentState <= state_initializeSystem;
end if;
Be careful, do not modify your code directly (hard coded). As the system increases, it becomes impossible to remember which parts of it you modified to simulate. Use constants instead, as the above example, to configure modules to simulation profile.
Scaled time/size constants: instead of using (everytime) the real values for time and sizes (such as time event, memory sizes, register file size, etc) use scaled values whenever possible. For example, if you are building a RTC that generates an interrupt to the main system every 60 seconds - scale your constants (if possible) to generate interrupts to about (6ms, 60us). Of course, the scale choice depends on your system. In my designs, I use two global configuration files. One of them I use for simulation and the other for synthesis. Most constant values are scaled down to enable lower simulation time.
Increase the abstraction: for bigger modules it might be useful to create a simplified and more abstract module, acting as a model of your module. For example, if you have a processor that has this RTC (you mentioned) as a peripheral, you may create a simplified module of this RTC. Pretending that you only need the its interrupt you may create a simplified model such as:
constant INTERRUPT_EVENTS array(1 to 2) of time := (
32 ns,
100 ms
);
process
for i in 1 to INTERRUPT_EVENTS'length loop
rtcInterrupt <= '0';
wait for INTERRUPT_EVENTS(i);
rtcInterrupt <= '1';
wait for clk = '1' and clk'event
end for
wait;
end process;