MACTOR stakeholder analysis

MACTOR stakeholder analysis preview image

1 collaborator

Default-person Carlos Roca (Author)

Tags

project management 

Tagged by Carlos Roca over 8 years ago

project managementR 

Tagged by Carlos Roca over 8 years ago

project managementh 

Tagged by Carlos Roca over 8 years ago

project managemento 

Tagged by Carlos Roca over 8 years ago

project managementz 

Tagged by Carlos Roca over 8 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 5.2.0 • Viewed 1627 times • Downloaded 73 times • Run 0 times
Download the 'MACTOR stakeholder analysis' modelDownload this modelEmbed this model

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


Info tab cannot be displayed because of an encoding error

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;; MACTOR Actors Analysis

extensions [matrix csv ]

globals
   [
     headerLine
     firstColumn
     TopOfScale
     lineStep
     interLine
     dataLine
     numActors
     numObjectives
     selectedActor
     selectedObj
     currentActor
     currentObjective
     minRange
     maxRange
     visConv visDiv visBN visAP filtered? ;; variables for select-actor function
     _MID ;; direct influences matrix
     _MID-exists?
     _2MAO-exists?
     _Involv ;; Involvement, implication, from _2MAO
     _rowsCoord ;; coordinates of submitted rows after factorial analysis of correspondences
     _colsCoord ;;     " of columns
     voronoi ;; voronoi flag
     
     all-matrices-calculated?
     _1MAO ;; Actors X Objectives matrix (approves/disapproves)
     _2MAO ;; Actors X Objectives matrix (degree of approval/disapproval)
     _3MAO
     _MIDI ;; Direct and indirect influences matrix
     _BN   ;; Net influence balance between actors
     _Ii    ;; Influences vector
     _Dj    ;; Dependances vector
     _Ri    ;; Balance of power ( for each actor)
     _Ai    ;; Ambivalence of actors
     _Cj    ;; Conflict index
     _1CAA  ;; Convergences between actors
     _1DAA  ;; Divergences bertween actors
     _2CAA  ;; Valuated
     _2DAA
     _3CAA  ;; Valuated & wieghted
     _3DAA
     _3RAA  ;; _3CAA - _3DAA
     _1COO  ;; Convergences between objectives
     _1DOO  ;; Divergences bertween objectives
     _2COO  ;; Valuated
     _2DOO
     _BNOO  ;; Net balance between objectives
     _ObjDistances
     _actorsDistances
   ]
   
breed [ actors actor ]
breed [ objectives objective ]
breed [ lines line ]  ;; lines for actors and objectives views
breed [ marks mark ]  ;; selection marks for actors and objectives views
breed [ titles title ] ;; titles for actors and objectives views
breed [ g-lines g-line ] ;; lines for graphics views

undirected-link-breed [ convergence-links convergence-link ]
undirected-link-breed [ divergence-links divergence-link ]
undirected-link-breed [ g-links g-link ]
directed-link-breed [ BN-links BN-link ]
directed-link-breed [ actor-position-links actor-position-link ]

actors-own [ actorNumber xpos ypos]
objectives-own [ objNumber xpos ypos]
titles-own [ titleName ]
marks-own [actorNumber objNumber]

to setup
  clear-all
  ask patches [ set pcolor white ]
  set numActors 0   ;; neither actors
  set numObjectives 0 ;; nor objectives at start
  set headerLine 49 ;; ycor of tittles line
  set dataLine 46   ;; ycor of first data
  set firstColumn 20 ;; xcor of first column ( names )
  set TopOfScale 60 ;; xcor of the topmost position for bars
  set lineStep 2  ;; inter lines step
  set interLine 5 ;; separation between vertical lines
  set _MID-exists? false
  set _2MAO-exists? false
  set all-matrices-calculated? false
  set filtered? false
  set verbose? true
  set multipleLinks? false
  create-titles 1
         [ set label "" set label-color black set shape "person" set size 0
           setxy firstColumn headerLine set titleName "header 1"
         ]
  create-titles 1
         [ set label "" set label-color black set shape "person" set size 0
           setxy firstColumn + 30 headerLine set titleName "header 2"
         ]
  create-titles 1
         [ set label "" set label-color black set shape "person" set size 0
           setxy firstColumn + 23 dataLine + 1 set titleName "header 3"
         ]
end 

to add-actor
  let actorsList []
  let firstActor true
  ;clear-output
  carefully [set actorsList read-from-string inputList] [ user-message "please enter a list of actors" stop]
  if not is-list? actorsList or actorsList = [ ] [ stop ]
  let qNewActors length actorsList
  let qOldActors numActors
  foreach actorsList
    [ create-actors 1
         [ set label ? set label-color black set shape "person" set size 0 set actorNumber numActors
           setxy firstColumn dataLine - numActors * lineStep hide-turtle
           set xpos xcor set ypos ycor
         ]
      if firstActor = true [ output-print "The following actors has been included:\n"
                             set firstActor false ]
      output-print ?
      set numActors numActors + 1
    ]
    ifelse qOldActors > 0
      [ let old_MID matrix:copy _MID
        let old_2MAO matrix:copy _2MAO
        set _MID matrix:make-constant numActors numActors 0
        if _2MAO-exists?
        [ 
          set _2MAO matrix:make-constant numActors numObjectives 0
        ]
        let i 0
        while [ i < qOldActors ]    ;; extend old columns
           [
             let thisRow matrix:get-row old_MID i
             let newZeroes n-values qNewActors [ 0 ]
             set thisRow sentence thisRow newZeroes
             matrix:set-row _MID i thisRow
             set i i + 1
           ]
        let j 0                     ;; create the new ones
        while [ j < qNewActors ]
           [ let zeroRow n-values numActors [ 0 ]
             matrix:set-row _MID ( i + j ) zeroRow
             set j j + 1
           ]
        if _2MAO-exists?
         [
         set i 0                     ;; copy old values, then add the new actors to _2MAO
         while [ i < numActors ]
           [ let thisRow [ ]
             ifelse i < qOldActors 
                [
                  set thisRow matrix:get-row old_2MAO i
                ]
                [          
                  set thisRow n-values numObjectives [ 0 ]
                ]
             matrix:set-row _2MAO i thisRow
             set i i + 1
           ]
         calculate
         ] 
      ]
      [
        set _MID matrix:make-constant numActors numActors 0
        set _MID-exists? true
      ]
end 

to add-objective
  if numActors = 0 [ user-message "Please enter some actors before." stop ]
  let objList []
  let firstObj true
  ;clear-output
  carefully [set objList read-from-string inputList] [ user-message "please enter a list of objectives" stop]
  if not is-list? objList or objList = [ ] [ user-message "please enter a list of objectives" stop ]
  let qNewObjectives length objList
  let qOldObjectives 0
  set qOldObjectives numObjectives
  foreach objList
    [ create-objectives 1
         [ set label ? set label-color black set shape "star" set size 0 set objNumber numObjectives
           setxy firstColumn dataLine - numObjectives * lineStep hide-turtle
           set xpos xcor set ypos ycor
         ]
      if firstObj = true [ output-print "The following objectives has been included:\n"
                             set firstObj false ]
      output-print ?
      set numObjectives numObjectives + 1
    ]
    ifelse qOldObjectives > 0
      [ 
        let old_2MAO matrix:copy _2MAO
        set _2MAO matrix:make-constant numActors numObjectives 0
        let j 0 let thisCol 0
         while [ j < numObjectives ]
           [
             ifelse j < qOldObjectives
               [ set thisCol matrix:get-column old_2MAO j
               ]
               [ set thisCol n-values numActors [ 0 ]
               ]
                 matrix:set-column _2MAO j thisCol
           set j j + 1
           ]
      calculate
      ]
      [
        set _2MAO matrix:make-constant numActors numObjectives 0
        set _2MAO-exists? true
      ]
end 

to delete-actors
 if not _MID-exists?
     [ user-message "nothing to delete." stop ]
 let listActors [ ]
 foreach sort-on [actorNumber] actors
     [ set listActors lput [label] of ? listActors ] 
 set selectedActor user-one-of "Select actor." listActors
 if not any? actors with [ label = selectedActor ] [stop]
 set currentActor [actorNumber] of one-of actors with [ label = selectedActor ]
 let old_MID matrix:copy _MID
 set _MID matrix:make-constant (numActors - 1) (numActors - 1) 0
 let old_2MAO 0
 if _2MAO-exists?
   [
    set old_2MAO matrix:copy _2MAO
    set _2MAO matrix:make-constant (numActors - 1) numObjectives 0
   ]
 let i 0 let rowPassed false let k 0
 while [ i < numActors ]
    [
      ifelse i != currentActor
         [ let thisRow matrix:get-row old_MID i
           set thisRow remove-item currentActor thisRow
           ifelse rowPassed = true [ set k i - 1 ] [ set k i ] 
           matrix:set-row _MID k thisRow
           if _2MAO-exists?
             [
               set thisRow matrix:get-row old_2MAO i
               ifelse rowPassed = true [ set k i - 1 ] [ set k i ] 
               matrix:set-row _2MAO k thisRow
             ]
         ]
         [ set rowPassed true ]
      set i i + 1
    ]
 set numActors numActors - 1
 ask actors with [ actorNumber = currentActor ] [ die ]
 ask actors with [ actorNumber > currentActor ] 
   [ set actorNumber actorNumber - 1 
     setxy xcor ycor + lineStep set xpos xcor set ypos ycor]
 ask turtles [ hide-turtle ] ask links [ die ]
 user-message ( word "Actor <" selectedActor "> has been removed." )   
 if _2MAO-exists? [ calculate]
end 

to delete-objectives
 if not _2MAO-exists?
     [ user-message "nothing to delete." stop ]
 let listObj [ ]
 foreach sort-on [objNumber] objectives
     [ set listObj lput [label] of ? listObj ] 
 let selectedObjective user-one-of "Select the objective you want to delete." listObj
 if not any? objectives with [ label = selectedObjective ] [stop]
 set currentObjective [objNumber] of one-of objectives with [ label = selectedObjective ]
 let old_2MAO matrix:copy _2MAO
 set _2MAO matrix:make-constant numActors ( numObjectives  - 1) 0
 let j 0 let colPassed false let k 0
 while [ j < numObjectives ]
    [
      ifelse j != currentObjective
         [ 
           let thisCol matrix:get-column old_2MAO j
           ifelse colPassed = true [ set k j - 1 ] [ set k j ] 
           matrix:set-column _2MAO k thisCol
         ]
         [ set colPassed true ]
      set j j + 1
    ]
 set numObjectives numObjectives - 1
 ask objectives with [ objNumber = currentObjective ] [ die ]
 ask objectives with [ objNumber > currentobjective ] [ set objNumber objNumber - 1 ]
 ask turtles [ hide-turtle ] ask links [ die ]
 user-message ( word "Objective <" selectedObjective "> has been removed. Please calculate again." )   
 calculate
end 

to viewMID
 if not _MID-exists?
     [ set _MID matrix:make-constant numActors numActors 0
       set _MID-exists? true
     ]
 let listActors [ ]
 foreach sort-on [actorNumber] actors
     [ set listActors lput [label] of ? listActors ] 
 set selectedActor user-one-of "Select actor." listActors
 if not any? actors with [ label = selectedActor ] [stop]
 set currentActor [actorNumber] of one-of actors with [ label = selectedActor ]
 set-view-mode "actors"
 ask lines [die] ask marks [die]
 ask objectives [ hide-turtle]
 ask titles with [ titleName = "header 1" ] [set label "ACTORS"]
 ask titles with [ titleName = "header 2" ] [set label (word "INFLUENCE OF " selectedActor " OVER EACH ACTOR")]
 ask titles with [ titleName = "header 3" ] [set xcor firstColumn + 23
                   set label "0              1              2              3              4 "]
 ask actors
    [ show-turtle
    ]
 let n 0
 while [ n < numActors ]
      [
       create-lines 1
          [ set color blue set heading 90 set size 20 set shape "line"
            setxy firstColumn + 12 dataLine - n * lineStep
          ]
       create-marks 1
            [set color red set shape "circle" set size 1 set actorNumber n
             let value matrix:get _MID currentActor n
             setxy firstColumn + 2 + value * interLine dataLine - n * lineStep
            ]
       set n n + 1
      ]
  set n 4 let p 0
  while [ n >= 0 ]
     [ create-lines 1
          [ set color blue set heading 0 set shape "line"
            setxy firstColumn + 2 + p * interLine  dataLine - numActors * lineStep / 2 + 1
            set size ( numActors - 1 ) * lineStep
          ]
       set n n - 1 set p p + 1
     ]
end 

to edit-mid
   let value 0
   if mouse-down?
      [
        if not any? actors with [ label = selectedActor ] [stop]
        set currentActor [actorNumber] of one-of actors with [ label = selectedActor ]
        ask marks with [ abs(ycor - mouse-ycor) <= 1 ]
          [ ifelse currentActor != actorNumber
            [ set color green 
              set value round((mouse-xcor - firstColumn - 2) / 5)
              set xcor firstColumn + 2 + value * interLine
              matrix:set _MID currentActor actorNumber value
            ]
            [ user-message "Only influences from one actor to another should be registered."
            ]
          ]
      ]
end 

to viewMAO
 if numObjectives = 0 or numActors = 0 [ stop ]
 if not _2MAO-exists?
    [ set _2MAO matrix:make-constant numActors numObjectives 0
      set _2MAO-exists? true
    ]
 let listActors [ ]
 foreach sort-on [actorNumber] actors
     [ set listActors lput [label] of ? listActors ] 
 set selectedActor user-one-of "Select actor from list." listActors
 if not any? actors with [ label = selectedActor ] [stop]
 set-view-mode "obj"
 ask lines [die] ask marks [die]
 ask actors [ hide-turtle]
 ask objectives
    [ show-turtle
    ]
 ask titles with [ titleName = "header 1" ] [set label "OBJECTIVES"]
 ask titles with [ titleName = "header 3" ] [ set xcor firstColumn + 43
               set label "-4            -3             -2             -1             0              1              2              3              4"]
 set currentActor [actorNumber] of one-of actors with [ label = selectedActor ]
 ask titles with [ titleName = "header 2" ] [set label (word "IMPORTANCE OF OBJECTIVES FOR ACTOR " selectedActor ) ]
 let n 0
 while [ n < numObjectives ]
      [
       create-lines 1
          [ set color blue set heading 90 set size 40 set shape "line"
            setxy firstColumn + 22 dataLine - n * lineStep
          ]
       create-marks 1
            [set color red set shape "circle" set size 1
             let value matrix:get _2MAO currentActor n
             setxy firstColumn + 2 + interLine * ( value + 4) dataLine - n * lineStep
            ]
       set n n + 1
      ]
  set n 8 let p 0
  while [ n >= 0 ]
     [ create-lines 1
          [ set color blue set heading 0 set shape "line"
            setxy firstColumn + 2 + p * interLine  dataLine - numObjectives * lineStep / 2 + 1
            set size ( numObjectives - 1 ) * lineStep
          ]
       set n n - 1 set p p + 1
     ]
end 

to edit-mao
   let value 0
   if mouse-down?
      [
        if not any? actors with [ label = selectedActor ] [stop]
        set currentActor [actorNumber] of one-of actors with [ label = selectedActor ]
        ask marks with [ abs(ycor - mouse-ycor) <= 1 ]
          [ set color green 
            set value round((mouse-xcor - firstColumn - 2) / 5) - 4
            set currentObjective (dataLine - ycor) / lineStep
            set xcor firstColumn + 2 + (value + 4) * interLine
            matrix:set _2MAO currentActor currentObjective value
            output-print matrix:pretty-print-text _2MAO
            ]
      ]
end 

to set-view-mode [ who-calls-me ]
  ifelse who-calls-me = "actors"
     [ ask actors [ setxy xpos ypos set size 0 show-turtle ] ]
     [ ask objectives [ setxy xpos ypos set size 0 show-turtle ] ]
  ask titles [ show-turtle ]
  ask g-lines [ die ] ask g-links [ die ]
  ask convergence-links [die ] ask divergence-links [die ] ask BN-links [ die ]
  ask actor-position-links [ die ]
end 

to write-csv
  file-close-all
  ifelse numActors <= 1 
     [ user-message "Nothing to be saved !" ]
     [
       let file user-new-file
       if is-string? file
          [
            if file-exists? file [ file-delete file ]
            file-open file       ;; open file
            let listActors [ ]   ;; write actors list
            foreach sort-on [actorNumber] actors
               [ set listActors lput [label] of ? listActors ] 
            let sCSV csv:to-row [ "ACTORS" ]
            file-print sCSV
            set sCSV csv:to-row listActors
            file-print sCSV
            let listObj [ ]      ;; write objectives list
            foreach sort-on [objNumber] objectives
               [ set listObj lput [label] of ? listObj ] 
            set sCSV csv:to-row [ "OBJECTIVES" ]
            file-print sCSV
            set sCSV csv:to-row listObj
            file-print sCSV 
            let nActor 0         ;; write _MID
            set sCSV csv:to-row [ "MID" ]
            file-print sCSV
            while [ nActor < numActors ]
                [ let rr matrix:get-row _MID nActor
                  set sCSV csv:to-row rr 
                  file-print sCSV
                  set nActor nActor + 1
                ]
            set nActor 0         ;; write _2MAO
            set sCSV csv:to-row [ "2MAO" ]
            file-print sCSV
            while [ nActor < numActors ]
                [ let rr matrix:get-row _2MAO nActor
                  set sCSV csv:to-row rr
                  file-print sCSV
                  set nActor nActor + 1
                ]
            file-close
            user-message "CSV File has been saved"
          ]
     ]
end 

to read-csv
  file-close-all
  let file user-file
  if is-string? file
     [
       if not file-exists? file [ user-message "read cancelled" stop ]
       setup
       file-open file       ;; open file
       let lA [] let lO []
       let dummy file-read-line ;; skip title line
       let cleanLine file-read-line set cleanLine clean-line cleanLine  
       set lA csv:from-row cleanLine 
       set dummy file-read-line
       set cleanLine file-read-line set cleanLine clean-line cleanLine ;; read actors and objectives lists
       set lO csv:from-row cleanLine ;; read actors and objectives lists
       foreach lA                        ;; create actors
         [ create-actors 1
              [ set label ? set label-color black set shape "person" set size 0 set actorNumber numActors
                setxy firstColumn dataLine - numActors * lineStep hide-turtle
                set xpos xcor set ypos ycor
              ]
           set numActors numActors + 1
         ]
       foreach lO                        ;; create objectives
         [ create-objectives 1
              [ set label ? set label-color black set shape "star" set size 0 set objNumber numObjectives
                setxy firstColumn dataLine - numObjectives * lineStep hide-turtle
                set xpos xcor set ypos ycor
              ]
           set numObjectives numObjectives + 1
         ]
       let n 0 let thisRow []     ;; read _MID
       set dummy file-read-line
       set _MID matrix:make-constant numActors numActors 0
       while [ n < numActors ]
          [ set cleanLine file-read-line set cleanLine clean-line cleanLine
            set thisRow csv:from-row clean-line cleanLine
            matrix:set-row _MID n thisRow
            set n n + 1
          ] set _MID-exists? true
       set n 0                    ;; read _2MAO
       set dummy file-read-line
       set _2MAO matrix:make-constant numActors numObjectives 0
       while [ n < numActors ]
          [ set cleanLine file-read-line set cleanLine clean-line cleanLine
            set thisRow csv:from-row clean-line cleanLine
            matrix:set-row _2MAO n thisRow
            set n n + 1
          ] set _2MAO-exists? true
       file-close
       user-message "File has been read"
       calculate
     ]
end 

to-report clean-line [ inString ] ;; removes commas at right
  let outString inString let lString length outString
  while [ item (lString - 1) outString = "," ]
     [ set outString but-last outString 
       set lString length outString
      ]
  report outString
end 

to print-matrices
  clear-output
  output-print "\nACTORS"
  foreach sort-on [actorNumber] actors
     [ ask ? [ output-print ( word "   " ( actorNumber + 1 ) " - " label ) ] ] 
  output-print "\nOBJECTIVES"
  foreach sort-on [objNumber] objectives
     [ ask ? [ output-print ( word "   " ( objNumber + 1 ) " - " label ) ] ] 
  if not verbose? [ stop ]
  if all-matrices-calculated?
     [ 
       output-print "\n               MACTOR METHOD MATRICES\n"
       print-matrix " - MID - Direct influences" _MID "actors" "actors" "Direct Infl." "ND" [ "Direct Dep."] [ "ND" ]
       print-matrix " - MIDI - Direct and indirect influences" _MIDI "actors" "actors" "Influence" "ND" [ "Dependence"] [ "ND" ]
       print-matrix "_Ri" _Ri "actors" "Relative power" "" "" [] []
       print-matrix "_Ai" _Ai "actors" "Ambivalence" "" "" [] []
       print-matrix "Net Balance of Power -BN-" _BN "actors" "actors" "Power of Actor" "SS" [] []
       print-matrix "1CAA" _1CAA "actors" "actors" "" "" [ "Convergences"] [ "SS" ]
       print-matrix "1DAA" _1DAA "actors" "actors" "" "" [ "Divergences"] [ "SS" ]
       print-matrix "2CAA" _2CAA "actors" "actors" "" "" [ "Convergences"] [ "SS" ]
       print-matrix "2DAA" _2DAA "actors" "actors" "" "" [ "Divergences"] [ "SS" ]
       print-matrix "3CAA" _3CAA "actors" "actors" "" "" [ "Convergences"] [ "SS" ]
       print-matrix "3DAA" _3DAA "actors" "actors" "" "" [ "Divergences"] [ "SS" ]
       print-matrix "3RAA" _3RAA "actors" "actors" "" "" [ ] [ ]
       print-matrix "1COO" _1COO "objectives" "objectives" "" "" [] []
       print-matrix "1DOO" _1DOO "objectives" "objectives" "" "" [] []
       print-matrix "2COO" _2COO "objectives" "objectives" "" "" [] []
       print-matrix "2DOO" _2DOO "objectives" "objectives" "" "" [] []
       print-matrix "1MAO" _1MAO "actors" "objectives" "Total" "SA" [ "Agreements" "Disagreements" "Positions #"] [ "SP" "SN" "SA"]
       print-matrix "2MAO" _2MAO "actors" "objectives" "Involvement" "SA" [ "ImportanceAgrts" "Import.Disagr." "Importance"] [ "SP" "SN" "SA"]
       print-matrix "Conflict Index" _Cj "Conflict Index" "objectives" "" "" [ ] [ ]
       print-matrix "3MAO" _3MAO "actors" "objectives" "Mobilization" "SA" [ "Imp.Agreements" "Intens.Disagr." "Pond.Importance"] [ "SP" "SN" "SA"]
      ]
  output-print "\n\n"
end 

to print-matrix [ MName M RType CType TitLCol ColType listLRowsTit  listLRowsType]
  ;; prints the matrix M, called MName, with titles and totals
  ;; RType - CType : rows & columns type ( "actors" or "objectives" )
  ;; TitLCol : title of last column (totals) if any, "" otherwise
  ;; ColType : operation to be done on last column : 
  ;;                     "SS" sum "ND" sum but diagonal "SA" sum absolute values
  ;; listRowsTit : titles of last (totals) rows. Must be of the same length as listRowsType
  ;; listRowsType : operations to be performed column-wise at bottom, [] if nothing
  ;;                          "SP" sum positives only  "SN" sum negatives only
  ;;                          "SA" sum absolute values "SS" sum "ND" dismiss main diagonal
  ;;
  output-print (word "\n Matrix " MName "   ( " RType " X " CType " )\n")
  let flWidth 20 let colWidth 6 ;; first/last column width - normal columns width
  let dim matrix:dimensions M ;; get matrix dimensions
  let dimI item 0 dim let dimJ item 1 dim
  let thisLine put-on-size " " flWidth let i 0 let j 0 let v 0

  let letterOnCol "A" if CType = "objectives" [ set letterOnCol "O" ] ;; print heading line
  ifelse dimJ > 1
    [ while [ i < dimJ ] [ set i i + 1 set thisLine ( word thisLine put-on-size (word letterOnCol i) colWidth ) ] ]
    [ set thisLine (word thisLine put-on-size (word CType "") flWidth) ]
  if TitLCol != "" [ set thisLine (word thisLine put-on-size TitLCol flWidth) ]
  output-print thisLine
  set i 0
  while [ i < dimI ]    ;; print matrix rows and -eventually- total
     [ 
      ifelse RType = "actors"
         [ set thisLine [label] of actors with [ actorNumber = i ] ]
         [ ifelse RType = "objectives"
           [ set thisLine [label] of objectives with [ objNumber = i ] ]
           [ set thisLine ( list RType ) ]
         ]
      set thisLine item 0 thisLine
      set thisLine put-on-size thisLine flWidth
      set j 0 let sumRow 0
      while [ j < dimJ ]
         [
          set v matrix:get M i j 
          if ColType = "SS" [ set sumRow sumRow + v ]
          if ColType = "SA" [ set sumRow sumRow + abs v ]
          if ColType = "ND" [ if i != j [set sumRow sumRow + v ] ]
          set v put-on-size (word v "") colWidth
          set thisLine (word thisLine v)
          set j j + 1
         ]
     if ColType != ""
        [ set sumRow precision sumRow 1
          set v put-on-size ( word sumRow "") flWidth 
          set thisLine (word thisLine v) 
        ] 
     output-print thisLine
    set i i + 1
    ]

  output-print "\n"

  if listLRowsTit != []  ;; something else to print at bottom ?
     [ 
       let listItem 0
       while [ listItem < length listLRowsTit ]
          [
            set thisLine item listItem listLRowsTit
            set thisLine put-on-size thisLine flWidth
            let action item listItem listLRowsType
            set j 0 let sumCol 0
            while [ j < dimJ ]
               [ set i 0 set sumCol 0
                 while [ i < dimi ]
                    [ set v matrix:get M i j
                      if action = "SP" [ if v > 0 [ set sumCol sumCol + v ] ]
                      if action = "SN" [ if v < 0 [ set sumCol sumCol + v ] ]
                      if action = "SA" [ set sumCol sumCol + abs v ]
                      if action = "SS" [ set sumCol sumCol + v ]
                      if action = "ND" [ if i != j [set sumCol sumCol + v ] ]
                      set i i + 1
                    ]
                 set sumCol precision sumCol 1
                 set v put-on-size (word sumCol "") colWidth
                 set thisLine (word thisLine v)
                 set j j + 1
               ]
            output-print thisLine
            set listItem listItem + 1
          ]
       output-print "\n"
     ]
end 

to-report put-on-size [ inputString outputSize ]
            let repString inputString
            ifelse length repString >= outputSize 
                     [ set repString substring repString 0 outputSize ]
                     [ while [ length repString < outputSize ] [ set repString ( word " " repString) ]
                     ]
            report repString
end 

to calculate
  ifelse _MID-exists? and _2MAO-exists?
     [ 
       let i 0 let j 0
       let k 0 let v 0 let v1 0 let v2 0
       ;; check _MID for zero rows
       let zRow n-values numActors [ 0 ] let zCol n-values numActors [ 0 ]
       while [ i < numActors ]    ;; check rows
          [
            let thisRow matrix:get-row _MID i
            let thisCol matrix:get-column _MID i
            if thisRow = zRow and thisCol = zCol
              [ let notConcerned [label ] of one-of actors with [ actorNumber = i ]
                user-message ( word "Actor " notConcerned " appears as not relevant (update or delete).")
                stop ]
          set i i + 1
          ]
       ;; check _2MAO for zero rows or columns
       set zRow n-values numObjectives [ 0 ] set zCol n-values numActors [ 0 ] 
       set i 0 
       while [ i < numActors ]    ;; check rows
          [
            let thisRow matrix:get-row _2MAO i
            if thisRow = zRow
              [ let notConcerned [label ] of one-of actors with [ actorNumber = i ]
                user-message ( word "Actor <" notConcerned "> appears to be concerned with no objective (update or delete).")
                stop ]
          set i i + 1
          ]
       set i 0
       while [ i < numObjectives ] ;; check columns
          [
            let thisCol matrix:get-column _2MAO i
            if thisCol = zCol
              [ let notConcerned [label ] of one-of objectives with [ objNumber = i ]
                user-message ( word "You need to update actor's positions now.")
                stop ]
          set i i + 1
          ]
                                             ;; calculate _MIDI , Ii, Dj
       set _MIDI matrix:make-constant numActors numActors 0
       set _Ii matrix:make-constant numActors 1 0  ;; Calculate Ii
       set _Dj matrix:make-constant 1 numActors 0 ;; Calculate Dj
       set i 0
       while [ i < numActors ]
          [ set j 0 
            while [ j < numActors ]
               [ set v matrix:get _MID i j
                 set k 0
                 while [ k < numActors ]
                    [ set v1 matrix:get _MID i k
                      set v2 matrix:get _MID k j
                      set v v + min (list v1 v2 )
                      set k k + 1
                    ]
                 matrix:set _MIDI i j v
                 if i != j [ matrix:set _Ii i 0 v + matrix:get _Ii i 0 
                             matrix:set _Dj 0 j v + matrix:get _Dj 0 j ]
                 set j j + 1
               ]
           set i i + 1
          ]
     set _Ri matrix:make-constant numActors 1 0 ;; Calculate Ri
     let sumIi reduce + matrix:get-column _Ii 0
     set i 0 let r 0 let ii 0 let dd 0 
     while [ i < numActors ]
        [
          set ii matrix:get _Ii i 0 set dd matrix:get _Dj 0 i
          set r ii * ( ii - matrix:get _MIDI i i ) / ( sumIi * ( ii + dd )) 
          matrix:set _Ri i 0 r
          set i i + 1
        ]
     let sumRi reduce + matrix:get-column _Ri 0 ;; now, normalize on mean
     let avgR sumRi / numActors
     set i 0
     while [ i < numActors ]
        [
          set r matrix:get _Ri i 0 / avgR set r precision r 2
          matrix:set _Ri i 0 r
          set i i + 1
        ]
     set i 0    ;; calculate involvement of each actor
     set _Involv matrix:make-constant numActors 1 0
     while [ i < numActors ]
        [ let s map [ abs(?) ] matrix:get-row _2MAO i
          set s reduce + s
          matrix:set _Involv i 0 s
          set i i + 1
        ]
     set _1MAO matrix:make-constant numActors numObjectives 0 ;; calculate _1MAO, _3MAO
     set _3MAO matrix:make-constant numActors numObjectives 0
     set i 0 set j 0 let vv 0
     while [ i < numActors ]
          [ set j 0
            while [ j < numObjectives ]
               [
                 set v matrix:get _2MAO i j
                 if v > 0 [ matrix:set _1MAO i j 1 ]
                 if v < 0 [ matrix:set _1MAO i j -1 ]
                 set vv precision (v * matrix:get _Ri i 0) 1
                 matrix:set _3MAO i j vv
                 set j j + 1
               ]
            set i i + 1
          ]
     set i 0                                ;; calculate _BN
     set _BN matrix:make-constant numActors numActors 0
     while [ i < numActors ]
        [ set j 0
          while [ j < numActors ]
             [
               set v1 matrix:get _MIDI i j     
               set v2 matrix:get _MIDI j i
               matrix:set _BN i j ( v1 - v2 )
               set j j + 1
             ]
          set i i + 1
        ]    
                               ;; Conflict index
      ;;  Conflict index varies between
      ;;       1 - Everybody agree, no conflict
      ;;       0 - Maximal potential of conflict 
      ;;      -1 - Everybody disagree, no conflict
      set j 0
      set _Cj matrix:make-constant 1 numObjectives 0
      while [ j < numObjectives ]
         [
           set i 0 let sumColP 0 let sumColN 0
           while [ i < numActors ]
              [ set v matrix:get _2MAO i j
                ifelse v > 0
                  [ set sumColP sumColP + v ]
                  [ set sumColN sumColN + v ]
                set i i + 1
              ]
           set sumColP abs sumColP set sumColN abs sumColN 
           let maxCol max ( list sumColN sumColP )
           let CI sumColP / maxCol - sumColN / maxCol
           set CI precision CI 1
           matrix:set _Cj 0 j CI
           set j j + 1
         ]
                               ;; Calculate _1CAA & _1DAA
     set _1CAA matrix:make-constant numActors numActors 0
     set _1DAA matrix:make-constant numActors numActors 0
     set _2CAA matrix:make-constant numActors numActors 0
     set _2DAA matrix:make-constant numActors numActors 0
     set _3CAA matrix:make-constant numActors numActors 0
     set _3DAA matrix:make-constant numActors numActors 0
     set _3RAA matrix:make-constant numActors numActors 0
     
     set i 0  let j_a 0 ;; calculate xCAA & xDAA matrices
     while [ i < numActors ]     ;; for each actor ...
        [
          set j 0
          while [ j < numActors ]  ;; ... face-to-face any other
             [
               ifelse i = j   ;; that is, for different actors
                  [ matrix:set _1CAA i j 0 matrix:set _1DAA i j 0
                    matrix:set _2CAA i j 0 matrix:set _2DAA i j 0 ]
                  [ set j_a 0
                    while [ j_a < numObjectives ]  ;; check their positions ...
                       [ 
                         if matrix:get _1MAO i J_a != 0 and matrix:get _1MAO j J_a != 0  ;; ... when they have one !
                           [
                             ifelse matrix:get _1MAO i j_a = matrix:get _1MAO j j_a ;; if position is similar
                               [ matrix:set _1CAA i j 1 + matrix:get _1CAA i j ] ;; it is a convergence
                               [ matrix:set _1DAA i j 1 + matrix:get _1DAA i j ] ;; else, it is a divergence
                           ]
                         if matrix:get _2MAO i J_a != 0 and matrix:get _2MAO j J_a != 0  ;; ... when they have one !
                           [
                             ifelse matrix:get _2MAO i j_a * matrix:get _2MAO j j_a > 0 ;; if positive
                               [ ;; it is a convergence
                                 set vv matrix:get _2CAA i j + (abs(matrix:get _2MAO i j_a) + abs(matrix:get _2MAO j j_a)) / 2 
                                 matrix:set _2CAA i j precision vv 1 
                                 set vv matrix:get _3CAA i j + (abs(matrix:get _3MAO i j_a) + abs(matrix:get _3MAO j j_a)) / 2
                                 matrix:set _3CAA i j precision vv 1
                                 ]
                               [ ;; else, it is a divergence
                                 set vv matrix:get _2DAA i j + (abs(matrix:get _2MAO i j_a) + abs(matrix:get _2MAO j j_a)) / 2 
                                 matrix:set _2DAA i j precision vv 1 
                                 set vv matrix:get _3DAA i j + (abs(matrix:get _3MAO i j_a) + abs(matrix:get _3MAO j j_a)) / 2
                                 matrix:set _3DAA i j precision vv 1
                                 ]
                           ]
                         set j_a j_a + 1
                       ]
                  ]
               set j j + 1
             ]
          set i i + 1
     ]
     set  _3RAA matrix:minus _3CAA _3DAA
     set i 0 
     while [i < numActors ] ;; adjust _3RAA precision to 1 decimal
        [ set j 0 
          while [ j < numActors ] 
             [ set v matrix:get _3RAA i j
               matrix:set _3RAA i j ( precision v 1 ) set j j + 1 ]
          set i i + 1
        ]
     set i 0                  ;; Ambivalence of actors
     set _Ai matrix:make-constant numActors 1 0
     while [ i < numActors ]
       [
        set j 0
        let minusSum 0 let plusSum 0
        while [ j < numActors ]
           [ 
             set minusSum minusSum + abs ((matrix:get _3CAA i j) - (matrix:get _3DAA i j))
             set plusSum  plusSum + abs ((matrix:get _3CAA i j) + (matrix:get _3DAA i j))
             set j j + 1
           ]
        set minusSum abs minusSum set plusSum abs plusSum
        let ambiv precision (1 - minusSum / plusSum) 2
        matrix:set _Ai i 0 ambiv
        set i i + 1
       ]
     set _1COO matrix:make-constant numObjectives numObjectives 0
     set _1DOO matrix:make-constant numObjectives numObjectives 0
     set _2COO matrix:make-constant numObjectives numObjectives 0
     set _2DOO matrix:make-constant numObjectives numObjectives 0
     set j 0  let i_a 0 ;; calculate xCOO & xDOO matrices
     while [ j < numObjectives ]     ;; for each objjectives ...
        [
          set i 0
          while [ i < numObjectives ]  ;; ... face-to-face any other
             [
               ifelse i = j   ;; that is, for different objectives
                  [ matrix:set _1COO i j 0 matrix:set _1DOO i j 0
                    matrix:set _2COO i j 0 matrix:set _2DOO i j 0 ]
                  [ set i_a 0
                    while [ i_a < numActors ]  ;; check positions of actors ...
                       [ 
                         if matrix:get _1MAO i_a i != 0 and matrix:get _1MAO i_a j != 0  ;; ... when they have one !
                           [
                             ifelse matrix:get _1MAO i_a i = matrix:get _1MAO i_a j ;; if position is similar
                               [ matrix:set _1COO i j 1 + matrix:get _1COO i j ] ;; it is a convergence
                               [ matrix:set _1DOO i j 1 + matrix:get _1DOO i j ] ;; else, it is a divergence
                           ]
                         if matrix:get _2MAO i_a i != 0 and matrix:get _2MAO i_a j != 0  ;; ... when they have one !
                           [
                             ifelse matrix:get _2MAO i_a i * matrix:get _2MAO i_a j > 0 ;; if positive
                               [ ;; it is a convergence
                                 set vv matrix:get _2COO i j + (abs(matrix:get _2MAO i_a i ) + abs(matrix:get _2MAO i_a j )) / 2 
                                 matrix:set _2COO i j precision vv 1 
                                 ]
                               [ ;; else, it is a divergence
                                 set vv matrix:get _2DOO i j + (abs(matrix:get _2MAO i_a i ) + abs(matrix:get _2MAO i_a j )) / 2 
                                 matrix:set _2DOO i j precision vv 1 
                                 ]
                           ]
                         set i_a i_a + 1
                       ]
                  ]
               set i i + 1
             ]
          set j j + 1
     ]
     set _actorsDistances get-distances _2CAA _2DAA ;; distances
     set _objDistances get-distances _2COO _2DOO

     set all-matrices-calculated? true
     print-matrices
     ]
     [ user-message "Not enough data to do calculation." stop ]
end 

to-report get-distances [ matrix1 matrix2 ]
     let dim matrix:dimensions matrix1 set dim first dim
     set _BNOO matrix:minus matrix1 matrix2 ;; calculate net balance
     let M1 matrix:times matrix1 ( -1 )    ;; invert sign to consider it as a distance
     set _BNOO matrix:plus matrix2 M1
     let i 0 let j 0 let minMat 0 let vv 0 ;; make all elements positive
     while [ i < dim ] 
        [ set j 0 
          while [ j < dim ] 
           [ set vv matrix:get _BNOO i j
             if minMat > vv [ set minMat vv ]
             set j j + 1 
           ] set i i + 1
        ]
     set minMat abs(minMat) * 1.1       
     set _BNOO matrix:plus _BNOO minMat
     set i 0      ;; be sure diagonal is zero, and adjust precision 
     while [ i < dim ] 
        [
        set j 0
        while [ j < dim ]
           [ set vv matrix:get _BNOO i j set vv precision vv 2
             matrix:set _BNOO i j vv
             if i = j [ matrix:set _BNOO i j 0 ]
             set j j + 1
           ] 
        set i i + 1
        ]
     report calculate-distances _BNOO
end 

to save-graph
  file-close-all
  ifelse numActors <= 1 
     [ user-message "Nothing to be saved !" ]
     [
       let file user-new-file
       if is-string? file [ export-view file ]
     ]
  file-close-all
end 

to draw-graph
  if all-matrices-calculated?
   [
     let availableGraphs (list "influence-dependence" "convergences" "divergences" "net-balance-of-influence")
     set availableGraphs sentence availableGraphs (list "influence-of-actors" "dependence-of-actors" "power-of-actors" "ambivalence-of-actors")
     set availableGraphs sentence availableGraphs (list "distance-between-actors" "distance-between-objectives" "playing-field"  "actors-over-objectives" )
     set availableGraphs sentence availableGraphs (list "involvement-balance-of-power" "actors-objectives-map-order-2" "actors-objectives-map-order-3" )
     set availableGraphs sentence availableGraphs (list "importance-of-agreements-Vs-disagr." )
     let whatToGraph user-one-of "Select graph type" availableGraphs
     ask patches [ set pcolor white ]
     ask g-lines [ die ]
     ask lines [ die ] ask marks [die ]
     ask BN-links [ die ]
     ask actor-position-links [ die ]
     ask turtles [ hide-turtle ]       ;; **** la había sacado y la coloco de nuevo
     ask objectives [ set xcor xpos set ycor ypos set size 0 hide-turtle]
     if filtered? [ when-filtered-true ]
     run whatToGraph
   ]
end 

to clear-all-links
     ask BN-links [ die ]
     ask actor-position-links [ die ]
   ask convergence-links [ die ]
   ask divergence-links [ die ]
end 

to set-g-title [ theTitle ]
   create-g-lines 1
         [ set size 0 set label theTitle set label-color black
           setxy 30 48
         ]
end 

to net-balance-of-influence
   ask convergence-links [ die ]
   ask divergence-links [ die ]
   ask actors [ show-turtle]
   let minR min matrix:get-column _Ri 0
   let maxR max matrix:get-column _Ri 0
   let rangeR maxR - minR ;; range used to scale actors size
   set-g-title "NET BALANCE OF INFLUENCE GRAPH"
   let i 0 ;; set links according _BN
   while [ i < numActors - 1 ]
      [
      let j i + 1
      while [ j < numActors ]
         [
         let v matrix:get _BN i j
         ask actors with [actorNumber = i]
           [ set size 2 + 4 * ( matrix:get _Ri i 0 - minR ) / rangeR
             ifelse v > 0
                [create-BN-links-to actors with [ actorNumber = j ]
                   [ set color red set label v set label-color black set shape "arrow"
                   ]
                ]
                [create-BN-links-from actors with [ actorNumber = j ]
                   [ set color red set label 0 - v set label-color black set shape "arrow"
                   ]
                ]
           ]
         set j j + 1
         ]
      set i i + 1
      ]
   ask actors with [actorNumber = numActors - 1]
           [ set size 2 + 4 * ( matrix:get _Ri i 0 - minR ) / rangeR ]
   ;ask actors [ setxy 20 + random 40 20 + random 30 ]
   ;repeat 30 [ layout-spring actors divergence-links 0.5 20 2 wait .1 ]
   layout-circle actors 18
end 

to divergences
   let gType user-one-of "Select divergence type :" [ "simple" "valuated" "weighted & valuated" ]
   if gType = "simple" [ draw-divergences _1DAA ]
   if gType = "valuated" [ draw-divergences _2DAA ]
   if gType = "weighted & valuated" [ draw-divergences _3DAA ]
   set-g-title ( word "DIVERGENCES GRAPH ( " gType " )" )
   layout-circle actors 18
end 

to convergences
   let gType user-one-of "Select convergence type :" [ "simple" "valuated" "weighted & valuated" ]
   if gType = "simple" [ draw-convergences _1CAA ]
   if gType = "valuated" [ draw-convergences _2CAA ]
   if gType = "weighted & valuated" [ draw-convergences _3CAA ]
   set-g-title ( word "CONVERGENCES GRAPH ( " gType " )" )
   layout-circle actors 18
end 

to draw-convergences [ CAA ]
   ask convergence-links [ die ] ask BN-Links [ die ]
   ifelse multipleLinks? [ ask divergence-links [ show-link ] ] [ ask divergence-links [ die ] ]
   set_thickness_ranges CAA
   let i 0 ;; set links according CAA
   while [ i < numActors - 1 ]
      [
      let j i + 1
      while [ j < numActors ]
         [
         let v matrix:get CAA i j
         if v != 0
         [
         ask actors with [actorNumber = i]
           [ 
             create-convergence-links-with actors with [ actorNumber = j ]
                [ set color 67 set label v set label-color black
                  set thickness .3 set color 95
                  if v < minRange [ set thickness .2 set color 97]
                  if v > maxRange [ set thickness .4 set color 93 ] 
                ]
           ]
         ]
         set j j + 1
         ]
      set i i + 1
      ]
      ask actors [ show-turtle set size 2 ]
end 

to draw-divergences [ DAA ]
   ask divergence-links [ die ] ask BN-links [ die ]
   ifelse multipleLinks? [ ask convergence-links [ show-link ] ] [ ask convergence-links [ die ] ]
   set_thickness_ranges DAA
   let i 0 ;; set links according DAA
   while [ i < numActors - 1 ]
      [
      let j i + 1
      while [ j < numActors ]
         [
         let v matrix:get DAA i j
         if v != 0
         [
         ask actors with [actorNumber = i]
           [ 
             create-divergence-links-with actors with [ actorNumber = j ]
                [ set label v set label-color black set shape "curved"
                  set thickness .3 set color 25
                  if v < minRange [ set thickness .2 set color 27]
                  if v > maxRange [ set thickness .4 set color 23 ] 
                  ]
           ]
         ]
         set j j + 1
         ]
      set i i + 1
      ]
      ask actors [ show-turtle set size 2 ]
end 

to set_thickness_ranges [ inputMatrix ] ;; input matrix must be a square matrix
;; sets range to adjust links thickness
   let dimM matrix:dimensions inputMatrix
   set dimM first dimM
   let i 0 let j 0
   let minM 300 let maxM 0
   while [ i < dimM ]
      [ set j 0
        while [ j < dimM ]
           [ if i != j
               [ let v matrix:get inputMatrix i j
                 if v != 0
                   [ if minM > v [ set minM v ]
                     if maxM < v [ set maxM v ]
                   ]
               ]
           set j j + 1
           ]
        set i i + 1
      ]
   let rankM maxM - minM
   set minRange minM + 0.3 * rankM
   set maxRange minM + 0.7 * rankM
end 

to drag-actors
  if mouse-down?
    [ let thisItem min-one-of turtles [ distancexy mouse-xcor mouse-ycor ]
      if is-actor? thisItem or is-objective? thisItem 
         [
            ask thisItem
            [
            while [ mouse-down?]
               [ setxy mouse-xcor mouse-ycor ]
            ]
         ]
    ]
end 

to select-actor
  ifelse filtered? = false
  [
   while [ not mouse-down?] [ ];; do nothing
   let thisItem min-one-of turtles [ distancexy mouse-xcor mouse-ycor ]  ;; take the closest actor
      if is-actor? thisItem or is-objective? thisItem 
        [
         set visConv false set visDiv false set visBN false set visAP false
         ifelse any? convergence-links ;; if any conv links, remember if they are visibles or not
            [ set visConv [not hidden?] of one-of convergence-links ] [ set visConv false]
         ifelse any? divergence-links  ;; the same for div links
            [ set visDiv [not hidden?] of one-of divergence-links ] [ set visDiv false]
         ifelse any? BN-links          ;; ... and BN links
            [ set visBN [not hidden?] of one-of BN-links ] [ set visBN false]
         ifelse any? actor-position-links          ;; ... and AP links
            [ set visAP [not hidden?] of one-of actor-position-links ] [ set visAP false]
         ask convergence-links [hide-link] ;; at first, hide all
         ask divergence-links [hide-link]
         ask BN-links [hide-link]
         ask actor-position-links [hide-link]
         ask thisItem
            [ ask my-in-links [show-link]
              ask my-out-links [show-link]
              ask my-links [show-link]
            ]
         set filtered? true stop
        ]
  ]
  [   when-filtered-true stop
  ]
end 

to when-filtered-true
  ask actors [ show-turtle ]
  if visConv = true [ ask convergence-links [ show-link ] ]
  if visDiv = true [ ask divergence-links [ show-link ] ]
  if visBN = true [ ask BN-links [ show-link ] ]
  if visAP = true [ ask actor-position-links [ show-link ] ]
  set visConv false set visDiv false set visBN false set visAP false 
  set filtered? false
end 

to influence-dependence
      let listInfluence matrix:get-column _Ii 0
      let listDependence matrix:get-row _Dj 0
      let t1 "INFLUENCE - DEPENDENCE GRAPH"
      let t2 "Dependence" let t3 "Influence"
      draw-positions-of-actors listInfluence listDependence t1 t2 t3
end 

to involvement-balance-of-power
      let listInvolv matrix:get-column _Involv 0
      let listPower matrix:get-column _Ri 0
      let t1 "INVOLVEMENT - POWER GRAPH"
      let t2 "Involvement" let t3 "Power"
      draw-positions-of-actors listPower listInvolv t1 t2 t3
end 

to draw-positions-of-actors [ Vect1 Vect2 t1 t2 t3 ]
      draw-square 40 "middleLines" 0 0

      let sumV1 reduce + Vect1 ;; Y axis
      let avgV1 sumV1 / numActors
      let m1 map [ ? - avgV1 ] Vect1
      let difV1 max map [ abs ? ] m1
      let rangeV1  2 * difV1 * 1.2 let minV1 avgV1 - difV1 * 1.2 

      let sumV2 reduce + Vect2 ;; X axis
      let avgV2 sumV2 / numActors
      let m2 map [ ? - avgV2 ] Vect2
      let difV2 max map [ abs ? ] m2
      let rangeV2  2 * difV2 * 1.2 let minV2 avgV2 - difV2 * 1.2 

      ask actors
         [ show-turtle set size 2
           let x item actorNumber Vect2 let y item actorNumber Vect1
           set xcor 5 + 40 * ( x - minV2 ) / rangeV2 set ycor 5 + 40 * ( y - minV1 ) / rangeV1
         ]
      set-g-title t1
      create-g-lines 1 ;; x axis title
         [ set size 0 set label t2 set label-color black
           setxy 46 4
         ]
      create-g-lines 1 ;; y axis title
         [ set size 0 set label t3 set label-color black
           setxy 7 46
         ]
end 

to draw-square [ w SquareType XAxis YAxis] ;; square size, type
  if XAxis > 40 [ set XAxis 40 ]
  if YAxis > 40 [ set YAxis 40 ]
  if SquareType = "Obj"
     [ 
       create-g-lines 1
          [ set shape "line" set color blue set size w 
            set heading 90
            setxy 5 + w / 2 YAxis ]
       create-g-lines 1
          [ set shape "line" set color blue set size w 
            set heading 0
            setxy XAxis 5 + w / 2 ]
     ]
  if SquareType = "middleLines"
     [ 
       create-g-lines 1
          [ set shape "line" set color blue set size w 
            set heading 90
            setxy 5 + w / 2 5 + w / 2 ]
       create-g-lines 1
          [ set shape "line" set color blue set size w 
            set heading 0
            setxy 5 + w / 2 5 + w / 2 ]
     ]
  create-g-lines 1
          [ set shape "line" set color blue set size w 
            set heading 0
            setxy 5 5 + w / 2 ]
  create-g-lines 1
          [ set shape "line" set color blue set size w 
            set heading 0
            setxy 5 + w 5 + w / 2 ]
  create-g-lines 1
          [ set shape "line" set color blue set size w 
            set heading 90
            setxy 5 + w / 2 5 ]
  create-g-lines 1
          [ set shape "line" set color blue set size w 
            set heading 90
            setxy 5 + w / 2 5 + w ]
end 

to influence-of-actors
  set-view-mode "actors" ask titles [ hide-turtle]
  set-g-title "INFLUENCE OF ACTORS GRAPH"
  draw-actors-histogram matrix:get-column _Ii 0
end 

to dependence-of-actors
  set-view-mode "actors" ask titles [ hide-turtle]
  set-g-title "DEPENDENCE OF ACTORS GRAPH"
  draw-actors-histogram matrix:get-row _Dj 0
end 

to power-of-actors
  set-view-mode "actors" ask titles [ hide-turtle]
  set-g-title "RELATIVE POWER OF ACTORS GRAPH"
  draw-actors-histogram matrix:get-column _Ri 0
end 

to ambivalence-of-actors
  set-view-mode "actors" ask titles [ hide-turtle]
  set-g-title "AMBIVALENCE OF ACTORS GRAPH"
  draw-actors-histogram matrix:get-column _Ai 0
end 

to draw-actors-histogram [ listToDraw ]
   ;; Put on scale
   if length listToDraw != numActors [ stop ]
   let maxInList max listToDraw
   let maxLength TopOfScale - firstColumn - 1 ;; max lenght of a bar
   create-g-lines 1
      [ set size 0 set label ( word "MAX= " maxInList ) set label-color black
        setxy TopOfScale dataLine + 1
      ]
   let adjList []
   foreach listToDraw [ set adjList lput ( maxLength * ? / maxInList) adjList ] ;; adjust accordingly
   let n 0
   while [ n < numActors ]
      [
       create-marks 1
          [ set color red set size 1 set shape "suit diamond" set actorNumber n
            setxy firstColumn + 1 + item n adjList dataLine - n * lineStep
            if n >= 1
               [ create-g-links-with marks with [ actorNumber = n - 1 ]
                    [ set color red ]
               ]
          ]
       create-g-lines 1
          [ set shape "line" set color blue set size maxLength 
            set heading 90   setxy firstColumn + 1 + maxLength / 2 dataLine - n * lineStep ]
       create-g-lines 1
          [ set size 0 set label item n listToDraw set label-color black
            setxy TopOfScale + 3 dataLine - n * lineStep
          ]
       set n n + 1
      ]
      create-lines 1
          [ set color blue set heading 0 set shape "line"
            setxy firstColumn + 1 dataLine - numActors * lineStep / 2 + 1
            set size ( numActors - 1 ) * lineStep
          ]
      create-lines 1
          [ set color blue set heading 0 set shape "line"
            setxy firstColumn + 1 + maxLength / 2 dataLine - numActors * lineStep / 2 + 1
            set size ( numActors - 1 ) * lineStep
          ]
      create-lines 1
          [ set color blue set heading 0 set shape "line"
            setxy firstColumn + 1 + maxLength dataLine - numActors * lineStep / 2 + 1
            set size ( numActors - 1 ) * lineStep
          ]
end 

to distance-between-actors
   ask convergence-links [ die ]
   ask divergence-links [ die ]
   set-g-title "DISTANCES BETWEEN ACTORS GRAPH"
   let xcoordCol matrix:get-column _actorsDistances 0
   let ycoordCol matrix:get-column _actorsDistances 1
   let minX ( -1 ) + min xcoordCol let maxX max xcoordCol let rngX maxX - minX
   let minY ( -1 ) + min ycoordCol let maxY max ycoordCol let rngY maxY - minY
   ask actors
      [ show-turtle set size 2 set shape "person"
        let myX matrix:get _actorsDistances actorNumber 0
        let myY matrix:get _actorsDistances actorNumber 1
        set xcor 5 + 40 * ( myX - minX ) / rngX
        set ycor 5 + 40 * ( myY - minY ) / rngY
      ] 
   draw-square 40 "Obj" 5 + 40 * ( - minX ) / rngX 5 + 40 * ( - minY ) / rngY
end 

to distance-between-objectives
  set voronoi false
  let t1 "DISTANCES BETWEEN OBJECTIVES GRAPH"
  obj-distance-graph t1
end 

to playing-field
  set voronoi true
  let t1 "PLAYING FIELD GRAPH"
  obj-distance-graph t1
end 

to obj-distance-graph [ t1 ]
   ask convergence-links [ die ]
   ask divergence-links [ die ]
   set-g-title t1
   let xcoordCol matrix:get-column _objDistances 0
   let ycoordCol matrix:get-column _objDistances 1
   let minX ( -1 ) + min xcoordCol let maxX max xcoordCol let rngX maxX - minX
   let minY ( -1 ) + min ycoordCol let maxY max ycoordCol let rngY maxY - minY
   ask objectives
      [ show-turtle set size 1 set shape "circle2"
        let CI abs matrix:get _Cj 0 objNumber
        ifelse CI > 0.75 
           [ set color green ] ; 68 soft ;; green
           [ ifelse CI > 0.25
               [ set color yellow ] ;;  48 ;; yellow
               [ set color red ]     ;; 18 ;; red
           ]  
        let myX matrix:get _objDistances objNumber 0
        let myY matrix:get _objDistances objNumber 1
        set xcor 5 + 40 * ( myX - minX ) / rngX
        set ycor 5 + 40 * ( myY - minY ) / rngY
      ] 
   draw-square 40 "Obj" 5 + 40 * ( - minX ) / rngX 5 + 40 * ( - minY ) / rngY
   if voronoi = true
      [ ask patches with [ pxcor >= 5 and pxcor <= 45 and pycor >= 5 and pycor <= 45 ]
          [ set pcolor [ color ] of min-one-of objectives [ distance myself ]
          ]
      ] 
end 

to importance-of-agreements-Vs-disagr.
   ask convergence-links [ die ]
   ask divergence-links [ die ]
   set-g-title "IMPORTANCE OF AGREEMENTS VS DISAGREEMENTS"
   let j 0
   let _Agreements matrix:make-constant 1 numObjectives 0
   let _Disagreements matrix:make-constant 1 numObjectives 0
   while [ j < numObjectives ]
      [ let i 0 let impAgr 0 let impDis 0
        while [ i < numActors ]
           [  let a matrix:get _3MAO i j
              ifelse a > 0 [ set impAgr impAgr + a ] [ set impDis impDis + abs a ]
              set i i + 1
           ]
        matrix:set _Agreements 0 j impAgr
        matrix:set _Disagreements 0 j impDis
        set j j + 1
      ]
   let xcoordCol matrix:get-row _Disagreements 0
   let ycoordCol matrix:get-row _Agreements 0
   let minX min xcoordCol let maxX max xcoordCol let rngX maxX - minX
   let minY min ycoordCol let maxY max ycoordCol let rngY maxY - minY
   ask objectives
      [ show-turtle set size 2 set shape "target"
        let myX matrix:get _Disagreements 0 objNumber
        let myY matrix:get _Agreements 0 objNumber
        set xcor 5 + 40 * ( myX - minX ) / rngX
        set ycor 5 + 40 * ( myY - minY ) / rngY
      ] 
   draw-square 40 "middleLines" 0 0
      create-g-lines 1 ;; x axis title
         [ set size 0 set label "Disagreements" set label-color black
           setxy 46 4
         ]
      create-g-lines 1 ;; y axis title
         [ set size 0 set label "Agreements" set label-color black
           setxy 7 46
         ]
end 

to actors-objectives-map-order-2
  actors-objectives-map "ACTORS - OBJECTIVES MAP - ORDER 2 GRAPH" _2MAO
end 

to actors-objectives-map-order-3
  actors-objectives-map "ACTORS - OBJECTIVES MAP - ORDER 3 GRAPH" _3MAO
end 

to actors-objectives-map [ titString MtoAnalyze ]
   ask convergence-links [ die ]
   ask divergence-links [ die ]
   set-g-title titString
   analyze-correspondence MtoAnalyze
   let xcoord1 matrix:get-column _rowsCoord 0
   let ycoord1 matrix:get-column _rowsCoord 1
   let xcoord2 matrix:get-column _colsCoord 0
   let ycoord2 matrix:get-column _colsCoord 1
   
   let minX1 min xcoord1 let maxX1 max xcoord1
   let minY1 min ycoord1 let maxY1 max ycoord1
   let minX2 min xcoord2 let maxX2 max xcoord2
   let minY2 min ycoord2 let maxY2 max ycoord2
   let minX min ( list minX1 minX2 ) let maxX max ( list maxX1 maxX2 )
   let minY min ( list minY1 minY2 ) let maxY max ( list maxY1 maxY2 )
   let rngX maxX - minX  if rngX = 0 [ set rngX 2 ]
   let rngY maxY - minY if rngY = 0 [ set rngY 2 ]
   ask actors
      [ show-turtle set size 2
        let myX matrix:get _rowsCoord actorNumber 0
        let myY matrix:get _rowsCoord actorNumber 1
        set xcor 5 + 40 * ( myX - minX ) / rngX
        set ycor 5 + 40 * ( myY - minY ) / rngY
      ]
   ask objectives
      [ show-turtle set size 1 set shape "target"
        let myX matrix:get _colsCoord objNumber 0
        let myY matrix:get _colsCoord objNumber 1
        set xcor 5 + 40 * ( myX - minX ) / rngX
        set ycor 5 + 40 * ( myY - minY ) / rngY
      ]  
   draw-square 40 "Obj" 5 + 40 * ( - minX ) / rngX 5 + 40 * ( - minY ) / rngY
end 

to actors-over-objectives
   ask convergence-links [ die ] ask divergence-links [ die ]
   set-g-title "ACTORS OVER OBJECTIVES GRAPH"
   let i 0 let j 0 let v 0
   ask actors
      [ show-turtle set size 2
        set xcor 5 + random 20 set ycor 5 + random 40
        set j 0 
        while [ j < numObjectives ]
           [ set v matrix:get _2MAO actorNumber J
             let aN actorNumber
             if v != 0
             [
               create-actor-position-links-to objectives with [ objNumber = j ]
                   [ set shape "arrow"  set label-color black
                     set label matrix:get _2MAO aN j
                     ifelse v > 0 [ set color blue ] [ set color red ]
                     set v abs( v )
                     ifelse v = 1 [ set thickness .2 ]
                                  [ ifelse v = 2 [ set thickness .3 ]
                                                 [ set thickness .4 ]
                                  ]
                   ]
             ]
             set j j + 1
           ]
      ]
   ask objectives
      [ show-turtle set size 2 set shape "target"
        set xcor 45 + random 20 set ycor 5 + random 40 ]    
end 

to analyze-correspondence [ M1 ]
  let i 0 let j 0 let v 0
  let TRows item 0 matrix:dimensions M1
  let TCols item 1 matrix:dimensions M1
  ;; all elements must be >=0
  let M matrix:make-constant TRows TCols 0 ;; but don't change M
  let minElement 0 ;; take the smallest element
  while [ i < TRows ]
     [ 
       let min-in-row reduce [min list ?1 ?2] matrix:get-row M1 i
       if minElement > min-in-row [ set minElement min-in-row ]
       set i i + 1
     ]
  set i 0 set minElement abs minElement ;; and add it : M1ij = Mij + min
  while [ i < TRows ]
     [ set j 0
       while [ j < Tcols ]
          [ set v minElement + matrix:get M1 i j
            matrix:set M i j v
            set j j + 1
          ]
       set i i + 1
     ]
  let _sumRows matrix:make-constant 1 TCols 0 ;; sum of rows : column vector
  let _sumCols matrix:make-constant TRows 1 0 ;; sum of columns : row vector
  set i 0 ;; calculate sum of rows (sumRows) & sum of columns (sumCols)
  while [ i < TRows ]
     [
       set j 0
       while [ j < TCols ]
          [
            set v matrix:get M i j
            matrix:set _sumRows 0 j ( v + matrix:get _sumRows 0 j )
            matrix:set _sumCols i 0 ( v + matrix:get _sumCols i 0 )
            set j j + 1 
          ]
          set i i + 1
     ]
  let totalItems reduce + matrix:get-column _sumCols 0
  set i 0 ;; calculate row and column profiles
  let _rProfile matrix:make-constant TRows TCols 0 
  let _cProfile matrix:make-constant TRows TCols 0 
  let _rPsum matrix:make-constant 1 TCols 0 ;; sum of cols of Rprofile
  let _cPsum matrix:make-constant TRows 1 0 ;; sum of rows of Cprofile
  while [ i < TRows ]
     [
       set j 0
       while [ j < TCols ]
          [
            set v matrix:get M i j / matrix:get _sumRows 0 j
            matrix:set _cProfile i j precision v 2
            set v matrix:get M i j / matrix:get _sumCols i 0
            matrix:set _rProfile i j precision v 2
            set j j + 1 
          ]
          set i i + 1
     ]
     
  set i 0    ;; calculate totals for r & cProfile
  while [ i < TCols ]
     [
      set v matrix:get _sumRows 0 i / totalItems
      matrix:set _rPsum 0 i v
      set i i + 1
     ]
  set i 0    ;; calculate totals for r & cProfile
  while [ i < TRows ]
     [
      set v matrix:get _sumCols i 0 / totalItems
      matrix:set _cPsum i 0 v
      set i i + 1
     ]
  set i 0 ;; calculate distances on row and column profiles
  let _cDist matrix:make-constant TCols TCols 0 
  while [ i < TCols ] ;; let start with cDist 
     [
       set j i + 1
       while [ j < TCols ]
          [ 
            ;; working on cols i & j
            let r1 0 set v 0
            while [ r1 < TRows ]
               [
                 set v ( matrix:get _cProfile r1 i - matrix:get _cProfile r1 j ) ^ 2 / matrix:get _cPsum r1 0
                 set v v + matrix:get _cDist i j
                 matrix:set _cDist i j v
                 set r1 r1 + 1
               ]
            set v precision sqrt ( matrix:get _cDist i j ) 2
            matrix:set _cDist i j v
            matrix:set _cDist j i v
            set j j + 1
          ] 
       set i i + 1
     ]
  set i 0     ;; now rDist
  let _rDist matrix:make-constant TRows TRows 0 
  while [ i < TRows ] ;; let start with cDist 
     [
       set j i + 1
       while [ j < TRows ]
          [ 
            ;; working on cols i & j
            let r1 0 set v 0
            while [ r1 < TCols ]
               [
                 set v ( matrix:get _rProfile i r1 - matrix:get _rProfile j r1 ) ^ 2 / matrix:get _rPsum 0 r1
                 set v v + matrix:get _rDist i j
                 matrix:set _rDist i j v
                 set r1 r1 + 1
               ]
            set v precision sqrt ( matrix:get _rDist i j ) 2
            matrix:set _rDist i j v
            matrix:set _rDist j i v
            set j j + 1
          ] 
       set i i + 1
     ]
  set _rowsCoord calculate-distances _rDist
  set _colsCoord calculate-distances _cDist
  set i 0
  while [ i < 2 ]
     [ 
       let rC matrix:get-column _rowsCoord i
       set rC map [ precision ? 2 ] rC
       matrix:set-column _rowsCoord i rC
       let cC matrix:get-column _colsCoord i
       set cC map [ precision ? 2 ] cC
       matrix:set-column _colsCoord i cC
       set i i + 1
     ]
end 

to-report calculate-distances [ M ]
   let M2 matrix:times-element-wise M M
   let dimM matrix:dimensions M set dimM first dimM
   let Id1 matrix:make-identity dimM
   let Unos matrix:make-constant dimM dimM 1
   let J1 matrix:times 0.25 Unos
   let J matrix:minus Id1 J1
   let B ( matrix:times -0.5 J M2 J)
   let LEignV matrix:real-eigenvalues B ;; get eigenvalues vector
   let EigVB matrix:eigenvectors B
   let SLEignV sort-by > LEignV
   let E1 item 0 SLEignV let E2 item 1 SLEignV ;; two bigger values
   let E1p position E1 LEignV let E2p position E2 LEignV ;; index of them
   let C1 matrix:get-column EigVB E1p let C2 matrix:get-column EigVB E2p
   let SelEV matrix:from-column-list (list C1 C2 ) 
   set E1 sqrt abs E1 set E2 sqrt abs E2
   let l1 (list ( list E1 0 ) (list  0 E2) )
   let EVMat matrix:from-row-list l1
   let X ( matrix:times SelEV EVMat )
   report X
end 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Carlos Roca, for MoNET ( Modelización del negocio, la Empresa y su tecnología). 2015. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

There are 3 versions of this model.

Uploaded by When Description Download
Carlos Roca about 8 years ago just a little refactoring Download this version
Carlos Roca over 8 years ago Info tab updates Download this version
Carlos Roca over 8 years ago Initial upload Download this version

Attached files

File Type Description Last updated
AdP1.csv data Sample : Aeroport de Paris over 8 years ago, by Carlos Roca Download
MACTOR stakeholder analysis.png preview Preview for 'MACTOR stakeholder analysis' over 8 years ago, by Carlos Roca Download
segAlim.csv data Sample file over 8 years ago, by Carlos Roca Download

This model does not have any ancestors.

This model does not have any descendants.