CODE NETLOGO 1

 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;    SPRITE Negotiation Model     ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variable and Breed declarations ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

globals [

        datafile
        resfile        
        resfile0
        resfileN

        iteration
            
        ;;number of turtles with each strategy
        num-turtles

        num-for-increased
        num-for-decreased
        num-for-maintained
        
        num-for-more-provision-to-increase
        num-for-more-control-to-increase
        num-for-more-newregulation-to-increase
        num-for-more-currentregulation-to-increase
        num-for-more-supply-to-increase
        num-for-more-promotion-to-increase
        num-for-more-cooperation-to-increase
        
        num-for-less-control-to-increase
        num-for-less-newregulation-to-increase
        num-for-less-currentregulation-to-increase
        num-for-less-supply-to-increase
        num-for-less-promotion-to-increase
        num-for-less-cooperation-to-increase
        num-for-others-to-increase          
 
        num-for-more-provision-to-decrease
        num-for-more-control-to-decrease
        num-for-more-newregulation-to-decrease
        num-for-more-currentregulation-to-decrease
        num-for-more-supply-to-decrease
        num-for-more-promotion-to-decrease
        num-for-more-cooperation-to-decrease
        
        num-for-less-control-to-decrease
        num-for-less-newregulation-to-decrease
        num-for-less-currentregulation-to-decrease
        num-for-less-supply-to-decrease
        num-for-less-promotion-to-decrease
        num-for-less-cooperation-to-decrease
        num-for-others-to-decrease          
 
        num-for-more-provision-to-maintain
        num-for-more-control-to-maintain
        num-for-more-newregulation-to-maintain
        num-for-more-currentregulation-to-maintain
        num-for-more-supply-to-maintain
        num-for-more-promotion-to-maintain
        num-for-more-cooperation-to-maintain
        
        num-for-less-control-to-maintain
        num-for-less-newregulation-to-maintain
        num-for-less-currentregulation-to-maintain
        num-for-less-supply-to-maintain
        num-for-less-promotion-to-maintain
        num-for-less-cooperation-to-maintain
        num-for-others-to-maintain          
 
        num-optimization
        num-suboptimization
               
        ;;total actors resources of each strategy
        resources-for-increased
        resources-for-decreased
        resources-for-maintained
        
        resources-for-more-provision-to-increase
        resources-for-more-control-to-increase
        resources-for-more-newregulation-to-increase
        resources-for-more-currentregulation-to-increase
        resources-for-more-supply-to-increase
        resources-for-more-promotion-to-increase
        resources-for-more-cooperation-to-increase
        
        resources-for-less-control-to-increase
        resources-for-less-newregulation-to-increase        
        resources-for-less-currentregulation-to-increase
        resources-for-less-supply-to-increase
        resources-for-less-promotion-to-increase
        resources-for-less-cooperation-to-increase
        resources-for-others-to-increase          
 
        resources-for-more-provision-to-decrease
        resources-for-more-control-to-decrease
        resources-for-more-newregulation-to-decrease
        resources-for-more-currentregulation-to-decrease
        resources-for-more-supply-to-decrease
        resources-for-more-promotion-to-decrease
        resources-for-more-cooperation-to-decrease
        
        resources-for-less-control-to-decrease
        resources-for-less-newregulation-to-decrease
        resources-for-less-currentregulation-to-decrease
        resources-for-less-supply-to-decrease
        resources-for-less-promotion-to-decrease
        resources-for-less-cooperation-to-decrease
        resources-for-others-to-decrease          
 
        resources-for-more-provision-to-maintain
        resources-for-more-control-to-maintain
        resources-for-more-newregulation-to-maintain
        resources-for-more-currentregulation-to-maintain
        resources-for-more-supply-to-maintain
        resources-for-more-promotion-to-maintain
        resources-for-more-cooperation-to-maintain
        
        resources-for-less-control-to-maintain
        resources-for-less-newregulation-to-maintain
        resources-for-less-currentregulation-to-maintain
        resources-for-less-supply-to-maintain
        resources-for-less-promotion-to-maintain
        resources-for-less-cooperation-to-maintain
        resources-for-others-to-maintain
                    
        ;;;;;;;;;; base scenario ;;;;;;;;;;;;;        
        px
        xpartners
        xTp
    
        numof-conflictsXi-between-controllers-and-controllers
        numof-conflictsXi-between-controllers-and-businesses
        numof-conflictsXi-between-controllers-and-gatekeepers
        numof-conflictsXi-between-controllers-and-communities                                
        numof-conflictsXi-between-controllers-and-institutions

        numof-conflictsXi-between-businesses-and-controllers
        numof-conflictsXi-between-businesses-and-businesses
        numof-conflictsXi-between-businesses-and-gatekeepers
        numof-conflictsXi-between-businesses-and-communities                                
        numof-conflictsXi-between-businesses-and-institutions

        numof-conflictsXi-between-gatekeepers-and-controllers
        numof-conflictsXi-between-gatekeepers-and-businesses
        numof-conflictsXi-between-gatekeepers-and-gatekeepers
        numof-conflictsXi-between-gatekeepers-and-communities                                
        numof-conflictsXi-between-gatekeepers-and-institutions

        numof-conflictsXi-between-communities-and-controllers
        numof-conflictsXi-between-communities-and-businesses
        numof-conflictsXi-between-communities-and-gatekeepers
        numof-conflictsXi-between-communities-and-communities                                
        numof-conflictsXi-between-communities-and-institutions
                
        numof-conflictsXi-between-institutions-and-controllers
        numof-conflictsXi-between-institutions-and-businesses
        numof-conflictsXi-between-institutions-and-gatekeepers
        numof-conflictsXi-between-institutions-and-communities                                
        numof-conflictsXi-between-institutions-and-institutions


        numof-conflictsEi-between-controllers-and-controllers
        numof-conflictsEi-between-controllers-and-businesses
        numof-conflictsEi-between-controllers-and-gatekeepers
        numof-conflictsEi-between-controllers-and-communities                                
        numof-conflictsEi-between-controllers-and-institutions

        numof-conflictsEi-between-businesses-and-controllers
        numof-conflictsEi-between-businesses-and-businesses
        numof-conflictsEi-between-businesses-and-gatekeepers
        numof-conflictsEi-between-businesses-and-communities                                
        numof-conflictsEi-between-businesses-and-institutions

        numof-conflictsEi-between-gatekeepers-and-controllers
        numof-conflictsei-between-gatekeepers-and-businesses
        numof-conflictsEi-between-gatekeepers-and-gatekeepers
        numof-conflictsEi-between-gatekeepers-and-communities                                
        numof-conflictsEi-between-gatekeepers-and-institutions

        numof-conflictsEi-between-communities-and-controllers
        numof-conflictsEi-between-communities-and-businesses
        numof-conflictsEi-between-communities-and-gatekeepers
        numof-conflictsEi-between-communities-and-communities                                
        numof-conflictsEi-between-communities-and-institutions
                
        numof-conflictsEi-between-institutions-and-controllers
        numof-conflictsEi-between-institutions-and-businesses
        numof-conflictsEi-between-institutions-and-gatekeepers
        numof-conflictsEi-between-institutions-and-communities                                
        numof-conflictsEi-between-institutions-and-institutions
                
        ;;Sliders
        ;Iterations ;; determines the number of simulations to be done
        ;VisionRange ;;tetaci varies from 0 to 1 (i.e. from 0 to 100 (all the actors))
        ;WillingnessToListen;; tetadi varies from 0 to 1 in order to modulate the impact of the resources
        ;ActionsWeight; determines the weight of diffrences on actions among the actors in the alculation of Dij and US/UFij
        ;NetworksWeight; determines the weight of groups involvement of actor in the resources calculation

        ;;Actors knowledge (pefect or imperfect information)
        ;;There are two error sliders, one affects knowledge of Pij, the other affects the agents' knowledge on USij and UFij.         
        ;ErrorOnProbOfSuccAccess  ;; varies from 0 (perfect information) to 10 (great uncertainty)
        ;ErrorOnConsequeOfShifts ;; varies from 0 (perfect information) to 10 (great uncertainty)               
        ;;Determines the standard deviation used for the normal distribution
        ;;of which the mean is the true value of UFsi, USb or Pij for the turtle
        ;;A random number drawn from this distribution determines the agents' guesses about the values of UFij, USij and Pij.

        ;EmotionalDM ;;tetapi = either 0n (EMOTIONAL Decision-Making) or Off (RAIONAL DM)
        ;;RATIONAL agent i uses the principle of maximum expected utility: it only attempts to challenge j
        ;;when its perception of the expected utility of challenging j is greater than that of not challenging j
        ;;EMOTIONAL agent i attempts to challenge j whenever it estimates USij to be more than twice UFij
        ;;and does not attempt to chanllenge j whenever it estimates USij to be less than half UFij
        ;;When it estimates that USij and UFij are similar
        ;;its chance of attempting to challenge is proportional to its estimate of Pij.       

        ;SubOptimalGains
        ;SubOptimaCosts
        ;;With SubOptimalGains Off and SubOptimalCosts Off actor i only attempts to challenge actor j
        ;;if i's challenging j i gets the maximum U (MaxEiUij); i.e. if j's positions are very far to i's positions
        ;;and j only adopt the i's position if j gives in the minimum U (MinEjUji); i.e. if i's positions are very close to the j's positions
        ;;With SubOptimalGains On actor i attempts to challenge actor j even if challenging j doesn't give to him the maximum gain
        ;;With SubOptimaCosts On actor and j accepts to be challenged by actor i even if adopting the i's position requires more than the smallest cost         
        ]
        
;patches
        ;[
        ;pxcor        ;; patch x coordinate: varies from -12 to +12
        ;pycor        ;; patch y coordinate: varies from -12 to +12
        ;pcolor       ;; patch color: varies with Q2(Xi)
        ;plabel       ;; nil
        ;plabel-color ;; grey (9.9999)
        ;]

;patches-own
        ;[
        ;]

;turtles
       ;[
        ;who         ;; rank order number of each turtle: varies from 0 to ...
        ;color       ;; turtle color: varies with breed
        ;heading     ;; turtle orientation
        ;xcor        ;; turtle x coordinate = Q4 (Ei): varies from -12 to +12
        ;ycor        ;; turtle y coordinate = Q2 (Xi) modulo Q1 (Si): varies from -12 to +12
        ;shape       ;; turtle shape (default)
        ;pen-down?   ;; false
        ;label       ;; first letter of breed + rank order number in the database
        ;label-color ;; grey (9.9999)
        ;breed       ;; group (complete name of role)
        ;hidden?     ;; false
        ;size        ;; default
       ;]
       
breeds [
        gatekeepers
        controllers
        businesses
        communities
        institutions
        
        nodes
        edges
       ]

turtles-own  
        [
        ;;inputs
        ;;SPRITE worldForNegatiation imported from the Base Scenario
        role            ;; 1=I, 2=R 3=G, 4=B, 5=C
        Ri              ;; Qx-power: resources varies from 0 to 1
        Gi              ;; groups-involvement = poi+(poi'-1) varies from 0 to 3        
        Si              ;; Q1-salience: varies from 1 to 4 Q1-salience
        Xi              ;; Q2-expect: expectation about k varies from -1 to 1
        Ei              ;; Q4 preferred way to achieve Xi: 0 (PROV+), 2 (CONT+), ... 12 (COOP+)
        Dij             ;; list of correlations between i and its closer actors (ref. HCA DistancesAll ; varies from 0 to 1))
        Nij             ;; list of the closer actors in same order than dijk
     
        ;;intermediate variables
        ;WillingnessToShift   ;;tetapi = Gi/Gi+1: varies from 0 to 1 with the inverse of networking involvement
          
        ;;actors knowledge on probability (Pij), benefit (ESij), cost (EFij) of challenges
        guessp          ;; Pij bias = random-normal (value-from (turtle-here) [Pij]) (ErrorOnProbOfSuccessAccess / 10)   
        guessb          ;; USij bias= random-normal (value-from (turtle-here) [USij]) (ErrorOnConsequOfShifts)
        guessc          ;; UFij bias = random-normal (value-from (turtle-here) [UFij]) (ErrorOnConsequOfShifts)
        
        Pij             ;; probability of i accessing to j
                        ;; Pij = Ri/(Rj-(Rj*WillingnessToListenj)) with:
                        ;; WillingnessToListen varies from 0 to 0.9
        Uij             ;; reciprocal utilities = Pearson correlation between the expected and planed actions of i and j
                        ;; Uij = 1- Dij if Xi and Xj = 0 else Uij= Dij*|Xi+Xj|/2
        USij            ;; utility for i to succed in challenging j
                        ;; USij = (2-(4*[(2-(Rj*Sj*WillingnessToShiftj*Uij))/4])) with:
                        ;; WillingnessToShiftj = 1/exp(Gj)
        UFij            ;; utility for i to fail in challenging j                        
                        ;; UFij = -1*((2-(4*[(2-(Ri*Si*WillingnessToShifti)*Uij-1))/4])) with:
                        ;; WillingnessToShifti = 1/exp(Gi)
        EiUij           ;; i's perception of utility for i to challenge j
                        ;; without taking account multilateral utilities for i to defeat j
                        ;; EiUij = (Pij*USij)+((1-Pij)*UFij))
        EiUji           ;; i's perception of utility for j to challenge i
                        ;; EiUji = ((1-Pij)*USij)+(Pij*UFij)

        challenger      ;; id number (who) of actor that convinced an other actor (nobody of is not a challenger)
        challenger-newneighbours  ; list of convinced partners
        challenger-shiftedobjectives ; list of shifts (objectives abandonned by the challenged partners)
        challenger-shiftedstrategies ; list of shifts (actions abandonned by the challenged partners)        
        ;MaxOfferOfi     ;; EjUji expected utility of the partner to be challenged by challenger
        challenged?     ;; am I challenged by an other actor, i.e. have I been convinced by an other actor?
        partnered?      ;; am I partnered with an other actor, i.e. have I convinced an other actor?
        partner         ;; WHO of my partner (nobody if not partnered)
        partner-newneighbours  ; list of challengers
        partner-newsobjectives ; list of shifts (objectives adopted by the challenged partners)
        partner-newsstrategies ; list of shifts (actions adopted by the challenged partners)        
        gains            ;; utilities gained by the challengers
        losses           ;; utilities loss by the challenged partners

        ;; intermediate variables
        n Lij W NSi NSj NRi NRj NXi Nxj NGi NGj NDij NPij NUij NUSij NUFij NPji NUSji NUFji
                
        ;  score
        ;  strategy
        ;  defect-now?
        ;  partner-defected?
        conflictXi-with-R
        conflictXi-with-B
        conflictXi-with-C
        conflictXi-with-G
        conflictXi-with-I        

        conflictEi-with-R
        conflictEi-with-B
        conflictEi-with-C
        conflictEi-with-G
        conflictEi-with-I        
                                                
        ]

;;;;;;;;;;;;;;;;;;;;;
;; Setup Procedures ;;
;;;;;;;;;;;;;;;;;;;;;

; setup clears all and then creates turtles
; import actors and patches features

to setup
  locals [country region event a b c d]
  ca
  clear-all-plots

  set-default-shape edges "line"

  set country (user-choice "Country?" [ "CZ" "IR" "UK" "SP" "GR" "FR"])
  set region  (user-choice "Region (Please refer to the name of your database)?" [ "1" "2"])
  set event  (user-choice "Event (GS=General event; RSS=Region-specific event)?" [ "-GS" "-RSS"])
  set a word "SPRITE-" country
  set b word a region
  set c word b event
  set datafile word c "worldForNegotiation-jpb-b.txt"

  print "Please, wait for a few moment..."
  print "... I am loading the database"
  print datafile
  ;import-world "SPRITE-CZ1-RSSworldForNegotiation-jpb-b.txt"  
  import-world datafile
    
  ifelse "Yes" = (user-choice "OK with the values of the parameters?" [ "Yes" "No" ])
  [
  print "Suggested values of the parameters:"
  type "PoliticalDistance " print PoliticalDistance
  type "NbOf Iterations " print Iterations
  type "ThirdParty " print ThirdParty
  type "VisionRange " print VisionRange
  type "ActionsWeight " print ActionsWeight
  type "NetworksWeight " print NetworksWeight
  type "Willingness To Listen " print WillingnessToListen
  type "Error On Prob Of Access " print ErrorOnProbOfSuccAccess
  type "Error On Cons.Of Shifts " print ErrorOnConsequeOfShifts
  print "Please, wait for a few moment..."
  print "... I am building the base scenario"
  store-initial-turtle-counts ;;record the number of turtles for each strategy
  setup-common-variables   ;;sets the variables that all turtles share  
  do-plot-objectives
  do-plot-actions-to-increase
  do-plot-actions-to-maintain
  do-plot-actions-to-decrease    
    
  do-plot-optimization
 
  do-base-scenario
 
  set iteration 0      
  ;set results-filename word "SPRITE-CZ1-RSSresultsOfNegotiation-jpb-b" iteration
  ;set extended-results-filename word results-filename ".csv"  
  ;export-world extended-results-filename
  set d word c "resultsOfNegotiation-jpb-b"  
  set resfile0 word d iteration  
  ;set resfile0 word z ".dat"  
  export-world resfile0
  print "Now, run the simulations"
  ]
  [
  print "Setup the parameters"
  ]
end

to setup-patches
  ask turtles with [breed = edges]
  [
  die
  ]
end

to do-base-scenario
    controllers-views-and-others
    businesses-views-and-others
    gatekeepers-views-and-others
    communities-views-and-others
    institutions-views-and-others                
    print "Possible future conflicts generated by the actors expectations"
    count-conflictsXi-amongRBGCI
    print "Possible future conflicts generated by the actors strategies"     
    count-conflictsEi-amongRBGCI    
end

to controllers-views-and-others
   ask turtles with [breed = controllers]
   [;open ask1
   without-interruption
      [;open without
      set px Xi
      count-conflicts-for-Xi
      set px Ei
      count-conflicts-for-Ei      
      ];close without
   ];close ask 1
end

to businesses-views-and-others
   ask turtles with [breed = businesses]
   [;open ask1
   without-interruption
      [;open without
      set px Xi
      count-conflicts-for-Xi
      set px Ei
      count-conflicts-for-Ei      
      ];close without
   ];close ask 1
end

to gatekeepers-views-and-others
   ask turtles with [breed = gatekeepers]
   [;open ask1
   without-interruption
      [;open without
      set px Xi
      count-conflicts-for-Xi
      set px Ei
      count-conflicts-for-Ei      
      ];close without
   ];close ask 1
end

to communities-views-and-others
   ask turtles with [breed = communities]
   [;open ask1
   without-interruption
      [;open without
      set px Xi
      count-conflicts-for-Xi
      set px Ei
      count-conflicts-for-Ei      
      ];close without
   ];close ask 1
end

to institutions-views-and-others
   ask turtles with [breed = institutions]
   [;open ask1
   without-interruption
      [;open without
      set px Xi
      count-conflicts-for-Xi
      set px Ei
      count-conflicts-for-Ei      
      ];close without
   ];close ask 1
end

to count-conflicts-for-Xi            
      set xpartners turtles with [breed = controllers and self != myself and Xi != px]      
      set xTp count xpartners
      ;if xpartners != []
      if (xTp > 0)
          [
          set conflictXi-with-R xTp
          ];close if

      set xpartners turtles with [breed = businesses and self != myself and Xi != px]      
      set xTp count xpartners
      ;if xpartners != []
      if (xTp > 0)
          [
          set conflictXi-with-B xTp
          ];close if

      set xpartners turtles with [breed = communities and self != myself and Xi != px]      
      set xTp count xpartners
      ;if xpartners != []
      if (xTp > 0)
          [
          set conflictXi-with-C xTp
          ];close if
          
      set xpartners turtles with [breed = gatekeepers and self != myself and Xi != px]      
      set xTp count xpartners
      ;if xpartners != []
      if (xTp > 0)
          [
          set conflictXi-with-G xTp
          ];close if

      set xpartners turtles with [breed = institutions and self != myself and Xi != px]      
      set xTp count xpartners
      ;if xpartners != []
      if (xTp > 0)
          [
          set conflictXi-with-I xTp
          ];close if
end                    

to count-conflicts-for-Ei            
      set xpartners turtles with [breed = controllers and self != myself and Ei != px]      
      set xTp count xpartners
      ;if xpartners != []
      if (xTp > 0)
          [
          set conflictEi-with-R xTp
          ];close if

      set xpartners turtles with [breed = businesses and self != myself and Ei != px]      
      set xTp count xpartners
      ;if xpartners != []
      if (xTp > 0)
          [
          set conflictEi-with-B xTp
          ];close if

      set xpartners turtles with [breed = communities and self != myself and Ei != px]      
      set xTp count xpartners
      ;if xpartners != []
      if (xTp > 0)
          [
          set conflictEi-with-C xTp
          ];close if
          
      set xpartners turtles with [breed = gatekeepers and self != myself and Ei != px]      
      set xTp count xpartners
      ;if xpartners != []
      if (xTp > 0)
          [
          set conflictEi-with-G xTp
          ];close if

      set xpartners turtles with [breed = institutions and self != myself and Ei != px]      
      set xTp count xpartners
      ;if xpartners != []
      if (xTp > 0)
          [
          set conflictEi-with-I xTp
          ];close if
end                    

to count-conflictsXi-amongRBGCI
    set numof-conflictsXi-between-controllers-and-controllers
    ((sum values-from turtles with [breed = controllers][conflictXi-with-R]) / count turtles with [breed = controllers])
    set numof-conflictsXi-between-controllers-and-businesses
    ((sum values-from turtles with [breed = controllers][conflictXi-with-B]) / count turtles with [breed = controllers])    
    set numof-conflictsXi-between-controllers-and-gatekeepers
    ((sum values-from turtles with [breed = controllers][conflictXi-with-G]) / count turtles with [breed = controllers])    
    set numof-conflictsXi-between-controllers-and-communities             
    ((sum values-from turtles with [breed = controllers][conflictXi-with-C]) / count turtles with [breed = controllers])                       
    set numof-conflictsXi-between-controllers-and-institutions
    ((sum values-from turtles with [breed = controllers][conflictXi-with-I]) / count turtles with [breed = controllers])    

    set numof-conflictsXi-between-businesses-and-controllers
    ((sum values-from turtles with [breed = businesses][conflictXi-with-R]) / count turtles with [breed = businesses])    
    set numof-conflictsXi-between-businesses-and-businesses
    ((sum values-from turtles with [breed = businesses][conflictXi-with-B]) / count turtles with [breed = businesses])        
    set numof-conflictsXi-between-businesses-and-gatekeepers
    ((sum values-from turtles with [breed = businesses][conflictXi-with-G]) / count turtles with [breed = businesses])        
    set numof-conflictsXi-between-businesses-and-communities             
    ((sum values-from turtles with [breed = businesses][conflictXi-with-C]) / count turtles with [breed = businesses])                           
    set numof-conflictsXi-between-businesses-and-institutions
    ((sum values-from turtles with [breed = businesses][conflictXi-with-I]) / count turtles with [breed = businesses])    
    
    set numof-conflictsXi-between-gatekeepers-and-controllers
    ((sum values-from turtles with [breed = gatekeepers][conflictXi-with-R]) / count turtles with [breed = gatekeepers])        
    set numof-conflictsXi-between-gatekeepers-and-businesses
    ((sum values-from turtles with [breed = gatekeepers][conflictXi-with-B]) / count turtles with [breed = gatekeepers])            
    set numof-conflictsXi-between-gatekeepers-and-gatekeepers
    ((sum values-from turtles with [breed = gatekeepers][conflictXi-with-G]) / count turtles with [breed = gatekeepers])            
    set numof-conflictsXi-between-gatekeepers-and-communities             
    ((sum values-from turtles with [breed = gatekeepers][conflictXi-with-C]) / count turtles with [breed = gatekeepers])                               
    set numof-conflictsXi-between-gatekeepers-and-institutions
    ((sum values-from turtles with [breed = gatekeepers][conflictXi-with-I]) / count turtles with [breed = gatekeepers])        

    set numof-conflictsXi-between-communities-and-controllers
    ((sum values-from turtles with [breed = communities][conflictXi-with-R]) / count turtles with [breed = communities])        
    set numof-conflictsXi-between-communities-and-businesses
    ((sum values-from turtles with [breed = communities][conflictXi-with-B]) / count turtles with [breed = communities])            
    set numof-conflictsXi-between-communities-and-gatekeepers
    ((sum values-from turtles with [breed = communities][conflictXi-with-G]) / count turtles with [breed = communities])            
    set numof-conflictsXi-between-communities-and-communities             
    ((sum values-from turtles with [breed = communities][conflictXi-with-C]) / count turtles with [breed = communities])                               
    set numof-conflictsXi-between-communities-and-institutions
    ((sum values-from turtles with [breed = communities][conflictXi-with-I]) / count turtles with [breed = communities])        

    set numof-conflictsXi-between-institutions-and-controllers
    ((sum values-from turtles with [breed = institutions][conflictXi-with-R]) / count turtles with [breed = institutions])        
    set numof-conflictsXi-between-institutions-and-businesses
    ((sum values-from turtles with [breed = institutions][conflictXi-with-B]) / count turtles with [breed = institutions])            
    set numof-conflictsXi-between-institutions-and-gatekeepers
    ((sum values-from turtles with [breed = institutions][conflictXi-with-G]) / count turtles with [breed = institutions])            
    set numof-conflictsXi-between-institutions-and-communities             
    ((sum values-from turtles with [breed = institutions][conflictXi-with-C]) / count turtles with [breed = institutions])                               
    set numof-conflictsXi-between-institutions-and-institutions
    ((sum values-from turtles with [breed = institutions][conflictXi-with-I]) / count turtles with [breed = institutions])        
                                                
    type "numof-conflictsXi-between-controllers-and-controllers: " print precision numof-conflictsXi-between-controllers-and-controllers 2
    type "numof-conflictsXi-between-controllers-and-businesses: " print precision numof-conflictsXi-between-controllers-and-businesses 2
    type "numof-conflictsXi-between-controllers-and-gatekeepers: " print precision numof-conflictsXi-between-controllers-and-gatekeepers 2
    type "numof-conflictsXi-between-controllers-and-communities: " print precision numof-conflictsXi-between-controllers-and-communities 2                                
    type "numof-conflictsXi-between-controllers-and-institutions: " print precision numof-conflictsXi-between-controllers-and-institutions 2

    type "numof-conflictsXi-between-businesses-and-controllers: " print precision numof-conflictsXi-between-businesses-and-controllers 2
    type "numof-conflictsXi-between-businesses-and-businesses: " print precision numof-conflictsXi-between-businesses-and-businesses 2
    type "numof-conflictsXi-between-businesses-and-gatekeepers: " print precision numof-conflictsXi-between-businesses-and-gatekeepers 2
    type "numof-conflictsXi-between-businesses-and-communities: " print precision numof-conflictsXi-between-businesses-and-communities 2                                
    type "numof-conflictsXi-between-businesses-and-institutions: " print precision numof-conflictsXi-between-businesses-and-institutions 2

    type "numof-conflictsXi-between-gatekeepers-and-controllers: " print precision numof-conflictsXi-between-gatekeepers-and-controllers 2
    type "numof-conflictsXi-between-gatekeepers-and-businesses: " print precision numof-conflictsXi-between-gatekeepers-and-businesses 2
    type "numof-conflictsXi-between-gatekeepers-and-gatekeepers: " print precision numof-conflictsXi-between-gatekeepers-and-gatekeepers 2
    type "numof-conflictsXi-between-gatekeepers-and-communities: " print precision numof-conflictsXi-between-gatekeepers-and-communities 2                                
    type "numof-conflictsXi-between-gatekeepers-and-institutions: " print precision numof-conflictsXi-between-gatekeepers-and-institutions 2

    type "numof-conflictsXi-between-communities-and-controllers: " print precision numof-conflictsXi-between-communities-and-controllers 2
    type "numof-conflictsXi-between-communities-and-businesses: " print precision numof-conflictsXi-between-communities-and-businesses 2
    type "numof-conflictsXi-between-communities-and-gatekeepers: " print precision numof-conflictsXi-between-communities-and-gatekeepers 2
    type "numof-conflictsXi-between-communities-and-communities: " print precision numof-conflictsXi-between-communities-and-communities 2                                
    type "numof-conflictsXi-between-communities-and-institutions: " print precision numof-conflictsXi-between-communities-and-institutions 2

    type "numof-conflictsXi-between-institutions-and-controllers: " print precision numof-conflictsXi-between-institutions-and-controllers 2
    type "numof-conflictsXi-between-institutions-and-businesses: " print precision numof-conflictsXi-between-institutions-and-businesses 2
    type "numof-conflictsXi-between-institutions-and-gatekeepers: " print precision numof-conflictsXi-between-institutions-and-gatekeepers 2
    type "numof-conflictsXi-between-institutions-and-communities: " print precision numof-conflictsXi-between-institutions-and-communities 2                                
    type "numof-conflictsXi-between-institutions-and-institutions: " print precision numof-conflictsXi-between-institutions-and-institutions 2
end

to count-conflictsEi-amongRBGCI
    set numof-conflictsEi-between-controllers-and-controllers
    ((sum values-from turtles with [breed = controllers][conflictEi-with-R]) / count turtles with [breed = controllers])
    set numof-conflictsEi-between-controllers-and-businesses
    ((sum values-from turtles with [breed = controllers][conflictEi-with-B]) / count turtles with [breed = controllers])    
    set numof-conflictsEi-between-controllers-and-gatekeepers
    ((sum values-from turtles with [breed = controllers][conflictEi-with-G]) / count turtles with [breed = controllers])    
    set numof-conflictsEi-between-controllers-and-communities             
    ((sum values-from turtles with [breed = controllers][conflictEi-with-C]) / count turtles with [breed = controllers])                       
    set numof-conflictsEi-between-controllers-and-institutions
    ((sum values-from turtles with [breed = controllers][conflictEi-with-I]) / count turtles with [breed = controllers])    

    set numof-conflictsEi-between-businesses-and-controllers
    ((sum values-from turtles with [breed = businesses][conflictEi-with-R]) / count turtles with [breed = businesses])    
    set numof-conflictsEi-between-businesses-and-businesses
    ((sum values-from turtles with [breed = businesses][conflictEi-with-B]) / count turtles with [breed = businesses])        
    set numof-conflictsEi-between-businesses-and-gatekeepers
    ((sum values-from turtles with [breed = businesses][conflictEi-with-G]) / count turtles with [breed = businesses])        
    set numof-conflictsEi-between-businesses-and-communities             
    ((sum values-from turtles with [breed = businesses][conflictEi-with-C]) / count turtles with [breed = businesses])                           
    set numof-conflictsEi-between-businesses-and-institutions
    ((sum values-from turtles with [breed = businesses][conflictEi-with-I]) / count turtles with [breed = businesses])    
    
    set numof-conflictsEi-between-gatekeepers-and-controllers
    ((sum values-from turtles with [breed = gatekeepers][conflictEi-with-R]) / count turtles with [breed = gatekeepers])        
    set numof-conflictsEi-between-gatekeepers-and-businesses
    ((sum values-from turtles with [breed = gatekeepers][conflictEi-with-B]) / count turtles with [breed = gatekeepers])            
    set numof-conflictsEi-between-gatekeepers-and-gatekeepers
    ((sum values-from turtles with [breed = gatekeepers][conflictEi-with-G]) / count turtles with [breed = gatekeepers])            
    set numof-conflictsEi-between-gatekeepers-and-communities             
    ((sum values-from turtles with [breed = gatekeepers][conflictEi-with-C]) / count turtles with [breed = gatekeepers])                               
    set numof-conflictsEi-between-gatekeepers-and-institutions
    ((sum values-from turtles with [breed = gatekeepers][conflictEi-with-I]) / count turtles with [breed = gatekeepers])        

    set numof-conflictsEi-between-communities-and-controllers
    ((sum values-from turtles with [breed = communities][conflictEi-with-R]) / count turtles with [breed = communities])        
    set numof-conflictsEi-between-communities-and-businesses
    ((sum values-from turtles with [breed = communities][conflictEi-with-B]) / count turtles with [breed = communities])            
    set numof-conflictsEi-between-communities-and-gatekeepers
    ((sum values-from turtles with [breed = communities][conflictEi-with-G]) / count turtles with [breed = communities])            
    set numof-conflictsEi-between-communities-and-communities             
    ((sum values-from turtles with [breed = communities][conflictEi-with-C]) / count turtles with [breed = communities])                               
    set numof-conflictsEi-between-communities-and-institutions
    ((sum values-from turtles with [breed = communities][conflictEi-with-I]) / count turtles with [breed = communities])        

    set numof-conflictsEi-between-institutions-and-controllers
    ((sum values-from turtles with [breed = institutions][conflictEi-with-R]) / count turtles with [breed = institutions])        
    set numof-conflictsEi-between-institutions-and-businesses
    ((sum values-from turtles with [breed = institutions][conflictEi-with-B]) / count turtles with [breed = institutions])            
    set numof-conflictsEi-between-institutions-and-gatekeepers
    ((sum values-from turtles with [breed = institutions][conflictEi-with-G]) / count turtles with [breed = institutions])            
    set numof-conflictsEi-between-institutions-and-communities             
    ((sum values-from turtles with [breed = institutions][conflictEi-with-C]) / count turtles with [breed = institutions])                               
    set numof-conflictsEi-between-institutions-and-institutions
    ((sum values-from turtles with [breed = institutions][conflictEi-with-I]) / count turtles with [breed = institutions])        
                                                
    type "numof-conflictsEi-between-controllers-and-controllers: " print precision numof-conflictsEi-between-controllers-and-controllers 2
    type "numof-conflictsEi-between-controllers-and-businesses: " print precision numof-conflictsEi-between-controllers-and-businesses 2
    type "numof-conflictsEi-between-controllers-and-gatekeepers: " print precision numof-conflictsEi-between-controllers-and-gatekeepers 2
    type "numof-conflictsEi-between-controllers-and-communities: " print precision numof-conflictsEi-between-controllers-and-communities 2                                
    type "numof-conflictsEi-between-controllers-and-institutions: " print precision numof-conflictsEi-between-controllers-and-institutions 2

    type "numof-conflictsEi-between-businesses-and-controllers: " print precision numof-conflictsEi-between-businesses-and-controllers 2
    type "numof-conflictsEi-between-businesses-and-businesses: " print precision numof-conflictsEi-between-businesses-and-businesses 2
    type "numof-conflictsEi-between-businesses-and-gatekeepers: " print precision numof-conflictsEi-between-businesses-and-gatekeepers 2
    type "numof-conflictsEi-between-businesses-and-communities: " print precision numof-conflictsEi-between-businesses-and-communities 2                                
    type "numof-conflictsEi-between-businesses-and-institutions: " print precision numof-conflictsEi-between-businesses-and-institutions 2

    type "numof-conflictsEi-between-gatekeepers-and-controllers: " print precision numof-conflictsEi-between-gatekeepers-and-controllers 2
    type "numof-conflictsEi-between-gatekeepers-and-businesses: " print precision numof-conflictsEi-between-gatekeepers-and-businesses 2
    type "numof-conflictsEi-between-gatekeepers-and-gatekeepers: " print precision numof-conflictsEi-between-gatekeepers-and-gatekeepers 2
    type "numof-conflictsEi-between-gatekeepers-and-communities: " print precision numof-conflictsEi-between-gatekeepers-and-communities 2                                
    type "numof-conflictsEi-between-gatekeepers-and-institutions: " print precision numof-conflictsEi-between-gatekeepers-and-institutions 2

    type "numof-conflictsEi-between-communities-and-controllers: " print precision numof-conflictsEi-between-communities-and-controllers 2
    type "numof-conflictsEi-between-communities-and-businesses: " print precision numof-conflictsEi-between-communities-and-businesses 2
    type "numof-conflictsEi-between-communities-and-gatekeepers: " print precision numof-conflictsEi-between-communities-and-gatekeepers 2
    type "numof-conflictsEi-between-communities-and-communities: " print precision numof-conflictsEi-between-communities-and-communities 2                                
    type "numof-conflictsEi-between-communities-and-institutions: " print precision numof-conflictsEi-between-communities-and-institutions 2

    type "numof-conflictsEi-between-institutions-and-controllers: " print precision numof-conflictsEi-between-institutions-and-controllers 2
    type "numof-conflictsEi-between-institutions-and-businesses: " print precision numof-conflictsEi-between-institutions-and-businesses 2
    type "numof-conflictsEi-between-institutions-and-gatekeepers: " print precision numof-conflictsEi-between-institutions-and-gatekeepers 2
    type "numof-conflictsEi-between-institutions-and-communities: " print precision numof-conflictsEi-between-institutions-and-communities 2                                
    type "numof-conflictsEi-between-institutions-and-institutions: " print precision numof-conflictsEi-between-institutions-and-institutions 2
end

;;record the number of turtles created for each strategy
;;The number of turtles of each strategy is used when calculating average payoffs.
;;Slider values might change over time, so we need to record their settings.
;;Counting the turtles would also work, but slows the model.
to store-initial-turtle-counts
  set num-turtles count turtles

  set num-for-increased count turtles with [Xi = 1]
  set num-for-decreased count turtles with [Xi = -1]
  set num-for-maintained count turtles with [Xi = 0]
 
  set num-for-more-provision-to-increase count turtles with [Xi = 1 And Ei = 0]
  set num-for-more-control-to-increase count turtles with [Xi = 1 And Ei = 2]
  set num-for-more-newregulation-to-increase count turtles with [Xi = 1 And Ei = 4]
  set num-for-more-currentregulation-to-increase count turtles with [Xi = 1 And Ei = 6]
  set num-for-more-supply-to-increase count turtles with [Xi = 1 And Ei = 8]
  set num-for-more-promotion-to-increase count turtles with [Xi = 1 And Ei = 10]
  set num-for-more-cooperation-to-increase count turtles with [Xi = 1 And Ei = 12]

  set num-for-others-to-increase count turtles with [Xi = 1 And Ei = -1]  
  set num-for-less-control-to-increase count turtles with [Xi = 1 And Ei = -2]
  set num-for-less-newregulation-to-increase count turtles with [Xi = 1 And Ei = -4]  
  set num-for-less-currentregulation-to-increase count turtles with [Xi = 1 And Ei = -6]
  set num-for-less-supply-to-increase count turtles with [Xi = 1 And Ei = -8]
  set num-for-less-promotion-to-increase count turtles with [Xi = 1 And Ei = -10]
  set num-for-less-cooperation-to-increase count turtles with [Xi = 1 And Ei = -12]

  set num-for-more-provision-to-decrease count turtles with [Xi = -1 And Ei = 0]
  set num-for-more-control-to-decrease count turtles with [Xi = -1 And Ei = 2]
  set num-for-more-newregulation-to-decrease count turtles with [Xi = -1 And Ei = 4]
  set num-for-more-currentregulation-to-decrease count turtles with [Xi = -1 And Ei = 6]
  set num-for-more-supply-to-decrease count turtles with [Xi = -1 And Ei = 8]
  set num-for-more-promotion-to-decrease count turtles with [Xi = -1 And Ei = 10]
  set num-for-more-cooperation-to-decrease count turtles with [Xi = -1 And Ei = 12]
  set num-for-others-to-decrease count turtles with [Xi = -1 And Ei = -1]  
 
  set num-for-less-control-to-decrease count turtles with [Xi = -1 And Ei = -2]
  set num-for-less-newregulation-to-decrease count turtles with [Xi = -1 And Ei = -4]  
  set num-for-less-currentregulation-to-decrease count turtles with [Xi = -1 And Ei = -6]
  set num-for-less-supply-to-decrease count turtles with [Xi = -1 And Ei = -8]
  set num-for-less-promotion-to-decrease count turtles with [Xi = -1 And Ei = -10]
  set num-for-less-cooperation-to-decrease count turtles with [Xi = -1 And Ei = -12]

  set num-for-more-provision-to-maintain count turtles with [Xi = 0 And Ei = 0]
  set num-for-more-control-to-maintain count turtles with [Xi = 0 And Ei = 2]
  set num-for-more-newregulation-to-maintain count turtles with [Xi = 0 And Ei = 4]
  set num-for-more-currentregulation-to-maintain count turtles with [Xi = 0 And Ei = 6]
  set num-for-more-supply-to-maintain count turtles with [Xi = 0 And Ei = 8]
  set num-for-more-promotion-to-maintain count turtles with [Xi = 0 And Ei = 10]
  set num-for-more-cooperation-to-maintain count turtles with [Xi = 0 And Ei = 12]
 
  set num-for-others-to-maintain count turtles with [Xi = 0 And Ei = -1]  
  set num-for-less-control-to-maintain count turtles with [Xi = 0 And Ei = -2]
  set num-for-less-newregulation-to-maintain count turtles with [Xi = 0 And Ei = -4]  
  set num-for-less-currentregulation-to-maintain count turtles with [Xi = 0 And Ei = -6]
  set num-for-less-supply-to-maintain count turtles with [Xi = 0 And Ei = -8]
  set num-for-less-promotion-to-maintain count turtles with [Xi = 0 And Ei = -10]
  set num-for-less-cooperation-to-maintain count turtles with [Xi = 0 And Ei = -12]

  set resources-for-increased sum values-from turtles with [Xi = 1] [Ri]
  set resources-for-decreased sum values-from turtles with [Xi = -1] [Ri]
  set resources-for-maintained sum values-from turtles with [Xi = 0] [Ri]

  set num-optimization 0
  set num-suboptimization 0

end

;;set the variables that all turtles share
to setup-common-variables
  ask turtles
  [
    ;set shape "boy-shape"  
    set partnered? false
    set partner nobody
    set challenged? false
    set challenger nobody        
    set guessp 1
    set guessc 1
    set guessb 1
    setup-parameters
    
    ifelse (PoliticalDistance = "FromQ3&Q4&Q5")
        [setup-emptylists-1 setup-knowledge-1]    
        [setup-emptylists-2 setup-knowledge-2]    
  ]
  ;setup-history-lists ;;initialize PARTNER-HISTORY list in all turtles
end

;to setup-maxofferofi
;   locals [n]
;   set n 0
;   set MaxOfferOfi 0
;end

to setup-parameters
   ; for each actor i, create copies of the lsit of the item numbers (who) of its 10 closest actors
   if ErrorOnProbOfSuccAccess > 1 [guessofp]
   if ErrorOnConsequeOfShifts > 1 [guessofb]
   if ErrorOnConsequeOfShifts > 1 [guessofc]
;  guessp          ;; Pij bias = random-normal (value-from (turtle-here) [Pij]) (ErrorOnProbOfSuccAccess)   
;  guessb          ;; USij bias= random-normal (value-from (turtle-here) [USij]) (ErrorOnConsequeOfShifts)
;  guessc          ;; UFij bias = random-normal (value-from (turtle-here) [UFij]) (ErrorOnConsequeOfShifts)
end

to setup-emptylists-2 ;;for computing distances from responses to Q3&Q4&Q5
;   without-interruption
   ;OP1
;   [

   set Dij []
   
   set Lij []
   ;set NDij []
   set Uij []
   ;set USij []
   set UFij []
   set EiUij []
   set EiUji []   

   set challenger-newneighbours []  ; list of actors j challenged by i (partners of i)
   set challenger-shiftedobjectives []; list of shifts (adopted objectives)
   set challenger-shiftedstrategies [] ; list of shifts (adopted objectives)        
   set partner-newneighbours [] ; list of challengers of j
   set partner-newsobjectives []; list of shifts (adopted objectives)
   set partner-newsstrategies [] ; list of shifts (adopted objectives)
   set gains []
   set losses []    
   
   set n 0
   while [n < (num-turtles - 1)]
    ;OP2
    [
    set Lij lput (item n Nij) Lij
    ;set NDij lput 0 NDij
    set Uij lput 0 Uij
    ;set USij lput 0 USij
    set UFij lput 0 UFij    
    set EiUij lput 0 EiUij
    set EiUji lput 0 EiUji
    set n n + 1           
    ];CP2endwhile
;  ];CP1endwithout          
end

to setup-emptylists-1 ;;for computing distances from responses to Q4 only
;   without-interruption
   ;OP1
;   [
   set Lij []
   ;set NDij []
   set Uij []
   ;set USij []
   set UFij []
   set EiUij []
   set EiUji []   

   set challenger-newneighbours []  ; list of actors j challenged by i (partners of i)
   set challenger-shiftedobjectives []; list of shifts (adopted objectives)
   set challenger-shiftedstrategies [] ; list of shifts (adopted objectives)        
   set partner-newneighbours [] ; list of challengers of j
   set partner-newsobjectives []; list of shifts (adopted objectives)
   set partner-newsstrategies [] ; list of shifts (adopted objectives)
   set gains []
   set losses []    
   
   set n 0
   while [n < (num-turtles - 1)]
    ;OP2
    [
    set Lij lput (item n Nij) Lij
    ;set NDij lput 0 NDij
    set Uij lput 0 Uij
    ;set USij lput 0 USij
    set UFij lput 0 UFij    
    set EiUij lput 0 EiUij
    set EiUji lput 0 EiUji
    set n n + 1           
    ];CP2endwhile
;  ];CP1endwithout          
end

to setup-knowledge-2 ;; for computing distances from responses to Q3&Q4&Q5
   ;locals [n Lij W NSi NSj NRi NRj NXi Nxj NGi NGj NDij NPij NUij NUSij NUFij NPji NUSji NUFji]
   without-interruption
   ;OP1
   [
    set n 0
    while [n < (num-turtles - 1)]                         
    ;OP2
    [
    ;set Lij lput (item n Nij) Lij                   ; get the item number of the j's closest actors to i           
    
    set NRi Ri-of turtle (who) + (NetworksWeight * (Gi-of turtle (who) / 10)) ; get the n i's resources
    if NRi > 1 [set NRi 1]
    set partner item n Lij                          ; get the n j's item number (whho) of the n farest possible partner of i
    set NRj Ri-of turtle (partner) + (NetworksWeight * (Gi-of turtle (partner) / 10)) ; get the j's resources
    if NRj > 1 [set NRj 1]
    
    set NPij calc-Pij NRi NRj                       ; calc the prob of i to access to j  
    ;set Pij replace-item n Pij (calc-Pij NRi NRj)  ; increment the list of probs of i to access its partners  
    ;set Pij replace-item n Pij NPij                
    ;   list         index list value
                    
    set NXi Xi                                      ; get the i's objective
    set NXj Xi-of turtle (partner)                  ; get the j's objective
    
    ;set NDij item n Dij                            ; get the correlations between the i's and j's expected actions
    ;set NDij ((25 - distance-nowrap turtle(partner)) / 25) ; get the correlation from the screen distance between the i's and j's positions            
    ifelse (xcor != xcor-of turtle(partner)); get the correlation from the screen distance between the i's and j's positions            
        [ifelse ((xcor * xcor-of turtle(partner)) < 0)
            [set NDij -0.9]
            [ifelse (xcor = 4 or xcor-of turtle (partner) = 4 )
                [
                set NDij -0.9
                ]
                [ifelse (xcor = 12 or xcor-of turtle (partner) = 12 )
                    [set NDij -0.7]
                    [set NDij -0.5]                
                ]
            ]
        ]
        [
        set NDij 1
        ]
    ;type "distance from " type partner  type " to " show NDij     
    
    set NUij calc-Uij NDij NXi NXj                  ; calc the utility for i to challenge j
    ;set Uij replace-item n Uij (calc-Uij NDij NXi NXj)
    set Uij replace-item n Uij NUij                 ; increment the list of utility for i to challenge j
    
    set NSj Si-of turtle (partner)                  ; get the salience of k for j
    set NSi Si                                      ; get the salience of k for i
    set NGi Gi                                      ; get the i's group involvement
    set NGj Gi-of turtle (partner)                  ; get the j's group involvement
    set NUSij calc-USij NUij NRj NSj NGj            ; calc the i's utility to successful challenging j  
    set NUFij calc-UFij NUij NRi NSi NGi            ; calc the i's utility to fail in challenging j
    ;set USij replace-item n USij (calc-USij NUij NRj NSj NGj)
    ; report                      (NUij * NRj * (NSj / 4) * (1 / (NGj + 1))
    ;set USij replace-item n USij NUSij    
    ;set UFij replace-item n UFij (calc-UFij NUij NRi NSi NGi)   
    set UFij replace-item n UFij NUFij       
   
    set NPji calc-Pij NRj NRi                       ; calc the prob of j to access to i (increment a list of 10 prob)  
    set NUSji calc-USij NUij NRi NSi NGi            ; calc the i's utility to successful challenging j
    set NUFji calc-UFij NUij NRj NSj NGj            ; calc the i's utility to fail in challenging j                                                                                                              

    set EiUij replace-item n EiUij (calc-EiUij NPij NSj NUSij NUFij) ;(increment list of the i's perceptions of i's expected utilities)
    set EiUji replace-item n EiUji (calc-EiUji NPji NSi NUSji NUFji) ;(increment list of the i's perception of the j's expected utilities)
    ;to-report calc-EiUij [NPij NSj NUSij NUFij]               
    ;  report precision ((NPij * NUSij) + ((1 - NPij) * NUFij) + ((1 - (NSj / 4)) * NUSij)) 4
    ;end
    ;to-report calc-EiUji [NPji NSi NUSji NUFji]
    ;    report precision ((NPji * NUSji) + ((1 - NPji) * NUFji) + ((1 - (NSi / 4)) * NUSji)) 4
    ;end
    ;;                 (Expected U to challenge j)               + (Expected U to not challenging j)
    ;;         EiUij =    (Pij   * USij)  + ((1 - Pij)  * UFij)) + ((1 -  Sj)       * USij) i's view od is' expected U
    ;;         EiUji =    (Pji   * USji)  + ((1 - Pji)  * UFji)  + ((1 -  Si)       * USji) i's view of j's expected U        
    set n n + 1
    ]
    ;CP2endwhile
    
    ;type "Nij of " show Nij
    ;type "Dij of " show Dij
    ;show USij
    ;show UFij
    ;show EiUij
    ;show EiUji    
   ]  
   ;CP1endwithout
end

to setup-knowledge-1;; for computing distances from responses to Q4 only
   ;locals [n Lij W NSi NSj NRi NRj NXi Nxj NGi NGj NDij NPij NUij NUSij NUFij NPji NUSji NUFji]
   without-interruption
   ;OP1
   [
    set n 0
    while [n < (num-turtles - 1)]                         
    ;OP2
    [
    ;set Lij lput (item n Nij) Lij                   ; get the item number of the j's closest actors to i           
    
    set NRi Ri-of turtle (who) + (NetworksWeight * (Gi-of turtle (who) / 10)) ; get the n i's resources
    if NRi > 1 [set NRi 1]
    set partner item n Lij                          ; get the n j's item number (whho) of the n farest possible partner of i
    set NRj Ri-of turtle (partner) + (NetworksWeight * (Gi-of turtle (partner) / 10)) ; get the j's resources
    if NRj > 1 [set NRj 1]
    
    set NPij calc-Pij NRi NRj                       ; calc the prob of i to access to j  
    ;set Pij replace-item n Pij (calc-Pij NRi NRj)  ; increment the list of probs of i to access its partners  
    ;set Pij replace-item n Pij NPij                
    ;   list         index list value
                    
    set NXi Xi                                      ; get the i's objective
    set NXj Xi-of turtle (partner)                  ; get the j's objective
    set NDij item n Dij                             ; get the correlations between the i's and j's expected actions
    set NUij calc-Uij NDij NXi NXj                  ; calc the utility for i to challenge j
    ;set Uij replace-item n Uij (calc-Uij NDij NXi NXj)
    set Uij replace-item n Uij NUij                 ; increment the list of utility for i to challenge j
    
    set NSj Si-of turtle (partner)                  ; get the salience of k for j
    set NSi Si                                      ; get the salience of k for i
    set NGi Gi                                      ; get the i's group involvement
    set NGj Gi-of turtle (partner)                  ; get the j's group involvement
    set NUSij calc-USij NUij NRj NSj NGj            ; calc the i's utility to successful challenging j  
    set NUFij calc-UFij NUij NRi NSi NGi            ; calc the i's utility to fail in challenging j
    ;set USij replace-item n USij (calc-USij NUij NRj NSj NGj)
    ; report                      (NUij * NRj * (NSj / 4) * (1 / (NGj + 1))
    ;set USij replace-item n USij NUSij    
    ;set UFij replace-item n UFij (calc-UFij NUij NRi NSi NGi)   
    set UFij replace-item n UFij NUFij       
   
    set NPji calc-Pij NRj NRi                       ; calc the prob of j to access to i (increment a list of 10 prob)  
    set NUSji calc-USij NUij NRi NSi NGi            ; calc the i's utility to successful challenging j
    set NUFji calc-UFij NUij NRj NSj NGj            ; calc the i's utility to fail in challenging j                                                                                                              

    set EiUij replace-item n EiUij (calc-EiUij NPij NSj NUSij NUFij) ;(increment list of the i's perceptions of i's expected utilities)
    set EiUji replace-item n EiUji (calc-EiUji NPji NSi NUSji NUFji) ;(increment list of the i's perception of the j's expected utilities)
    ;to-report calc-EiUij [NPij NSj NUSij NUFij]               
    ;  report precision ((NPij * NUSij) + ((1 - NPij) * NUFij) + ((1 - (NSj / 4)) * NUSij)) 4
    ;end
    ;to-report calc-EiUji [NPji NSi NUSji NUFji]
    ;    report precision ((NPji * NUSji) + ((1 - NPji) * NUFji) + ((1 - (NSi / 4)) * NUSji)) 4
    ;end
    ;;                 (Expected U to challenge j)               + (Expected U to not challenging j)
    ;;         EiUij =    (Pij   * USij)  + ((1 - Pij)  * UFij)) + ((1 -  Sj)       * USij) i's view od is' expected U
    ;;         EiUji =    (Pji   * USji)  + ((1 - Pji)  * UFji)  + ((1 -  Si)       * USji) i's view of j's expected U        
    set n n + 1
    ]
    ;CP2endwhile
    
    ;type "Nij of " show Nij
    ;type "Dij of " show Dij
    ;show USij
    ;show UFij
    ;show EiUij
    ;show EiUji    
   ]  
   ;CP1endwithout
end

;        guessp          ;; Pij bias = random-normal (value-from (turtle-here) [Pij]) (ErrorOnProbOfSuccAccess)   
;        guessb          ;; USij bias= random-normal (value-from (turtle-here) [USij]) (ErrorOnConsequeOfShifts)
;        guessc          ;; UFij bias = random-normal (value-from (turtle-here) [UFij]) (ErrorOnConsequeOfShifts)

to guessofb
    ;set guessb random-normal (mean USij) (ErrorOnConsequeOfShifts / 10)
    set guessb random-normal 0.5 (ErrorOnConsequeOfShifts / 10)    
    if guessb >= 1 [guessofb]
    if guessb <= 0 [guessofb]
end

to guessofc
    ;set guessc random-normal (mean UFij) (ErrorOnConsequeOfShifts / 10)    
    set guessc random-normal 0.5 (ErrorOnConsequeOfShifts / 10)    
    if guessc >= 1 [guessofc]
    if guessc <= 0 [guessofc]
end

to guessofp
    ;set guessp random-normal (mean Pij) (ErrorOnProbOfSuccAccess / 10)    
    set guessp random-normal 0.5 (ErrorOnProbOfSuccAccess / 10)    
    if guessp >= 1 [guessofp]
    if guessp <= 0 [guessofp]
end        

;;initialize PARTNER-HISTORY list in all turtles
to setup-history-lists
  locals [ default-history]
  set default-history [] ;;initialize the DEFAULT-HISTORY variable to be a list
  ;;create a list with NUM-TURTLE elements for storing partner histories
  repeat num-turtles [ set default-history (fput false default-history) ]
  ;;give each turtle a copy of this list for tracking partner histories
  ;ask turtles [ set partner-history default-history ]
end

;;;;;;;;;;;;;;;;;;;;;;;
;; Runtime Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;;

to run-model
  locals [ partnered-turtles results-filename extended-results-filename]
 
  if iteration = 0
  [
  print "Fixed values of the parameters:"
  type "PoliticalDistance " print PoliticalDistance
  type "NbOf Iterations " print Iterations
  type "ThirdParty " print ThirdParty
  type "VisionRange " print VisionRange
  type "ActionsWeight " print ActionsWeight
  type "NetworksWeight " print NetworksWeight
  type "Willingness To Listen " print WillingnessToListen
  type "Error On Prob Of Access " print ErrorOnProbOfSuccAccess
  type "Error On Cons.Of Shifts " print ErrorOnConsequeOfShifts
  ]  
 
  without-interruption
  [
  clear-last-round
  ]
  ifelse iteration < Iterations
  [
  set iteration iteration + 1
  type "Alternative scenario, iter " print iteration  
;  ifelse EmotionalDM = true
;         [type "Alternative scenario, iter " print iteration
;          ask turtles [partner-up-emotional setup-knowledge]
;         ]   
;         [type "Alternative scenario, iter " print iteration
;          ask turtles [partner-up-rational setup-knowledge]
;         ]
  ifelse PoliticalDistance = "FromQ3&Q4&Q5"
         [ ask turtles [set size 1 set shape "circle" partner-up-rational-1 setup-knowledge-1] ]
         [ ask turtles [set size 1 set shape "circle" partner-up-rational-2 setup-knowledge-2] ]

  re-sum
  do-plot-objectives
  do-plot-actions-to-increase
  do-plot-actions-to-maintain
  do-plot-actions-to-decrease
 
  do-plot-optimization
  set num-optimization 0
  set num-suboptimization 0

  setup-patches    
 
  ;set partnered-turtles turtles with [ partnered? ]
  ;ask partnered-turtles [ select-action ]           ;;all partnered turtles select action
  ;ask partnered-turtles [ play-a-round ]
  ;do-bookkeeping

  ;type "End of iteration " print iteration
  ;set results-filename word "SPRITE-CZ1-RSSresultsOfNegotiation-jpb-b" iteration
  ;set extended-results-filename word results-filename ".csv"  
  ;export-world extended-results-filename
  ;wait 1.0 ; - speed ;;control the model speed
  ]
  [
  do-base-scenario
  type "End of iteration " print iteration
  ;set results-filename word "SPRITE-CZ1-RSSresultsOfNegotiation-jpb-b" iteration
  ;set extended-results-filename word results-filename ".cvs.txt"  
  ;export-world extended-results-filename
  set resfile word resfile0 "-W"    
  set resfileN word resfile WillingnessToListen
  set resfile word resfileN "-N"            
  set resfileN word resfile NetworksWeight  
  set resfile word resfileN "-"            
  set resfileN word resfile Iteration  
  export-world resfileN
  print "End of the simulations"  
  print "Save &Clear the Command Center"
  stop
  ]
end

to clear-last-round
  locals [ partnered-turtles challenged-turtles ]
  set partnered-turtles turtles with [ partnered? ]
  ask partnered-turtles [ release-partners ]
  set challenged-turtles turtles with [ challenged? ]
  ask challenged-turtles [ release-challengers ]  
end

;;release partner and turn around to leave
to release-partners
  set partnered? false
  set partner nobody
  ;rt 180
  ;set label no-label
end

;;release challenger and turn around to leave
to release-challengers
  set challenged? false
  set challenger nobody
  ;rt 180
  ;set label no-label
end

to re-sum
  set num-for-increased count turtles with [breed  != edges and ycor  >= 5]
  set num-for-decreased count turtles with [breed  != edges and ycor  <= 0]
  set num-for-maintained count turtles with [breed  != edges and ycor  > 0 And ycor < 5]
               
  set num-for-more-provision-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = 0]
  set num-for-more-control-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = 2]
  set num-for-more-newregulation-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = 4]
  set num-for-more-currentregulation-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = 6]
  set num-for-more-supply-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = 8]
  set num-for-more-promotion-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = 10]
  set num-for-more-cooperation-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = 12]
 
  set num-for-others-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = -1]
  set num-for-less-control-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = -2]
  set num-for-less-newregulation-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = -4]
  set num-for-less-currentregulation-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = -6]
  set num-for-less-supply-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = -8]
  set num-for-less-promotion-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = -10]
  set num-for-less-cooperation-to-increase count turtles with [breed  != edges and ycor  >= 5 And xcor = -12]
    
  set num-for-more-provision-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = 0]
  set num-for-more-control-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = 2]
  set num-for-more-newregulation-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = 4]
  set num-for-more-currentregulation-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = 6]
  set num-for-more-supply-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = 8]
  set num-for-more-promotion-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = 10]
  set num-for-more-cooperation-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = 12]
 
  set num-for-others-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = -1]
  set num-for-less-control-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = -2]
  set num-for-less-newregulation-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = -4]
  set num-for-less-currentregulation-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = -6]
  set num-for-less-supply-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = -8]
  set num-for-less-promotion-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = -10]
  set num-for-less-cooperation-to-decrease count turtles with [breed  != edges and ycor  <= 0 And xcor = -12]

  set num-for-more-provision-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = 0]
  set num-for-more-control-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = 2]
  set num-for-more-newregulation-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = 4]
  set num-for-more-currentregulation-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = 6]
  set num-for-more-supply-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = 8]
  set num-for-more-promotion-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = 10]
  set num-for-more-cooperation-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = 12]
 
  set num-for-others-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = -1]
  set num-for-less-control-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = -2]
  set num-for-less-newregulation-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = -4]
  set num-for-less-currentregulation-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = -6]
  set num-for-less-supply-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = -8]
  set num-for-less-promotion-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = -10]
  set num-for-less-cooperation-to-maintain count turtles with [breed  != edges and ycor  > 0 And ycor < 5 And xcor = -12]
 
  set resources-for-increased sum values-from turtles with [breed  != edges and ycor  >= 5 ] [Ri]
  set resources-for-decreased sum values-from turtles with [breed  != edges and ycor  <= 0] [Ri]
  set resources-for-maintained sum values-from turtles with [breed  != edges and ycor  > 0 And ycor < 5 ] [Ri]  
 
  ;set num-optimization 0
  ;set num-suboptimization 0
 
  ask turtles
  [
   ifelse (breed = institutions)
       [set shape "organisation-shape"]
       [set shape "boy-shape"]   
   ifelse (Ri > 5)
       [set size 5 ]
       [set size (1 + (Ri * 4))]       
  ]
 
end

;;have turtles try to find a partner with the higher probability of successful access
;;This will be done using without-interruption.
;;This is so that other turtles can't act while one is trying to partner up.
;;Also, since other turtles that have already executed partner-up may have
;;caused the turtle executing partner-up to be partnered,
;;a check is needed to make sure the calling turtle isn't partnered.

;;RATIONAL agent i uses the principle of maximum expected utility: it only attempts to challenge j
;;when its perception of the expected utility of challenging j is greater than that of not challenging j
;;agent j adopts the positions of i whenever its perception of the utility to challenge i is lesser than the reverse

to partner-up-rational-2 ;;turtle procedure
    partner-up-rational-1
end

to partner-up-rational-1 ;;turtle procedure
   locals
   [
   MEj PCi PCj TNi TNj NNij NNji NEiUij NNEiUij NEiUji MaxEiUij MinEjUji
   PositionOfMaxEiUij PositionOfMinEjUji ValEiUji ValEiUij
   Nji PositionOfChallengerEjUji NEjUji NNEjUji NEjUij ValEjUij ValEjUji
   c d i j k l m o p q r s t u v PositionOfPartnerNij PositionOfChallengerNij
   OptimalChallenger x]
   
   if VisionRange < 100 [set x precision (VisionRange / 100 * (num-turtles - 1)) 0]
   if VisionRange = 100 [set x (num-turtles - 1)]   
   
   without-interruption                 ;;we don't want other turtles acting
   [;*OP1 of without                                    
    ifelse ; 1
    EiUij != []
    ;And (not partnered?)
    ;;make sure i is still not partnered, because if partnered i can't challenge any other actor j before the next run
    ; not checking partenerd? allows i to challenge many other actors during a same run

    [;*OP2 of if of ifelse 1                                   
     set challenger who               ; [who] of the challenger i       
     ;show label-of turtle (challenger); i's name
     set TNi count turtles-here       ; number of actors sharing the same objective and the same preferred action
     set s sum values-from turtles-here [Ri]
     set t sum values-from turtles-here [Si]
     set u (s * t / TNi)
     set PCi pcolor-of patch-here
     set k 1
     set m 0
     set p 1
     set q 0
     set v 1

     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     ;; RATIONAL OPTIMAL DM
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     ;;i searches for the best j and sends a request to j
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     
     set NNij Nij-of turtle (challenger); create a new list with the closest j to i
     ;set j random (num-turtles - 1)
     ;set MaxEiUij item j NEiUij         ; max value of i's perception of i's U to challenge j     
     set NEiUij sort EiUij             ; sort EiUij in increasing order
     set MaxEiUij last NEiUij          ; max value of i's perception of i's U to challenge j
     set PositionOfMaxEiUij position MaxEiUij EiUij-of turtle (challenger) ; position of optimal j in the unsorted list of utilities
     set partner item PositionOfMaxEiUij NNij ; select j (partner) that gives max utility to i (i's view))
     set ValEiUji item PositionOfMaxEiUij EiUji ; i's perception of j's utility to challenge i (i's view)  
     set ValEjUji item PositionOfMaxEiUij EiUij-of turtle (partner) ; j's perception of j's utility to challenge i (j's view)
     
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     ;;j evaluates the request of i
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     
     set NNji Nij-of turtle (partner)

     ;set NEjUji sort EiUij-of turtle (partner) ; sort EjUji in increasing order
     ;;set NEjUji sort UFij-of turtle (partner) ; sort UFji in increasing order;
     ;; UFji = -1 * (distance between i's and j's positions * weighted by resources and saliences)
     ;; So, the last item of NEjUji is the lowest cost of the political shifts of j
     
     set NEjUji sort Uij-of turtle (partner) ; sort Uji in increasing order;
     ;; Uij = Uji = is increasing in distance between i's and j's positions
     ;; So, the first item of NEjUji is the lowest cost of the political shifts of j
     set MinEjUji first NEjUji          ; min value of j's perception of costs of adoption of i's positions
     
     ;set PositionOfMinEjUji position MinEjUji EiUij-of turtle (partner) ; position of optimal i in the unsorted list of utilities
     set PositionOfMinEjUji position MinEjUji Uij-of turtle (partner) ; position of optimal i in the unsorted list of utilities
     set c item PositionOfMinEjUji NNji ; optimal challenger of j
     set OptimalChallenger label-of turtle(c)      

     ifelse ; 2
     
     challenged?-of turtle (partner) = false
     ;;make sure j still not challenged, because if challenged j can't be challenged by any other actor before the next run
     ;And PositionOfMaxEiUij < (VisionRange + (x * iteration))      
     And PositionOfMaxEiUij <= x
     ;; i knows j i.e. j is visible given the value of the VisionRange parameter
     ;And xcor-of turtle (challenger) != xcor-of turtle(partner)
     ;And ycor-of turtle (challenger) != ycor-of turtle(partner)
     And MaxEiUij > 0
     ;; if i expects gains in challenging j
     And MaxEiUij > ValEiUji

     ;; if i believes that he/she has more U to challenge j than that j has U to challenge i
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     ;; (that situation matches the sectors 1, 8 and 7 of the dynamics of the Bueno de Mesquita model)
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     And challenger = c
     And ValEjUji <= 0
     ;; if j believes that he/she has no U to challenge i          
     
     [;*OP3 of then of if of ifelse 2
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;; j accepts the request of i because i is the costless possible challenger
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      set OptimalChallenger label-of turtle(c)         
      ;type label-of turtle (challenger) type ";" print label-of turtle (partner)
      set num-optimization num-optimization + 1
     ];*CP3 of then of if of ifself 2
     
     [;*OP3 of then of else of ifelse 2
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;; j doesn't accept the request of i because there are other costless challengers
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;     
      
      set k 1
      
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;;EMOTIONAL SUBOPTIMAL DM
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;if SubOptimalDm = true
      ;if EmotionalDM = true
      ;[;*OP32 then of else of SubOptimalDM false ; i.e. if SubOptimalDM = true
      ;;EMOTIONAL agent i attempt to challenge j and j adopts positions of i like in rational excepted that
      ;;decision of j depends on the total amont of resources that supporters of i can mobilize to defend their policy XiEi
      ;;and on the total amount of resources that supporters of j can mobilize to defend their policy XjEj
      ;;with total amount of resources of i = sum of resources of actors on patch of i * average salience of k for these actors
       while [challenger != c And NEiUij != [] And k < (x - 1)]
       ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       ;;i searches for an other j with MaxEiUij inferior to previous MaxEiUij
       ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        
       [;*OP311 while k
               
        set NNEiUij but-last NEiUij
        set NEiUij NNEiUij
        set MaxEiUij last NEiUij          ; max value of i's perception of i's U to challenge j
        set PositionOfMaxEiUij position MaxEiUij EiUij-of turtle (challenger) ; position of optimal j in the unsorted list of utilities
        set partner item PositionOfMaxEiUij NNij ; select j (partner) that gives max utility to i (i's view))                                               
        set ValEiUji item PositionOfMaxEiUij EiUji ; i's perception of j's utility to challenge i (i's view)  
        set ValEjUji item PositionOfMaxEiUij EiUij-of turtle (partner) ; j's perception of j's utility to challenge i (j's view)

        set NNji Nij-of turtle (partner)
        
        ;set NEjUji sort EiUij-of turtle (partner) ; sort EjUji in increasing order
        ;set NEjUji sort UFij-of turtle (partner) ; sort UFji in increasing order        
        ;; UFji = -1 * (weighted distance between i's and j's positions)
        ;; So, the last item of NEjUji is the lowest cost of the political shifts of j
        ;; and the first item is the highest cost
        ;; set MinEjUji last NEjUji          ; min cost among costs adoption of i's positions
        
        set NEjUji sort Uij-of turtle (partner) ; sort Uji in increasing order;
        ;; Uij = Uji = is increasing in distance between i's and j's positions
        ;; So, the first item of NEjUji is the lowest cost of the political shifts of j
        set MinEjUji first NEjUji          ; min value of j's perception of costs of adoption of i's positions

        set l first NEjUji ; min cost
        set m last NEjUji ; max cost
        ;set PositionOfMinEjUji position MinEjUji EiUij-of turtle (partner) ; position of optimal i in the unsorted list of utilities
        set PositionOfMinEjUji position MinEjUji Uij-of turtle (partner) ; position of optimal i in the unsorted list of utilities        
        set c item PositionOfMinEjUji NNji ; optimal challenger of j
        set OptimalChallenger label-of turtle(c)      
                
        ifelse ; 4
        challenged?-of turtle (partner) = false
        ;;make sure j still not challenged, because if challenged j can't be challenged by any other actor before the next run
        ;And PositionOfMaxEiUij < (VisionRange + (x * iteration))      
        And PositionOfMaxEiUij <= x
        ;; i knows j i.e. j is visible given the value of the VisionRange parameter
        And MaxEiUij > 0
        ;; if i expects gains in challenging j
        And MaxEiUij > ValEiUji
        
        ;; if i believes that he/she has more U to challenge j than that j has U to challenge i
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;; (that situation matches the sectors 1, 8 and 7 of the dynamics of the Bueno de Mesquita model)
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        And challenger = c        
        And ValEjUji <= 0
        ;; if j believes that he/she has no U to challenge i          
       
        [;*OP321 of then of if of ifelse 4
         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
         ;; j accepts the request of i because i is the costless possible challenger
         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
         set OptimalChallenger label-of turtle(c)         
         ;type label-of turtle (challenger) type ";" print label-of turtle (partner)
         set num-optimization num-optimization + 1         
        ];*CP321 of then of if of ifself 4
        
        [;*OP322 of then of else of ifelse 4
         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
         ;; j doesn't accept the request of i because i is not the costless challenger
         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
         ;type label-of turtle (challenger) type " failed to challenge " type label-of turtle (partner)
         ;type " with best challenger:" type label-of turtle (c)
         ;type " MinEjUji:" type MinEjUji
         ;type " MaxEiUij:" type MaxEiUij
         ;type " ValEiUji:" type ValEiUji
         ;type " ValEjUji:" print ValEjUji
        
         set p 1
         set TNj value-from (patch (xcor-of turtle (partner)) (ycor-of turtle (partner))) [count turtles in-radius 0.5]   
         set s value-from (patch (xcor-of turtle (partner)) (ycor-of turtle (partner))) [sum values-from turtles in-radius 0.5 [Ri]]
         set t value-from (patch (xcor-of turtle (partner)) (ycor-of turtle (partner))) [sum values-from turtles in-radius 0.5 [Si]]
         set v (s * t / TNj)
         set q calc-Q l m u v                

         ;;to-report calc-Q [l m u v]
         ;;    report precision (l - (abs (l - m) * u / (u + v) * ThirdParty)) 3
         ;;end
                  
         while [challenger != c And NEjUji != [] And MinEjUji > q And p < (x - 1)]
         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
         ;; j checks if i is among the acceptable challengers; i.e MinEjUji > q
         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

         [;*OP32221 while p
           ;set MinEjUji item p NEjUji          ; peme value of U among the j's perceptions of j's U to challenge i
           set NNEjUji but-first NEjUji
           set NEjUji NNEjUji
           set MinEjUji first NEjUji          ; min value of j's perception of costs of adoption of i's positions

           ;set PositionOfMinEjUji position MinEjUji EiUij-of turtle (partner) ; position of optimal i in the unsorted list of utilities
           set PositionOfMinEjUji position MinEjUji Uij-of turtle (partner) ; position of optimal i in the unsorted list of utilities
           set c item PositionOfMinEjUji NNji ; optimal challenger of j
           set OptimalChallenger label-of turtle(c)
             
           ifelse
           challenged?-of turtle (partner) = false
           ;;make sure j still not challenged, because if challenged j can't be challenged by any other actor before the next run
           ;And PositionOfMaxEiUij < (VisionRange + (x * iteration))      
           And PositionOfMaxEiUij <= x
           ;; i knows j i.e. j is visible given the value of the VisionRange parameter
           And MaxEiUij > 0
           ;; if i expects gains in challenging j
           And MaxEiUij > ValEiUji
           
           ;; if i believes that he/she has more U to challenge j than that j has U to challenge i
           ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
           ;; (that situation matches the sectors 1, 8 and 7 of the dynamics of the Bueno de Mesquita model)
           ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
           And challenger = c        
           And ValEjUji <= 0 ;; j believes that he/she has no U to challenge i
           And MinEjUji > q  ;; j believes that he/she can accept (cost * -1) < q

           [
           ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
           ;; j accepts the request of i because i is the costless possible challenger
           ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
           set OptimalChallenger label-of turtle(c)         
           ;type label-of turtle (challenger) type ";" print label-of turtle (partner)
           set num-suboptimization num-suboptimization + 1
           ]      
           [;*OP of then of else
           ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;; j doesn't accept the request of i because adoption of i's position i is too much costly
           ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
           ;type label-of turtle (challenger) type " failed to challenge " type label-of turtle (partner)
           ;type " with best challenger:" type label-of turtle (c)
           ;type " MinEjUji:" type MinEjUji
           ;type " MaxEiUij:" type MaxEiUij
           ;type " ValEiUji:" type ValEiUji
           ;type " ValEjUji:" print ValEjUji
           ];*CP of then of else
         set p p + 1
         ];*CP 322221 end of while p
        ];*CP322 of then of else of ifelse 4
       set k k + 1
       ];*CP 322221 end of while k
      ;];*CP32 of then of else 3 i.e. if suboptimalDM = true
     ];*CP3 of then of else of ifelse 2 j; i.e. j is not a good partner to i

     ;set TNj value-from (patch (xcor-of turtle (partner)) (ycor-of turtle (partner))) [count turtles in-radius 0.5]             
     set PCj pcolor-of patch (xcor-of turtle (partner)) (ycor-of turtle (partner))
     ;show challenger                  ; i's id number
     ;show label                       ; i's name (challenger)
     ;show NNij                        ; list of the id numbers ("who") of farest j of i (from Dij view)
     ;show EiUij                       ; list of the i's perceptions of the utilities for i to challenge j
     ;show PositionOfMaxEiUij          ; position of the max utility for i to challeng j in i's utilities (from i's view)       
       
     ifelse
     challenged?-of turtle (partner) = false
     ;;make sure j still not challenged, because if challenged j can't be challenged by any other actor before the next run
     ;And PositionOfMaxEiUij < (VisionRange + (x * iteration))      
     And PositionOfMaxEiUij <= x
     ;; i knows j i.e. j is visible given the value of the VisionRange parameter
     And MaxEiUij > 0
     ;; if i expects gains in challenging j
     And MaxEiUij > ValEiUji
     ;; if i believes that he/she has more U to challenge j than that j has U to challenge i
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     ;; (that situation matches the sectors 1, 8 and 7 of the dynamics of the Bueno de Mesquita model)
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     And challenger = c        
     And ValEjUji <= 0
     And (Xi-of turtle(partner) != Xi-of turtle(challenger) Or Ei-of turtle(partner) != Ei-of turtle(challenger))
     ;; make sure that the objective or the preferred action of j is different positions to the one of i
     ;; similar positions of i and j are possible because ???
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     ;; SHIFT POSITIONS and CIRCULATE INFORMATION
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     
      [;OP3if
       ;show partner                     ; j's id number ([who] of j that gives max utility to i (from i's view))
       ;type label-of turtle (challenger) type "(" type who-of turtle (challenger) type ") tries to challenge " type label-of turtle (partner)
       ;type "expecting MaxEiUij=" print MaxEiUij  ; utility for i to challeng j (from i's view)      
       ;show ValEiUji                    ; utility for j to challeng i (from i's view)
       ;show xcor
       ;show xcor-of turtle (partner)
       set Nji Nij-of turtle (partner)   ; list of the known actors of j (partner)
       ;show Nji
    
       ifelse member? challenger Nji
       ;if member? challenger Nji
       ;; j knows i
       [ ;OP4if
        set PositionOfChallengerEjUji position challenger Nji ; position of i in the list of known actors to j
        ;show PositionOfChallengerEjUji
        
        ;ifelse PositionOfChallengerEjUji < (VisionRange + (x * iteration)) ; length NEjUji
        ifelse PositionOfChallengerEjUji <= x
        ;; j knows i (increasing in the level of the VisionRange, decreasing in the level of the similarity of the expected actions)
        
        [;OP5if
         ;type label-of turtle (partner) type " knows " show label-of turtle (challenger)  
         set NEjUji EiUij-of turtle (partner)
         ;show NEjUji
         set NEjUij EiUji-of turtle (partner)
         ;show NEjUij                   
         set ValEjUji item PositionOfChallengerEjUji NEjUji    ; j's perception of its (j's) utility to challenge i
         ;show ValEjUji
         set ValEjUij item PositionOfChallengerEjUji NEjUij    ; j's perception of i's utility to challenge itself (j)
         ;show ValEjUij
         ;set MEj MaxOfferOfi-of turtle (partner)
         ;show MEj
       
         ifelse partner != nobody
         [;OP6if                                             ; if successful grabbing a partner, partner up
          ;set MaxOfferOfi-of turtle (partner) ValEjUij
          ;show label-of turtle (challenger)             ; i's name (challenger)
          ;show label-of turtle (partner)                ; j's name (partner)
             
         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
         ;;RESULTS
         ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;,         
          
          type label-of turtle (challenger) type " challenged " type label-of turtle (partner)
          type " who moved from:" type Xi-of turtle(partner) type ";" type Ei-of turtle(partner)
          type " to:" type Xi-of turtle(challenger) type ";" print Ei-of turtle(challenger)
          ;type " so " type label-of turtle (challenger) type" gains " type "(" type k type "°EiUij): " type MaxEiUij
          ;type " while " type label-of turtle (partner) type" loses " type "(" type p type "°EjUji):" type MinEjUji
          ;type " max cost: " type m type " min cost: " type l type " u:" type u type " v:" type v type " accepted cost:" print q
          ;type " EiUij:" type MaxEiUij type ">EiUji:" type ValEiUji
          ;type " EjUji:" type ValEjUji type "<EjUij:" print ValEjUij
          
          ;type xcor-of turtle (challenger) type ";" type ycor-of turtle (challenger) type ";"  show TNi
          ;type xcor-of turtle (partner) type ";" type ycor-of turtle (partner) type ";" type PXj type ";" type PYj show TNj         
          ;show xcor-of turtle (challenger)
          ;show ycor-of turtle (challenger)
          ;show TNi
          ;show TNj
          ;show PCi                                      ; i's patch color
          ;show PCj                                      ; j's patch color     
          ;type partner type ";" type TNi type ";" Type TNj Type ";" show label-of turtle (partner)  ; j's name (challenged)
          set partnered? true
          ;set (partnered?-of turtle (partner)) true
          set (challenged?-of turtle (partner)) true
          ask turtle (partner) [ set challenger myself ]
                    
          ask turtle (partner)
          [
           hatch 1
           [
           set breed edges         
           setxy (xcor-of myself) (ycor-of myself)           
           set heading towards challenger
           set size distance challenger
           fd (distance challenger / 2)
           ]
          ]

          ;; replace positions of j with positions of i               
          ;set heading towards turtle (partner)           ; 270 ; face partner
          ;set (heading-of turtle (partner)) towards turtle (challenger) ; 90
          set pcolor-of patch-here PCj                   ; (patch-at xcor ycor)
          ;set pcolor-of patch (xcor-of turtle (partner)) (ycor-of turtle (partner)) PCi
          set ycor-of turtle (partner) ycor-of turtle (challenger) ; j adopts i's objective (Xi)          
          set xcor-of turtle (partner) xcor-of turtle (challenger) ; j adopts i's preferred actions (Ei)
          set Xi-of turtle (partner) Xi-of turtle (challenger) ; j adopts i's objective (Xi)          
          set Ei-of turtle (partner) Ei-of turtle (challenger) ; j adopts i's preferred actions (Ei)
          set Dij-of turtle (partner) Dij-of turtle (challenger) ; j adopts i's other actions (correlations with actions of others)
          ;set NNij remove turtle (partner) NNij          ; remove the id number ("who") of j from the list of i
          ;set NEiUij but-last NeiUij                     ; remove the utility for i to challenge j from the list of utilities
          ;set EiUij NEiUij                               ; copy the shorted list as list of utilities as list of utilities

          ;; store results
          set challenger-newneighbours-of turtle (challenger) lput label-of turtle (partner) challenger-newneighbours-of turtle (challenger)  ; list of convinced partners
          set challenger-shiftedobjectives-of turtle (challenger) lput Xi-of turtle (partner) challenger-shiftedobjectives-of turtle (challenger); list of shifts (adopted objectives)
          set challenger-shiftedstrategies-of turtle (challenger) lput Ei-of turtle (partner)challenger-shiftedstrategies-of turtle (challenger); list of shifts (adopted objectives)        
          set partner-newneighbours-of turtle (partner) lput label-of turtle (challenger) partner-newneighbours-of turtle (partner); list of challengers
          set partner-newsobjectives-of turtle (partner) lput Xi-of turtle (challenger) partner-newsobjectives-of turtle (partner); list of shifts (adopted objectives)
          set partner-newsstrategies-of turtle (partner) lput Ei-of turtle (challenger) partner-newsstrategies-of turtle (partner) ; list of shifts (adopted objectives)          

          set gains-of turtle (challenger) lput NUSij-of turtle (challenger) gains-of turtle (challenger)
          set losses-of turtle (partner) lput NUFji-of turtle (partner) losses-of turtle (partner)

          ;; replace utilities of positions of j with utilities of positions of i in all actors that know i                         
          ;;setup-knowledge
         ];CP6endif
         [;OP6else
         ;else partner != nobody And ValEjUij > 0 And ValEjUij > ValEjUji ; And ValEjUij > MEj    
         set partnered? false
         ;set (partnered?-of turtle (partner)) false
         set (challenged?-of turtle (partner)) false                  
         ;type label-of turtle (partner) type " has no utility in moving to " type label-of turtle (challenger)
         ;type " ValEjUij-ValEjUji (<=0)= " print precision (ValEjUij - ValEjUji) 4
         ];CP6endelse
        ];CP5endif
        [;OP5else
        ;else member? challenger Nji  ;; access failed because j doesn't know i ;; j doesn't evaluates the request of i
        ;type label-of turtle (challenger) type " is too close to " print label-of turtle (partner)
        ];CP5endelse
       ];CP4endif
       [;OP4else
       ;else PositionOfMaxEiUij < (VisionRange ...          ;; i doesn't try to challenge j
       ;type label-of turtle (challenger)
       ;type " is not known by " type label-of turtle (partner)          
       ;type " Position: " print PositionOfMaxEiUij              
       ];CP4endelse
      ];CP3endif                                                 ;; end of ifelse PositionOfMaxEiUij
      [;OP3else
      ;if challenged?-of turtle(partner) = true
      ;                          [
      ;                            type label-of turtle (challenger)
      ;                            type " can't challenge the already challenged "
      ;                            print label-of turtle (partner)
      ;                          ]
      ;if MaxEiUij - ValEiUji < 0 [
      ;                            type label-of turtle (challenger)
      ;                            type " has no U in challenging "
      ;                            type label-of turtle (partner)
      ;                            type " MaxEiUij-ValEiUji="
      ;                            print precision (MaxEiUij - ValEiUji) 4
      ;                          ]
      ];CP3endelse
    ];*CP2 of then of if of ifelse 1
    [;*OP2 of then of else of ifelse 1
    ;else(not partnered?) And EiUij != []                   ;; don't do anything
    ;type label-of turtle (challenger) print " is already partnered!"  
    ];*CP2 of then of else of ifelse 1
  ];*CP1 end of without interuption        
end

;;;;;;;;;;;;;;;;;;;;;;;;
;; Plotting Functions ;;
;;;;;;;;;;;;;;;;;;;;;;;;

;; plots the graph of the system
;to plot-graph
;  plot-value "Milk Supply" milk-supply
;  plot-value "Grass Supply" grass-supply
;  plot-value "Goat Population" goat-population
;  plot-value "Average Revenue" avg-revenue/farmer
;end

;; plot value on the plot called name-of-plot
;to plot-value [ name-of-plot value ]
;  set-current-plot name-of-plot
;  plot value
;end

to do-plot-actions-to-increase
   set-current-plot "Actions To Increase"
   
   set-current-plot-pen "MoreProvision"
   plot num-for-more-provision-to-increase
   set-current-plot-pen "MoreControl"
   plot num-for-more-control-to-increase
   set-current-plot-pen "CreateNewRegulation"
   plot num-for-more-newregulation-to-increase
   set-current-plot-pen "MoreApplyRegulation"
   plot num-for-more-currentregulation-to-increase   
   set-current-plot-pen "MoreSupplying"
   plot num-for-more-supply-to-increase
   set-current-plot-pen "MorePromotion"
   plot num-for-more-promotion-to-increase
   set-current-plot-pen "MoreCooperation"
   plot num-for-more-cooperation-to-increase
   
   set-current-plot-pen "Others"
   plot num-for-others-to-increase
   set-current-plot-pen "LessControl"
   plot num-for-less-control-to-increase
   ;set-current-plot-pen "AgainstRegulation"
   ;plot num-for-less-newregulation-to-increase
   set-current-plot-pen "LessApplyRegulation"
   plot num-for-less-currentregulation-to-increase   
   set-current-plot-pen "LessSupplying"
   plot num-for-less-supply-to-increase
   set-current-plot-pen "LessPromotion"
   plot num-for-less-promotion-to-increase
   set-current-plot-pen "LessCooperation"
   plot num-for-less-cooperation-to-increase   
end

to do-plot-actions-to-decrease
   set-current-plot "Actions To Decrease"
   set-current-plot-pen "MoreProvision"
   plot num-for-more-provision-to-decrease
   set-current-plot-pen "MoreControl"
   plot num-for-more-control-to-decrease
   set-current-plot-pen "CreateNewRegulation"
   plot num-for-more-newregulation-to-decrease
   set-current-plot-pen "MoreApplyRegulation"
   plot num-for-more-currentregulation-to-decrease   
   set-current-plot-pen "MoreSupplying"
   plot num-for-more-supply-to-decrease
   set-current-plot-pen "MorePromotion"
   plot num-for-more-promotion-to-decrease
   set-current-plot-pen "MoreCooperation"
   plot num-for-more-cooperation-to-decrease
   set-current-plot-pen "Others"
   plot num-for-others-to-decrease
   set-current-plot-pen "LessControl"
   plot num-for-less-control-to-decrease
   ;set-current-plot-pen "AgainstRegulation"
   ;plot num-for-less-newregulation-to-decrease
   set-current-plot-pen "LessApplyRegulation"
   plot num-for-less-currentregulation-to-decrease   
   set-current-plot-pen "LessSupplying"
   plot num-for-less-supply-to-decrease
   set-current-plot-pen "LessPromotion"
   plot num-for-less-promotion-to-decrease
   set-current-plot-pen "LessCooperation"
   plot num-for-less-cooperation-to-decrease   
end

to do-plot-actions-to-maintain
   set-current-plot "Actions To Maintain"
   set-current-plot-pen "MoreProvision"
   plot num-for-more-provision-to-maintain
   set-current-plot-pen "MoreControl"
   plot num-for-more-control-to-maintain
   set-current-plot-pen "CreateNewRegulation"
   plot num-for-more-newregulation-to-maintain
   set-current-plot-pen "MoreApplyRegulation"
   plot num-for-more-currentregulation-to-maintain   
   set-current-plot-pen "MoreSupplying"
   plot num-for-more-supply-to-maintain
   set-current-plot-pen "MorePromotion"
   plot num-for-more-promotion-to-maintain
   set-current-plot-pen "MoreCooperation"
   plot num-for-more-cooperation-to-maintain
   set-current-plot-pen "Others"
   plot num-for-others-to-maintain
   set-current-plot-pen "LessControl"
   plot num-for-less-control-to-maintain
   ;set-current-plot-pen "AgainstRegulation"
   ;plot num-for-less-newregulation-to-maintain
   set-current-plot-pen "LessApplyRegulation"
   plot num-for-less-currentregulation-to-maintain   
   set-current-plot-pen "LessSupplying"
   plot num-for-less-supply-to-maintain
   set-current-plot-pen "LessPromotion"
   plot num-for-less-promotion-to-maintain
   set-current-plot-pen "LessCooperation"
   plot num-for-less-cooperation-to-maintain   
end

to do-plot-objectives
   set-current-plot "Objectives Of Actions"
   set-current-plot-pen "Increase"
   plot num-for-increased
   set-current-plot-pen "Decrease"
   plot num-for-decreased
   set-current-plot-pen "Maintain"
   plot num-for-maintained
   
   set-current-plot "Objectives Of Actors"
   set-current-plot-pen "Increase"
   plot resources-for-increased
   set-current-plot-pen "Decrease"
   plot resources-for-decreased
   set-current-plot-pen "Maintain"
   plot resources-for-maintained
end

to do-plot-optimization
   set-current-plot "Decision-Making Style"
   set-current-plot-pen "Optimization"
   plot num-optimization
   set-current-plot-pen "SubOptimization"
   plot num-suboptimization
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Calculation Functions ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; For Setup Procedures
; Ri              ;; Qx-power: resources varies from 0 to 1
; Gi              ;; groups-involvement = poi+(poi'-1) varies from 0 to 3        
; Si              ;; Q1-salience: varies from 1 to 4 Q1-salience
; Xi              ;; Q2-expect: expectation about k varies from -1 to 1
; Ei              ;; Q4 preferred way to achieve Xi: 0 (PROV+), 2 (CONT+), ... 12 (COOP+)
; Dij             ;; list of correlations between i and its closer actors (ref. HCA DistancesAll ; varies from 0 to 1))
; Nij             ;; list of the closer actors in same order than dijk
; Willingness to listen of j = Slider WillingnessToListen ; may vary from 0.1 to 0.9
; WillingnessToShift tetapi  = 1/Gi+1: varies from 0 to 1 with the inverse of networking involvement
; guessp          ;; Pij bias = random-normal (value-from (turtle-here) [Pij]) (ErrorOnProbOfSuccessAccess / 10)   
; guessb          ;; USij bias= random-normal (value-from (turtle-here) [USij]) (ErrorOnConsequOfShifts)
; guessc          ;; UFij bias = random-normal (value-from (turtle-here) [UFij]) (ErrorOnConsequOfShifts)
;; Pij   = Ri*(1-(Rj * (1-WillingnessToListenj)) ; anticipated probability of success in i challenging j (i.e. that j changes its positions)
;; Uij   = f (Xi, Xj) * g (1-Dij) see bellow
;; USij  =   Rj*Uij*WillingnessToShiftj
;; UFij  = - Ri*Uij*WillingnessToShifti
;; EiUij =(Sj/4         *((    Pij   * USij ) + ((1-Pij) * UFij  )) + (1-Sj)     * USij )
;;        (i's perception of i's U of i challenging j                                   ) - (i's percep of i's U of i not challenging j)
;;        (i accessed j *((i wins    * Gains) + (i fails * Losses)) + (j accepts * Gains)
;; EiUji =(Si/4         *((    Pji   * USji ) + ((1-Pji) * UFji  )) + (1-Si)     * USji )
;;        (i's perception of j's U of j challenging i                                   ) - (i's percep of j's U of j not challenging i)
;;        (j accessed i *((j wins    * Gains) + (j fails * Losses)) + (i accepts * Gains)

;; EiUij= {Sj*[Pi*(Uisi) + (1- Pi)*Uifi + (1-Sj)* Uisi ) + ?k#i,j [Sk*(Pik + Pjk-1)*(Uiki - Uikj)]}- Uiqi
;; EiUji= {Si*[Pj*(Uisj) + (1- Pj)*Uifj + (1-Sj)* Uisj ) + ?k#i,j [Sk*(Pik + Pjk-1)*(Uikj - Uiki)]}- Uiqj
;; EjUji= {Si*[Pj*(Ujsj) + (1- Pj)*Ujfj + (1-Sj)* Ujsj ) + ?k#i,j [Sk*(Pik + Pjk-1)*(Ujkj - Ujki)]}- Ujqj
;; EjUij= {Sj*[Pi*(Ujsi) + (1- Pi)*Ujfi + (1-Sj)* Ujsi ) + ?k#i,j [Sk*(Pik + Pjk-1)*(Ujki - Ujkj)]}- Ujqi

to-report calc-Pij [rNRi rNRj] ; Ri Rj 0 .. 1
   report precision  (guessp * rNRi * (1 - (rNRj * (1 - WillingnessToListen)))) 4
end

to-report calc-Uij [rNDij rNXi rNXj]
;;  Uij    = (f * diff between objectives) + (g * diff between actions of i and actions of j
;;  Uij    =  f * (NXi - NXj)              +  g * NDij
;;  0 .. 1 =  f * (0   ..  2)              +  g * (- 1 .. 1)
;;  0 if   =  f * 0 if NXi=NXj             +  g *  1  if all actions of i are the same to the actions of j
;;  1 if   =  f * 2 if NXi= 1 and NXj = -1 +  g * -1  if all actions of i are different to the actions of j
;;  consequently:
       
    ifelse rNDij <= 0                                       ;; if less than 50% of the expected actions of i anj are similar
                                                            ;; situation d'autant + utile que NDij est élevée
        [;OP1 of if 1
        ifelse (rNXi = rNXj)      ;; if objectives of i and j are similar (diagonale = utilité nulle des objectifs)     
            [;OP2 of if 2
                report precision ((0.01 * (1 - ActionsWeight)) + (ActionsWeight * abs(rNDij))) 4
                ;;     Uij = max ActionsWeight                                     if NDij = -1
                ;;     Uij = min 0                                                 if NDij =  0
            ];CP2 end of if 2                
            [;OP2 else of if 2             ;; if objectives of i and j are different (off diagonale = utiité) des objectifs)
            if (rNXi + rNXj = 1)   ;; if i or j is for maintaining and the other for increasing
               [report precision ((0.50 * (1 - ActionsWeight)) + (ActionsWeight * abs(rNDij))) 4]
                ;;     Uij = max 0.5 * (1 - ActionsWeight) + ActionsWeight         if NDij = -1               
                ;;     Uij = min 0.5 * (1 - ActionsWeight)                         if NDij = 0
            if (rNXi + rNXj = -1)  ;; if i or j is for maintaining and the other for decreasing
               [report precision ((0.50 * (1 - ActionsWeight)) + (ActionsWeight * abs(rNDij))) 4]
                ;; idem above
            if (rNXi + rNXj = 0)   ;; if objectives of i and j are opposite (extrema position in triangle = max utility of objectives)            
               [report precision ((1.00 * (1 - ActionsWeight)) + (ActionsWeight * abs(rNDij))) 4]
                ;;     Uij = max 1.0 * (1 - ActionsWeight) + ActionsWeight         if NDij = -1               
                ;;     Uij = min 1.0 * (1 - ActionsWeight)                         if NDij = 0
            ];CP2end of else of if 2
        ];CP1 end of if
        [;OP1else i.e. Dij >0                                ;; if more than 50% of the expected actions of i and j are similar
                                                             ;; situation d'autant - utile que NDij est élevé
        ifelse (rNXi = rNXj)      ;; if objectives of i and j are similar (diagonale = utilité nulle des objectifs)     
            [;OP2if  
                report precision ((0.01 * (1 - ActionsWeight)) + (1 - (ActionsWeight * abs(rNDij)))) 4  
                ;;     Uij = max ActionsWeight                                       if NDij = 0
                ;;     Uij = min 0                                                   if NDij = 1
            ];CP2endif
            [;OP2else              ;; if objectives of i and j are different (off diagonale = utiité) des objectifs)
            if (rNXi + rNXj = 1)   ;; if i or j is for maintaining and the other for increasing
               [report precision ((0.50 * (1 - ActionsWeight)) + (1 - (ActionsWeight * abs(rNDij)))) 4]
                ;;     Uij = max 0.5 * (1 - ActionsWeight) + ActionsWeight           if NDij = 0               
                ;;     Uij = min 0.5 * (1 - ActionsWeight)                           if NDij = 1
            if (rNXi + rNXj = -1)  ;; if i or j is for maintaining and the other for decreasing
               [report precision ((0.50 * (1 - ActionsWeight)) + (1 - (ActionsWeight * abs(rNDij)))) 4]
                ;; idem above
            if (rNXi + rNXj = 0)   ;; if objectives of i and j are opposite (extrema position in triangle = max utility of objectives)
               [report precision ((1.00 * (1 - ActionsWeight)) + (1 - (ActionsWeight * abs(rNDij)))) 4]
                ;;     Uij = max 1.0 * (1 - ActionsWeight) + ActionsWeight           if NDij = 0
                ;;     Uij = min 1.0 * (1 - ActionsWeight)                           if NDij = 1
            ];CP2endelse         
         ];CP1endelse
end


to-report calc-USij [rNUij rNRj rNSj rNGj] ;;Rj 0..1 Sj 1..4 Gj 0 ..3
    ;report precision (guessb * (1 - ( rNRj * (rNSj / 4) *  rNUij * (1 / (rNGj + 1))))) 3
    ;report precision (guessb * (    ( rNRj * (rNSj / 4) *  rNUij * (1 / (rNGj + 1))))) 4
     report precision (guessb * (    ( rNRj *               rNUij * (1 / (rNGj + 1))))) 4
end

to-report calc-UFij [rNUij rNRi rNSi rNGi]
    ;report precision (guessc *      ((rNRi * (rNSi / 4) * (rNUij * (1 / (rNGi + 1)))) - 1 ) 3     
    ;report precision (guessc *      ((rNRi * (rNSi / 4) * (rNUij * (1 / (rNGi + 1))))     ) 4         
     report precision (guessc * -1 * ((rNRi *               rNUij * (1 / (rNGi + 1))))     ) 4             
end

to-report calc-EiUij [rNPij rNSj rNUSij rNUFij]               
  report precision ((rNSj / 4) * ((rNPij * rNUSij) + ((1 - rNPij) * rNUFij)) + ((1 - (rNSj / 4)) * rNUSij)) 4
end

to-report calc-EiUji [rNPji rNSi rNUSji rNUFji]
  report precision ((rNSi / 4) * ((rNPji * rNUSji) + ((1 - rNPji) * rNUFji)) + ((1 - (rNSi / 4)) * rNUSji)) 4
end

;;            EiUij =(Sj/4     *(( Pij   * USij )   + ((1-Pij)    * UFij  )) + (1-Sj)            * USij )
;;                  accessed j *((i wins * Gains)   + (i fails    * Losses)) + (j accepts        * Gains)
;;            EiUji =(Si/4     *(( Pji   * USji )   + ((1-Pji)    * UFji  )) + (1-Si)            * USji )
;;                j accessed i *((j wins * Gains)   + (j fails    * Losses)) + (i accepts        * Gains)

;; For Runtime Procedures

to-report calc-Q [l m u v]
    report precision (l - (abs (l - m) * u / (u + v) * ThirdParty)) 4
end

;to-report neighbor-turtle
;    report random-one-of
;             value-from
;               random-one-of (neighbors with [any turtles-here])
;                 [turtles-here]
;end

; *** Negotiation Model Copyright Notice ***
;
; This model was created as part of the SPRITE project
; These projects gratefully acknowledge the support of the
; European Union SPRITE project (QLK5-2000-0211)
;
; This model was wrote in NetLogo (Wilensky, U. 1999. NetLogo)
; Center for Connected Learning and Computer-Based Modeling, Northwestern University. Evanston, IL.
; https://ccl.northwestern.edu/netlogo/
;
; Permission to use, modify or redistribute this model is hereby granted,
; provided that both of the following requirements are followed:
; a) this copyright notice is included.
; b) this model will not be redistributed for profit without permission
;    from the copyright holders.
; Contact the copyright holders for appropriate licenses for redistribution
; for profit.
;
; To refer to this model in academic publications, please use:
; Bousset, J-P. (2003).  Negotiation model, SPRITE project,
; Cemagref, 24 av. des Landais,
; 63200 Aubiere, France.
;
; *** End of SPRITE Negotiation Model Copyright Notice ***

@#$#@#$#@
GRAPHICS-WINDOW
10
158
496
665
12
12
19.04
1
10
0
1

CC-WINDOW
9
665
497
780
Command Center

BUTTON
66
18
176
51
run one round
run-model
NIL
1
T
OBSERVER

BUTTON
10
18
65
51
NIL
setup
NIL
1
T
OBSERVER

SLIDER
307
53
495
86
WillingnessToListen
WillingnessToListen
0.1
0.9
0.9
0.1
1
NIL

SLIDER
307
18
495
51
VisionRange
VisionRange
10
100
20
5
1
NIL

SLIDER
307
85
495
118
ErrorOnProbOfSuccAccess
ErrorOnProbOfSuccAccess
0
10
0
1
1
NIL

SLIDER
307
119
495
152
ErrorOnConsequeOfShifts
ErrorOnConsequeOfShifts
0
10
0
1
1
NIL

PLOT
498
157
816
476
Actions To Increase
Iteration
Supporters
0.0
10.0
0.0
50.0
true
true
PENS
"MoreProvision" 1.0 0 -16777216 true
"MoreControl" 1.0 0 -65281 true
"CreateNewRegulation" 1.0 0 -16711681 true
"MoreApplyRegulation" 1.0 0 -16745473 true
"MoreSupplying" 1.0 0 -8716033 true
"MorePromotion" 1.0 0 -16711936 true
"MoreCooperation" 1.0 0 -65536 true
"LessControl" 1.0 2 -65281 true
"LessApplyRegulation" 1.0 2 -16745473 true
"LessSupplying" 1.0 2 -8716033 true
"LessPromotion" 1.0 2 -16711936 true
"LessCooperation" 1.0 2 -6524078 true
"Others" 1.0 2 -16777216 true
"LessNewRegulation" 1.0 2 -16711681 true

PLOT
497
18
749
157
Objectives Of Actions
Iteration
Supporters
0.0
10.0
0.0
100.0
true
true
PENS
"Increase" 1.0 0 -16711936 true
"Decrease" 1.0 0 -65536 true
"Maintain" 1.0 0 -16777216 true

PLOT
809
159
1124
473
Actions To Maintain
Iteration
Supporters
0.0
10.0
0.0
50.0
true
true
PENS
"MoreProvision" 1.0 0 -16777216 true
"MoreControl" 1.0 0 -65281 true
"CreateNewRegulation" 1.0 0 -16711681 true
"MoreApplyRegulation" 1.0 0 -16776961 true
"MoreSupplying" 1.0 0 -8716033 true
"MorePromotion" 1.0 0 -16711936 true
"MoreCooperation" 1.0 0 -65536 true
"LessControl" 1.0 2 -65281 true
"LessApplyRegulation" 1.0 2 -16776961 true
"LessSupplying" 1.0 2 -8716033 true
"LessPromotion" 1.0 2 -16711936 true
"LessCooperation" 1.0 2 -6524078 true
"Others" 1.0 2 -16777216 true
"LessNewRegulation" 1.0 2 -16711681 true

PLOT
497
472
812
782
Actions To Decrease
Iteration
Supporters
0.0
10.0
0.0
50.0
true
true
PENS
"MoreProvision" 1.0 0 -16777216 true
"MoreControl" 1.0 0 -65281 true
"CreateNewRegulation" 1.0 0 -16711681 true
"MoreApplyRegulation" 1.0 0 -16776961 true
"MoreSupplying" 1.0 0 -8716033 true
"MorePromotion" 1.0 0 -16711936 true
"MoreCooperation" 1.0 0 -65536 true
"LessControl" 1.0 2 -65281 true
"LessApplyRegulation" 1.0 2 -16776961 true
"LessSupplying" 1.0 2 -8716033 true
"LessPromotion" 1.0 2 -16711936 true
"LessCooperation" 1.0 2 -6524078 true
"Others" 1.0 2 -16777216 true
"LessNewRegulation" 1.0 2 -16711681 true

BUTTON
179
18
305
51
run forever
run-model
T
1
T
OBSERVER

PLOT
809
18
1058
160
Objectives Of Actors
Iteration
Resources
0.0
10.0
0.0
20.0
true
true
PENS
"Increase" 1.0 0 -11352576 true
"Decrease" 1.0 0 -65536 true
"Maintain" 1.0 0 -16777216 true

SLIDER
180
53
305
86
Iterations
Iterations
1
50
20
1
1
NIL

SLIDER
10
53
177
86
ThirdParty
ThirdParty
0
1
1.0
0.1
1
NIL

SLIDER
10
88
178
121
ActionsWeight
ActionsWeight
0.1
0.5
0.5
0.1
1
NIL

PLOT
812
473
1125
782
Decision-Making Style
Iteration
Frequency
0.0
10.0
0.0
100.0
true
true
PENS
"Optimization" 1.0 0 -16776961 true
"SubOptimization" 1.0 0 -65536 true

CHOICE
180
89
305
134
PoliticalDistance
PoliticalDistance
"FromQ3&Q4&Q5" "OnlyFromQ4"
1

SLIDER
10
123
177
156
NetworksWeight
NetworksWeight
0.1
1
0.1
0.1
1
NIL

@#$#@#$#@
What is this?
------------
 
The “Setup” button must be activated to load the input data and the parameters values.

The “Run” buttons lauches the simulation of the model with the loaded data and parameters (one run)
“Run for ever” lauches the simulation “Iterations” times without interuption between iterations.

The “Command Center” window reports some results of the simulations.
You can select, copy and paste the content of this window into a Word file.

The “VisionRange” slider (ref. tetac in the model (see D18)) is to be used to study how the results of the simulation vary when the maximum number of actors that each actor well knows before the first meeting varies (it may vary from 0 to 30 ( ))..

The “WillingnessToListen” slider (ref. tetad in the model) is to be used to stiudy how indicates the results of the simulation vary when the probability that each actor well hears an other one varies (it may vary from 0.1 to 0.9). It modulates the influences of the actors resources on their behaviour.

The “ErrorOnProbOfSuccAccess” slider is to be used to study how the results of the simulation vary when the error of actors in estimating the accessibility of an other one varies (it may vary from 0 (perfect information) to 10 (great uncertainty)).

The “ErrorOnConsequeOfShifts” slider is to be used to study how the results of the simulation vary when the error of actors in estimating the consequences of challenging an other one vaies (it may vary from 0 (perfect information) to 10 (great uncertainty)).

The “ThirdParty” slider (ref. (tetap in the model) is to be used to study how the results of the simulation vary when the decision-making of actors to accept or not to shift their positions is more (1) or less (0.1) infuenced by the positions of the other actors.


How to build an alternative scenario?
-------------------------------------
 
a.      Click on the Setup button to load the data
 
You should be in the face to a square grid that represents the surveyed actor:
. Cyan squared-shapes will represent the Institutions
. Red man-shapes will represent the Resources Controllers
. Gray man-shapes will represent the Gatekeepers
. Yellow man-shapes will represent the Businesses
. Lime man-shpae will the represent the Communities

The size of the actor varies in proportion of their own resources.
 
The location of actors on the grid varies with their objectives (expectations) and their preferred actions to achive their objectives.

The actors' positions on the Y axis will indicate their expectations about the evolution of k. The Y axis is divided in 3 parts: a black area, a brown area, and a blue area .
. Actors on a blue back-ground support an increase of k (expected evoluation of = +1)
. Actors on a brown back-ground are for the maintaining of k (0)
. Actors on a black back-ground are for e decrease of k (-1)

The actors' positions on the X axis will indicate their preferred actions to achieve their expectations about the evolution of k. The X axis is divided in 24 parts (from 12 to +12). Looking at the bottom of this grid, you can find the correspondance between each X value and the actors’ positions.

b.      Run the simulations for ever
 
You should see some actors move towards some other ones.
Thye bring with them the colour of the patch where they were located.
So, for example, the blue area (supporters of tourism development)
may be polluted by some "black" actors (against tourism development)

The Command Center gives more indication on the shifts of actors positions.
 
At the end of the simulations:
. the Base Scenario will be autoamtically stored in “SPRITE-CZ1-GsresultsOfNegotiation0.csv”.
. the Alternative Scenario will be automatically saved in “SPRITE-CZ1-GsresultsOfNegotiation10.csv”.
 
c.       Analyse the results of the simulation
 
Look at the graphs
 
Curves in the left graph at the top of the screen indicates a possible future evolution of the number of actors that currently would like the number of tourists increases, the number of actors that currently would like this number be maintained, and the number of actors that currently would like this number be decreased.
 
Curves in the right graph at the top of the screen indicates a the evolution of the total amont of the resources of actors that currently would like the number of tourists increases, of actors that currently would like this number be maintained, and of actors that currently would like this number be decreased.
 
Curves in the 3 other graphs indicates a possible future evolution of the number of actors that currently would like to see done more provision of resources, more control of resources,… The left graph indicates the possible future evolution of the number of supporters of such strategies to increase the number of tourists. The right graph indicates the possible future evolution of the number of supporters of such strategies to maintain the number of tourists. the possible future evolution of the number of supporters of such strategies to decrease the number of tourists.
 
Run EXCEL  and Open the 3 following workbooks:
( 1) “SPRITE-CZ1-GSresultsOfNegotiation0.csv”
( 2) “SPRITE-CZ1-GSresultsOfNegotiation10.csv”
( 3) “WP8Alternative Scenarios.xls”
 
Select the whole content of the sheet “SPRITE-Reg-GsresultsOfNegotiati” in the workbook (1). Copy and Paste these data into the sheet “BaseScenario” of the workbook (3).
Select the whole content of the sheet “SPRITE-Reg-GsresultsOfNegotiati” in the workbook (2). Copy and Paste these data into the sheet “ResultsOfNegotiationForGS” of the workbook (3).
Move to the sheet “GeneralScenario” of the workbook (3).
Click on “Create Supports For Chapter 4 Of D19” in sheet “GeneralScenario”
 
The main results of the simulations are reported in the 5 tables of sheet “GeneralScenario”.
Table 1 gives the possibles future policy networks that come from the analysis of the declarations of the surveyed actors (Base Scenario).
Table 2 gives other possible future policy networks that come from the simulation of the negotiation model (Alternative Scenario)
The other tables give indications on the dynamics of the construction off the alternative scenario
 
The analysis of this dynamics can be refined by using the following procedure:
 
Run Word and Load the file “FormForPajek.doc”
Open the sheet “DynamicsOfNegotiationForGS2” in the workbook “AlternativeScenarios.xls”
Select and Copy the Range “A1:I94” of this sheet
Paste the selected data in the Word file with option “text without format”
Click on ‘Format For  Pajek” at the top of the first page
 
Save the content of the Word file as “SPRITE-Reg-GSWorldForPajek.txt” with option “text only”
Run PAJEK and Load the file “SPRITE-Reg-GSWorldForPajek.txt
Run the Pajek Macro “Draw”,  Option Draw
Run the Pakjek Macro “Energy”, with Positions “Circular”
Select Option “3D Fruchterman” with Distance = 3
Run the Pajek Macro “Options”, with  Mark = “Label” and Scroll Bar = “On”
You should be in the face of a figure that shows the dynamics of construction of possible future policy networks.
Running the Pajek Macro Net, Option Partition, Sub option Degree Input, then Degree Output, will give an estimation of the motivity and dependency of each actor.
@#$#@#$#@
default
true
0
Polygon -7566196 true true 150 5 40 250 150 205 260 250

arrow
true
0
Polygon -7566196 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150

box
true
0
Polygon -7566196 true true 45 255 255 255 255 45 45 45

boy-shape
false
0
Circle -7566196 true true 107 15 84
Line -7566196 true 150 75 150 224
Line -7566196 true 150 150 74 135
Line -7566196 true 150 149 224 135
Line -7566196 true 150 224 195 284
Line -7566196 true 150 226 105 284

circle
true
0
Circle -7566196 true true 35 35 230

line
true
0
Line -7566196 true 150 0 150 301

organisation-shape
false
14
Line -16711681 false 14 17 285 17
Line -16711681 false 13 16 13 286
Line -16711681 false 12 286 284 286
Line -16711681 false 284 17 284 287

person
false
0
Circle -7566196 true true 155 20 63
Rectangle -7566196 true true 158 79 217 164
Polygon -7566196 true true 158 81 110 129 131 143 158 109 165 110
Polygon -7566196 true true 216 83 267 123 248 143 215 107
Polygon -7566196 true true 167 163 145 234 183 234 183 163
Polygon -7566196 true true 195 163 195 233 227 233 206 159

spacecraft
true
0
Polygon -7566196 true true 150 0 180 135 255 255 225 240 150 180 75 240 45 255 120 135

thin-arrow
true
0
Polygon -7566196 true true 150 0 0 150 120 150 120 293 180 293 180 150 300 150

truck-down
false
0
Polygon -7566196 true true 225 30 225 270 120 270 105 210 60 180 45 30 105 60 105 30
Polygon -8716033 true false 195 75 195 120 240 120 240 75
Polygon -8716033 true false 195 225 195 180 240 180 240 225

truck-left
false
0
Polygon -7566196 true true 120 135 225 135 225 210 75 210 75 165 105 165
Polygon -8716033 true false 90 210 105 225 120 210
Polygon -8716033 true false 180 210 195 225 210 210

truck-right
false
0
Polygon -7566196 true true 180 135 75 135 75 210 225 210 225 165 195 165
Polygon -8716033 true false 210 210 195 225 180 210
Polygon -8716033 true false 120 210 105 225 90 210

turtle
true
0
Polygon -7566196 true true 138 75 162 75 165 105 225 105 225 142 195 135 195 187 225 195 225 225 195 217 195 202 105 202 105 217 75 225 75 195 105 187 105 135 75 142 75 105 135 105

@#$#@#$#@
NetLogo 1.3
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@

 

Contact

© 2014 Tous droits réservés.

Créer un site internet gratuitWebnode