max-one-of

25 views
Skip to first unread message

San

unread,
Jun 17, 2022, 10:54:52 AM6/17/22
to netlogo-users
Hello,

According to Netogo dictionary max-one-of "Reports the agent in the agentset that has the highest value for the given reporter. If there is a tie this command reports one random agent with the highest value. If you want all such agents, use with-max instead.". 

In my model patches are endowed with a number of votes and a distict-number. A turtle ("party") receives a patches' votes if it is closest to that patch. Now, I want to identify the single turtle that receives most votes from district-1 patches. In the enclosed model this turtle becomes "winner-1". I thought to do so via max-one-of. The full model is enclosed. The relevant lines are here:

if electoral-system = "FPTP" [
    ask patches [
      set closest-party min-one-of parties [distance myself]
      ;;patches find their closest party  
      if district = 1 [set pcolor blue]]
    ]
   
    ask parties [
      if n-districts > 0 [
        set district-size-1 sum [votes] of patches with [closest-party = myself and district = 1]
        set district-size-1-list [district-size-1] of parties      
        set winner-1 max-one-of parties [district-size-1]
        if self = winner-1 [set district-mysize 1]
        if self != winner-1 [set district-mysize 0]
        ifelse district-mysize > 0 [set color yellow] [set color green]
    ]


The code runs, but the problem is that it doesn't always return me a single winner through max-one-of. When I ask the observer to show winner-1 it does only return one name. But, as you see when you run the code, sometimes multiple winners (color: yellow) occur simultaneously in the 2D-space. Moreover, they do not even (always) tie. The cases I observed where  two yellow winners occurred always entailed one party that had a higher district-size-1 value and thus should clearly have been the single winner.

Does anyone know how to make sure only one winner is identified? 

Thanks in advance for your help!
max-one-of.nlogo

James Steiner

unread,
Jun 17, 2022, 11:03:31 AM6/17/22
to San, netlogo-users
I think it has to do with all the parties doing the vote counting and I am thinking about an good solution. 

I think it may be useful to use a breed of turtles to represent each district and count votes and determine the winner for the district. 

Hopefully will have something later today. 

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/75fda2ef-9582-4b66-b37b-aa55c9dd2300n%40googlegroups.com.

San

unread,
Jun 17, 2022, 11:15:55 AM6/17/22
to netlogo-users
Hello!

Thank you very much for your quick reply. Would be great if you have some time later today to look further into it.

Do you think it would also be possible to keep the districts as they are? For the sake of the experiment I'm running I'm not sure I can change them.

Cheers,

San

Op vrijdag 17 juni 2022 om 17:03:31 UTC+2 schreef gregortroll:

Sanne van Vliet

unread,
Jun 17, 2022, 1:55:15 PM6/17/22
to netlogo-users
Hello,

With your input I changed the code for ask parties into

ask parties [
      if n-districts > 0 [
        set winner-1 max-one-of parties [sum [votes] of patches with [closest-party = myself and district = 1]]
        ifelse self = winner-1 [set district-mysize 1] [set district-mysize 0]

        ifelse district-mysize > 0 [set color yellow] [set color green]        

This seems to avoid the problem. Do you agree?

Thanks,

San

Op vr 17 jun. 2022 om 17:15 schreef San <sannevan...@gmail.com>:

wade.s...@gmail.com

unread,
Jun 17, 2022, 3:11:09 PM6/17/22
to netlogo-users
I'm attaching a revised version of your model which seems to work,  or looks like it can be tweaked to do what you want.
I modified two lines in your code, marked with "<<<<<<<<" to add English names to the parties so it's a little less numeric.
I added a routine at the very end called "tally" that you can run from the Command Center.
it seems to work and produces a sort of couble-entry bookkeeping audit trrail and check sum.
It's wordy but you can suppress the print statements once you confirm it works and are done tweaking it.
The output includes sections like this:


 ------> for district: 49 this many votes: 12801.954344857973 broken out below
.....in district 49 party (party 0): has this many votes: 302.9649675865895
.....in district 49 party (party 1): has this many votes: 1457.5052709454735
.....in district 49 party (party 2): has this many votes: 0
.....in district 49 party (party 3): has this many votes: 830.4743848217157
.....in district 49 party (party 4): has this many votes: 1393.6496323186223
.....in district 49 party (party 5): has this many votes: 4418.5271517613455
.....in district 49 party (party 6): has this many votes: 147.01914867815847
.....in district 49 party (party 7): has this many votes: 3005.0957136873785
.....in district 49 party (party 8): has this many votes: 976.2462740954787
.....in district 49 party (party 9): has this many votes: 270.4718009632105
.................... subtotal: 12801.954344857973  District Winner with 4418.5271517613455 is (party 5)

Wade Schuette

unread,
Jun 17, 2022, 3:12:51 PM6/17/22
to netlogo-users
Well NOW I'm attaching the revised model.

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
max-one-of-tally.nlogo

James Steiner

unread,
Jun 17, 2022, 8:19:01 PM6/17/22
to San, netlogo-users
Oh certainly. 

Making the parties / candidates move around was just for the fun of it, to see that voting was working right, and to get a good feel for that particular bi-level visualization. 

You can certainly construct the districts, number , size, shape, whatever, in any way you want, and likewise define the vote heuristic any way you want, and define the party number, and placement anyway you want. 

The key part of this demonstration is using “tally” links between districts and parties as a relatively simple way to count, evaluate, and report on the election. 

I isolated most of the visualization stuff at the end so it would be clear it was not important to the function of the vote counter. 

But likewise, the shapes, shape sizes, shape colors, link shapes, link colors, headings, patch colors, and whether any of those things are hidden or not, is all entirely non essential. 

Later today is not possible, but I have time tomorrow (Saturday) morning. 

Email me directly. 
Reply all
Reply to author
Forward
0 new messages