setting an attribute in a create action

A place for Ventity software questions & answers
Post Reply
apmoorepa
Junior Member
Posts: 15
Joined: Mon May 21, 2018 2:25 pm
Vensim version: DSS

setting an attribute in a create action

Post 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
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: setting an attribute in a create action

Post by tomfid »

I think this may be a glitch in the if-then-else code for attributes. I'm investigating & will report back ASAP.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: setting an attribute in a create action

Post 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
apmoorepa
Junior Member
Posts: 15
Joined: Mon May 21, 2018 2:25 pm
Vensim version: DSS

Re: setting an attribute in a create action

Post 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.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: setting an attribute in a create action

Post 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.
apmoorepa
Junior Member
Posts: 15
Joined: Mon May 21, 2018 2:25 pm
Vensim version: DSS

Re: setting an attribute in a create action

Post 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!
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: setting an attribute in a create action

Post by tomfid »

Can you post the model, or mail it to us at info at ventity dot biz?
apmoorepa
Junior Member
Posts: 15
Joined: Mon May 21, 2018 2:25 pm
Vensim version: DSS

Re: setting an attribute in a create action

Post by apmoorepa »

I sent the model to info@ventity.biz. I'll try to summarize the resolution, if any to this forum. Thanks!
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: setting an attribute in a create action

Post 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).
apmoorepa
Junior Member
Posts: 15
Joined: Mon May 21, 2018 2:25 pm
Vensim version: DSS

Re: setting an attribute in a create action

Post 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!
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: setting an attribute in a create action

Post by tomfid »

Great! We'll have to clarify that in the Help system.
apmoorepa
Junior Member
Posts: 15
Joined: Mon May 21, 2018 2:25 pm
Vensim version: DSS

Re: setting an attribute in a create action

Post 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.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: setting an attribute in a create action

Post 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.
apmoorepa
Junior Member
Posts: 15
Joined: Mon May 21, 2018 2:25 pm
Vensim version: DSS

Re: setting an attribute in a create action

Post 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.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: setting an attribute in a create action

Post by tomfid »

No problem.
apmoorepa
Junior Member
Posts: 15
Joined: Mon May 21, 2018 2:25 pm
Vensim version: DSS

Re: setting an attribute in a create action

Post 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!
Post Reply