Is it possible to split an exit block into multiple enter blocks in Anylogic using a set of parameters that can be optimised? - optimization

I want to be able to split activity across a number of sites, but I want that split to be determined by an optimisation experiment so I need a way of splitting activity in the exit and sending it to the respective enter blocks. I'd welcome any advice on how to set up my exit block to do this. I recognise I'll need a variable per option.
I know I can do it with a SelectOut block, but I may need a large number of options and so this doesn't work.
I've added the enter blocks into a collection and I can route agents to a particular enter block, but the optimisation engine can't use agent level parameters.

Create a function f_getEnterBlockToUse that takes as an argument your agent and returns an Enter block (select the return type "Other" and then write Enter in the code field).
Now, you can write any sophisticated code in there yourself to select which block to be chosen.
In the Exit block, you only call the function f_getEnterBlockToUse(agent).take(agent). This will send your agent to your desired enter block

Related

Setting up multiple schedules for a ResourcePool

I am doing a simulation of a production line, which is built through Excel.
Now there is one, which needs free setting of worker shifts for each machine, three shifts in total.
My idea is to create three different Schedules, representing each of the three shifts, and then in the ResourcePool, use the If statement to set up the use of each shift. As shown in the picture enter image description here
But it didn't work. If it is possable, Could you please tell me if there is something wrong with the Java statement or the idea is wrong.
If possible, could you please tell me how to set multiple schedules in ResourcePool?
Additions to the question:
The model is to do the evaluation of the production system and the shift of the workers is an important evaluation parameter. What I want to do is to enter the shift of the workers directly in the Excel sheet and ResourcePool recognizes and uses the corresponding Schedule.
I tried to generate the corresponding Schedule by code, but the Schedule of Resourcepool cannot be set dynamically. So I would like to try to manually input multiple Schedules into the model and then set the corresponding Schedule in ResourcePool by If statement like the image.
Thanks in advance
The first thing you need to know is that the location where you placed the code is a static parameter, thus it is only evaluated once, when the object is created and not checked continuously.
This is indicated by the little popup when you hover over the button that change the entry field from code to value
If it was dynamic it would state Dynamic Value instead of Static Value
Secondly, inside that field you must use a ternary operator, not an if statement, so that the result of the formula is a scheduled object, else you will get a "misplaced construct(s)" error
If you changed the code to
v_Shift == "Shift1" ?
s_Shift1 : v_Shift == "Shift2" ? s_Shift2 : s_Shift3
It will work BUT:
It will only be evaluated when the object is created and not again
Rather not use == on Strings, always use .equals(), on Strings it might work, and sometimes it might not. You can do some research as to why ;-)
Solution: You will have to use a function to change the schedule of the resource pool. Call this function whenever the v_Shift variable changes

How to execute if there's a certain block within a radius

I'm trying to figure out how to execute (for example /say hi) when there's Yellow Terracotta in a certain radius or field, however I can't figure out how to do it.
Anyone knows?
Using Minecraft 1.16,
"Execute" command has several syntax options. You can use the form "execute if block run "
Using the proper block name, we can get:
execute if block 1015 63 989 minecraft:yellow_glazed_terracotta run say hi
This targets a specific position.
I am a little less clear on how to achieve specifically what you are asking, but here are my thoughts:
The syntax provides for another form "execute if blocks..." This form allows you to select a range by corners, but it must be compared against a third selection of the exact same size (only the corner can be specified). I think the regions must be exactly the same, and may not allow for random placement of the block anywhere within the region.
Another way might be using different execute if commands instead to select an entity, and test where the entity is standing.
If you put a button on a command block and set it to:
execute at #p if block ~ ~-1 ~ minecraft:yellow_glazed_terracotta run say hi
When the player hits the button on the command block (obviously they must be within range of the button to press it) it shall check if the block -1 under the #p is "yellow_glazed_terracotta", and it will run say hi.
#p can be modified with [distance=..3] which means the player targeted by the command block must be within 3 blocks of the command block:
execute at #p[distance=..3] if block ~ ~-1 ~ minecraft:yellow_glazed_terracotta run say hi
So, this is sort of creating that range that you were looking for.
Some sources use "execute as #a at #s..." as a way to target any player when they step on a certain block anywhere at anytime. It may be possible to modify this into a distance as well, but it seems that the player will need to stand at a specific relative position to the terracotta.
If I find a better way to achieve this, I'll follow up.
The subreddit r/MinecraftCommands has a decent community that messes with Minecraft commands and command blocks. They may have further insight.
If I find a better way to achieve this, I'll follow up.
Edit- The only other thing I can think at this point is to take the first command I suggested and repeat it for every single coordinate in an area. If a terracotta block is any of those spaces, it will run the say hi command.
If you place all of these command lines into a function file you can call for the function when the command block is activated.

Pentaho/PDI: Increment a value automatically by one if a load-job (within a metajob) fails

in PDI I've got the following structure
0_Metajob
1_Load_1
1_Load_2
1_SimpleEvaluation
1_Mail
As of now
1_Load_1 and 1_Load_2 are independent of each other. The second one will run, irrespective of the success of the first one. That is okay, I want it that way!
Issue
I want to have a counter that is incremented by one every time one of the single loads fails, i.e. in my example the counter can take the values 0, 1 or 2.
What do I need it for? Customer will receive a mail at the end of the metajob. The aforementioned value determines the subject of the mail, i.e. 0=everything fine, 1=so-so, 2=load totally failed!
Why not mailing within every single the Load-Job? I do that but without attaching the log-file because it is usually non-finished. Therefore the log-file is mailed with the mail that is sent when the Metajob is finished.
Tried
"Set a variable". Thought I can simply increment it with adding a one in the value field, i.e. "${VariableName}+1". Of course, this step is implementened within a fail path of each Load-Job.
However, it didn't work.
Would anyone mind helping me? I would appreciate that!
Set Variable doesn't do calculations, you'll need a Javascript step for that.
Fortunately, variables can be also be set within the Javascript step. This bit of code should go into each of the steps you put in place of the Set Variable steps:
var i = parseInt(parent_job.getVariable("Counter"),0);
i = i + 1;
parent_job.setVariable("Counter",i);
true;
This bit of code gets the variable "Counter" from the parent job and converts it to int, since all Pentaho variables are strings. Then it increments it and sets the job variable again. The "true" at the end is to ensure that the javascript step reports success to the main job.
IMPORTANT: This works roughly as you would expect in a Job. It will NOT in a transformation!

Can you print variables that are dynamically generated?

I am trying to setup a program that takes user input for database ddl generation. I have it working to the point where it can ask a user for the name of the table, the number of columns and any attributes that might be needed. The problem comes when I try to print a string that includes the variables used for the column names. Due to trying to let users have as many columns as they want I used variables similar to this newvar(number that increases every time you enter a column name). This works fine and I can get the values if i do send %newvar1% but it doesn't work to do send newvar%increasing number%. I need to know if this is possible or if I'm just missing something obvious. Also I don't have the code with me but I can post it once I get back to my main computer.
I have tried quite a few things like, send %newvar%%number%, send newvar%number%, othervar = newvar%number% send %othervar%.
I'll show some once I have access to it in about 2 hours.
I expect to be able to output names for increasing variables using an ever increasing number. Class is starting I'll clarify some things later.
You can use a lone percent % beginning the first argument for the send command to achieve what you want. This will make everything after it to be evaluated (up to the next comma). Here is an example:
f1::
newvar1 := "This " , newvar2 := "is just a " , newvar3 := "test."
Loop , 3
Send , % newvar%A_Index%
Return
See: https://www.autohotkey.com/docs/Language.htm#-expression

Dynamically declaring parameters from table

Is it possible to dynamically create parameters from table entries?
For example like this:
SELECTION-SCREEN BEGIN OF BLOCK example WITH TITLE text-01
LOOP AT example_internal_table INTO example_workarea
IF example_workarea-field = criteria.
PARAMETERS: (example_workareafield) AS CHECKBOX.
ENDIF.
ENDLOOP.
SELECTION-SCREEN END OF BLOCK example.
The code snippet above throws the error that example-workarea-field is not a constant. Does this mean it isn't possible to dynamically declare parameters or am I just doing it wrong? Thanks
Correct. PARAMETERS statements compile into selection screens at compile time, not at runtime. Therefore you cannot do what you want in the way you have proposed.
However, it is possible to have some form of dynamic screens.
Look at the answers to this question: For the I/O fields in a normal ABAP screen, can i get them to behave like a SELECT-OPTIONS?
This gives you two starting points: The use of subscreens, which you can call dynamically, or the use of FREE_SELECTIONS_INIT as examples.
Depending on how crazy you are about this, you can also investigate:
http://help.sap.com/abapdocu_702/en/abenabap_language_dynamic.htm
You could load the DYNPRO and dynamically change the screen, activate and then run a report that calls the changed screen.
This is of course a different approach from using PARAMETERS and should only be used for pet projects, not real production code as these statements are for internal use. I believe this is the approach that SE16 uses when it generates a selection screen for a table.