# Agent Based Force Vector Model of Social Influence

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

## Abstract

The model is based on a 2-dimensional vector representation of the agents. The components of the vector for an agent are the key continuous “attributes” that determine the social behavior of the agent. A simple mathematical force vector model is used to predict the effect of each agent on all other agents. The force law used is motivated by gravitational force laws and electrical force laws for dipoles. It assumes that the force between two agent is proportional to the similarity of attributes or the dot product of the vectors representing the attributes of the agents and goes as the inverse square of the difference in attributes, which mathematically is expressed as the distance in attribute space between the two vectors. The force between the agents may be positive, zero, or negative. A positive force causes the attributes of the agents to become more similar and the corresponding vectors to become more nearly parallel. Interaction between all agents is allowed unless the difference between the attributes representing the agents exceeds a confidence limit (the Attribute Influence Bound) set in the simulation. Similar agents tend to form groups. As the Attribute Influence Limit is increased, and agents with increasingly different attributes can communicate, fewer groups remain at the end of a simulation, and the remaining groups have increasingly different characteristic attributes. With a large Attribute Influence Bound all agents are connected and extreme bi- or tri-and occasional quadri-polarization results. The simulations show collective behaviors of consensus, clustering, fragmentation and polarization as well as certain symmetries specific to the model, for example, the average of the attributes for all agents does not change significantly during a simulation. The model is deterministic yet shows wide variability in the evolution of the simulations for initial conditions based on statistically well defined groups, such as a normal distributions of agent attributes.

## WHAT IS IT?

This model is exploring how simple rules can create complex behaviors. We start with several basic rules.

* The universe is represented by a vector space, currently 2-D, in which the coordinates represent continuous measurable attributes characterizing the agents in the space. It is assumed that the behavior of the agents (ie their movement in the vector space) depends on their attributes and their interactions with other agents.

* Each agent is represented by a vector A(xa, ya) in the space. All vectors start at the origin (0,0) and end at the point (xa, ya), where -100

* Each agent A has a mass m_{A } associated with it. The influence of an agent A on another agent is proportional to its mass m_{A }

* There are forces, attractive and repulsive, between any two agents A(xa,ya) and B(xb,yb) that depend on the relative orientation of the vectors representing the agents. The force of A on B is proportional to the dot product of the vectors AdotB times the mass of A, divided by the square of the distance between the agents (A-B)^2=R^2, times an overall scale factor g. The force is a vector directed along the line connecting the heads of the vectors. The force is akin to a gravitational force except for presence of the dot product, which is reminiscent of the force between electrical dipoles.

* The force of agent A on agent B causes an accelertion of agent B which equals the force of A on B divided by the mass m_{B } of agent B. The acceleration is exerted on an agent for a time interval DT, which causes a movement of the agent which equals the acceleration times (DT)^{2} . In each iteration, all movements are calculated for each agent and the agents are moved accordingly.

> F_{AonB} = g m_{A} ( (A . B) / R^{2}) (A-B)/R

We assume

F_{AonB} = m_{B} a_{B}

solving for the acceleration a_{B} on B due to force of A, we get

a_{B} = g (m_{A} / m_{B}) ( (A . B) / R^{2}) (A-B)/R

where A, B, and F are vectors and R is the magnitude of the vector A-B

R = sqrt ((xa - xb) ^{2} + (ya - yb) ^{2})

g is the gravitational constant and a is the acceleration.

The force between two agents is attractive if their vectors tend to point in the same direction, which means the absolute value of the angle between the vectors representing the agents is 90 degrees or less

(or the algebraic difference in the angles is between -90 and +90).

The force between two agents is repulsive if their vectors tend to point in opposite directions, which means the absolute value of the angle between the vectors representing the agents is greater than 90 degrees

(or the algebraic difference in the angles is greater than 90 and less than 270).

Attribute Influence Bound (AIB)

If the distance R between two agents exceeds the value set in the Attribute Influence Bound (AIB) slider then we assume the agents do not communicate and the force between the agents is automatically set to zero. The maximum value of the AIB is about 280, which is the distance from one corner of the 200x200 space to the opposite corner.

Setting the time interval DT

If DTDynamic is NOT selected:

Then DT=1 or the value on the DT slider is used. In each iteration of the simulation, the movement of each agent is computed. If the largest movement computed for all agents is less than the Coalescence Radius, the simulation is terminated. If the GO ONCE button is pushed, then one more movement will occur despite the motion being less than the coalescence radius.

If DTDynamic IS selected:

If the forces are very small, then DT is increased until the largest movement of an agent is set equal to the Coalescence Radius. On the other hand if the forces are very large, then DT is reduced so that the maximum distance traveled in one iteration for any agent is equal to the Coalescence Radius CR. Use of DTDynamic provides an efficient way to simulate situations in which forces are small and yet may act for long times. However, very small forces may be in the noise level and hence it is believed should not necessarily dominate the long term behavior. To provide an option to prevent this, if DTDynamic is selected, then one must also select DTMax, which is the maximum allowable value of DT. When the forces are so small that DT has to be increased beyond DTMax to insure the distance moved by an agent is equal to the coalescence distance, the simulation will terminate. If the GO ONCE button is pushed, then one more movement will occur with a value of DT that may exceed DTMax.

Movement of Agents

The force of A on B causes an acceleration a_{B} of the vector B that goes inversely with m_{B}, the inertial mass of B resisting the change in the vector B. The acceleration acts for a time step DT causing a displacement of the vector B equal to DeltaB. The displacements of all agents due to the force on each other are computed in each time step.

> DeltaB = (F_{AonB} / m_{B})(DT)^{2}

DeltaB = g (m_{A} /m_{B}) (DT)^{2} ((A . B)/ R^{2})(A - B)/R

This particular model demonstrates attraction and repulsion in a vector space. If the distance R between two agents becomes less than a preset value, the Coalescence Radius CR, the agents are merged into a group, with a mass equal to the sum of the masses of the component agents. The force laws for groups are the same as for individual agents. Once an agent is part of a group, the agent cannot leave the group.

Agents cannot move beyond the boundaries of the 200 x 200 universe. Agents can move along the boundaries, but if they become trapped at corners, the simulation is stopped.

## HOW TO USE IT

### Controls

#### Setup

* Before setup, select / setup the following parameters:

* **Number** of agents- 0-200

* **Spatial** distribution of agents: Random, Normal, or Exponential

* **Random** Distribution - mmean and stddev are ignored for random distribution

* **Normal** Distribution - mmean gives the location (mmean,mmean) of the center of the distribution. The standard deviation ranges from 0 to 1. A standard deviation of 1 means a distance of 100 in our coordinate system. NOTE: In random or normal distributions, if the random number generator places a particular agent outside the boundaries 200 x 200, then a new random number is chosen for the next agent, and the process is continued until the number of initial agents requested are all placed within the boundaries. This process occurs regularly for a normal distribution with a standard deviation above about 0.5.

* **Exponential** Distribution - is equivalent to ( - mean ) * ln random-float 1.0. This is scaled to the size of the universe 200 x 200.

* **Mass** distribution of the agents that are created. Maxmass - this is the maximum mass that is allowed for any of the mass distributions. The SD standard deviation in mass also needs to be specified for the normal distribution. The force of agent A on agent B is proportional to the mass of agent A. The movement of agent B from the force due to A goes inversely as the mass of agent B.

* **Random** - all agent masses are between 1 and maxmass

* **Normal** - all masses are normally distributed around mass-mean with mass-stddev and between 1 and maxmass.

* **Exponential** - is equivalent to ( - mass-mean ) * ln random-float 1.0. The mass is always between 1 and maxmass

* **Attribute Influence Bound (AIB)** - This is the maximum distance between two agents at which they affect each other. There is no interaction between agents that are farther apart than the AIB. The largest possible distance in the 200 x 200 universe is the hypoteneuse 200 SqRt(2) = 283.

* **Distance exponent** - this is exponent for the distance (R - normally set to 2) in the force equation: F_{AonB} = g m_{A} ( (A . B) / R^{DistanceExponent}) (A-B)/R

* **Coalescence Radius (CR)** - If two agents move closer together than the coalescence radius, then the agents are merged into one group agent and the mass of the group is the sum of the masses of the component agents. CR is typically set to 0.3. The location of an individual agent is shown by a circle. After two individual agents coalesce, the resulting group is represented as a triangle. The numbers beside the symbols indicate the corresponding mass.

* **g** - This is the overall constant that scales the force between two agents, similar to the gravitational constant for gravitational forces. Typically set to 7 x 10^-5 .

* **DTDynamic** - time granularity is important for running the simulation in reasonable time frames. The default value for the time step is DT=1. If DTDynamic set to "on" , the simulation runs and the value of DT is varied to insure that the maximum movement of an agents equals the Coalescence Radius. The current value of DT is displayed in the slider for each iteration and plotted in the DT plot. We have noticed more than an order of magnitude reduction in elapsed time to reach a final state with DTDynamic. We have compared the end results and verified that the end results are equivalent with a DTDynamic and a low value of DT for smooth dynamics.

_IMPORTANT:_ If DTDynamic is selected, then one must also set the value for DTMax. This is the maximum value of DT allowed in the simulation. This effectively sets the lower threshold of force that is allowed in the simulation to affect agents. Values of DTMax above about 125 tend to magnify the effects of very small repulsive forces.

With DtDynamic off, you can set the value of DT that you want to use for the simulation with the slider. The value is fixed for all iterations. The default is 1.

* **Randomseed** - if set to 0, each simulation run will generate a different random placements of agents and their masses. If Randomseed is set to a nonzero integer, that seed will allow you to start the simulation with the exactly the same random initial conditions of agent placements and masses and colors. This is useful for repeating scenarios where you want to test the same initial condition while varying some of the other parameters, e.g., Coalescence Radius.

* **track** - agents / groups leave a track of their trajectory as they move.

#### Optional Controls

On the LEFT side of the display

* **tickstop** - if nonzero, stop after that many iterations.

* **forceAdj** - changes the application of the force law.

* **Normal** - both positive and negative forces are in play. If A . B is positive, the force is attractive, If A . B is negative, the force is repulsive.

* **AttractOnly** - all forces are attractive only. If A . B is negative it's absolute value is used

* **RepulseOnly** - all force calculation are turned negative, minus the absolute value of F is used.

* **NoAttract** - all attractive forces are set to zero so that only repulsive forces are in play.

* **NoRepulse** - all repulsive forces are set to zero so that only attractive forces are in play.

* **Invert** - forces are inverted. If attractive, they are made repulsive and vice versa.

* **Create** Agent - allows manual creation of an agent by using the mouse to place agents on the display grid. Multiple agents may be created, one at a time.

* **Initial**-mass sets the mass of the created agent and

* **Agent**-color sets the color of the created agent (a number between 0 and 140).

* **debug** - shows debug messages at various simulation points.

* **center** - calculates the center of mass of all the agents and moves them so that the center of mass is at the origin.

* **World** - Clicking this button at any time will create a "world.csv" file that captures all the data on the interface, i.e., all the plots, values of global variables, all the positions and attributes of all the agents, and all the attibutes of each cell of the universe.

* **OutputData** - Clicking this button exports all the plots on the interface as a csv file called "counter.csv"

* **rotateAxes**-slider to set value to 0 to 360 degrees

* **ROTATE** button, this causes the system to rotate the coordinate system clockwise the number of degrees specified in the rotateAxes slider.

* **Record view** - if clicked before go, it will make a movie of the simulation with one frame for each iteration.

* **Record intfc** - if clicked before go, it will make a movie of the interface with one frame for each iteratin.

### Plots

**Agent Counter**

* **turtles** - the total count of all the active agents for each iteration which equals the sum of individual agents and group agents

* **groups** - the total number of all agent groups resulting from coalescence of individual agents for each iteration

**mean distances**

* **meandist**- mean distance between all the agents for each iteration, irrespective of whether a particular agent is within the AIB

* **meanxsd** - standard deviation of the mean x distance between agents for each iteration

* **meanysd** - standard deviation of the mean y distance between agents for each iteration

* **meandistclosestneighbor** - the mean distance to the closesest neighbor for all agents for each iteration irrespective of the AIB

* **dcnsd** - standard deviation of distance to closest neighbor for each iteration (if the screen display is made smaller, sometimes the legend for this does not display fully)

**maxdist meanxy**

* **meanxloc** - mass weighted mean x coordinate for all agents for each iteration, equals sum [mass of agent i times its x coordinate x_i]/total mass

* **meanyloc** - mass weighted mean y coordinate for all agents for each iteration calculated same way as meanxloc

* **maxdist** - the maximum distance that is traveled by an agent for each iteration. If DynamicDT is on, then maxdist will equal the Coalescence Radius.

**Median R**

* **median** of the distances of the agents from the origin

* **mean** of the distances of the agents from the origin

* **standard** deviation of the median of the distances

**DeltaT**

* plot of the value of DT versus the iteration number. DT would be constant equal to 1 or the set value of DT if DtDynamic is off. If DTDynamic is on, the plot gives the values of DT employed in the simulation to secure maximum agent movements equal to the Coalescence Radius.

**Elapsed Time**

*Plot of the elapsed time (which is the sum of the values of DT) on the y-axis versus the iteration number on the x-axis.

**mass distribution**

* **histogram** of the mass distribution of the active agents (both individual and group agents)

### Monitors

On the bottom of display:

* **totmass** - at bottom of display, this monitor give the total mass of all agents in the simulation

* **agents** - shows the total number of agents active at any given time in the simulation which equals individual agents plus group agents

* **elapsed-time** shows the sum of the DT values used in the simulation to this point.. One additional DT value is added to elapsed time for each iteration .

* **iterations** - total number of iterations (time steps) that the model has run at any point in the simulation. **Note:** With dynamic dt, ticks (on the top) actually shows elapsed time. Iterations shows the actual number of iterations of the simulation.

* **stopreason** - why simulation stopped

* **Final DT** - final value of dt at end of simulation

## Copyright and License

Copyright 2020 Moody Ahmad, G Jordan Maclay.

Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License

License details at https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode

Note: For full disclosure: This model base was the N-Bodies model in the Netlogo Sample Models library under Chemistry and Physics -> Mechanics -> unverified -> N-Bodies. That

was a starting point. The model has been modified almost completely from the starting point.

## Comments and Questions

extensions [profiler shell csv vid] turtles-own [ fx ;; x-component of force vector fy ;; y-component of force vector xc ;; real x-coordinate (in case agent leaves world). these are used for all calculations and then used to update xcor, ycor. yc ;; real y-coordinate (in case agent leaves world) mass ;; the particle's mass dxc ;; delta x coord change dyc ;; delta y coord change dcn ;; distance to closest neighbor calculate for each iteration. mag ;; size of vector. Calculated for each iteration. angle ;; angle of vector. Calculated for each iteration. ] globals [ center-of-mass-yc ;; y-coordinate of the center of mass. Used to recenter all agents around the center of mass of the whole population. center-of-mass-xc ;; x-coordinate of the center of mass maxforce ;; max force on each iteration. Used to determine when to stop the simulation - when maxforce < min force cutoff maxdist ;; max distance traveled in an iteration peakdist ;; peak dist for an iteration. When dynamic dt is on: the max dist traveled is =< than the coalescence radius. meandist ;; mean distance between all agents repulsive ;; total repulsive force across all agents for each iteration attractive ;; total attractive force meanxloc ;; mass weighted x location for all agents meanyloc meanxsd ;; mass weighted x location standard deviation for all agents meanysd meandistclosestneighbor ;; mean distance to closest neighbor dcnsd ;; standard deviation of distance to closest neighbor meandistorigin ;; eman distance to the origin scale ;; scale multiplier factor from a -1,1 world. masscale ;; sise of agent scaled by mass (.1 for scale 1) totmass ;; total mass of agents used for debugging only elapsed-time ;; time elapsed is sum of dts iterations ;; number of simulation iterations stopflag ;; when set, stop simulation stopreason ;; why the simulation was stopped mergeCount ;; number of mergers in an iteration mergeTotMass ;; merge mass for each iteration groups ;; number of groups finaldt ;; final dt at end of simulation record-view ;; make movie of view record-interface ;; make movie of interface ] ; Basic Model Design: ; Setup initializes the model for a simulation run. ; The spatial and mass distributions selected for the agents are set up ; All necessary globals are initialized ; Note: randomseed is initialized for repeatable runs ;;;;;;;;;;;;;;;;;;;;;;;; ;;; Setup Procedures ;;; ;;;;;;;;;;;;;;;;;;;;;;;; to setup clear-all set scale 100 set stopflag false set masscale .03 set peakdist 0 set dt 1 set elapsed-time 0 set iterations 0 set-default-shape turtles "circle" set record-view False set record-interface False if randomseed != 0 [ random-seed randomseed ] create-turtles number [ set color ( random 5 ) + (( random 14 ) * 10) ] ask patches [ set pcolor white ] random-initial-setup mass-setup set totmass 0 ask turtles [ set totmass totmass + mass ] reset-ticks end to random-initial-setup ask turtles [ if SpatialDistribution = "Random" [ set xcor random-float (2 * scale) - scale set ycor random-float (2 * scale) - scale ] if SpatialDistribution = "Normal" [ set xcor random-normal-in-bounds mmean (scale * stddev) (- scale) scale set ycor random-normal-in-bounds mmean (scale * stddev) (- scale) scale ] if SpatialDistribution = "Exponential" [ set xcor random-exponential-pos-in-bounds mmean (- scale) scale set ycor random-exponential-pos-in-bounds mmean (- scale) scale ] set xc xcor set yc ycor if track [ pen-down ] ] end to mass-setup let locmass 0 ask turtles [ if mass-distribution = "Random" [ set locmass ( random-float maxmass ) ] if mass-distribution = "Normal" [ set locmass random-normal-in-bounds mass-mean mass-stddev 1 maxmass ] if mass-distribution = "Exponential" [ set locmass random-exponential-in-bounds mass-mean 1 maxmass ] set mass locmass set size masstosize mass ] end to create-agent if mouse-down? [ let mx mouse-xcor let my mouse-ycor let mz 0 if (not any? turtles-on patch mx my ) [ create-turtles 1 [ set xc mx ;initial-position-x set yc my ;initial-position-y setxy xc yc set mass initial-mass set size masstosize mass set color agent-color if track [ pen-down ] ] display ] ] while [mouse-down?] [] end ;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Runtime Procedures ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;; ; Runtime Design ; There are several controls that determine what happens at runtime: ; tickstop - set to a nonzero value, will stop the simulation when the number of iterations selected is reached ; record-view or record-interface - start a movie creation for the run ; AIB and MaxDT settings can both stop a simulation if those values are reached. If this happens, a stopflag and ; stopreason is set to indicate the end of the simulation. The go function checks this flag at the end of each iteration ; and stops the simulation. ; ; NOTE: the coordinates used for the simulation are defined agent variables xc, xy. The netlogo agent coordinates ; are used to set xc, xy at the beginning of each iteration. Then xc, xy are used for all the movement calculations. ; Agent xcor, ycor are set by function adjust-position after all the force and movement calculations are done. ; This is done near the end of each iteration before plots are updated. ; NOTE; for clarity of design and modularity, the ask turtles functions is invoked for collision / merger checks, ; force calculations, max movement calculations (for stopping conditions and dynamic dt setting), ; to go if tickstop != 0 [ if iterations > tickstop [ stop movie ] ] if record-view or record-interface [ if vid:recorder-status = "inactive" [ vid:start-recorder ] movie-init ] set attractive 0 set repulsive 0 set stopflag false set mergeCount 0 set mergeTotMass 0 ask turtles [ set fx 0 set fy 0 set xc xcor set yc ycor set label int mass set label-color black ] set maxforce 0 set maxdist 0 set peakdist 0 ;; must do all of these steps separately to get correct results ;; since all turtles interact with one another ask turtles [ check-for-collisions set label int mass ] meanlocation ask turtles [ update-force ] ask turtles [ peakdist-calc ] ifelse peakdist = 0 [ set stopflag true set stopreason "No movement" update-plots ][ if DtDynamic [ set dt sqrt ( CoalescenseRadius / peakdist ) ] ifelse dt > DTMax [ set stopflag true set finaldt dt set stopreason "DT Max" update-plots ] [ ask turtles [ update-position ] update-plots set elapsed-time elapsed-time + dt set iterations iterations + 1 tick-advance dt ] ] if stopflag [ movie stop ] end ; if any agents are within coalescence radius, merge into one agent to check-for-collisions ask other turtles [ if realdist self myself <= CoalescenseRadius [ merge self myself ] ] end ; Merge two agents into one. ; Note: the position of the merged agent is the position of the agent with the larger mass. ; the color of the merged agent is the color of the agent with the larger mass. to merge [ a b ] ;; a merges with with b set mergeTotMass mergeTotMass + mass + [mass] of b let mergemass mass if mass > [mass] of b [ ask b [ set color [color] of a set xc [xc] of a set yc [yc] of a ] ] ask b [ set mass mass + mergemass set shape "triangle" set size masstosize mass ] set mergeCount mergeCount + 1 ask a [ ;; user-message (word "Turtle " [who] of a " is dead now") die ] end to update-force ;; Turtle Procedure ;; This is recursive over all the turtles, each turtle asks this of all other turtles ;; Note: the force calculations are for all the other agents, not the asking agent, i.e., myself ;; the force of myself on all other agents is set in this procedure. ask other turtles with [ distance myself <= AIB ] [ sum-its-force-on-me myself ] end ; The force calculations are done. 'it' is the asking agent. ; Note: The force adjustment control determines the force direction. to sum-its-force-on-me [it] ;; Turtle Procedure let distsq vecdistsq it self let dist sqrt distsq let ab adotb it self let fxt 0 let fyt 0 if forceAdj != "Normal" [ ifelse forceAdj = "AttractOnly" [ set ab abs ab ][ ifelse forceAdj = "Repulse" [ set ab ( - abs ab ) ][ ifelse forceAdj = "NoRepulse" [ if ab < 0 [ set ab 0 ] ][ ifelse forceAdj = "NoAttract" [ if ab > 0 [ set ab 0 ] ][ set ab ( - ab ) ] ]]]] set fxt g * ( (( [xc] of it - xc ) / dist) * ( [mass] of it ) * ab ) / ( (dist ^ DistanceExponent) ) set fyt g * ( (( [yc] of it - yc ) / dist) * ( [mass] of it ) * ab ) / ( (dist ^ DistanceExponent) ) set fx fx + fxt set fy fy + fyt ifelse ab >= 0 [ set attractive attractive + sqrt ( fxt ^ 2 + fyt ^ 2) ] [ set repulsive repulsive + sqrt ( fxt ^ 2 + fyt ^ 2) ] ;; if debug ;; [ user-message (word "who " who " it= " it " adotb " ab " dist " distsq " fxdir " fxdir " fydir " fydir " fx " fx " fy " fy) ] end ; The position is update for the agent depending on the forces on the agent. ; Note: the force is divided by the mass of the agent being updated. The mass is considered to be ; its passive mass / inertia to the movement. to update-position ;; Turtle Procedure ;; As our system is closed, we can safely recenter the center of mass to the origin. let stopq false set dxc fx * ( dt ^ 2) / mass set dyc fy * ( dt ^ 2) / mass let dist sqrt ( dxc ^ 2 + dyc ^ 2) if dist > maxdist [ set maxdist dist ] let newxc (xc + dxc) let newyc (yc + dyc) if abs(newxc) > max-pxcor [ ifelse newxc > 0 [ set newxc max-pxcor ] [ set newxc min-pxcor ] set stopq true ] if abs(newyc) > max-pycor [ ifelse newyc > 0 [ set newyc max-pycor ] [ set newyc min-pycor ] if stopq [ set stopflag true set stopreason "Corner" ] ] set xc newxc set yc newyc ;; if debug [ ;; if newxc < min-pxcor or newxc > max-pxcor or newyc < min-pycor or newyc > max-pycor [ ;; user-message (word "up who " who " dxc dxy " dxc " " dyc " newxc newrxy " xc " " yc " xcor ycor " xcor " " ycor) ;; ] ;; ] adjust-position end ; set agent coordinates from coordinate variables used to do all the force calculations. to adjust-position ;; Turtle Procedure setxy xc yc end ; calculate the square of the distance between two agents to-report vecdistsq [a b] report ([xc] of a - [xc] of b) ^ 2 + ([yc] of a - [yc] of b) ^ 2 end ; calculate the a dot b value of two agents to-report adotb [a b] report ( ([xc] of a * [xc] of b) + [yc] of a * [yc] of b ) end ; calculate distance between two agents to-report realdist [a b] report sqrt ( ( [xc] of a - [xc] of b) ^ 2 + ([yc] of a - [yc] of b) ^ 2) end ; calculate the force on an agent to-report force-on-me [it] report sqrt ( [fx] of it ^ 2 + [fy] of it ^ 2 ) end ; convert mass to size parameter for displaying agents proportional to their size. ; Note: this is done on a log scale to-report masstosize [m] report scale * masscale * log m 10 end ; generate a random distribution within the min max ; parameters given with the given mean and standard deviation to-report random-normal-in-bounds [ mid dev mmin mmax ] let result random-normal mid dev if result < mmin or result > mmax [ report random-normal-in-bounds mid dev mmin mmax ] report result end ; generate an exponential distribution within the min / max ; range given with the given mean. Move half the results to ; the negative coordinates since the universe is -max to +max to-report random-exponential-pos-in-bounds [ distmean mmin mmax ] let result random-exponential distmean if result < mmin or result > mmax [ report random-exponential-pos-in-bounds distmean mmin mmax ] if random 2 = 1 [ set result ( - result) ] report result end ; generate an exponential distribution within the min / max ; range given with the given mean. to-report random-exponential-in-bounds [ distmean mmin mmax ] let result random-exponential distmean if result < mmin or result > mmax [ report random-exponential-in-bounds distmean mmin mmax ] report result end ; calculate the magnitude of the given vector / agent to-report vecmag [vec] report sqrt ( ([xc] of vec) ^ 2 + ([yc] of vec) ^ 2) end ; calculate the distance to be traveled by the agent calling ; with a dt of 1. set the global max if distance exceeds the current maximum ; also set the global maxforce for this iteration to peakdist-calc if force-on-me self > maxforce [ set maxforce force-on-me self ] set dxc fx / mass set dyc fy / mass let dist sqrt ( dxc ^ 2 + dyc ^ 2 ) if dist > peakdist [ set peakdist dist ] end ; Calculate means, standard deviations, etc. for display. to meanlocation let agentcount count turtles let masscount 0 let distorigin 0 set meanxloc 0 set meanyloc 0 set groups count turtles with [ shape = "triangle" ] ; Calculate the mass weighted mean x and y locations of all the agents ; Calculate distance to the origin for each agent for the mean distance to the origin calc. ; Calculate the total mass of all the agents to get the mean x,y location divisor. ; Set mag (size), angle of each agent ask turtles [ set meanxloc meanxloc + ( xc * mass ) set meanyloc meanyloc + ( yc * mass ) set masscount masscount + mass set mag vecmag self set distorigin distorigin + mag set angle atan xcor ycor ] set meandistorigin distorigin / agentcount ;; mean distance to the origin of all the agents set meanxloc meanxloc / masscount ; mass weighted mean of x,y locations of all the agents set meanyloc meanyloc / masscount ; Calculate mean distance to neighbors for all the agents ; Calculate mean distance to closest neighbor for all agents ; For each agent, store the distance to closest neighbor let mindist 0 let dcnsum 0 let tempdist 0 let mymeandist 0 set meandist 0 ask turtles [ set mindist 10 * scale set mymeandist 0 ; Calculate the distance to closest neighbor. ; Sum mean distance to others for each agent. ask other turtles [ set tempdist realdist self myself if tempdist < mindist [ set mindist tempdist ] set mymeandist mymeandist + tempdist ] set dcn mindist ; set distance to closest neighbor set dcnsum dcnsum + mindist ; sum dcns for mean calcs ; Then divide by agentcount -1 to not include self) to gat the mean dist to all agents ifelse agentcount = 1 [ set meandist 0 ][ ; Note that distance to self is 0 and is not counted in calculating the mean, hence agent count - 1 set meandist meandist + ( mymeandist / ( agentcount - 1 ) ) ; sum each agents mean distance to neighbors ] ] ; Get the means across all agents. set meandist meandist / agentcount ; get mean distance to neighbor across all agents set meandistclosestneighbor dcnsum / agentcount ; Calculate the standard deviations for x, y, and dist to closest neighbor set dcnsd 0 set meanxsd 0 set meanysd 0 ask turtles [ set meanxsd meanxsd + ( xc - meanxloc ) ^ 2 set meanysd meanysd + ( yc - meanyloc ) ^ 2 set dcnsd dcnsd + ( meandistclosestneighbor - dcn ) ^ 2 ] set meanxsd sqrt ( meanxsd / agentcount ) set meanysd sqrt ( meanysd / agentcount ) set dcnsd sqrt ( dcnsd / agentcount ) end ;; Center of Mass to recenter find-center-of-mass ask turtles [ set xc (xc - center-of-mass-xc) set yc (yc - center-of-mass-yc) adjust-position ] end to find-center-of-mass if any? turtles [ set center-of-mass-xc sum [mass * xc] of turtles / sum [mass] of turtles set center-of-mass-yc sum [mass * yc] of turtles / sum [mass] of turtles ] end ; Record the view as a movie to movie if record-view [ vid:save-recording "view.mp4" vid:stop ] if record-interface [ vid:save-recording "interface.mp4" vid:stop ] end ; Record the interface as a movie to movie-init if record-view [ vid:record-view ] if record-interface [ vid:record-interface ] end ;Copyright 2020 Moody Ahmad, G Jordan Maclay. ;Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ;License details at https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode ;Note: For full disclosure: This model base was the N-Bodies model in the Netlogo Sample Models library under Chemistry and Physics -> Mechanics -> unverified -> N-Bodies. That ;was a starting point. The model has been modified almost completely from the starting point.

There are 4 versions of this model.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

Agent Based Force Vector Model of Social Influence.png | preview | Model Interface | 3 months ago, by Moody Ahmad | Download |

This model does not have any ancestors.

This model does not have any descendants.