I have agents population as "MyAgents" and I am trying to update the parameters during the process flow. pic shows that I am updating parameter with value of 1
Then in the below simple function trying to sum it up but it is not giving any value.
I have traced the parameter value in the sink block and it can viewed there but when I am using function to sum up it is giving zero output.
My goal is to update parameters on the entry or exit of block.
Is here a way to manage this?
The problem is that you're updating the parameter once the agent enters the sink. After an agent enters the sink, it will be removed from the population. So the population myAgents will not contain the agent with the updated parameter value and thus the sum will always be zero.
Instead, I would suggest to create a global variable total_amount (e.g. in Main) and change the code "on enter" at the sink to (if the total_amount should be incremented by 1):
total_amount++;
Or if the total_amount should be incremented by a given value:
total_amount += <parameter_value>;
Related
I need to create a Dimension (calculated field) that depends on a filter.
My dataset has four columns: ID (Int), Variable Name (String), Value (Int) and Client ID (String). For each client ID there will be a value for each type of variable.
There are 6 types of Variable Name, and for each row there is unique ID.
I'm using a filter by Variable Name so there is one, and only one variable type available at the same time.
In order to display it in a stacked bar chart by that dimension, I have created this calculation field (In reality if has six IFs, but I'll use just one to illustrated it):
IF ATTR([1 (ML_Output)].[Variable Name])= "Interest Rate" THEN [Interest Rate] END
That way, when the filter is in "Monthly Interest Rate", the ATTR function should show the only type of variable available in the Variable Name field, which would be "Monthly Interest Rate". The problem is that it shows the "Cannot mix aggregate and non-aggregate arguments with this function" error.
I've been trying to solve this with many tutorials, but none of them work for one reason of another.
Any ideas?
EDIT:
PS: The original calculation that was doing what I wanted used a Parameter. However, since parameters won't update automatically when the dataset changes, I can't use it anymore. The original calculation was:
IF [Parameter 1]="Interest Rate" THEN [Interest Rate] END
I need the calculated field as a dimension. So, if I aggregated the result of the calculation, then it would be a measure, and that can't be used to create a stacked bar.
new_Screenshot
Questions revised:
In my model, I have 10000 "Persons" as a type of agents at "Main" level. As shown new_Screenshot, there is a process like the statechart. "variable1" is determined by the process. For example, Person 1 will have 10 for the value of "variable1" while Person 2 will have 100 through the process. My question is how to obtain the values (e.g. Person 1: 10, Person 2: 100,.....Person 10000: 10) in AnyLogic.
Thank you.
previous version: My model has 10000 "Persons" as a type of agents. "Persons" have a statechart and a variable ("variable1" in the Screenshot) obtains a set of different values from the statechart. I am trying to collect all those values from a variable for all 10000 "Persons". How can I do this? I have tried to use traceln but it didn't work because I need the values and not the min, max, average, etc.
Thank you!
Screenshot
So the answer is the following:
If your agent is defined as an agent type, then you can't create a population of 10,000... to create a population of 10,000 you need to create an agent population, so I assume that's what you did, even though you say the opposite.
An element of a population of agents can be accessed the same way as any collection using:
persons.get(N); where N is any integer between 0 and 9999.
If you want to access a variable in that particular agent:
persons.get(N).variable1
I am creating a subscription for a report and want to use the default value for a query based parameter that is time sensitive. My question is, when is the default value set for the parameter? At the moment the subscription is created or executed?
The query based default value is calculated at execution time.
How the default value for parameter is get calculated at execution time? Are you using the cascading parameter?
When you check the subscription setting page, the default value for parameter is the same as the default you set for that parameter in SSDT, and the cascading parameter value will be changed corresponding to the first default parameter value.
I was wondering if there is any way to have a predefined name for behaviorspace result column name, for example if one of the outputs is count agents with [some condition] , instead of Count agents with [some condition] column name be The condition .
Currently I have defined a global variable with my desired column name and I update it at the end of experiment run, but if my experiment ends with an error, I will get zero instead of that variable. Is there any other way for having proper column name?
Thanks :)
Define a procedure:
to-report the-condition
report count agents with [...]
end
then in the BehaviorSpace experiment, change the metric to the-condition.
I am working in Postgres and I need to send in a full result set with many rows and column into a stored procedure or a function. Is this possible? If so, where can I see resources for syntax?
OK this is how I have it set up without being able to send in a result set, it forces me to break out comparison logic and put it in two different spots, however my goal is to keep the actual finding the promotion logic in one place, which I have done here. This may change one day, the comparison logic is less likely to change, it is pretty standard.
Promotion Line Item Logic
-There will be triggers set on INSERT for the promo_objects, promo_buy_objects, and promo_get_objects tables, there will be an UPDATE trigger on the promo table.
-The trigger for the xrefs will call a stored procedure called set_best_product_promos that will decide which promotion is best for that object and it will then save to a new table:
promo_best_product_promos
promo_id,
object_id,
expiration_date
-The trigger for promo will call update_best_product_promos and will send in the promo_id and if active = true it will update the expiration date for that promo else it will delete all entries for that promo
The new table has been added to the promo.sql script, however the triggers and function can not be added until the function is written.
A script will run at midnight every night to delete the entries that have expired.
PSEUDO FOR cart code (application code)
Run the union query just as we are now shown_object_promotions (this gets all available promotions for the item)
Loop through results
if buy_quantity > 0
IF the quantity of the buy item in the cart is greater than or = the buy_quantity (I think c.active_items is the items in the cart)
IF get_quantity > 0
If the get item is in the cart AND it is the item sent into this function (I think c.active_items is the items in the cart)
run the get_best_product_promos function
run comparison logic
else
run the get_best_product_promos function
run comparison logic
EDIT: So I guess I could dump this cart logic as a stored procedure as well, and then make one for the comparison logic, and boom its all in stored procedures and portable and generic?
PSEUDO FOR set_best_product_promos:
-You will send in the object_id and promo_id
-You will declare all of your variables
-Go ahead an query the end date of the promo
-You will then query the promo_best_product_promos table to see if an entry exists for this product
IF exists:
RUN YOUR UNION QUERY accept this time you will have to explicitly say all the fields you want and what variables to select them into
Then loop through your query
LOOP
run get_best_product_promos
run comparison logic
END LOOP
Now take those variables you set in the crazy logic and update promo_best_product_promos
ELSE:
insert the object_id, promo_id, and end date (expiration_date) into the promo_best_product_promos table
PSEUDO FOR get_best_product_promos:
If no buy and no get quantities
If discount type = percent
calculate value of the promotion for this item to compare later
calculate the new price for the product and update the estimated unit price
If discount type = dollar
calculate value of the promotion for this item to compare later
calculate the new price for the product and update the estimated unit price
If discount type = price
calculate value of the promotion for this item to compare later
calculate the new price for the product and update the estimated unit price
If discount amount = Free
do nothing
pass
If buy quantity but no get quantity
If discount type = percent
calculate value of the promotion for this item to compare later
If discount type = dollar
calculate value of the promotion for this item to compare later
If discount type = price
calculate value of the promotion for this item to compare later
If discount amount = Free
do nothing
pass
Else (assumes there is both buy and get)
IF the quantity of the buy item in the cart is >= the buy_quantity (I think c.active_items is the items in the cart)
If discount type = percent
calculate value of the promotion for this item to compare later
If discount type = dollar
calculate value of the promotion for this item to compare later
If discount type = price
calculate value of the promotion for this item to compare later
If discount amount = Free
#Use a different var here like in select_cart_promotion - they will always get this promotion
calculate the value of the promotion for these items
do something here to ensure the get product is in the cart
Take a look at cursors.
Postgres user defined functions can be written in many languages
On the formats of input and output parameters for PL/pgSQL you can check the documentation here
Are you sure that you need to pass this to a function? I believe you could structure your functions to avoid this, functions can return tables and get get tables inside of them. If this table of yours is a query/table/view then you can use SQL inside the function to get to it (passing only parameters of other data type); if this table is the result of another function you can call the function to get to the table. What's your scenario?