Luke Kho
Luke Kho

Reputation: 3

How do I sort a group with predetermined group sizes?

I am currently working on sample-pooling methods, and right now, I am stuck on how to sort a group by pre-determined sizes.

So far, I was able to

1) make a list of desired group sizes and

2) sort the group with "one-of" the group sizes , which was written as follows:

`to assign-by-size
  ask hardticks [ set my-group -1]
  let unassigned hardticks
  let current 0
  let groupsize (list 4 9 13 20 20)
  while [any? unassigned]
  [ask n-of (min (list one-of groupsize (count unassigned))) unassigned
  [set my-group current]
  set current current + 1
  set unassigned unassigned with [my-group = -1]
]
end`

However, since one-of only allows you to pick a random number within the group, it does not quite perform as I wish, which is to sort the group in the order of the list, or at least use all of the predetermined groupsize in the list once.

Which function or codes should I use to make it work as I want to?

Upvotes: 0

Views: 38

Answers (1)

Wade Schuette
Wade Schuette

Reputation: 1473

I think something like this might work. I may have a syntax error. The idea is to first pull the next item off the groupsize list using the index you already have of "counter", and then when that's exhausted, fall back on your old test.

By the way I was very confused by your use of the word "sort" as I'm American and to me to "sort" means to put into a sequence, but I suspect you mean the slang UK meaning, what I'd call to "populate a group."

 while [any? unassigned]
  [

      if-else current < length groupsize [
          ask n-of (min (list (item current groupsize) (count unassigned))) unassigned
          [set my-group current]
      ]
      [ 
          ask n-of (min (list one-of groupsize (count unassigned))) unassigned
          [set my-group current]
      ]



      set current current + 1
      set unassigned unassigned with [my-group = -1]
  ]

Upvotes: 1

Related Questions