AnyLogic-how to randomly select agents in a particular state - random

I am new to AnyLogic. I need help on the following issue.
I would like to randomly select agents in a specific state. I would like to set up a parameter for the # of agents selected. For example, I would like to have a random sample of 10 people in illness state. I want to make the # of selection flexible, so I would like to use a parameter to set the # of random sample size, as well.
My vision is to have a slider to change the sample size in Main. I also set up a population called Patient and that will have a state charts includes health state and ill state. Among those who are in ill state, I would like to sample randomly with the number given by the parameter.
Would anyone help me with this?

I would try to make a list of individuals in the State you wanna select and then do a for loop to get the index of X individuals from that List. Where X is how many times the for loop will be executed and can be user-defined.

Related

Webi: On opening, filter data by current user name which can be in or not in a given list (no prompt)

(SAP BusinessObjects BI Platform 4.3 Support Pack 1 Patch 11 Version : 14.3.1.4142.11)
Disclosure: I'm not born english speaking, but if I have understood correctly, we should now use "they", instead of he/she, etc. That is what I did here. Just to be sure no one is confused while reading.
Hi everyone, it's me again for a webi question.
I have this report in which I have data for a group of workers. These data are: their name, when they work, where, which activity they do, etc.
Worker name
Other information
Worker A
...
Worker B
...
...
...
Worker M
...
Worker Z for example is not in the list.
I currently have a filter "name" (multi-list), which allows us to select one or more workers (Worker A, Worker B,...). By default, it shows all data.
There is an auto-refresh on opening.
The function CurrentUser() returns the worker ID, not the name.
Worker name
Worker ID
Worker A
238x01f93
Worker B
4j192h60a
...
...
Worker Z
09ad812jn
I have two kind of user, that can see this report:
A user whose name is present in the list of workers (e.g. Worker A).
A user whose name is not present in the list of workers (e.g. Worker Z).
My goal:
When the user opens the report, the filter "name" is set by default with their name (e.g. Worker A). This way, they see only their data. If they want to see the data of other workers, they can easily change the filter to select other workers (e.g. Worker B and C). It should not be limited.
When the user (Worker Z) opens the report, they see all data. They can naturally use the filter to select only one or a few workers if they want to.
What I did/tried:
I can change things in the view (database), in the universe or/and in the report. I only tried things on the report level, because I could not see any ways to help me solve this on universe or view level. (But I am open to suggestions! :-) )
Create a variable to:
Filter for only current user ID. It worked, but only if the user name was in the list. Another problem is that the workers don't know this user ID and can't work with it.
=CurrentUser()
Search in the list, if the current user ID exists. Does not work. It shows always all data.
If (Pos([Personalnumber];CurrentUser()) > 0) Then CurrentUser() Else [Personalnumber]
Link the current worker ID with their name if they are in the list. It worked well for them, but I could not find a way to have all workers, if the current user name is not in the list.
If (CurrentUser() = [Personalnumber]) Then [Name] Else "All"
I read so many posts, but none for my case. It is often to prevent user to see all the data, which is not what I want. They should be able to see everything, if they want to.
We only want to filter for the current user for performance means and also efficiency. The user does not have to select themselves the right filter and loose time. Most of the time, they only wants to see their data.
Can anyone help me?
Don't hesitate to tell me if something is unclear or missing. :-)
Thanks for your time!

Handling a controlled input when using RTK Query in React

When using RTK Query, you abstract away all the state management that comes with data fetching -- you call an endpoint and the documents are loaded into a variable, ready for use. Like so:
const {data: rangesInfo = []} = useGetRangesQuery(userId);
Let's say this rangesInfo variable contains a uniquely identifying ID, uuid, as well as a number, rangeValue, which specifies its position. This number can run from 0 to 100. For the sake of this example, let's imagine these ranges describe a user's food preferences. John is a 0 for sushi and a 100 for pizza. And as the end user clicks around the website, they can load other users' preferences, and so this set of ranges is constantly updating.
This all works fine -- you can call rangesInfo.map(range => <RangeComponent key={range.uuid} rangeValue={range.rangeValue}/>), and this will render a collection of children components, which all know how to display the UI of the actual HTML input[type=range].
But when using an range slider input in React, you must choose between either a controlled or an uncontrolled input. React's preference is for the input to be controlled by the state of its parent. In this case, the state of its parent is an RTK black box, and if you want to modify the cached data you must invalidate it, typically by triggering a mutation. This is RTK Query's term for a POST or an UPDATE request that will affect data in your backend. The thing is that in Chrome, a range input's onChange event triggers dozens of times a second, and it seems ridiculous to pummel your API with 40 requests when only the last one makes a difference.
That means we have to go with an uncontrolled component. The problem then becomes updating the display of the range when the props change. Because the props do change -- RTK is working fine -- but the props no longer have any bearing on the position of the range's value. (Remember, if you want to control an input's value via prop, you're no longer described an uncontrolled component!). If we could guarantee that the child components were remounted every time their props changed, we should be in the clear, but that wasn't my experience.
Even though those RangeComponents were given unique ids, and even though the docs suggest that this is sufficient, the new data was out of sync. When I loaded the page, I had User 0's info, and then I clicked on User 1 I still saw User 0. When I clicked on User 2, now User 1 popped in, and so forth.
My ultimately hacky solution was to attach a ref to the input range's DOM, and then use a side effect to dictate the its value, like so:
useEffect(() => {inputRef.current.value = props.rangeValue})
This solved my consistency problem, but introduced a ton of jank to the UX -- when I set the input range to a new state, it flickers back to its original position briefly.
Is there a way to solve this issue while staying in the RTK Query paradigm?
The no-jank, no-ref-necessary solution: Be extra sure that your child component's key is unique, because RTK is going to rerender it multiple times, and the render that "sticks" may not have the updated props at that point.
My fix was to append the value of the range to the key. So now the code looks like:
rangesInfo.map(range => <RangeComponent key={range.uuid + rangeValue} rangeValue={range.rangeValue}/>)
By linking the props and the keys together, you're guaranteeing that React will remount the child component.
Hope this saves somebody some time!

Time Measuring from order placement to delivery in AnyLogic

I'd like to measure the time from order placement (agent Order) to delivery to the shop.
There are some delays inbetween due to assembly of the goods. But after that I need to transport it to a defined port by trucks and vice versa in the country of destination.
I figuered I have to use sources (creates my good agents) and sinks (arrival of my good at destination) for timemeasuring. So I can use TimeMeasureStart and TimeMeasureEnd but I am having trouble with how I acutally implement this in my flowchart in AnyLogic.
Any thoughts?
Thanks in advance!
Benj
Create three parameters in your order agent: timeEnter, timeLeave, timeInSystem. When the order is created, set agent.timeEnter=time() and whenever you dispose of them, type
agent.timeLeave=time();
agent.timeInSystem=agent.timeLeave-agent.timeEnter;
You can add this value into a dataSet, for example.
You can use the time measure start and time measure end blocks.
You simply place the 'start' block where you want to start measuring and the 'end' block where you want to stop measuring and then refer to the associated start block inside the end block
The screenshot is from the how to model that can be found in the AnyLogic How to examples in the Software
Or check the link here https://anylogic.help/library-reference-guides/process-modeling-library/time-in-system.html#measuring-time-in-system

PredictionIO customization Universal Recommender

I want to implement a Universal Recommender for our site.
I've successfully set up the base configuration customized by the tutorial.
The service we provide is a e-commerce, where users can buy, like, rate from 0 to 5 and save a product among the other actions.
I'm a little confused about how to set up these:
Like / unlike;
Save / remove;
Rate.
I know I can attach properties on the events, but I don't get how set a negative weight to the unlike and remove events.
Also I don't know how the rating could be weighted by the algorithm, if I didn't set anywhere a range in which evaluate a product.
Hope you can enlighten me.
Bests
The Universal Recommender is build on the Correlated Cross-Occurrence algorithm, which measures the correlation of any number of indicators with the action to be recommended. In your case you want a user to "buy" so you should include that as the primary event—the one by which all others are compared.
The primary event is
buy
So that makes the secondary events:
like
unlike
save (to shopping cart?)
remove (from shopping cart? if so not much of an indicator probably)
rate (is there a range?)
You could make some guesses about low rating means "hate" and high ratings mean "love", toss out middle/ambiguous ratings and replace rate with these 2 new events.
If you don't have "buy" you could substitute something like "love" or "like" in it's place as the primary event.
The point of separating the events into 2 types is that the Universal Recommender will test to see which of the secondary events correlate with "buy" and will automatically weight them so that all of them can be used for recommendations.

Keeping of track of the states of object - SOS

Hi the wise folks at SO. This is an SOS.
I'm in a deep trouble. In my web application there is an object (Say it is a request for something). User submits his/her request. After this it comes to the people who can approve/disapprove that request. During the period from submission to approval/disapproval many actions can be taken on the request. I have to present user with actions panel (collections of links) using which he/she can modify the state of the request.
Now based on which stage of processing the request is some actions are not allowed. Also if some action has already been taken it excludes the possibility of other actions.
Overall it creates a pretty complex matrix of allowed/forbidden actions that my tiny head is not able to take care of it.
I've create some static classes/methods which returns the arrays of allowed actions based on the state of the request. There are about 20 states that a application can be in. I've taken care based on state to remove/disable links for actions that are not possible in that state.
Now problem arises is that suppose request is in state X.
Now if in past action l has been taken on request we may not allow l or based on this some arbitrary actions m,n,o.
After writing all the methods to get arrays of links for 20 states, I have to filter the arrays based on the past history of actions (which is stored in sql db) which is very very big task.
Please suggest me some pattern which is easier to implement and efficient. It is getting on my nerves.
As I understand you have a real-world workflow scenario. In this case I would:
Model entire state as a single entity if possible (a single row with fixed number of fields). I would not model this as a set of actions.
Model each action as some change in the row. It is quite obvious when user enters some data, but I would also model each acceptance as either - a boolean field or a state field - depending on whether the acceptance is done by independent departments or it is a cascade of acceptance in a single department.
Also there may be a situation when an acceptance is given for some particular parameter and the parameter may change in the future, requiring new acceptance. In this case I would model such scenario as two fields. On for the parameter value and the second one for the accepted value. I would make the decision on whether an acceptance is still needed based on the difference of this two fields. This allows for implementing some thresholds.
Having a state modeled as a single row I would implement independent predicates for action allowance.
I think that point 4 is the most important one. If your are able to implement independent predicates for enabling actions then you will be able to easily modify them in the future.
Having 1-3 properly implemented you will be able to easily implement acceptance revoking, which may be required and in this case may make overall code size smaller.
Sounds like a job for a state machine workflow, or a few giant nested switches (which ever you prefer).
First thing that came into my mind: Statemachine. Each State is some kind of object. All states have some method "processRequest" that transits the execution into the next state.
The second thing that came into my mind - theses states have to be organized like a tree or graph. The graph represents the history of requests. You start in the initial State. You get Request A, you proceed to State A. After that, you get request B, you proceed to AB. Wether state AB is equal to BA is not clear by your description.
That way, you get far more states then your 20 states you have now, but each state includes the history. I'd suggest a naming convention after the path you had to take to get there (like AB before). And perhaps you can reuse state A and B in AB, to minimize coding.

Resources