Mahsa soltani
Mahsa soltani

Reputation: 25

How can I make a blacklist in netlogo?

I want to know how I can code the concept like blacklist?

I have 150 customers and 3 providers. all customers have this possibility to choose between providers based on specific rules. The model should run for 5 years and each year customers evaluate their provider and if it is not desirable, customers should change their providers. For the next years, customers choose between the remaining providers (the last provider now should be in blacklist just for 1 year) based on the same rule. The provider which is blocked by the customer just remains on the blacklist for 1 years.

Note. For example, customer 1 chooses provider 1 for the first years. At the end of the first year, customer evaluates the provider 1 and decide to change the provider. Now for the second year, the customer can choose just between provider 2 and 3. Then assume that for the second year, the customer selected provider 2 and at the end of the second year again wanted to change the provider. Then the customer can choose between provider 1 and 3 for the third year.

Upvotes: 0

Views: 47

Answers (2)

ccjo
ccjo

Reputation: 101

I believe you can use a list for each customer (as an attribute) for that. For example, if you have p providers (and you give them an id from 0 to p-1), then you star with set blacklist n-values p [-1]. When a provider with id = n goes to the list, you make its value zero: replace-item n blacklist 0. Each year, you ask customers to increase the values of their blacklist that are >= 0. Like,

foreach blacklist [ provider_id -> 
  if provider_id >= 0 [
    replace-item n blacklist (item provider_id blacklist + 1)
  ] 
]

Finally, you replace-item n blacklist -1 if ever the provider n gets out of the blacklist!

Hope this helps. If you have any doubt, please ask!

Upvotes: 1

JenB
JenB

Reputation: 17678

I believe that you want each customer to maintain its own blacklist rather than have a single blacklist that is available to all customers. If that is correct, then you need to create a turtles-own attribute for customers that contains their blacklist.

That blacklist is easiest to use if it is an agentset. That way, you can use not member? to exclude the providers when choosing. However, you will need to store it as a list of agents (never use identifiers like the who number) if you need more complex operations like remembering the order that they were added to the blacklist.

This code creates a blacklist, excludes the members from the selection, and adds and deletes from the blacklist probabilistically.

breed [providers provider]
breed [customers customer]
customers-own [blacklist]

to setup
  clear-all
  create-providers 3 [setxy random-xcor random-ycor set color red]
  create-customers 10
  [ setxy random-xcor random-ycor
    set color blue
    set blacklist (turtle-set [])
  ]
  reset-ticks
end

to go
  ask customers
  [ let choice ifelse-value any? blacklist
      [ one-of providers with [not member? self [blacklist] of myself] ]
      [ one-of providers ]
    ; stuff here about purchasing from their choice
    ask blacklist [ if random-float 1 < 0.3 [ die ] ]
    if random-float 1 < 0.2 [ set blacklist (turtle-set blacklist choice) ]
    show blacklist
  ]
  tick
end

Upvotes: 2

Related Questions