Search code examples
netlogoagent-based-modeling

comparing attributes of 2 different turtles breed


I have 2 turtles bread:

globals [ max-applicant ]
breed [ applicants applicant ]
breed [ investors investor ]

applicants-own [ ask-amount applied? industry country-of-origin funded? ]
investors-own [ allowed-industries-list allowed-countries-list no-of-applicants-funded ]

I want to perform a transaction based on whether the investor is allowed to do business with the applicant's industry and country of origin. An Investors can only perform a limited number of transactions based on the max-applicant value

In the code below, I'm trying to select an investor that hasn't reached the max transaction limit and then select an applicant that meets the conditions of the selected investor and fund that applicant:

to close-deal
  let investorPerson one-of investors-here with [no-of-applicants-funded < max-applicant]
  if investorPerson != nobody  [
    ask investorPerson  [
      let applicantPerson one-of applicants-here with [
        industry member? [allowed-industries] and country-of-origin member? [allowed-countries] of myself
      ]
      if applicantPerson != nobody  [
        ask applicantPerson [
          set funded? TRUE
        ]
      ]
      set no-of-applicants-funded no-of-applicants-funded + 1
      
    ]
  ]
end

This code doesn't run. is this the right way to design this operation?


Solution

  • There seem to be two problems:

    1. See here the syntax of member?: it is member? value list, while in your code you have value member? list.
    2. In the first of the two boolean statements where you use member?, you omitted the of myself that should address [allowed-industries].

    Combining the two points above, you should have:

    let applicantPerson one-of applicants-here with [
            (member? industry [allowed-industries] of myself) AND (member? country-of-origin [allowed-countries] of myself)
          ]
    

    The use of parentheses and the capitalisation of boolean operators are optional, just my own stylistic choice.

    Side note: be aware that you are asking your investorPerson to

    set no-of-applicants-funded no-of-applicants-funded + 1
    

    outside of the command block that gets executed if there actually is an applicantPerson; i.e. your investors will increment no-of-applicants-funded even when applicantPerson = NOBODY.