Save density map and flow counters
Save density map and flow counters
Hello,
I wanted to know if it's possible to record data of density and flow counters automatically after each simulation.
More specifically I want to run a scenario with a high number of replications (few thousands), is it possible to store the data in an excel file for each run without doing it one by one?
And if it's possible how can I do this ?
Thank you in advance for your help
I wanted to know if it's possible to record data of density and flow counters automatically after each simulation.
More specifically I want to run a scenario with a high number of replications (few thousands), is it possible to store the data in an excel file for each run without doing it one by one?
And if it's possible how can I do this ?
Thank you in advance for your help
-
- Posts: 18
- Joined: Monday 28 May, 2018 - 10:44
Re: Save density map and flow counters
Hi Erick,
First of all we would like to sincerely apologise for this late reply. We somehow missed this post.
What you are asking is perfectly possible. I have attached some code in a txt file. The code attaches all the data of all flow counter in the model for all selected scenario’s and replications in the experiment wizard to a text file or to an excel files. You can run the code from the interact (Shift + F6).
Please allow me to further illustrate what the functions do and how to use them. As you know, in Pedestrian Dynamics it’s possible to define a scenario which consists of multiple replications of a Simulation. When you go to the Experiment Wizard in the Simulate tab, you can define and edit your Scenarios. The given code checks in Experiment wizard for which scenarios have been selected to be executed (i.e. 1 in the execute). For these scenarios, the code will write the data for all the Flowcounters defined in the model and it will do so for each of the replications defined per scenario.
To wrap up, please do the follow. Run your experiments. Once you already have the output, select which scenarios you want to create the flowcounter excel or txt file by selecting to execute (1) in the experiment wizard scenario’s tab. Please make sure that the directory specified in each scenario is actually where the output files are located. Then, open the interact (Shift + F6) and copy the code of one of the attached txt files. Run the code. Each excel or txt file will be stored in each replication directory.
Sorry again for the late reply. Please let me know if that is what I provided you is what you were looking for.
Best Regards,
Ignasi
First of all we would like to sincerely apologise for this late reply. We somehow missed this post.
What you are asking is perfectly possible. I have attached some code in a txt file. The code attaches all the data of all flow counter in the model for all selected scenario’s and replications in the experiment wizard to a text file or to an excel files. You can run the code from the interact (Shift + F6).
Please allow me to further illustrate what the functions do and how to use them. As you know, in Pedestrian Dynamics it’s possible to define a scenario which consists of multiple replications of a Simulation. When you go to the Experiment Wizard in the Simulate tab, you can define and edit your Scenarios. The given code checks in Experiment wizard for which scenarios have been selected to be executed (i.e. 1 in the execute). For these scenarios, the code will write the data for all the Flowcounters defined in the model and it will do so for each of the replications defined per scenario.
To wrap up, please do the follow. Run your experiments. Once you already have the output, select which scenarios you want to create the flowcounter excel or txt file by selecting to execute (1) in the experiment wizard scenario’s tab. Please make sure that the directory specified in each scenario is actually where the output files are located. Then, open the interact (Shift + F6) and copy the code of one of the attached txt files. Run the code. Each excel or txt file will be stored in each replication directory.
Sorry again for the late reply. Please let me know if that is what I provided you is what you were looking for.
Best Regards,
Ignasi
- Attachments
-
FlowCountersToTextFile.txt
- (5.34 KiB) Downloaded 729 times
-
FlowCountersToExcelFile.txt
- (7.26 KiB) Downloaded 760 times
Re: Save density map and flow counters
Hi Ignasi,
Thank you for your answer it helped me really much.
I have one more question. In order to perform a sensibility analysis i want to read specific value in a Excel table (xls format or csv), is it possible ?
Best regards,
Erick
Thank you for your answer it helped me really much.
I have one more question. In order to perform a sensibility analysis i want to read specific value in a Excel table (xls format or csv), is it possible ?
Best regards,
Erick
- HarryBunnik
- Posts: 362
- Joined: Monday 07 February, 2011 - 11:22
Re: Save density map and flow counters
Hello Erick,
It is possible to create a link between an Excel file and PD. However, that will involve some additional coding using ActiveX. I am more than happy to show you how you can do this, however, I'm wondering if there is a more user-friendly way of dealing with this.
So perhaps it is a possibility to use a "User table" (under the Ribbon "Modelling")? There you can easily paste the data from Excel and read/write to it. This you then can use within your experimentation using the Experiment wizard.
Perhaps you can give me a bit more information, so I can search for the easiest/fastest solution?
Regards,
Harry
It is possible to create a link between an Excel file and PD. However, that will involve some additional coding using ActiveX. I am more than happy to show you how you can do this, however, I'm wondering if there is a more user-friendly way of dealing with this.
So perhaps it is a possibility to use a "User table" (under the Ribbon "Modelling")? There you can easily paste the data from Excel and read/write to it. This you then can use within your experimentation using the Experiment wizard.
Perhaps you can give me a bit more information, so I can search for the easiest/fastest solution?
Regards,
Harry
Re: Save density map and flow counters
Hello Harry,
Thank you for your interest. I'm generating some initial values in table (like speed for an agent) to run the model with a python program.
So I want to read this values in the table (one row corresponding to sample of different input values (size, speed, creation time...)) to create new sample of input parameter.
Unfortunately i can't generate them with random law in Pedestrian Dynamics, my analysis require to generate my input with my python program.
Best regards,
Erick
Thank you for your interest. I'm generating some initial values in table (like speed for an agent) to run the model with a python program.
So I want to read this values in the table (one row corresponding to sample of different input values (size, speed, creation time...)) to create new sample of input parameter.
Unfortunately i can't generate them with random law in Pedestrian Dynamics, my analysis require to generate my input with my python program.
Best regards,
Erick
- HarryBunnik
- Posts: 362
- Joined: Monday 07 February, 2011 - 11:22
Re: Save density map and flow counters
Hello Erick,
So if I understand correctly, you can't use the random generator that is present in (and forms the basis of) Pedestrian Dynamics but you have to use the Python program to generate these.
And then, as some sort of go-between, you want to use Excel to read these Phyton generated variables into Pedestrian Dynamics?
If that is the case you can use more or less the same code as is already present in the "FlowCountersToExcelFile.txt" that Ignasi provided. In here is already shown how you can create a link to an Excel file and how you can write to it. And reading from it is not that much different.
So that would be the following steps:
Kind regards,
Harry
So if I understand correctly, you can't use the random generator that is present in (and forms the basis of) Pedestrian Dynamics but you have to use the Python program to generate these.
And then, as some sort of go-between, you want to use Excel to read these Phyton generated variables into Pedestrian Dynamics?
If that is the case you can use more or less the same code as is already present in the "FlowCountersToExcelFile.txt" that Ignasi provided. In here is already shown how you can create a link to an Excel file and how you can write to it. And reading from it is not that much different.
So that would be the following steps:
- Make sure that you have a vbOle defined.
- Open the application using the OLE
- Read data from the Excel
- Close Excel when done
- do(
var([strExcelFile], vbString),
var([excelOLE], vbOle),
var([valNrScenarios], vbValue),
excelOLE := 0,
strExcelFile := [Path to your Excel file],
{Check if file is existing, otherwise give an error}
if(
Not(FileExists(strExcelFile)),
do(
Msg(Concat([File: ], strExcelFile, [, does not yet exist!], 3)),
return
),
{**Open existing**}
do(
{** Note that it is necessary for the Ole connection that all "\" in the path are replaced with a double one "\\"! **}
strExcelFile := StringReplace(strExcelFile, [\], [\\], SR_REPLACE_ALL),
excelOLE := CreateOLE([Excel.application]),
Ole(excelOLE, [visible], [1]),
Ole(excelOLE, Concat([WorkBooks.Open(], sbo, strExcelFile, sbc, [)]))
)
),
{Activate sheet}
{**Get data**}
Cell(2, 3, refYourTable) := String(OLE(excelOLE, Concat([ActiveSheet.Cells(], string(6), [,], string(2), [).Value]))),
Cell(3, 3, refYourTable) := String(OLE(excelOLE, Concat([ActiveSheet.Cells(], string(7), [,], string(2), [).Value]))),
{...}
{...}
{**Close and save the workbook**}
Ole(excelOLE, [ActiveWorkbook.Save]),
Ole(excelOLE, [ActiveWorkbook.Saved], True),
Ole(excelOLE, [ActiveWorkbook.Close]),
Ole(excelOLE, [Application.Quit]),
excelOLE := 0
)
Kind regards,
Harry
Re: Save density map and flow counters
Hello Harry,
Thanks for your help but i didn't succed to use this code, but i manage to solve my problem with the creation of 1 file per parameter
Erick
Thanks for your help but i didn't succed to use this code, but i manage to solve my problem with the creation of 1 file per parameter
Erick