Anylogic: How to link a radio button to a variable with type double? - variables

I'd like to use radio buttons in my Anylogic model to make it easier to change values before a simulation. I am running different szenarios (szenario A: electricity price Winter (Strompreis Winter); szenario B: electricity price Summer (Strompreis Sommer), szenario C: electrity price Fall (Strompreis Übergang) and I don't want to change all the formulas in my model when using another electricity price. Instead, I would like to just use the variable "electricityprice" in my formulas and then change the value(s) of that variable by using the radio button.
I tried to use a radio button to set the value of the variable "electricityprice" (Strompreis) / link it to the variable "electricityprice" (Strompreis). This is because I have hourly electricity prices for several type weeks (e.g. electricityprice winter) which are shown by dynamic variable who read them from an excel file.
Anylogic screenshot
excel file
In the field Action of the radio button I typed:
if (value==0) {
Strompreis = StrompreisWinter;
}
else if (value==1) {
Strompreis = StrompreisSommer;
}
else if (value==2) {
Strompreis = StrompreisÜbergang;
}
However, the electricity prices are of type double (e.g. 4.45€). It's only possible to link the radio buttons to a variable of type int. Any idea how I could solve that problem? Thank you!

Several things are "off" here:
When AnyLogic says you can only use Int values for radio buttons, they mean this: the value relates to the user choice made. Your radio button has 3 choices in your example so the value can only be 0, 1 or 2. Nothing else. How you map them to any action is your business.
Next: Your issue should be solved differently. Either, you want to dynamically change a variable value over the course of a year (case 1). Or you want the user to change a variable value during runtime (case 2).
Case 1: dynamically change variable value
Several ways to do this: if you only have 4 seasons, probably easiest to use a simple mapping function "getCurrentElecPrice" that returns a different dbase value based on the current season:
Case 2: let user change value
You can always change a variable directly at runtime: click on it and then on the value to edit it, see below:
More elegantly, you might want to use a slider or editbox. Or a radio button with limited options, but you wouldn't use that for a price, like in your case.
hope that helps

Here is an example model that does what you want, hope this helps :-)
download

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

Building a (process) variable in Appian using the value of another one?

As far as I understand, it is not possible in Appian to dynamically construct (process) variable names, just like you would do e.g. with bash using backticks like MY_OBJECT=pv!MY_CONS_`extract(valueOfPulldown)`. Is that correct? Is there a workaround?
I have set of Appian constants, let's call them MY_CONS_FOO, MY_CONS_BAR, MY_CONS_LALA, all of which are e.g. refering to an Appian data store entity. I would like to write an Appian expression rule which populates another variable MY_OBJECT of the same type (here: data store entity), depending e.g. of the options of a pull-down menu having the possible options stored in an array MY_CONS_OPTIONS looking as follows
FOO
BAR
LALA
I could of course build a lengthy case-structure which I have to maintain in addition to MY_CONS_OPTIONS, so I am searching for a more dynanmic approach using the extract() function depending on valueOfPulldown as the chosen value of the pulldown-menu.
Edit: Here the expression-rule (in pseudo-code) I want to avoid:
if (valueOfPulldown = 'FOO') then MY_OBJECT=pv!MY_CONS_FOO
if (valueOfPulldown = 'BAR') then MY_OBJECT=pv!MY_CONS_BAR
if (valueOfPulldown = 'LALA') then MY_OBJECT=pv!MY_CONS_LALA
The goal is to be able to change the data store entity via pulldown-menu.
This can help you find what is behind your constant.
fn!typeName(fn!typeOf(cons!YOUR_CONSTANT)).
Having in mind additional details I would do as follows:
Create separate expression that will combine details into list of Dictionary like below:
Expression results (er):
{
{dd_label: "label1", dd_value: 1, cons: "cons!YOUR_CONSTANT1" }
,{dd_label: "label2", dd_value: 2, cons: "cons!YOUR_CONSTANT2" }
}
on UI for your dropdown control use er.dd_label as choiceLabels and er.dd_value as choiceValues
when user selects value on Dropdown save dropdown value to some local variable and then use it to find your const by doing:
property( index(er, wherecontains(local!dropdownselectedvalue, tointeger(er.dd_value))), "cons")
returned value of step 3 is your constant
This might not be perfect as you still have to maintain your dictionary but you can avoid long if...else statements.
As a alternative have a look on Decisions Tables in Appian https://docs.appian.com/suite/help/21.1/Appian_Decisions.html

How to keep initial value of a field after POST is done

I have an Oracle Forms app. There is a form with a date field and I need to keep it initial value (when form is loaded), to compare it with actual value in the field. Also there is a button on the form, that posts changes.
I've tried to store initial value with global variable and check if it's changed, also I've tried to simply check that :system.record_status != 'QUERY' to track if date is modified.
Problem that at the moment, when button is pressed and post is done the values of all global variables become null, so I can't compare the initial value with the new one and :system.record_status becomes 'QUERY' again, and I don't see any more if user modified something.
How to keep the initial values or track that data was changed, doesn't matter if user posts changes or not?
This:
Problem that at the moment, when button is pressed and post is done the values of all global variables become null, so I can't compare the initial value with the new one
doesn't work that way. Post (if you refer to POST built-in) (nor COMMIT, as we're at it) doesn't clear global variables. Explicitly setting it to NULL does, so - check the form whether you've done it somewhere in your code. How? Run the form in debug mode, trace its execution and see what's going on.
Another thing that might be going wrong is that global variables's datatype is CHAR so - if you plan to compare it to a different datatype value, you should perform conversion. As it is a date value, consider applying TO_DATE function to the global variable with appropriate format mask.
this will work:
IF GET_ITEM_PROPERTY(:SYSTEM.CURSOR_ITEM,UPDATE_COLUMN) ='TRUE' THEN
Copy(Get_Item_Property(itm, Database_Value), :System.Cursor_Item);

Formatting duration for display

In a SAP database there are values formatted as PxDTyH where x is the number of days and y is the number of hours. A value like P2DT0H is 2 days + 0 hours. I can see that via SE16:
Unfortunately, this is exactly displayed like that to the user, "3" corresponds to the index in the database (not seen in the screenshot above).
I'd like to see it displayed
without the index (changing the options "show keys within drop-down lists" did not have an effect)
instead of the technical name P2DT0H I'd like to see "2 days and 0 hours" (or similar)
Is there a way to process the data before it gets displayed in the combo box? The developers can't change the format in the database because it would change the API.
FYI: I'm just a tester, I don't know how to code in ABAP, but from knowledge of other programming languages, I'd say that the data can be converted before it's displayed. I don't need a fully-fledged answer, just a pointer to a SAP hook or event which enables writing a conversion function.
Probably, conversion routines can be an option for you. What you should do is to:
Take your domain (which is used for PxDTyH values) or create new one specially for this.
Create FM with name CONVERSION_EXIT_%NAME%_OUTPUT, and put conversion logic in there. Mandatory parameters INPUT and OUTPUT should exist.
Enter the %NAME% into Convers.routine field in domain properties.
Enable Check conversion exits checkbox in user parameters.
More info is here.

How to use a single NSValueTransformer subclass to toggle the titles of multiple menu items

I would like to make some bindings that toggle item titles in a popup menu based on a single numerical value in a text field. Let me explain:
This is my UI:
I want my menu items to automatically adjust to singular or plural based on the number in the text field. For example, when I type "1" in the box, I want the menu items to be labeled "minute", "hour" and "day". When I type "4", I want the menu items to be labeled "minutes", "hours" and "days".
What I did to date:
I bound the three menu item's labels to the same key path as the text field's value.
I created an NSValueTransformer subclass to interpret the value in the text field and return singular or plural to be used as item titles.
I applied this value transformer to the three bindings.
The issue:
My value transformer can either return singular or plural but it can't set the appropriate string based on the menu item it's applied to.
It looks to me like a value transformer is generic and can't return different values for different destinations. That would mean that to have the three titles change automatically, I would need to have three different value transformers that return the appropriate string for each menu item. That doesn't seem optimal at all.
Ideally I would be able to combine a string stored in the destination menu item (let's say in the item's tag property) with an "s" in the value transformer when the text field's value is larger than one, or something similar that would enable me to use a single value transformer for all the menu items.
Is there something I missed? What would be an ideal solution?
Okay, this is probably not an ideal solution, but something you could consider: if you set your value transformers from your code (and not in IB), you could instantiate 3 different transformers of the same class. You could give your value transformer an ivar NSString *unit (and add something like [[MyValueTransformer alloc] initWithUnit:]) to allow each to return their own string, but you still have to write the value transformer's code only once.
(Also, if you're ever going to consider making your application localizable, simply appending an "s" to create the plurals is not going to work. You could of course add ivars for both NSString *singular and NSString *plural to do that.)
Edit: Wait, I just realized you can register value transformers! If you register them as MyValueTransformerHours and MyValueTransformerMinutes (by manually allocating and initializing them in your code), you can use them from Interface Builder. See also https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ValueTransformers/Concepts/Registration.html#//apple_ref/doc/uid/20002166-BAJEAIEE.