Page 1 of 1

setting an attribute in a create action

Posted: Mon May 21, 2018 2:57 pm
by apmoorepa
I'm having trouble setting the attribute in a create action, with which I'd appreciate help. The attribute new value is:

if(newVendorFix●VendorNum<1) {"Vendor1"} else if (newVendorFix●VendorNum<2){"Vendor2"} else {"Vendor3"}

VendorNum is a randomly assigned value:

RandomUniform(0,model.vendor population size-1)

The idea is that a list of (built-in data) vendors is used to pick a random vendor associated with a VendorFix.

This works when I don't include the elseif in the above expression. That is, no problems when the attribute new value is:

if(newVendorFix●VendorNum<1) {"Vendor1"} else {"Vendor3"}

With the elseif expression here is the error message that I get:

Generated code at (2883,2) }expected (context: Createntity by key (uint); COLLECTIONOF_collection_of_vendorfix_by_mpcvd_identity", in collection_of_vendorfix_by mpcvd_identity

It seems to be complaining about the creating of the collection of VendorFix. The fact that it works for the plain if-then-else, but not when the else if is added in seems strange. Is this a known limitation or error?

Any help is appreciated.

Thanks,
Andy

Re: setting an attribute in a create action

Posted: Tue May 22, 2018 10:17 pm
by tomfid
I think this may be a glitch in the if-then-else code for attributes. I'm investigating & will report back ASAP.

Re: setting an attribute in a create action

Posted: Wed May 23, 2018 12:18 am
by tomfid
Here's a workaround, using a Process List action. It's a little more complex to set up, but generally it's a lot better because
(a) there's no possibility of errors (a Buyer getting a reference to a Vendor that doesn't exist)
(b) you can change the size of the Vendor list just by changing the initialization data.
RandomizeCreateAttrib2.zip
(15.06 KiB) Downloaded 513 times

Re: setting an attribute in a create action

Posted: Sat May 26, 2018 3:51 pm
by apmoorepa
Thanks Tom! This is a very nice solution that allows easier extension to a larger numbers of vendor agents. Should be very useful for selecting random elements of a collection. I've got your approach working in my application already.

Re: setting an attribute in a create action

Posted: Tue May 29, 2018 2:51 am
by tomfid
Cool. We need one more piece to make this more efficient, which is a way to select an entity without having to run a Process List over the whole collection. That's coming.

Re: setting an attribute in a create action

Posted: Mon Jun 11, 2018 6:46 pm
by apmoorepa
Tom,
I have noticed one problem with my execution of the above fix. I am not pulling the data for vendors and buyers from a table as you are. I am generating them dynamically. For instance I generate 10 vendors as an action, and assigning an attribute to each vendor (whether it is a "player" or "nonplayer"). This allows generating subcollections of vendors showing aggregate values for players and nonplayers separately. This all works, but in the graphs of those aggregate values, a null run (for vendor_0001) shows up in addition to the aggregate values for the players and nonplayers. Is there a way to get rid of this null run. It does not provide an entry in the entity picker to deselect it. Thanks!

Re: setting an attribute in a create action

Posted: Mon Jun 11, 2018 6:51 pm
by tomfid
Can you post the model, or mail it to us at info at ventity dot biz?

Re: setting an attribute in a create action

Posted: Mon Jun 11, 2018 8:16 pm
by apmoorepa
I sent the model to info@ventity.biz. I'll try to summarize the resolution, if any to this forum. Thanks!

Re: setting an attribute in a create action

Posted: Mon Jun 11, 2018 9:28 pm
by tomfid
I think the problem is that you're using "No Data" which creates one entity of each type, with default settings. That would explain the presence of an extra one (though I'm not sure which one is surplus in your model).

Re: setting an attribute in a create action

Posted: Mon Jun 11, 2018 11:50 pm
by apmoorepa
You are quite right. I thought you had to use no data if you did not use any data from tables. Good lesson that there is a difference between no data and using a table with no data. That fixed my problem. Thank you!

Re: setting an attribute in a create action

Posted: Mon Jun 11, 2018 11:57 pm
by tomfid
Great! We'll have to clarify that in the Help system.

Re: setting an attribute in a create action

Posted: Sat Jun 16, 2018 2:41 pm
by apmoorepa
RandomizeCreateAttrib3.zip
(15.36 KiB) Downloaded 479 times
I'm having a problem with using if-then-else statements in actions when assigning the new value for an attribute. Ventity is giving me an error. I used the model that Tom sent in this thread previously to illustrate this problem - in the pickVendor action. Just setting the vendorID using an if then else creates the error. Am I doing something wrong here, is this a known bug, or is there a workaround to this. I can't seem to figure out a workaround on my own that works.

Re: setting an attribute in a create action

Posted: Mon Jun 18, 2018 3:00 pm
by tomfid
The error is definitely caused by the if statement in the attribute initialization, which is currently unsupported. You have:

if (true) {refVendor●VendorID} else {refVendor●VendorID}

The true and false clauses both set the same value - what would you like it to do if the if statement worked? I think I have a workaround.

Re: setting an attribute in a create action

Posted: Mon Jun 18, 2018 9:48 pm
by apmoorepa
Ok - thanks. I’ll send the full model to Ventity.biz for a possible workaround. I’ll report out any findings in this forum. Sorry I can’t post the full model to this public forum - just a policy of my employing organization.

Re: setting an attribute in a create action

Posted: Mon Jun 18, 2018 10:18 pm
by tomfid
No problem.

Re: setting an attribute in a create action

Posted: Wed Aug 15, 2018 1:13 pm
by apmoorepa
Tom pointed out that Ventity 2.0 (partially) resolves the issue with the if then elseif statements in setting an attribute in a create action. You just need to use the IFTHENELSE() construct instead of the if () {} else {}. Thanks for the fix!