Bill Dowd

Greenhorn
+ Follow
since Aug 17, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bill Dowd

I figured out a way around it. Thanks, all!
10 years ago
Hi all,

I'm a relative newcomer to Groovy/Java and have a question about efficiently outputting data to a .csv file. Basically, as my simulation model runs, I save key information in a list. For example, I track tasks undertaken by agents, so I save ID, duration, and action. I end up with a long list that is divisible by 3, but has a number of elements in it. I use the following code to output it into a 3 column csv file:

Essentially, I take the first three elements of my list, create a list that represents a row, add it to a list of maps, and then write to the csv file one row at a time. It produces perfect output, but it takes forever (these lists have thousands of elements in them). It's much faster to just write the original list to CSV, but then I end up with one row rather than a three-column table. I can always process the data in something that I'm more familiar with, like Stata, but I figured I'd ask about more efficient ways to do this. Thanks in advance for your thoughts!

Bill
10 years ago
Hmm, it looks like I got it. If I get the current object and call the maps with respect to that object (i.e., scheduler.schedmaps1) it works. That doesn't make sense, but I'll run with it!
11 years ago
It's driving me insane! I'm pretty new to groovy and programming in general, and I'm writing a simulation model using RePast, which is based on Groovy. I created a map 'schedmap' which has other maps' names as its values:



I also created an empty map called 'schedmaps1'. What follows is troubleshooting code:




I get the following output for lines 2-5 above:



So, for lines 2 and 3, I get the map printed, which is what I want. The problem is that I can't explicitly state that I want schedmaps1, because the map I need will vary from iteration to iteration, so I need to call the correct map from schedmap, based on another object's variables (line 4) or at least allow the spcID (from another class) to dictate the correct map (a la line 5). The funny thing is, I was able to call a map from a map in other code, but I am completely unable to get it to work now. I guess the ultimate question is, in lines 4 and 5, how do I get Groovy to see 'schedmaps1' as a reference instead of as final output?

Many thanks in advance!
11 years ago