/* * THIS FILE IS AUTOMATICALLY GENERATED BY THE s2j SCRIPT * DO NOT EDIT. * If you wish to make permanent changes, you should use this file * to test your changes, and then modify s2j so that the automatically * generated version of Model.java has those changes. * When committing changes to CVS, please commit both the s2j * script and the new version of Model.java */ /* * Model.java - stella2java model file. * Copyright 1999-2003 David A. Joiner and the Shodor Edcuation * Foundation, Inc. */ import java.awt.*; import java.applet.Applet; import java.util.*; class Model extends Diffeq { double PI = 3.14159; Random randomNumber = new Random(); double tinitial; double tfinal; double tstep_default; int try_model=0; int ntime; double []xtime; int method; int n_vars; int n_varfs; int n_vartot; int n_rates; int n_convs; int n_flows; int n_graphs; int n_tot; String [] var_label; String [] varf_label; String [] rate_label; String [] conv_label; String [] flow_label; String output_header; double [] var_minsb; double [] rate_minsb; double [] var_maxsb; double [] rate_maxsb; double [] var_defaultsb; double [] rate_defaultsb; int [] var_stylesb; int [] rate_stylesb; double ymin_default; double ymax_default; double [] rate; double [] conv; double [] flow; double [][] x_graph; double [][] y_graph; int [] type_graph; int [] n_graph; static int LINE_GRAPH=0; static int BOX_GRAPH=1; boolean [] allow_display; boolean [] default_display; String gr_title; String gr_depLabel; boolean it_enable; boolean ft_enable; boolean st_enable; boolean imeth_enable; boolean ymin_enable; boolean ymax_enable; boolean adap_enable; boolean adap_default; double tstep; public void init_problem(double st){ // set default status of control display. it_enable=true; ft_enable=true; st_enable=true; imeth_enable=true; ymin_enable=true; ymax_enable=true; adap_enable=true; adap_default=true; tstep_default=0.25 ; ymin_default=600000 ; ymax_default=1500000; tinitial=2004 ; tfinal=2029 ; tstep=st; time=tinitial; // CHANGE THE FOLLOWING WHEN USING THIS TEMPLATE // // --- Set the number of variables and rates --- // n_vars=0 ; n_varfs=1 ; n_vartot=n_vars+n_varfs; n_rates=4 ; n_convs=0 ; n_flows=4 ; n_tot=n_vartot+n_rates+n_convs+n_flows; allow_display = new boolean[n_tot]; default_display = new boolean[n_tot]; allow_display[0]=true; //Population default_display[0]=true; allow_display[1]=false; // default_display[1]=false; allow_display[2]=false; // default_display[2]=false; allow_display[3]=false; // default_display[3]=false; allow_display[4]=false; // default_display[4]=false; allow_display[5]=false; // default_display[5]=false; allow_display[6]=false; // default_display[6]=false; allow_display[7]=false; // default_display[7]=false; allow_display[8]=false; // default_display[8]=false; n_graphs=0; n_graph=new int[n_graphs]; type_graph=new int[n_graphs]; int max_graph=0; for (int i=0;imax_graph) max_graph=n_graph[i]; } // --------------------------------------------- // init(n_vartot); rate = new double[n_rates]; conv = new double[n_convs]; flow = new double[n_flows]; ntime=100; xtime = new double[ntime*(1+n_tot)]; var_label=new String[n_vars]; varf_label=new String[n_varfs]; rate_label=new String[n_rates]; conv_label=new String[n_convs]; flow_label=new String[n_flows]; var_minsb=new double[n_vars]; rate_minsb=new double[n_rates]; var_maxsb=new double[n_vars]; rate_maxsb=new double[n_rates]; var_defaultsb=new double[n_vars]; rate_defaultsb=new double[n_rates]; var_stylesb=new int[n_vars]; rate_stylesb=new int[n_rates]; // --- Set default size and value for model ---- // double Births; double migrants_in; double deaths; double migrants_out; rate[0] = 15.8/1000.0 ; rate[1] = 4.7/1000.0 ; rate[2] = 65.0/1000.0 ; rate[3] = 61.0/1000.0 ; x[0+n_vars] = 655000.0 ; flow[0] = x[0+n_vars]*rate[0] ; flow[1] = x[0+n_vars]*rate[3] ; flow[2] = x[0+n_vars]*rate[1] ; flow[3] = x[0+n_vars]*rate[2] ; rate_minsb[0]=0; rate_minsb[1]=0; rate_minsb[2]=0; rate_minsb[3]=0; rate_maxsb[0]=0.05; rate_maxsb[1]=0.05; rate_maxsb[2]=0.2; rate_maxsb[3]=0.2; rate_defaultsb[0]=rate[0]; rate_defaultsb[1]=rate[1]; rate_defaultsb[2]=rate[2]; rate_defaultsb[3]=rate[3]; rate_stylesb[0]=Slider.STYLE_LINEAR; rate_stylesb[1]=Slider.STYLE_LINEAR; rate_stylesb[2]=Slider.STYLE_LINEAR; rate_stylesb[3]=Slider.STYLE_LINEAR; gr_title = new String("AK"); gr_depLabel = new String("pop"); // --------------------------------------------- // // ------- Label variables and rates ----------- // varf_label[0]="Population"; rate_label[0]="Birth_rate"; rate_label[1]="Death_rate"; rate_label[2]="emigration_rate"; rate_label[3]="immigration_rate"; flow_label[0]="Births"; flow_label[1]="migrants_in"; flow_label[2]="deaths"; flow_label[3]="migrants_out"; output_header=new String(); // --- Set the header line for text output ----- // output_header= "\tTime\tvar1\tvar2\tvar3 \n"; output_header+="---------------------------------------------------"; // --------------------------------------------- // method=EULER; } public void reset_xtime(int newn) { if(newn==ntime) return; ntime=newn; xtime = new double[ntime*(1+n_tot)]; } public void solve(double [] x_var, double [] x_rate, double it, double ft,double st, boolean adaptive){ tinitial=it; tfinal=ft; time=tinitial; tstep=st; int newn=(int)((tfinal-tinitial)/st)+1; reset_xtime(newn); for(int i=0;ifirst_t && remainder(time,interval_t)>0.0 && remainder(time,interval_t)<=tstep) return (x/tstep); else return 0.0; } public double ramp(double slope) { return time*slope; } public double ramp(double slope,double ramp_start) { if (time>ramp_start) { return (time-ramp_start)*slope; } else { return 0; } } public double step(double height,double step_time) { if(time>=step_time) { return height; } else { return 0; } } public double graph(int index,double dep_var) { //access xgraph_i,j, ygraph_i,j, ngraph_i, n_graphs. if(dep_varx_graph[index][n_graph[index]-1]) { //take upper boundary value return y_graph[index][n_graph[index]-1]; } else { //find which element to use, linear intepolation for(int i=0;i=x_graph[index][i]&&dep_vartest) { retval++; product*=Math.random(); } return (double)retval; } }