/******************************************************************** * Reps come from the Candidate that wins an election. All the internal * parts are initialized to be the same as the candidates. If this is a * new Rep, the name is changed. Reps have the methods, tagAdapt and * BillVote. Since Reps are self-interested, and wish for everyone to * join their party, they alter the tags of the other representatives. * Reps consider the proposed bill versus the statusquo, and vote for the * closest position. They also keep track of their most recent tag. ********************************************************************/ public class Rep extends Individual{ public int age = 0; public int[] newTag; public int VoterID; public int votesReceived = 0; public double majority; // This constructor takes a Candidate and initializes all the // paramaters of the Rep public Rep(Candidate tempCand) { ideology = tempCand.ideology; strengths = tempCand.strengths; votingRecord = tempCand.votingRecord; partyTag = tempCand.partyTag; if (!tempCand.incumbent) { name = "Rep is " + tempCand.name; } else name = tempCand.name; age = tempCand.age + 1; VoterID = tempCand.VoterID; parent = tempCand.parent; newTag = new int[partyTag.length]; System.arraycopy(partyTag, 0, newTag, 0, partyTag.length); votesReceived = tempCand.votesReceived; } // Reps need to vote on bills to determine policy for Congress public int BillVote(int bill, int issue, int statusQuo, int[] billTag, int voteNumber) { // Find the distance between themselves and the bill double billDistance = Math.abs(ideology[issue] - bill); billDistance = billDistance * strengths[issue]; // Find the distance between themselves and the statusQuo double quoDistance = Math.abs(ideology[issue] - statusQuo); quoDistance = quoDistance * strengths[issue]; // Find the similarity of the tags double tagSimilarity = findSimilarity(billTag); double byTag = Math.random(); // If the tag influence is not strong enough if (byTag > Math.abs(tagSimilarity)) { // Vote for the position that is closest if (quoDistance > billDistance) { votingRecord[voteNumber] = 1; return 1; } else { votingRecord[voteNumber] = 0; return 0; } } // otherwise vote based on party tag. else { if (tagSimilarity >= 0) { votingRecord[voteNumber] = 1; return 1; } else { votingRecord[voteNumber] = 0; return 0; } } } // Based on the similarity of the voting record of another Rep, // this method alters the other Rep's tag. public void tagAdapt(Rep otherRep) { int similarity = 0; double tagSim = findSimilarity(otherRep.partyTag); if (Math.abs(tagSim) == 1) { //System.err.println("> 100% similar!"); return; } if (Math.abs(tagSim) >= .9) { //System.err.println("> 90% similar!"); } // When they voted the same, increment the similarity for (int i=0; i= 0) if (partyTag[bitChange] != otherRep.partyTag[bitChange]) otherRep.newTag[bitChange] = partyTag[bitChange]; else i--; // Otherwise, change the other Rep's tag to be dissimilar else if (partyTag[bitChange] == otherRep.partyTag[bitChange]) otherRep.newTag[bitChange] = (otherRep.partyTag[bitChange]+1) % 2; else i--; } } // isMajority determines the majority status of the representative // given the previous term in congress. This returns a double, // the percent they voted with the majority. public double isMajority() { int majorityCount = 0; for (int i=0; i