AnyLogic - assign number to agent and use it for calculations - variables

I need help programming a process in AnyLogic.
I want to assign a specific number to an Agent (50%=1,20%=2,30%=3). And later I want to use the number to add to a stock.
For example: if the Agent has the number 3 I want the stock (variable) to go down exaclly this amount.
I tried using a Parameter on the Agent, but I am only able to create a string and with that I can't calculate later…
I would be very happy if anyone knows a solution to the Problem! :)

Here is a simple solution for your case:
set the parameter type to "int"
Assign the initial value according to your probabilities, as below. Note that for numbers 2 and 3, it is a relative probability, given that it was not drawing value 1
Each agent instance will draw a number between 1 and 3 now (50% 1, 20% 2 and 30% 3). Then, you can do your stock adjustments with that param

Related

Calculate variable based on values of another variable

I'm learning SPSS for a research methods class but I'm a bit confused on how to enter and define values that represent a meaning after a certain point. For example, the problem I am working on states:
Suppose the following indexed scores represent performance on a new survey meant to understand an individual’s level of depression. Suppose a score of above 20 represents a depressed individual based on the survey design.
Scores: 13.5, 15.7, 14.3, 16.7, 21.2, 20.7, 22.3, 17.4, 16.8, and 12.4
What is the relative frequency of those individuals that represent depressed individuals?
How would one define or make the values over 20 marked as "depressed" to accurately calculate the relative frequency?
Please and thank you!
Picture of the variables and question
You need to calculate a new variable based on the existing one which will have a value of 1 if the original variable is over the threshold, and 0 if not. There are a few ways to do that, this is the simplest one:
compute depressed=(score>-20).
You can now add labels and analyse:
value labels depressed
1 "depressed: score over 20"
0 "score not over 20".
frequencies depressed.

How do I access the nth element in a GAMS set?

I'm trying some alteration to the DICE2013 model. I define a set of a hundred values and want to access one value for each period t. I.e. if t=5, I want GAMS to return the fifth value in the set cereq.
sets t Time periods (5 years per period) / 1*100 /
cereq list of multipliers /v1*v100/
I tried:
cereq(t)$ord((cereq)=t)
but that causes the program to crash.
How do I have to do this?
Many thanks

VLOOKUP two different items, use whichever one has a number

I have a list of financial metrics in column A, rest of the columns are the time periods the financial data is for.
Let's say I'm trying to calculate a ratio, but the financial metrics in A are not entirely unique, in the sense that a metric type may have more than one associated metric depending on how the company reports the metric.
For example, let's say I need Depreciation Expense on the income statement... that item may be reported as Depreciation, or DepreciationAndAmortization, or something else.
Any ideas how the formula in the ratio I'm trying to calculate can lookup the metric in A1, use the number immediately to the right as part of the formula... and if the metric Depreciation for example is 0, it would look for the next one I specify, like DepreciationAndAmortization, and use that one instead as the first one isn't reported.
If I understand correctly, this should do it:
=MAX(INDEX(B:B,MATCH("*depreciation*",A:A,)),INDEX(B:B,MATCH("*depreciation*",A:A,)+MATCH("*depreciation*",INDEX(A:A,1+MATCH("*depreciation*",A:A,)):INDEX(A:A,100+MATCH("*depreciation*",A:A,)),)))
If the alternatives are say in E2 and E3 then:
=MAX(VLOOKUP(E2,A:B,2,0),VLOOKUP(E3,A:B,2,0))
ie try both and take whichever is larger.
About your concern on the answer of Excel Hero that returns Value error, you can use the function "iferror" and returns "0" if the value/date you're looking for isn't available.
=IFERROR(MAX(INDEX(B:B,MATCH("*depreciation*",$A:$A,)),INDEX(B:B,MATCH("*depreciation*",$A:$A,)+MATCH("*depreciation*",INDEX($A:$A,1+MATCH("*depreciation*",$A:$A,)):INDEX($A:$A,100+MATCH("*depreciation*",$A:$A,)),))),0)

Two Dimensional Diagram with aggr function

I'm having a very curious Problem in QlikView.
I have a number of readouts from a Database which show certain amounts of time in a different state.
In that table there are 49 variables that describe the state, there are 7 levels of i.e the SOC and seven states of the Temperature.
i.e the one of the fields could be named: SOC1_T1 or SOC2_T1 and so on...
So what i get is a table full of readouts in which every i have an specific id for the object, the state of the variables and an age. There are multiple entries per Object.
What i want to do is to plot a two dimensional diagram over all the states so i get SOC over Temperatur Histogram(Average of the maximum (or newest) value of every object).
I tried creating to Dynamic (or syntethic) Dimensions (ValueLoop(1,7) and ValueLoop(1,8).
In the formulas i reffered to them with
=If(ValueLoop(1,7) = 1 and ValueLoop(1,8) = 1,
(avg(aggr(FirstSortedValue (SOC1_T1
, -age), id)) * 100))
and created 49 Formulas with each state variable output.
Problem now is:
It only shows the first entry. I can replace the whole expression in the if condition with a specific number (100) and get a result. I also plotted the inner expression into a Listbox and checked wheter the result is not null.
As soon as I delete the aggr function and just take the AVG over everything (which is not what i want). Everything works fine. When i turn back to aggr, only the first one is shown.
Doesnt help by the way when i delete one of the dimensions, this doesnt work one dimensional either.
Any ideas or workarounds?
Greetings
Julian

Qlikview guage chart - static variable

I am looking to create and use a gauge chart, but I am trying to figure how to compare selected vs the complete universe. For example, let's say I want to measure a monthly spending average of one department vs. the spending average of the entire organization. How do I make the organization average the segment marker? or make it a static variable that does not change with the selection?
As is the case with a lot of questions that pop up here, you can use set analysis to achieve this. In you gauge expression you could do something like this:
Assuming you are going to select one or more departments in the current state, you could do
percent_of_total_spending = avg({$}spending)/avg({1}spending)
The {} syntax is used in conjunction with the set identifiers $ and 1 to denote the the set of the current selections and the entire universe respectively. So the above expression will give you the percentage of average organizational spending for whatever departments you have selected.
You can use set modifiers in addition to the set identifiers to further customize what population you are including. See here for more information.
All you need to do is use set analysis and tell the expression what to ignore in the selections box.
Example:
Sum({<Month=, Year=>}Spending)
What the above is telling you is that it's taking the "Month" field and setting the selection for that specific expression to nothing, as well as the "Year" field. If you were to do the following:
Sum({<Month=, Year={"2014"}>}Spending)
It will calculate for that specific year, or even this
Sum({<Month=, Year={"2013","2014"}>}Spending)
Will make it calculate for both 2013 and 2014. Read up on the helpfile as well by pushing F1 and searching for set analysis.
So something like this will work for you
Sum(Spending) / Sum({<Month=, Year=>}Spending)