Commit 63bd70f8 authored by Juste Raimbault's avatar Juste Raimbault

added_model

parent f3322138
/**
* Exploration of Luti sub-model
* (scenarisation of urban shape and network)
*/
import java.util.Date
import java.text.SimpleDateFormat
logger.level("FINE")
// Parameters
val lambdaAcc = Val[Double]
val networkSpeed = Val[Double]
val gammaCDA=Val[Double]
val gammaCDE=Val[Double]
val betaDC=Val[Double]
val relocationRate=Val[Double]
val id = Val[Int]
val replication = Val[Int]
// scenarios variables
val scenario=Val[Int]
val nwType=Val[String]
val centerNumber=Val[Double]
val gammaSlimeMould=Val[Double]
// reporters
// sustainibility
val relativeAccessibility = Val[Double]
val nwCongestion = Val[Double]
// network shape
val nwRelativeLength = Val[Double]
val nwRelativeSpeed = Val[Double]
// urban form
val moranActives=Val[Double]
val meanDistanceActives=Val[Double]
val slopeActives=Val[Double]
val entropyActives=Val[Double]
val moranEmployments=Val[Double]
val meanDistanceEmployments=Val[Double]
val slopeEmployments=Val[Double]
val entropyEmployments=Val[Double]
// stylized facts
val corAccessDev=Val[Double]
val corAccessEmployments=Val[Double]
val corAccessTimeWeighted=Val[Double]
val corAccessTimeUnweighted=Val[Double]
// experiments-luti:setup-experiment-luti [relocationRate gammaA gammaE betaDC lambdaacc nwspeed scenario finalTime rnd-seed]
val cmds = List(
"experiments-luti:setup-experiment-luti ${relocationRate} ${gammaCDA} ${gammaCDE} ${betaDC} ${lambdaAcc} ${networkSpeed} ${scenario} 20 ${replication}",
"experiments-luti:run-experiment-luti"
)
val model = NetLogo5Task(workDirectory / "model/HEADLESS_Lutecia.nlogo",cmds,embedWorkspace=true) set(
inputs += (relocationRate,gammaCDA,gammaCDE,betaDC,lambdaAcc,networkSpeed,scenario,replication,id),
outputs += (relocationRate,gammaCDA,gammaCDE,betaDC,lambdaAcc,networkSpeed,scenario,replication,id),
netLogoOutputs += ("indicators:relative-accessibility",relativeAccessibility),
netLogoOutputs += ("indicators:mean-congestion",nwCongestion),
netLogoOutputs += ("network-indicators:relative-nw-length",nwRelativeLength),
netLogoOutputs += ("network-indicators:mean-relative-speed",nwRelativeSpeed),
netLogoOutputs += ("indicators:morphology:moran-actives",moranActives),
netLogoOutputs += ("indicators:morphology:mean-distance-actives",meanDistanceActives),
netLogoOutputs += ("indicators:morphology:slope-actives",slopeActives),
netLogoOutputs += ("indicators:morphology:entropy-actives",entropyActives),
netLogoOutputs += ("indicators:morphology:moran-employments",moranEmployments),
netLogoOutputs += ("indicators:morphology:mean-distance-employments",meanDistanceEmployments),
netLogoOutputs += ("indicators:morphology:slope-employments",slopeEmployments),
netLogoOutputs += ("indicators:morphology:entropy-employments",entropyEmployments),
netLogoOutputs += ("global:initial-nw-random-type",nwType),
netLogoOutputs += ("global:#-initial-territories",centerNumber),
netLogoOutputs += ("global:network-biological-gamma",gammaSlimeMould),
netLogoOutputs += ("indicators-stylized:cor-access-dev-avg",corAccessDev),
netLogoOutputs += ("indicators-stylized:cor-access-employments-avg",corAccessEmployments),
netLogoOutputs += ("indicators-stylized:cor-access-time-avg true",corAccessTimeWeighted),
netLogoOutputs += ("indicators-stylized:cor-access-time-avg false",corAccessTimeUnweighted)
)
/*
val dummy = ScalaTask("println(id+\" - \"+replication+\" - \"+scenario)") set (
inputs += (relocationRate,gammaCDA,gammaCDE,betaDC,lambdaAcc,networkSpeed,scenario,replication,id),
outputs += (relocationRate,gammaCDA,gammaCDE,betaDC,lambdaAcc,networkSpeed,scenario,replication,id)
)
*/
//val purpose = "TEST"
val purpose = "DIRECT_SAMPLING"
// output
val indics_hook = AppendToCSVFileHook(workDirectory / "exploration" / ((new SimpleDateFormat("yyyyMMdd_HHmmss")).format(new Date()))+"_"+purpose+".csv") set (
arraysOnSingleRow := true
)
//val env = LocalEnvironment(40)
val env = EGIEnvironment("vo.complex-systems.eu",openMOLEMemory = 4000 megabytes)
val replications =
Replication (
evaluation = (model on env by 10 hook indics_hook),
//evaluation = (dummy on env hook indics_hook),
seed = replication,
replications = 200
)
//relocationRate,gammaCDA,gammaCDE,betaDC,lambdaAcc,networkSpeed,scenario,replication,id
val exploration =
DirectSampling(
evaluation = replications,
sampling =
/*(((lambdaAcc in (0.002 to 0.01 by 0.002)) x
(networkSpeed in (2.0 to 6.0 by 2.0)) x
(gammaCDA in (0.1 to 1.0 by 0.1))x
(gammaCDE in (0.1 to 1.0 by 0.1))x
(betaDC in (0.5 to 2.0 by 0.5))x
(relocationRate in (0.1 to 1.0 by 0.1))x
(scenario in (0 to 5 by 1))
) withIndex id )*/
((LHS (
500
//1
//,lambdaAcc in Range(0.001,0.01)
//,networkSpeed in Range(2.5,10.0)
,gammaCDA in Range(0.5,1.0)
,gammaCDE in Range(0.5,1.0)
,betaDC in Range(0.5,2.0)
,relocationRate in Range(0.0,1.0)
) withIndex id) x (scenario in (0 to 7 by 1)) x (lambdaAcc is 0.005) x (networkSpeed is 5.0) )
)
exploration
This diff is collapsed.
This diff is collapsed.
;;;;;;;;;;;;;;
;; accessibility and utility functions
;;;;;;;;;;;;;;
;;
; update acc, form factor and utilities
to compute-patches-variables
compute-patches-accessibilities
compute-patches-form-factor
compute-patches-utilities
; color patches here, for more understanding of the infrastructure explo process
display:color-patches
end
;;
; Compute patches accessibilities
; given current distributions and effective distance matrix
to compute-patches-accessibilities
ask patches [
set patch:prev-accessibility patch:a-to-e-accessibility + patch:e-to-a-accessibility
; only one csp for now
set patch:a-to-e-accessibility patch:actives * list:scalar-product (global:patches-employments-list) map [exp (- global:lambda-accessibility * ?)] (matrix:get-row global:effective-distance-matrix patch:number)
set patch:e-to-a-accessibility patch:employments * list:scalar-product (global:patches-actives-list) map [exp (- global:lambda-accessibility * ?)] (matrix:get-row global:effective-distance-matrix patch:number)
set patch:current-accessibility patch:a-to-e-accessibility + patch:e-to-a-accessibility
; update also travel distances
set patch:a-to-e-distance patch:actives * list:scalar-product (global:patches-employments-list) (matrix:get-row global:effective-distance-matrix patch:number)
set patch:e-to-a-distance patch:employments * list:scalar-product (global:patches-actives-list) (matrix:get-row global:effective-distance-matrix patch:number)
]
end
;;
; Compute form factor, as couples [a-form-factor,e-form-factor]
;
to compute-patches-form-factor
; only one csp : nothing to do
ask patches [
set patch:form-factor (list actives-form-factor employments-form-factor)
]
end
;;
; patches utilities
; note : could be in same loop as accessibilities ? more flexibility.
to compute-patches-utilities
ask patches [
set patch:a-utility (patch:a-to-e-accessibility ^ global:gamma-cobb-douglas-a) * ((first patch:form-factor) ^ (1 - global:gamma-cobb-douglas-a))
set patch:e-utility (patch:e-to-a-accessibility ^ global:gamma-cobb-douglas-e) * ((last patch:form-factor) ^ (1 - global:gamma-cobb-douglas-e))
]
; renormalize utilities
let ma-a max [patch:a-utility] of patches let ma-e max [patch:e-utility] of patches
if ma-a > 0 [ask patches [set patch:a-utility patch:a-utility / ma-a]]
if ma-e > 0 [ask patches [set patch:e-utility patch:e-utility / ma-e]]
end
;;
; mean accessibility of employments and actives
; normalized by total quantities of employment and actives ? YES but not on patchset, all patches !
;
; -- symmetric a-e --
to-report accessibilities:mean-accessibility [patchset]
ifelse sum [patch:actives] of patches > 0 and sum [patch:employments] of patches > 0 and count patchset > 0 [
report (sum [patch:a-to-e-accessibility + patch:e-to-a-accessibility] of patchset) / (2 * (sum [patch:actives] of patches) * (sum [patch:employments] of patches))
][report 0]
end
;;
; form factor for actives :
; they search to flee from density, both of actives and employments
to-report actives-form-factor
if patch:actives = 0 or patch:employments = 0 [report 1]
report 1 / (patch:actives * patch:employments)
end
;;
; form factor for employments:
; take only accessibility into account (for now)
to-report employments-form-factor
report 1
end
;;;;;;;;;;;;;;;;
;; display.nls
;;;;;;;;;;;;;;;;
; plot mean accessibility of external facility
; if external-facility != 0 [plot (mean [current-accessibility] of patches with [member? number external-facility]) / initial-max-acc]
; plot externality employments
; plot externality-employments
to display:update-display
display:color-patches
display:update-nw-display
end
to display:display-target-fit
set global:patches-display "accessibility"
display:color-patches
ask ghost-transportation-links [set color blue set thickness 0.2 ask both-ends [set color blue]]
end
to display:color-patches
; basic
if global:patches-display = "governance"[
ask patches [set pcolor [color] of patch:governing-mayor]
]
if global:patches-display = "accessibility"[
color-gradient-patches "(a-to-e-accessibility + e-to-a-accessibility)" "green" "linear"
]
; cor variables
if member? global:patches-display ["patch:actives" "patch:employments" "a-utility" "e-utility" "a-to-e-accessibility" "e-to-a-accessibility"] [
;color-gradient-patches patches-display "green" "linear"
run (word "set mi min [" global:patches-display "] of patches set ma max [" global:patches-display "] of patches let me (mi + ma)/ 2 ask patches [ ifelse " global:patches-display " < me [set pcolor gradient:scale [[0 0 0] [0 255 0]] " global:patches-display " mi ma][set pcolor gradient:scale [[0 255 0][255 0 0]] " global:patches-display " mi ma]]")
]
; distances
if member? global:patches-display ["mean-effective-distance" "lbc-effective-distance" "center-effective-distance" "lbc-network-distance"] [
let md []
if global:patches-display = "mean-effective-distance" [set md map mean matrix:to-row-list global:effective-distance-matrix]
if global:patches-display = "lbc-effective-distance" [set md matrix:get-column global:effective-distance-matrix 0]
if global:patches-display = "center-effective-distance" [set md matrix:get-column global:effective-distance-matrix (floor (global:#-patches / 2))]
if global:patches-display = "lbc-network-distance" [if length global:nw-patches > 0 [let lbcn [patch:number] of one-of (patches with [member? patch:number global:nw-patches]) with-min [[pxcor] of self + [pycor] of self] set md matrix:get-column global:network-distance-matrix lbcn ]]
if length global:nw-patches > 0 or global:patches-display != "lbc-network-distance" [
let ma max md let mi min md
let p 0 foreach md [ask patch-with-number p [set pcolor scale-color yellow ? mi ma] set p p + 1]
]
]
; transportation
if global:patches-display = "congestion" [
ask patches [
ifelse member? self global:nw-patches [
color-gradient-patches "item who patches-congestion" "red" "linear"
][
set pcolor black
]
]
]
if global:patches-display = "network" [
ask patches [set pcolor black] ask patches with [member? patch:number global:nw-patches] [set pcolor pink]
]
ask patches with [patch:sea? = true] [set pcolor blue]
end
;;
; Update nw display, with link age coloring
to display:update-nw-display
ask transportation-links [
set thickness 0.4
;set color gradient:scale [[255 0 0] [255 255 0]] age 0 (ticks + 1)
set color gradient:scale [[0 0 255] [255 0 255]] transportation-link:age 0 (ticks + 1)
ask both-ends [set color [color] of myself]
]
end
;;;;
; Draw boundary between regions
; it is drawn permanently
to display:draw-boundaries
;; dirty way : ask each patch to sprout someone drawing its border with neighbors of different area
ask patches with [count neighbors4 with [[patch:governing-mayor] of myself != patch:governing-mayor] > 0] [
let p self
sprout 1 [
set color pink set shape "circle" ;set size patch-size / 2
foreach list:to-list [neighbors4 with [[patch:governing-mayor] of p != patch:governing-mayor]] of myself [
let xp [pxcor] of p let yp [pycor] of p let xn [pxcor] of ? let yn [pycor] of ?
ifelse xp = xn [
setxy xp - 0.499 (yp + yn) / 2 pen-down setxy xp + 0.499 (yp + yn) / 2 pen-up
][
setxy (xp + xn) / 2 yp - 0.499 pen-down setxy (xp + xn) / 2 yp + 0.499 pen-up
]
]
die
]
]
end
;;
; specific setup for some plots
to display:setup-plots
carefully [
set-current-plot "accessibility" set-plot-y-range precision (accessibilities:mean-accessibility patches - 0.001) 3 precision (accessibilities:mean-accessibility patches + 0.001) 3
;set-current-plot "mean-travel-distance" set-plot-y-range (mean-travel-distance - 0.001) (mean-travel-distance + 0.001)
][]
end
This diff is collapsed.
;;
; Specific experiments for the luti part of the model
; (including scenarios for transportation lines, synthetic initial networks)
to experiments-luti:setup-experiment-luti [relocationRate gammaA gammaE betaDC lambdaacc nwspeed scenario finalTime rnd-seed]
clear-all
show (word "Luti experiments with : relocation-rate = " relocationRate " ; gammaA = " gammaA " ; gammaE = " gammaE " ; betaDC = " betaDC " ; lamddaacc = " lambdaacc " ; nwspeed = " nwspeed " ; scenario = " scenario " ; finalTime = " finalTime " ; seed = " rnd-seed)
setup:setup-headless-vars
set global:headless? true
set global:failed 0
;;
; fixed params for luti
set global:setup-type "random"
set global:evolve-network? false
set global:evolve-landuse? true
set global:stopping-type "time"
set global:initial-nw? true
; dirty scenarios selection (difficult to do otherwise : \gamma = f(centers) is eyeball validated..)
if scenario = 0 [set global:initial-nw-random-type "tree-skeleton" set global:#-initial-territories 3]
if scenario = 1 [set global:initial-nw-random-type "tree-skeleton" set global:#-initial-territories 5]
if scenario = 2 [set global:initial-nw-random-type "full" set global:#-initial-territories 3]
if scenario = 3 [set global:initial-nw-random-type "full" set global:#-initial-territories 5]
if scenario = 4 [set global:initial-nw-random-type "slime-mould" set global:#-initial-territories 3 set global:network-biological-gamma 1.2]
if scenario = 5 [set global:initial-nw-random-type "slime-mould" set global:#-initial-territories 5 set global:network-biological-gamma 1.1]
if scenario = 6 [set global:initial-nw-random-type "slime-mould" set global:#-initial-territories 3 set global:network-biological-gamma 1.8]
if scenario = 7 [set global:initial-nw-random-type "slime-mould" set global:#-initial-territories 5 set global:network-biological-gamma 1.8]
;;
; run parameters
; set global:#-initial-territories 3
; set global:network-biological-gamma 1.2
set global:relocation-rate relocationRate
set global:gamma-cobb-douglas-a gammaA
set global:gamma-cobb-douglas-e gammaE
set global:beta-discrete-choices betaDC
set global:lambda-accessibility lambdaacc
set global:network-speed nwspeed
set global:total-time-steps finalTime
set global:seed rnd-seed
set global:world-size 15
setup:setup
end
;;
; luti experiment
;
; Indicators :
; - urban form actives/employments
; - relative access gain
; - relative
to experiments-luti:run-experiment-luti
experiments:run-experiment
end
to experiments-luti:test-experiment-luti
tic
experiments-luti:setup-experiment-luti 0.1 0.9 0.8 1.8 0.005 5 4 20 0
experiments-luti:run-experiment-luti
indicators:compute-indicators
toc
end
to experiments-luti:all-scenarios
foreach list:seq 0 5 1 [
experiments-luti:setup-experiment-luti 0.1 0.9 0.8 1.8 0.005 5 ? 20 0
show ?
experiments-luti:run-experiment-luti
indicators:compute-indicators
]
end
;;;;;
;; procedures for oml experiment
to experiments:setup-experiment [regionalproba lambdaacc nwspeed game coll-cost roadLength gammaCDA gammaCDE betaDC relocationRate evolveNetwork evolveLanduse target-network setuptype conffile stoptype finalValue rnd-seed]
clear-all
show (word "Params : regionalproba = " regionalproba " ; lambdaacc = " lambdaacc " ; network-speed = " nwspeed " ; game = " game " ; coll-cost = " coll-cost
" ; gammaCDA = " gammaCDA " ; gammaCDE = " gammaCDE " ; betaDC = " betaDC " ; evolveNetwork = " evolveNetwork
)
; conf file
;if conf-file = 0 [set conf-file "setup/conf/synth_nonw.conf"] if conf-file = 1 [set conf-file "setup/conf/synth_cross.conf"] if conf-file = 2 [set conf-file "setup/conf/synth_spider.conf"]
set global:conf-file conffile
let conf file:read-conf-file global:conf-file
set global:setup-from-world-file? false
if table:has-key? conf "world-file" [set global:setup-from-world-file? true]
;; cache setup for performance in case of gis real situation
if global:setup-from-world-file? [
import-world (table:get conf "world-file")
set global:setup-from-world-file? true
random-seed rnd-seed
]
setup:setup-headless-vars
set global:headless? true
set global:failed 0
set global:seed rnd-seed
set global:regional-decision-proba regionalproba
;ifelse regionalproba > 0.5 [set regional-decision-proba 1][set regional-decision-proba 0]
set global:lambda-accessibility lambdaacc
set global:network-speed nwspeed
if floor game = 0 [set global:game-type "random"] if floor game = 1 [set global:game-type "simple-nash"] if floor game = 2 [set global:game-type "discrete-choices"]
set global:collaboration-cost coll-cost
set global:road-length roadLength
set global:gamma-cobb-douglas-e gammaCDE ;0.9
set global:gamma-cobb-douglas-a gammaCDA ;0.65
set global:beta-discrete-choices betaDC ; 1.8
set global:relocation-rate relocationRate ;0.1
; dirty boolean conversion
if evolveNetwork = 0 [set global:evolve-network? false] if evolveNetwork = 1 [set global:evolve-network? true]
if evolveLanduse = 0 [set global:evolve-landuse? false] if evolveLanduse = 1 [set global:evolve-landuse? true]
set global:with-externalities? false
;ifelse with-ext = 1 [set with-externalities? true][set with-externalities? false]
;set ext-growth-factor ext-growth
; target network file
; network0 : planned ; network1 : real
set global:target-network-file (word "setup/target/network" target-network ".shp")
; setup type
if setuptype = 0 [set global:setup-type "random"]
if setuptype = 1 [set global:setup-type "gis-synthetic"]
if setuptype = 2 [set global:setup-type "gis"]
set global:stopping-type stoptype
if global:stopping-type = "time" [set global:total-time-steps finalValue]
if global:stopping-type = "infrastructure-stock" [set global:total-infrastructure-stock finalValue]
if global:setup-from-world-file? = false [
set global:world-size 15
setup:setup
]
end
to experiments:run-experiment
;; run
carefully[
while [main:stopping-condition? = false] [
main:go
]
]
[show error-message set global:failed 1]
; indicators then called from openmole
; cache network measures first
network:cache-nw-measures
end
to experiments:export-real-world
experiments:setup-experiment 1.0 0.01 5 1 0.005 2 0.9 0.65 1.8 0.1 1 1 0 2 "setup/conf/real_fullsetup.conf" "time" 10 0
show "setup ok, exporting world"
export-world "setup/realsetup.csv"
end
;;;;;;;;;;;;;;;
;; Exploration and partial validations
;;;;;;;;;;;;;;;
;;
; visualize many final network, for a fixed value of parameters
to vis-network-shape [resdir r]
setup:setup
repeat global:total-time-steps [
main:go
]
export-view (word resdir "/" r ".png")
end
;; hardcoded exploration
to explore-network-shapes [#-repets dir]
;let resdir (word shell:pwd "/res/networkValidation/20150810")
;let resdir (word (shell:getenv "CN_HOME") "/Results/Governance/Validation/InfrastructureOptimality/20150811_global_rlength2_expl50")
let resdir (word (shell:getenv "CN_HOME") "/Results/Governance/Validation/InfrastructureOptimality/" dir)
;output-print shell:exec (word "mkdir " resdir)
export-interface (word resdir "/_INTERFACE.png" )
let r 0
let nwpos [] let meanacc []
repeat #-repets [
vis-network-shape resdir r
set r r + 1
set nwpos lput global:nw-patches nwpos
set meanacc lput ([(list patch:number (patch:a-to-e-accessibility + patch:e-to-a-accessibility))] of patches) meanacc
]
; vis mean nw and mean acc and export csv
setup:setup
let nwfreq list:rep 0 global:#-patches
foreach nwpos [
foreach ? [
set nwfreq replace-item ? nwfreq ((item ? nwfreq) + 1)
]
]
let ma max nwfreq let mi min nwfreq
file:print-in-file (word resdir "/_NW_FREQ.csv") "x;y;freq"
let p 0 foreach nwfreq [ask patch-with-number p [set pcolor scale-color red ? mi ma file:print-in-file (word resdir "/_NW_FREQ.csv") implode-with-delimiter (list pxcor pycor (? / #-repets)) ";"] set p p + 1]
export-view (word resdir "/_NW_FREQ.png")
setup:setup
let macc list:rep 0 global:#-patches
foreach meanacc [
foreach ? [
set macc replace-item (first ?) macc ((item (first ?) macc) + (last ?))
]
]
set ma max macc set mi min macc
file:print-in-file (word resdir "/_MEAN_ACC.csv") "x;y;mean-acc"
set p 0 foreach macc [ask patch-with-number p [set pcolor scale-color red ? mi ma file:print-in-file (word resdir "/_MEAN_ACC.csv") implode-with-delimiter (list pxcor pycor (? / #-repets)) ";"] set p p + 1]
export-view (word resdir "/_MEAN_ACC.png")
end
This diff is collapsed.
This diff is collapsed.
ifeq ($(origin JAVA_HOME), undefined)
JAVA_HOME=/usr
endif
ifeq ($(origin NETLOGO), undefined)
NETLOGO=../..
endif
JAVAC=$(JAVA_HOME)/bin/javac
SRCS=$(wildcard src/*.java)
gradient.jar: $(SRCS) manifest.txt Makefile
mkdir -p classes
$(JAVAC) -g -deprecation -Xlint:all -Xlint:-serial -Xlint:-path -encoding us-ascii -source 1.5 -target 1.5 -classpath $(NETLOGO)/NetLogoLite.jar -d classes $(SRCS)
jar cmf manifest.txt gradient.jar -C classes .
gradient.zip: gradient.jar
rm -rf gradient
mkdir gradient
cp -rp gradient.jar README.md Makefile src manifest.txt Gradient\ Example.nlogo gradient
zip -rv gradient.zip gradient
rm -rf gradient
# NetLogo gradient extension
This package contains the NetLogo color gradient extension.
## Using
The following reporter is provided:
* `gradient:scale` _rgb-colors_ _number_ _range1_ _range2_
* Reports an RGB color proportional to _number_ along a gradient.
* _rgb-colors_ should be a list of two RGB colors. An RGB color is a list containing three values between 0 and 255; see the [Programming Guide](http://ccl.northwestern.edu/netlogo/5.0/docs/programming.html) for details.
* If _range1_ is less than _range2_, the color will be directly mapped to gradient colors. While, if _range2_ is less than _range1_, the color gradient is inverted. If _number_ is less than _range1_, then the first color of is _rgb-colors_ is chosen. If _number_ is greater than _range2_, then the last color of is _rgb-colors_ is chosen.
Example usage:
ask patches [ set pcolor gradient:scale [[255 0 0] [0 0 255]] pxcor min-pxcor max-pxcor ]`
See also the included Gradient Example model.
## Building
Use the NETLOGO environment variable to tell the Makefile which NetLogo.jar to compile against. For example:
NETLOGO=/Applications/NetLogo\\\ 5.0 make
If compilation succeeds, `gradient.jar` will be created.
## Credits
This extension is a subset of the [palette extension](http://ccl.northwestern.edu/extensions/palette/) written by Daniel Kornhauser. The palette extension includes more primitives for working with color. It works with NetLogo 4.0, but has not been updated to support more recent NetLogo versions.
## Terms of Use
For more info about the MIT license refer to: http://www.opensource.org/licenses/mit-license.php
Copyright (c) 2007 Daniel Kornhauser
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Manifest-Version: 1.0
Extension-Name: gradient
Class-Manager: org.nlogo.extensions.gradient.GradientExtension
NetLogo-Extension-API-Version: 5.0
package org.nlogo.extensions.gradient;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
public class ColorGradient extends BufferedImage {
double[][] GradientRGBArray;
// create a rectangle of 1 by 256 pixels with all the gradients.
public ColorGradient (Color startColor, Color endColor, int width)
{
super(width, 1, BufferedImage.TYPE_INT_RGB);
//System.out.println("startColor: " + startColor);
//System.out.println("endColor: " + endColor );
//System.out.println("width: " + width);
GradientPaint gradientPaint = new GradientPaint(0, 0, startColor,
width, 0, endColor ,
false);
Graphics2D g = createGraphics();
g.setPaint(gradientPaint);
g.fillRect(0, 0, width, 1);
}
// returns an array with 3 arrays with the separate rgb channels.
public int [] getPixelRGBArray(int x , int y)
{
int rgb = getRGB(x,y);
Color c = new Color(rgb);
int[] pixelRGBArray = {c.getRed(), c.getGreen(), c.getBlue()};
return pixelRGBArray;
}
// returns an array with arrays of rgb colors in the gradient
public double [][] getGradientRGBArray()
{
// Get all the pixels
final int w = getWidth();
final int h = getHeight();
final int[] gradientRGB = new int[w*h];
getRGB(0, 0, w, h, gradientRGB, 0, w);
GradientRGBArray = new double[gradientRGB.length][3];
Color c;
for (int i=0; i < gradientRGB.length; i++)
{
c = new Color(gradientRGB[i]);
GradientRGBArray[i][0] = c.getRed();
GradientRGBArray[i][1] = c.getGreen();
GradientRGBArray[i][2] = c.getBlue();
}
return GradientRGBArray;
}
}
package org.nlogo.extensions.gradient;
import org.nlogo.api.DefaultClassManager;
import org.nlogo.api.PrimitiveManager;
public class GradientExtension extends DefaultClassManager {
public void load(PrimitiveManager primitiveManager) {
primitiveManager.addPrimitive ("scale", new Scale());
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment