import java.util.*; import org.apache.xerces.parsers.*; import org.w3c.dom.*; import org.xml.sax.*; import java.io.*; // T J Finney, 2001 // Not to be sold without my permission. class MSS { // static methods // main public static void main (String [] args) throws IOException, SAXException { // time stamp Date d = new Date(); System.out.println("Simulation run on " + d.toString()); System.out.println(); // load parameters System.out.println("Parameters"); DOMParser dp = new DOMParser(); //dp.setFeature("http://xml.org/sax/features/validation", true); dp.parse("config.xml"); Document doc = dp.getDocument(); // load audiences NodeList nl0, nl1; nl0 = doc.getElementsByTagName("audience"); int num = nl0.getLength(); String name = new String(); String lat = new String(); String lon = new String(); double pop, growth, limit; Audience[] centre = new Audience[num]; for (int i = 0; i < num; i++) { nl1 = nl0.item(i).getChildNodes(); name = nl1.item(1).getFirstChild().getNodeValue(); lat = nl1.item(3).getFirstChild().getNodeValue(); lon = nl1.item(5).getFirstChild().getNodeValue(); pop = Double.parseDouble(nl1.item(7).getFirstChild().getNodeValue()); growth = Double.parseDouble(nl1.item(9).getFirstChild().getNodeValue()); limit = Double.parseDouble(nl1.item(11).getFirstChild().getNodeValue()); centre[i] = new Audience(name, lat, lon, pop, growth, limit, centre); System.out.println(name+", "+lat+", "+lon+", "+ (int) pop +", "+growth+", "+ (int) limit); } nl0 = doc.getElementsByTagName("startYear"); int startYear = Integer.parseInt(nl0.item(0).getFirstChild().getNodeValue()); System.out.println("start year: " + startYear); nl0 = doc.getElementsByTagName("endYear"); int endYear = Integer.parseInt(nl0.item(0).getFirstChild().getNodeValue()); System.out.println("end year: " + endYear); nl0 = doc.getElementsByTagName("pubYear"); int pubYear = Integer.parseInt(nl0.item(0).getFirstChild().getNodeValue()); System.out.println("archetype publication year: " + pubYear); nl0 = doc.getElementsByTagName("pubPlace"); String pubPlace = nl0.item(0).getFirstChild().getNodeValue(); System.out.println("archetype publication place: " + pubPlace); nl0 = doc.getElementsByTagName("p1"); double p1 = Double.parseDouble(nl0.item(0).getFirstChild().getNodeValue()); System.out.println("p(MS correction): " + p1 + " per year"); nl0 = doc.getElementsByTagName("p2"); double p2 = Double.parseDouble(nl0.item(0).getFirstChild().getNodeValue()); System.out.println("p(MS discard): " + p2 + " per year"); nl0 = doc.getElementsByTagName("p3"); double p3 = Double.parseDouble(nl0.item(0).getFirstChild().getNodeValue()); System.out.println("p(correct copying): " + p3 + " per unit"); nl0 = doc.getElementsByTagName("r1"); double r1 = Double.parseDouble(nl0.item(0).getFirstChild().getNodeValue()); System.out.println("MSS / audience members: " + r1); nl0 = doc.getElementsByTagName("r2"); double r2 = Double.parseDouble(nl0.item(0).getFirstChild().getNodeValue()); System.out.println("imported / local MSS: " + r2); nl0 = doc.getElementsByTagName("r3"); double r3 = Double.parseDouble(nl0.item(0).getFirstChild().getNodeValue()); System.out.println("recovered / discarded MSS: " + r3); System.out.println(); // initialise // global variation data MS.initStates(); // archetype MS archetype = MS.makeArchetype(); // cycle through years for (int date = startYear; date <= endYear; date++) { System.out.println("Year " + date); System.out.println(); // introduce archetype if (date == pubYear) { for (int i = 0; i < num; i++) { if (centre[i].getName().equals(pubPlace)) { centre[i].addMS(archetype); System.out.println("Archetype introduced into " + pubPlace); System.out.println(); } } } // do cycle for each city for (int i = 0; i < num; i++) { System.out.println(centre[i].getName()); centre[i].cycle(p1, p2, p3, r1, r2); centre[i].print(); System.out.println(); } } // recover mss from those discarded System.out.println("Recover discarded MSS"); System.out.println(); for (int i = 0; i < num; i++) { System.out.println(centre[i].getName()); MS ms; Vector mss = centre[i].getBin(); int discards = centre[i].getBinSize(); for (int j = 0; j < discards; j++) { if (Stats.trial(r3)) { ms = (MS) mss.get(j); ms.print(); } } System.out.println(); } // print states System.out.println("Final number of states for each unit"); MS.printStates(); } }