I have a model that outputs 5 different plots. I will run the model 100 times and need one single csv file containing all results of one of the plots. Using behaviourSpace outputs 100 separated files with irrelevant data like "color", "pen down?", "current pen", etc. so merging and cleaning them is time-consuming. I have read that csv and array extensions can be used but don't know how to properly use them to solve this issue. Thanks in advance for any help.
Related
Dear Anylogic Community,
I am struggling with finding the right approach for storing my simulation results. I have datasets created that keep track of every value I am interested in. They live in Main (see below)
My aim is to do a parameter variation experiment. In every run, I change the value for p_nDrones (see below)
After the experiment, I would like to store all the datasets in one excel sheet.
However, when I do the parameter variation experiment and afterwards check the log of the dataset (datasets_log), the changed values do not even show up (2 is the value I did set up in the normal simulation).
Now my question. Do I need to create another type of dataset if I want to track the values that are produced in the experiments? Why are they not stored after executing the experiment?
I really would appreciate if someone could share the best way to set up this export of experiment results. I would like to store the whole time series for every dataset.
Thank you!
Best option would be to write the outputs to some external file at the end of each model run.
If you want to use Excel, which I personally would not advise, even though it has a nice excelFile.writeDataSet() function, you can.
I would rather write the data to a text file as you will have much for control over the writing, the file itself, it is thread-safe, and useable in many many more platforms than Microsoft Excel.
See my example below:
Setup parameters in your model that you will write the data to at the end of the model of type TextFile. Here I used the model on destroy code to write out the data from the data sets.
Here you can immediately see the benefit of using the text file! You can add the number of drones we are simulating (or scenario name or any other parameter) in a column, whereas with Excel this would be a pain...
Now you can pass your specific text file to the model to use by adding it to the parameter variation page, providing it to the model through the parameters.
You will see that I also set up some headers for the text file in the Initial Experiment setup part, and then at the very end of the experiment, I close the text files in the After experiment section so that the text files can be used.
Here is the result if you simply right-click on the text files and open them in Excel. (Excel will always have a purpose, even if it is just to open text files ;-) )
I have been struggling with this issue for a few days now and I decided to see if someone more experienced could help me out. I am currently developing a data analysis program designed to load and manipulate various data files. I have 3 folders each with 1 type of 30 files, represented by trial_001...trial_30, trial_n3d_001...trial_n3d_030, and trial_com_n3d_001...trial_com_n3d_030. These files are similar but possess differences in terms of types of data as well as total number of data columns and rows. Currently, the portion of my code for loading the data looks like this:
cd = dir('*.csv');
n = length(cd);
data = cell(1,n);
for files = 1 : n %For the first file up to the total amount of files
data(files) = csvread(cd(files).name); %Read in csv files
endfor
data = cell2mat(data); %Create single large dataset
This is successful in looping through my current working directory and obtaining all files and then inputting them into a single large dataset which is intended. I am able to perform all of my calculations. The problem is that I cannot seem to specify subfolders with this method, rather it only works if I manually load directly from one of the folders. I need the program to work on multiple computers and I would prefer if I did not have to set the loadpath within the code each time and simply use the path I choose manually when starting octave in the file browser and instead specify generic folder names.
So my question is how do I do exactly what I am doing currently but from the previous folder containing all three folders and their respective files, and search each of these folders at different points in my code? I want my data variable to act as a working dataset, and load in each of the three types of files at different times and perform different calculations (effectively resetting that data variable after loading all files from each folder and performing calculations). I have tried addpath, genpath, etc. as well as manipulating the common directory and creating variables representing each folders location but I cannot seem to get it to work. Any suggestions?
I am simultaneously running a model with different input values and it is producing different output on each run. I am trying to create a code that will get anylogic to wright each experiment output run in a different cell in excel sheet i.e. throughput Vs. Time. I am using dataset. Wondering If there is any script or hint can help in solving the issue?
Currently I am using the following commands. They keep overwriting the output using the same cells.
Out_excelFile1.setCellValue("Sink1 Out",2,2,2);
Out_excelFile1.writeDataSet(Sink1_D,2,3,2);
Best if you actually use the build-in database for outputs and only write to Excel at the end of all runs, tbh.
But in your case, you need to change the row number by your replication/iteration number. Use getCurrentIteration() or getCurrentReplication() in your "after simulation run" or "after replication" or "after iteration" experiment code sections to get this right.
Then, it would look something like Out_excelFile1.setCellValue("Sink1 Out",2,getCurrentIteration(),2);
(Details depend on your actual implementation, check the help for further info on replications, iterations and those functions)
I have a number of excel files where there is a line of text (and blank row) above the header row for the table.
What would be the best way to process the file so I can extract the text from that row AND include it as a column when appending multiple files? Is it possible without having to process each file twice?
Example
This file was created on machine A on 01/02/2013
Task|Quantity|ErrorRate
0102|4550|6 per minute
0103|4004|5 per minute
And end up with the data from multiple similar files
Task|Quantity|ErrorRate|Machine|Date
0102|4550|6 per minute|machine A|01/02/2013
0103|4004|5 per minute|machine A|01/02/2013
0467|1264|2 per minute|machine D|02/02/2013
I put together a small, crude sample of how it can be done. I call it crude because a. it is not dynamic, you can add more files to process but you need to know how many files in advance of building your job, and b. it shows the basic concept, but would require more work to suite your needs. For example, in my test files I simply have "MachineA" or "MachineB" in the first line. You will need to parse that data out to obtain the machine name and the date.
But here is how may sample works. Each Excel is setup as two inputs. For the header the tFileInput_Excel is configured to read only the first line while the body tFileInput_Excel is configured to start reading at line 4.
In the tMap they are combined (not joined) into the output schema. This is done for the Machine A Excel and Machine B excels, then those tMaps are combined with a tUnite for the final output.
As you can see in the log row the data is combined and includes the header info.
My question has 2 parts.
Part 1:
I have 3 Excel files each with multiple sheets. I have loaded all files with sheets into the matlab using a small code. The files are loaded in a structured form. i.e. One main structure and 3 files as a seperate fields with multiple sheets as a value.
Part 2:
Now I have another seperate excel file having a single sheet with a single column. The col of this excel file has entries(or values/names) which are linked to each file of part one. In other words each excel file of part 1 is a data of each entry of a column of excel file in part 2.
Now my problem is that I want to link both of them. This is important because in further processes I want my program to run in a way that when I specify the value or tell the entry from excel file of part 2 it takes corresponding data from excel file of part 1. Is there any way of doing it?
This block diagram may be helpful to understand what I mean. BLock Diagram