/**
* Name: Distribution Examples
* Author: Philippe Caillou
* Description: A demonstration of charts using the distribution of values in a list
* Tags: gui, chart
*/
model distribution


global {
	map gauss_distrib;
	map gamma_distrib;
	map lognormal_distrib;
	map weibull_distrib;
	map weibull_trunc_distrib;
	map lognormal_trunc_distrib;
	map gamma_trunc_distrib;
	map gauss_trunc_distrib;	
	
	
	list gauss_test;
	list gamma_test;
	list lognormal_test;
	list weibull_test;
	list weibull_trunc_test;
	list lognormal_trunc_test;
	list gamma_trunc_test;
	list gauss_trunc_test;
	
	init {
		gauss_test <- [1, 2, 4, 1, 2, 5, 10.0];
		gauss_distrib <- distribution_of(gauss_test, 5);
		
		gamma_test <- [1, 2, 4, 1, 2, 5, 10.0];
		gamma_distrib <- distribution_of(gamma_test, 5);
		
		lognormal_test <- [1, 2, 4, 1, 2, 5, 10.0];
		lognormal_distrib <- distribution_of(lognormal_test, 5);
		
		weibull_test <- [1, 2, 4, 1, 2, 5, 10.0];		
		weibull_distrib <- distribution_of(weibull_test, 5);

		gauss_trunc_test <- [1, 2, 4, 1, 2, 5, 10.0];
		gauss_trunc_distrib <- distribution_of(gauss_trunc_test, 5);
		
		gamma_trunc_test <- [1, 2, 4, 1, 2, 5, 10.0];
		gamma_trunc_distrib <- distribution_of(gamma_trunc_test, 5);
		
		lognormal_trunc_test <- [1, 2, 4, 1, 2, 5, 10.0];
		lognormal_trunc_distrib <- distribution_of(lognormal_trunc_test, 5);
		
		weibull_trunc_test <- [1, 2, 4, 1, 2, 5, 10.0];		
		weibull_trunc_distrib <- distribution_of(weibull_trunc_test, 5);		
	}

	reflex update_distrib {
		add gauss_rnd(10,10) to: gauss_test; 
		gauss_distrib <- distribution_of(gauss_test, 15);
		
		add gamma_rnd(10,0.5) to: gamma_test; 
		gamma_distrib <- distribution_of(gamma_test, 15);
		
		add lognormal_rnd(10,0.5) to: lognormal_test; 
		lognormal_distrib <- distribution_of(lognormal_test, 15);
		
		add weibull_rnd(10,10) to: weibull_test; 
		weibull_distrib <- distribution_of(weibull_test, 15);	
		
		
		add truncated_gauss(10,10) to: gauss_trunc_test; 
		gauss_trunc_distrib <- distribution_of(gauss_trunc_test, 15);
		
		add gamma_trunc_rnd(10,0.5,6,true) to: gamma_trunc_test; 
		gamma_trunc_distrib <- distribution_of(gamma_trunc_test, 15);
		
		add lognormal_trunc_rnd(10,0.5,17000,false) to: lognormal_trunc_test; 
		lognormal_trunc_distrib <- distribution_of(lognormal_trunc_test, 15);
		
		add weibull_trunc_rnd(10,10,7,12) to: weibull_trunc_test; 
		weibull_trunc_distrib <- distribution_of(weibull_trunc_test, 15);							
	}
}

experiment "Example of Distribution" type: gui {
	output {
		layout #split;
		display "Gauss Distribution" {
			chart "Gauss Distribution" type: histogram {
				datalist (gauss_distrib at "legend") value: (gauss_distrib at "values");
			}
		}
		display "Gamma Distribution" {
			chart "Gamma Distribution" type: histogram {
				datalist (gamma_distrib at "legend") value: (gamma_distrib at "values");
			}
		}
		display "LogNormal Distribution" {
			chart "LogNormal Distribution" type: histogram {
				datalist (lognormal_distrib at "legend") value: (lognormal_distrib at "values");
			}
		}
		display "Weibull Distribution" {
			chart "Weibull Distribution" type: histogram {
				datalist (weibull_distrib at "legend") value: (weibull_distrib at "values");
			}
		}	
		
		
		display "Truncated Gauss Distribution" {
			chart "Truncated Gauss Distribution truncated_gauss(10,10)" type: histogram {
				datalist (gauss_trunc_distrib at "legend") value: (gauss_trunc_distrib at "values");
			}
		}
		display "Truncated Gamma Distribution" {
			chart "Truncated Gamma Distribution gamma_trunc_rnd(10,0.5,6,true)" type: histogram {
				datalist (gamma_trunc_distrib at "legend") value: (gamma_trunc_distrib at "values");
			}
		}
		display "Truncated LogNormal Distribution" {
			chart "Truncated LogNormal Distribution lognormal_trunc_rnd(10,0.5,17000,false)" type: histogram {
				datalist (lognormal_trunc_distrib at "legend") value: (lognormal_trunc_distrib at "values");
			}
		}
		display "Truncated Weibull Distribution" {
			chart "Truncated Weibull Distribution weibull_trunc_rnd(10,10,7,12)" type: histogram {
				datalist (weibull_trunc_distrib at "legend") value: (weibull_trunc_distrib at "values");
			}
		}								
	}
}