Skip to content

Commit

Permalink
Merge branch 'mesa-origin' of [email protected]:LABSS/PROTON-OC.git
Browse files Browse the repository at this point in the history
  • Loading branch information
mariopaolucci committed Jun 16, 2020
2 parents 7fd3ab2 + 0e747ba commit 11a740a
Show file tree
Hide file tree
Showing 72 changed files with 10,159 additions and 36 deletions.
53 changes: 27 additions & 26 deletions PROTON-OC.nlogo
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ globals [
number-weddings-sd
removed-fatherships
criminal-tendency-addme-for-weighted-extraction
criminal-tendency-subtractfromme-for-inverse-weighted-extraction
number-law-interventions-this-tick
correction-for-non-facilitators
number-protected-recruited-this-tick
Expand Down Expand Up @@ -419,7 +418,6 @@ to go
return-kids
]
calc-criminal-tendency-addme-for-weighted-extraction
calc-criminal-tendency-subtractfromme-for-inverse-weighted-extraction
wedding
reset-oc-embeddedness
commit-crimes
Expand Down Expand Up @@ -471,11 +469,6 @@ to calc-criminal-tendency-addme-for-weighted-extraction
set criminal-tendency-addme-for-weighted-extraction ifelse-value (min [ criminal-tendency ] of persons < 0)
[ -1 * min [ criminal-tendency ] of persons ] [ 0 ]
end
;
to calc-criminal-tendency-subtractfromme-for-inverse-weighted-extraction
set criminal-tendency-subtractfromme-for-inverse-weighted-extraction ifelse-value (max [ criminal-tendency ] of persons > 0)
[ max [ criminal-tendency ] of persons ] [ 0 ]
end

to socialization-intervene
let potential-targets all-persons with [ age <= 18 and age >= 6 and my-school != nobody ]
Expand Down Expand Up @@ -518,11 +511,12 @@ to-report limited-extraction [ the-set ]
end

to soc-add-more-friends [ targets ]
let mct max fput 0 [ criminal-tendency ] of persons
ask targets [
let support-set other persons
if any? support-set [
create-friendship-link-with rnd:weighted-one-of (limited-extraction support-set) [
criminal-tendency-subtractfromme-for-inverse-weighted-extraction - criminal-tendency
mct - criminal-tendency
]
]
]
Expand All @@ -536,7 +530,7 @@ to welfare-intervene
][
if welfare-support = "job-child" [
set targets all-persons with [ age > 16 and age < 24
and not any? my-school-links
and my-school = nobody
and any? in-offspring-link-neighbors with [ male? and oc-member? ]
and my-job = nobody ]
]
Expand Down Expand Up @@ -588,7 +582,7 @@ to family-intervene
]
let kids-to-protect persons with [
age < 18 and age >= 12 and any? in-offspring-link-neighbors with [
male? and oc-member? and runresult the-condition
male? and runresult the-condition
]
]
if any? kids-to-protect [
Expand All @@ -604,7 +598,7 @@ to family-intervene
let family (turtle-set self family-link-neighbors)
welfare-createjobs family with [
my-job = nobody and age >= 16
and not any? my-school-links
and my-school = nobody
]
soc-add-educational family with [
my-job = nobody and age < 18
Expand Down Expand Up @@ -1120,10 +1114,15 @@ end
to-report link-color
report [50 50 50 50]
end

to make-people-die
ask all-persons [
if random-float 1 < p-mortality or age > 119 [
; list tick father son
foreach removed-fatherships [ a ->
if self = last but-last a or self = last a [ ; will never see each other again. So sad.
set removed-fatherships remove a removed-fatherships
]
]
if facilitator? [
let new-facilitator one-of other persons with [ not facilitator? and not oc-member? and age > 18 ]
ask new-facilitator [ set facilitator? true ]
Expand Down Expand Up @@ -1206,20 +1205,22 @@ to commit-crimes
]
]
let criminals (turtle-set co-offender-groups)
if-else (intervention-on? and facilitator-repression?) [
ask criminals [ set arrest-weight ifelse-value (facilitator?) [ facilitator-repression-multiplier ] [ 1 ] ]
] [
if-else (intervention-on? and OC-boss-repression? and any? criminals with [ oc-member? ]) [
ask criminals with [ not oc-member? ] [ set arrest-weight 1 ]
calc-OC-status criminals with [ oc-member? ]
] [ ; no intervention active
ask criminals [ set arrest-weight 1 ]
if any? criminals [
if-else (intervention-on? and facilitator-repression?) [
ask criminals [ set arrest-weight ifelse-value (facilitator?) [ facilitator-repression-multiplier ] [ 1 ] ]
] [
if-else (intervention-on? and OC-boss-repression? and any? criminals with [ oc-member? ]) [
ask criminals with [ not oc-member? ] [ set arrest-weight 1 ]
calc-OC-status criminals with [ oc-member? ]
] [ ; no intervention active
ask criminals [ set arrest-weight 1 ]
]
]
let target-n-of-arrests number-arrests-per-year / ticks-per-year / 10000 * count persons
; if I don't add some 1, for low levels of arrests and few agents nobody ever will be arrested.
set target-n-of-arrests floor target-n-of-arrests + ifelse-value (random-float 1 < (target-n-of-arrests - floor target-n-of-arrests)) [ 1 ] [ 0 ]
ask rnd:weighted-n-of target-n-of-arrests criminals [ arrest-weight ] [ get-caught ]
]
let target-n-of-arrests number-arrests-per-year / ticks-per-year / 10000 * count persons
; if I don't add some 1, for low levels of arrests and few agents nobody ever will be arrested.
set target-n-of-arrests floor target-n-of-arrests + ifelse-value (random-float 1 < (target-n-of-arrests - floor target-n-of-arrests)) [ 1 ] [ 0 ]
ask rnd:weighted-n-of target-n-of-arrests criminals [ arrest-weight ] [ get-caught ]
end

to-report make-co-offending-histo [ co-offender-groups ]
Expand Down Expand Up @@ -1817,7 +1818,7 @@ num-persons
num-persons
100
10000
550.0
500.0
100
1
NIL
Expand Down Expand Up @@ -2170,7 +2171,7 @@ ticks-between-intervention
ticks-between-intervention
1
24
12.0
1.0
1
1
NIL
Expand Down
25 changes: 25 additions & 0 deletions experiments-xml/list_rp092
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
rp0.9.2_baseline_NOC_15.xml
rp0.9.2_baseline_NOC_45.xml
rp0.9.2_baseline_number-arrests-per-year_15.xml
rp0.9.2_baseline_number-arrests-per-year_45.xml
rp0.9.2_baseline_number-crimes-yearly-per10k_1000.xml
rp0.9.2_baseline_number-crimes-yearly-per10k_3000.xml
rp0.9.2_baseline_punishment-length_0.5.xml
rp0.9.2_baseline_punishment-length_1.5.xml
rp0.9.2_baseline_unemployment-multiplier_0.5.xml
rp0.9.2_baseline_unemployment-multiplier_1.5.xml
rp0.9.2_disruptive_NOC_15.xml
rp0.9.2_disruptive_NOC_45.xml
rp0.9.2_disruptive_number-arrests-per-year_15.xml
rp0.9.2_disruptive_number-arrests-per-year_45.xml
rp0.9.2_disruptive_number-crimes-yearly-per10k_1000.xml
rp0.9.2_disruptive_number-crimes-yearly-per10k_3000.xml
rp0.9.2_disruptive_punishment-length_0.5.xml
rp0.9.2_disruptive_punishment-length_1.5.xml
rp0.9.2_disruptive_unemployment-multiplier_0.5.xml
rp0.9.2_disruptive_unemployment-multiplier_1.5.xml
rp0.9.2_facilitators_NOC_15.xml
rp0.9.2_facilitators_NOC_45.xml
rp0.9.2_facilitators_number-arrests-per-year_15.xml
rp0.9.2_facilitators_number-arrests-per-year_45.xml
rp0.9.2_facilitators_number-crimes-yearly-per10k_1000.xml
25 changes: 25 additions & 0 deletions experiments-xml/list_rp092_b
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
rp0.9.2_facilitators_number-crimes-yearly-per10k_3000.xml
rp0.9.2_facilitators_punishment-length_0.5.xml
rp0.9.2_facilitators_punishment-length_1.5.xml
rp0.9.2_facilitators_unemployment-multiplier_0.5.xml
rp0.9.2_facilitators_unemployment-multiplier_1.5.xml
rp0.9.2_preventive_NOC_15.xml
rp0.9.2_preventive_NOC_45.xml
rp0.9.2_preventive_number-arrests-per-year_15.xml
rp0.9.2_preventive_number-arrests-per-year_45.xml
rp0.9.2_preventive_number-crimes-yearly-per10k_1000.xml
rp0.9.2_preventive_number-crimes-yearly-per10k_3000.xml
rp0.9.2_preventive_punishment-length_0.5.xml
rp0.9.2_preventive_punishment-length_1.5.xml
rp0.9.2_preventive_unemployment-multiplier_0.5.xml
rp0.9.2_preventive_unemployment-multiplier_1.5.xml
rp0.9.2_students_NOC_15.xml
rp0.9.2_students_NOC_45.xml
rp0.9.2_students_number-arrests-per-year_15.xml
rp0.9.2_students_number-arrests-per-year_45.xml
rp0.9.2_students_number-crimes-yearly-per10k_1000.xml
rp0.9.2_students_number-crimes-yearly-per10k_3000.xml
rp0.9.2_students_punishment-length_0.5.xml
rp0.9.2_students_punishment-length_1.5.xml
rp0.9.2_students_unemployment-multiplier_0.5.xml
rp0.9.2_students_unemployment-multiplier_1.5.xml
85 changes: 85 additions & 0 deletions experiments-xml/makeSensitivity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import xml.etree.ElementTree as ET

repetitions = "10"

#pretty print method
def indent(elem, level=0):
i = "\n" + level*" "
j = "\n" + (level-1)*" "
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + " "
if not elem.tail or not elem.tail.strip():
elem.tail = i
for subelem in elem:
indent(subelem, level+1)
if not elem.tail or not elem.tail.strip():
elem.tail = j
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = j
return elem

# ----------------------------------
version="rp0.9.2"

variations={'number-crimes-yearly-per10k': [1000, 3000],
'unemployment-multiplier': [1.5, 0.5],
'number-arrests-per-year': [15, 45],
'punishment-length': [1.5, 0.5]
}

for intervention in ['disruptive',
'students',
'baseline',
'preventive',
'facilitators']:

# this goes by itself as it has a double set to do
for nocc in [[15,6], [45,8]]:
tree = ET.parse('rp_base.xml')
root = tree.getroot()

al = tree.find('.//enumeratedValueSet[@variable="intervention"]')
for x in list(al): al.remove(x)
al.insert(1, ET.Element("value", value='"'+intervention+'"'))

al = tree.find('.//enumeratedValueSet[@variable="num-oc-persons"]')
for x in list(al): al.remove(x)
al.insert(1, ET.Element("value", value=str(nocc[0])))
al = tree.find('.//enumeratedValueSet[@variable="num-oc-families"]')
for x in list(al): al.remove(x)
al.insert(1, ET.Element("value", value=str(nocc[1])))

experiment = version + '_' + intervention + '_NOC_' + str(nocc[0])
al = tree.find('.//experiment')
al.set('name', version)
al.set('repetitions', repetitions)

#write to file
tree = ET.ElementTree(indent(root))
tree.write(experiment + '.xml', encoding='utf-8')

for var in variations:
for v in variations.get(var):
tree = ET.parse('rp_base.xml')
root = tree.getroot()

al = tree.find('.//enumeratedValueSet[@variable="intervention"]')
for x in list(al): al.remove(x)
al.insert(1, ET.Element("value", value='"'+intervention+'"'))

al = tree.find('.//enumeratedValueSet[@variable="' + var + '"]')
for x in list(al): al.remove(x)
al.insert(1, ET.Element("value", value=str(v)))

experiment = version + '_' + intervention + "_" + var + "_" + str(v)
al = tree.find('.//experiment')
al.set('name', version)
al.set('repetitions', repetitions)

#write to file
tree = ET.ElementTree(indent(root))
tree.write(experiment + '.xml', encoding='utf-8')


47 changes: 47 additions & 0 deletions experiments-xml/makeSensitivityMissing9.3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import xml.etree.ElementTree as ET

repetitions = "10"

#pretty print method
def indent(elem, level=0):
i = "\n" + level*" "
j = "\n" + (level-1)*" "
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + " "
if not elem.tail or not elem.tail.strip():
elem.tail = i
for subelem in elem:
indent(subelem, level+1)
if not elem.tail or not elem.tail.strip():
elem.tail = j
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = j
return elem

# ----------------------------------
version="rp0.9.3"

for intervention in ['disruptive',
'preventive',
'facilitators']:


tree = ET.parse('rp_base.xml')
root = tree.getroot()

al = tree.find('.//enumeratedValueSet[@variable="intervention"]')
for x in list(al): al.remove(x)
al.insert(1, ET.Element("value", value='"'+intervention+'"'))

experiment = version + '_' + intervention + "_"
al = tree.find('.//experiment')
al.set('name', version)
al.set('repetitions', repetitions)

#write to file
tree = ET.ElementTree(indent(root))
tree.write(experiment + '.xml', encoding='utf-8')


3 changes: 3 additions & 0 deletions experiments-xml/missing
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rp0.9.3_disruptive_.xml
rp0.9.3_facilitators_.xml
rp0.9.3_preventive_.xml
Loading

0 comments on commit 11a740a

Please sign in to comment.