import java.util.*;
import java.io.*;
import java.text.*; 
 
/******************************************************************** 
 *  Formation.java (version 1.0) written by Mark Rich 
 *  February 16th - April 26, 1999 @ University of Wisconsin - Madison 
 *  Copyright Mark Rich 1999
 *
 *  Updated October 23, 1999
 * 
 *  This program is an implementation of a theory of  
 *  Political Party formation based on the interaction 
 *  of Voters and Representatives.  For more on this  
 *  theory developed by Professor Charles Franklin and 
 *  Mark Rich, please see http://www.cs.wisc.edu/~richm/psci999/ 
 *
 *  For best results, pipe the output into a separate file, i.e.
 *
 *     java Formation > results.txt
 *
 *  This file is then easily processed by Matlab, Stata, Excel, etc
 *  for your number crunching pleasure.  The screen will update where
 *  the simulation is every 10 years.  Output from System.out follows
 *  the following 10 column format:
 *  SESSION  DISTRICT  CENTER  CANDIDATES  LAZINESS  VOTES  CENTRALTIY - 
 *    ELECTIONTYPE  NUMBEROFONES  PASCALSCALING
 ********************************************************************/ 
 
public class Formation { 
    static final int TERMLIMIT = 30; 
    static final int NUMOFDISTRICTS = 15; 
    static final int VOTERSPERDISTRICT = 501; 
    static final int POLICIES = 5; 
    static final int POSITIONS = 9; 
    static final int NUMOFBILLS = 19; 
    static final int TAGLENGTH = 40; 
    static final int SESSIONS = 2000; 

    public static void main (String args[]){ 
 
	System.err.println("Simulation in Progress..."); 
 
	// Create a Congress 
	Congress theHouse = new Congress(POLICIES, POSITIONS,  
					 NUMOFBILLS, TAGLENGTH); 
 
	// Establish the districts and place them in the Population Vector 
	Vector Population = new Vector(); 
	for (int i=0; i<NUMOFDISTRICTS; i++) { 
	    District tempDist = new District(VOTERSPERDISTRICT, 
					     POLICIES, NUMOFBILLS, POSITIONS, 
					     TAGLENGTH, "District" + i,  
					     TERMLIMIT); 
	    tempDist.Government = theHouse; 
	    Population.addElement(tempDist); 
	} 
	 
	// Have Congress run for the length of the simulation 
        for (int i=0; i<SESSIONS; i++) { 
	    //if (i%10 == 0) 
	    //System.err.print(i+1 + " "); 
 
	    // Elect the representatives from all the districts 
	    for (int j=0; j<NUMOFDISTRICTS; j++) { 
		System.out.print((i+1)+"\t"+(j+1)+"\t"); 
		theHouse.addElement(((District)Population.elementAt(j)).ElectRep()); 
		// ((Rep)theHouse.elementAt(j)).showIdeology(); 
		((Rep)theHouse.elementAt(j)).CrunchTag(); 
		System.out.print("\n"); 
	    } 
	    // Enaction of new policies and accumulation of voting record 
	    theHouse.ConductBusiness(); 
	    
	    // Send them home and cut their pay... :) 
	    theHouse.removeAllElements(); 
	} 
    } 
} 


