Ray Canadian
Ray Canadian

Reputation: 23

Netlogo Linking Breeds

I'm still trying to get used to Netlogo. I have two breeds, Buyers and Sellers. Buyers have their own "dPrice" and Sellers have their own "dPrice". All the buyers and sellers start with having done no trades. I need to have each buyer to search through sellers that have not made a trade yet, in a random way, and if the buyer's "dPrice is greater than a seller's "dPrice" then set itself and that seller as ones that have done deals and not available anymore. So here is my code.

Buyers-own [dPrice MadeNewTrade?]

Sellers-own [dPrice MadeNewTrade?]

to Test

  ask Buyers [

    let dBuyPrice dPrice

    ask Sellers with [MadeNewTrade? = false] [

      let dSellPrice dPrice

      if dBuyPrice >= dSellPrice [

        set MadeNewTrade? true

        ask myself [

          set MadeNewTrade? true

          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
          ; I want to break out. 
          ; So don't check the other sellers,
          ; move to the next buyer and
          ; check the remaining sellers.
          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ]
      ]

    ]
  ]
end

The prolem is that I don't know how to break out of the sellers loop such that I can prevent the buyer checking the other sellers once it has done a trade with one seller. Any help is very much appreciated.

Thx

Upvotes: 2

Views: 136

Answers (1)

Fernando Sancho
Fernando Sancho

Reputation: 141

Maybe you can make use of one-of and some filters on agensets using with. Probably they will facilitate your work and makes clear your intentions.

Buyers-own [dPrice MadeNewTrade?]
Sellers-own [dPrice MadeNewTrade?]
to Test
  ask Buyers [
    let dBuyPrice dPrice
    let SellersTrade Sellers with [MadeNewTrade? = false and dBuyPrice >= dPrice]
    if any? SellersTrade [
      ask one-of SellersTrade [set MadeNewTrade? true]
      set MadeNewTrade? true
    ]
  ]
end

I hope this will help you.

Upvotes: 3

Related Questions