Reputation: 3
I set up a model with a source that generates cars to enter a parking lot. In the source block I like to use an internal database table for the arrivals based on time stamps. So far I do not have any issues. However I like to make multiple simulation runs with different arrival tables. How can I avoid adjusting the tables and starting all the runs manually (since I must make 180 runs)?
I looked already at "parameter variation experiments" but could not find a solution because there seems to be no way to define a database table as a parameter that could be used and varied in the source block.
Thanks for any help!
Upvotes: 0
Views: 134
Reputation: 3
Thanks a lot for your help! After a lot of thinking and trying I found the following solution that is rather trivial actually:
I created another database table "arrivalsmain" that is emptied at the beginning of every new run. Then - depending an a parameter and by applying the parameter variation - this table is filled by the corresponding database table (e.g. if the parameter equals 10 it is filled from "arrivals10"). The parameter is varied accordingly. Instead of entering different tables "arrivals1", "arrivals2" and so on in the properties for the source the table "arrivalsmain" is entered all the time.
To manage the table contents I simply added some SQL-code in "On startup" for the main agent:
executeStatement("DELETE FROM arrivalsmain");
switch ( Parameter )
{
case 1: executeStatement("INSERT INTO arrivalsmain SELECT * FROM arrivals1 ORDER BY timestamp ASC");
break;
case 2: executeStatement("INSERT INTO arrivalsmain SELECT * FROM arrivals2 ORDER BY timestamp ASC");
break;
[...]
}
I had to use the "executeStatement" because my JAVA knowledge is not very good.
Upvotes: 0
Reputation: 2213
One solution that comes to mind, if you have your data in Excel format, is to use the Excel File element in AnyLogic instead of the database. I am not sure how your different tables are setup, but I am going to assume each table is in a sheet of the same excel file.
That way, you can use the sheet number as a parameter to be used in parameter variation. One example of the syntax is as follows:
excelFile.getCellNumericValue(sheetIndex, rowIndex, columnIndex);
Now the details on how to link the excel data to the arrival of agents will require some creativity. I recommend using the inject function in a user control event. Something similar to the below (where counter
is an int
variable you add to your model):
int n = excelFile.getCellNumericValue(sheetIndex, counter, 2);
source.inject(n);
double nextOccurence =
excelFile.getCellNumericValue(sheetIndex, counter + 1, 3)
-
excelFile.getCellNumericValue(sheetIndex, counter, 3)
;
event.restart( nextOccurence );
counter++;
The above for sure doesn't work because I used some random assumptions (e.g. the column number of where you have the number of arrivals, the column number of where you have the dates, etc.). So you should evaluate the code carefully and tailor it to your case. Also, you may need a different code for the first arrival.
An additional warning is that if your database is huge (i.e. 1000s of rows), using an Excel File will make your model slower.
Upvotes: 0