Many-to-Many Relationship Cohorts

A place for Ventity software questions & answers
Post Reply
atkamal
Junior Member
Posts: 14
Joined: Tue Aug 06, 2019 12:13 pm
Vensim version: Ventity

Many-to-Many Relationship Cohorts

Post by atkamal »

Hi Ventity Team!

Is there an example of creating cohorts for many-to-many relationship entities? (is it possible?)
It says in the help that we can "Initialize Relationship entities, or create them with Create Actions, to create the relationships"

I have added a model where i try to generate cohorts that belong to many-to-many relationship entities ("Find it attached") belonging to car size and engine type. Similar to the last problem, I am trying to generate cohorts which belong to different Car Size (SUV, Sedan) as well as Engine Type (Electric, Petrol, Hybrid).

I would really appreciate your help
Attachments
FMRelationship.rar
(13.05 KiB) Downloaded 278 times
atkamal
Junior Member
Posts: 14
Joined: Tue Aug 06, 2019 12:13 pm
Vensim version: Ventity

Re: Many-to-Many Relationship Cohorts

Post by atkamal »

PS why can't I access a relationship entity through attribute???
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Many-to-Many Relationship Cohorts

Post by tomfid »

I think you've nearly done it here - you just need to initialize the FMrelationship entity Car Size and Engine Type attributes in the Create Cohort action. This will be analogous to the Fleet initialization, i.e. you'd set Car Size = Invoker.HC Car Size.

Generally the easy way to do this is to write the expression and then use the right-click Draw Arrow method to add the inputs to the diagram.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Many-to-Many Relationship Cohorts

Post by tomfid »

Actually, that's not quite right - your cohorts need a separate ID. It's not sufficient to have Car Size|Engine Type|Fleet for the cohort key, because it's not unique. There will be multiple model years with the same attributes.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Many-to-Many Relationship Cohorts

Post by tomfid »

Also, you've deleted the "Head Cohort" attribute in the Fleet entity. That's needed to refer to the newest cohort of vehicles of a given size and type, so that sales can be inserted there.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Many-to-Many Relationship Cohorts

Post by tomfid »

This is more like what you need. Note that I've replaced the Fleet's key attribute, FleetID, with a compound key consisting of Size and Type. That wasn't really necessary, and it slightly complicates the Cohort. It does make plots of fleet items a little easier to read.
VehicleCohorts4.zip
(19.97 KiB) Downloaded 337 times
atkamal
Junior Member
Posts: 14
Joined: Tue Aug 06, 2019 12:13 pm
Vensim version: Ventity

Re: Many-to-Many Relationship Cohorts

Post by atkamal »

Hi Tom !!!
Thanks again for the help. I have a few questions as to how you solved the issue.
The model you shared is similar to one i tried before (but had problems). I had some mistakes with referencing with that model in the action tab. I have attached the "wrong model" for you to see. So the questions are :
1. As you have said that you have replaced the FleetID with Size and Type as keys, and then used them as invoker.Size and Invoker.Type to create attributes for the new cohort. If as you say this compound key is not necessary. Do we still have to make reference in Fleet entity of Size and Type and refer them to cohort and then use them to provide values for new cohorts?
2. Since the action and trigger are in the same entity (Fleet). Is providing the newCohort.CohortID to Parent.HeadCohort and Invoker.HeadCohort the same thing?
3. Is referencing through attributes necessary to move information between entities? The model (Fleet entity) you have shared has Vehicle Sales Rate from Market entity but does not have attribute that refers to Market.

I really appreciate your help. Because of the time difference it's difficult to be on the forums at the same time.
Attachments
SimpleStockWithTriggerMultTribEngine.rar
(11.57 KiB) Downloaded 266 times
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Many-to-Many Relationship Cohorts

Post by tomfid »

1. I could have left the FleetID alone, in which case the Cohort could look up Size and Type via a reference to the Fleet to which it belongs. Either way, the Cohort needs to have attributes storing the key for the Fleet.

2. True - this is often the case.

3. You always need a reference to access info in another entity, but you may not need an attribute. In this case, the Market is a singleton, like the Model entity. That means you don't need a key to reference it, because there's only one. You can just refer to the entitytype by name. If you take a look at the Market reference in the Fleet, you'll see that it has no fields to match. The other exception is that you can hardwire a reference by plugging in a text value rather than an attribute. For example, if you have a reference to a Friend you might use the attribute Name to define it. But if you want it to always point to a particular friend, you could plug in "Fred".
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Many-to-Many Relationship Cohorts

Post by tomfid »

For completeness, here's another version, implemented the other way:
- Market is not a singleton
- Fleet has a compound key (market|size|type)
VehicleCohorts7.zip
(20.79 KiB) Downloaded 337 times
Post Reply