private void gamesCsv(Round round) { File gamesCSV = new File(names[2]); if (gamesCSV.isFile() && gamesCSV.canRead()) { gamesCSV.delete(); } if (round.getSize() == 0) { return; } try { gamesCSV.createNewFile(); FileWriter fw = new FileWriter(gamesCSV.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write( "gameId;gameName;status;gameSize;gameLength;lastTick;" + "weatherLocation;weatherDate;logUrl;brokerId;brokerBalance;" + separator); String tourneyUrl = properties.getProperty("tourneyUrl"); String baseUrl = properties.getProperty("actionIndex.logUrl", "download?game=%d"); for (Game game : round.getGameMap().values()) { String logUrl = ""; if (game.isComplete()) { if (baseUrl.startsWith("http://")) { logUrl = String.format(baseUrl, game.getGameId()); } else { logUrl = tourneyUrl + String.format(baseUrl, game.getGameId()); } } String content = String.format( "%d;%s;%s;%d;%d;%d;%s;%s;%s;", game.getGameId(), game.getGameName(), game.getState(), game.getSize(), game.getGameLength(), game.getLastTick(), game.getLocation(), game.getSimStartTime(), logUrl); for (Agent agent : game.getAgentMap().values()) { content = String.format("%s%d;%f;", content, agent.getBrokerId(), agent.getBalance()); } bw.write(content + separator); } bw.close(); copyFile(gamesCSV, names[3]); } catch (IOException e) { e.printStackTrace(); } }
public void die() { score += (int) diescore; remove(); if (dieaction.equals("die")) { } else if (dieaction.equals("create1")) { Agent agt = newAgent(1); agt.setPos(x, y); } else if (dieaction.equals("create2")) { Agent agt = newAgent(2); agt.setPos(x, y); } else if (dieaction.equals("create3")) { Agent agt = newAgent(3); agt.setPos(x, y); } else if (dieaction.equals("create4")) { Agent agt = newAgent(4); agt.setPos(x, y); } else if (dieaction.equals("create5")) { Agent agt = newAgent(5); agt.setPos(x, y); } }
public static void main(String[] args) throws IOException { System.out.println("SimultaneousAscendingAuctionClient starting"); Socket auctSocket = null; PrintWriter out = null; BufferedReader in = null; String hostName = "127.0.0.1"; // IP of host (may be local IP) int socketNum = 1305; // the luckiest socket Agent agent = null; Valuation valuationMethod = null; try { in = new BufferedReader(new FileReader("./src/IP_and_Port.txt")); // two lines in this file. First is hostName/IP address, and second is socket number of host hostName = in.readLine(); socketNum = Integer.valueOf(in.readLine()); in.close(); } catch (IOException e) { } // These are values the agent should remember and use // Values are initialized when Server sends parameters int numSlotsNeeded = -1; int deadline = -1; double[] valuations = null; try { auctSocket = new Socket(hostName, socketNum); out = new PrintWriter(auctSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(auctSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host: " + hostName + "."); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to: host."); System.exit(1); } System.out.println("Connection to host established"); BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); String fromServer; // continue to prompt commands from host and respond while ((fromServer = in.readLine()) != null) { System.out.println("Server: " + fromServer); // Send host this client's unique ID if (fromServer.equalsIgnoreCase("Send client name")) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter a unique ID string..."); out.println(br.readLine()); // OPTIONAL CHANGE: // YOU MAY CHOOSE TO REPLACE THE LINE ABOVE WITH THE LINE BELOW // out.println("My_Hardcoded_Name"); System.out.println("User ID sent. If prompted again, choose another ID/Name string."); System.out.println("Waiting for server to start auction..."); } // *********************************************************************** else if (fromServer.startsWith("agent-parameters:")) { String[] params = fromServer.split("[ ]"); // tokens delimited with spaces numSlotsNeeded = Integer.valueOf(params[1]); // 1st param is number of slots needed deadline = Integer.valueOf(params[2]); // 2nd param is deadline // DEADLINE IS INDEX OF LAST AUCTION OF VALUE (0-indexed). // example: deadline = 1 --> first two time-slots can be used valuations = new double[params.length - 3]; // first 3 stings aren't valuations for (int i = 3; i < params.length; i++) valuations[i - 3] = Double.valueOf(params[i]); /////////////////////////////////////////////// // YOUR CODE HERE // You probably want to store the parameters sent from host. // For example, you could store them in global variables, // or use them to initialize an agent class you wrote. /////////////////////////////////////////////// // EDIT HERE // ?? how to define the number for each agent ? // ?? whether to change to another kind of agent valuationMethod = new SchedulingValuation(numSlotsNeeded, valuations); agent = new SunkawarePPAgent(0, valuationMethod, 0); // Send starting information= to agents // agent.postResult(new Result(null, false, 0, ar.getAskPrice(), 0, ar.getAskEpsilon())); agent.openAllAuctions(); /////////////////////////////////////////////// out.println("Parameters accepted"); } // *********************************************************************** else if (fromServer.equalsIgnoreCase("submit-bid")) { // Here are values you should use... be more clever than random! // numSlotsNeeded (int) // deadline (int) index of last timeSlot of value (starts at 0) // valuations (double[numSlots]) /////////////////////////////////////////////// // YOUR CODE HERE // Create a string, like myBids, with your bid(s). // If placing multiple bids, separate bids with spaces spaces. // If multiple bids, order bids as follows: // myBids = "timeSlot1Bid timeSlot2Bid ... timeslot5Bid"; // // Note: bids get rounded to 2 decimal places by host. 5.031 -> 5.03 /////////////////////////////////////////////// /* String myBids = ""; Random r = new Random();//make random bids... 1 for each time slot for(int i=0; i < valuations.length; i++){ myBids = myBids + (r.nextDouble()*10);//random bid 0 to 10 if(i < valuations.length-1) myBids = myBids + " ";//separate bids with a space! IMPORTANT! } */ // EDIT HERE! HashMap<Integer, Double> a_bids = agent.getBids(); String myBids = ""; for (int i = 0; i < valuations.length; i++) { if (a_bids.containsKey(i)) { myBids = myBids + a_bids.get(i); } else { myBids = myBids + 0.0; } if (i < valuations.length - 1) myBids = myBids + " "; } /////////////////////////////////////////////// out.println(myBids); // Send agent's bids to server System.out.println("Mybids: " + myBids + "\n"); } // *********************************************************************** // Observe the state of auction variables. Store information locally else if (fromServer.startsWith("observe-auction-state:")) { String[] stateVars = fromServer.split("[ ]"); // tokens delimited with spaces int numAgents = Integer.valueOf(stateVars[1]); int numTimeSlots = Integer.valueOf(stateVars[2]); int currentRound = Integer.valueOf(stateVars[3]); // 1st round -> 0 // currentRound is 0-indexed, so currentRound = 0 for first round String[] leaderIDs = new String[numTimeSlots]; // leaders and their bids for each time-slot double[] leaderBids = new double[numTimeSlots]; if (currentRound > 0) // no winners before first round for (int i = 0; i < (numTimeSlots * 2); i += 2) { // 2 records per time slot [leader, bid] leaderIDs[i / 2] = stateVars[4 + i]; leaderBids[i / 2] = Double.valueOf(stateVars[5 + i]); } System.out.println( "Observing state:\nNumber of agents = " + numAgents + "\nNumber of time slots = " + numTimeSlots); System.out.println("Current auction state:"); for (int i = 0; i < leaderIDs.length; i++) System.out.println( "Time-Slot " + i + ": current-leader: " + leaderIDs[i] + ", current bid = " + leaderBids[i]); /////////////////////////////////////////////// // YOUR CODE HERE // You may want to record some of the state // information here, especially the IDs of // current auction leaders for each time-slot // as well as the current leading bids. /////////////////////////////////////////////// // EDIT HERE /////////////////////////////////////////////// out.println("State Observed"); // let the server know client received state info System.out.println(""); // helps separate the output } // *********************************************************************** else if (fromServer.startsWith("observe-final-outcome:")) { // fromServer = "observe-final-outcome: winnerID_0 price_0 winnerID_1 price_1 ..." String[] outcomeVars = fromServer.split("[ ]"); // tokens delimited with spaces // for each slot, announce winner's ID and their price for (int i = 1; i < outcomeVars.length; i += 2) { String winnerID = outcomeVars[i]; double winPrice = Double.valueOf(outcomeVars[i + 1]); System.out.println( "Time Slot " + ((i + 1) / 2) + " awarded to [" + winnerID + "] for price = " + winPrice); } out.println("Final Outcome Observed"); // let the server know client received state info } // *********************************************************************** // The server says to end the connection else if (fromServer.equals("END")) { System.out.println("END called. closing"); break; } // *********************************************************************** else System.out.println("Unexpected input: " + fromServer); } out.close(); in.close(); stdIn.close(); auctSocket.close(); }
/** * Runs a test application that allocates streams, generates an SDP, dumps it on stdout, waits for * a remote peer SDP on stdin, then feeds that to our local agent and starts ICE processing. * * @param args none currently handled * @throws Throwable every now and then. */ public static void main(String[] args) throws Throwable { final Agent localAgent = createAgent(2020); localAgent.setNominationStrategy(NominationStrategy.NOMINATE_HIGHEST_PRIO); // localAgent.addStateChangeListener(new IceProcessingListener()); // let them fight ... fights forge character. localAgent.setControlling(false); String localSDP = SdpUtils.createSDPDescription(localAgent); // wait a bit so that the logger can stop dumping stuff: Thread.sleep(500); System.out.println( "=================== feed the following" + " to the remote agent ==================="); System.out.println(localSDP); System.out.println( "======================================" + "========================================\n"); String sdp = readSDP(); startTime = System.currentTimeMillis(); SdpUtils.parseSDP(localAgent, sdp); localAgent.startConnectivityEstablishment(); localAgent.addStateChangeListener( new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent propertyChangeEvent) { if (propertyChangeEvent.getPropertyName().equals(Agent.PROPERTY_ICE_PROCESSING_STATE) && propertyChangeEvent.getNewValue().equals(IceProcessingState.COMPLETED)) { System.out.println("************************!!!!!!!!!!!!! Start doing stuff here"); IceMediaStream stream = localAgent.getStream("video"); CandidatePair rtpPair = stream.getComponent(Component.RTP).getSelectedPair(); CandidatePair rtcpPair = stream.getComponent(Component.RTCP).getSelectedPair(); DatagramSocket rtpSocket = rtpPair.getLocalCandidate().getDatagramSocket(); DatagramSocket rtcpSocket = rtcpPair.getLocalCandidate().getDatagramSocket(); byte[] data = "sent".getBytes(); RemoteCandidate rem = rtpPair.getRemoteCandidate(); TransportAddress target = rem.getHostAddress(); DatagramPacket p = new DatagramPacket(data, data.length, target.getAddress(), target.getPort()); try { System.out.println("About to send packet.."); rtpSocket.send(p); System.out.println("Receiving packet.."); DatagramPacket p2 = new DatagramPacket(new byte[data.length], data.length); rtpSocket.receive(p2); System.out.println("========Received: " + new String(p2.getData())); } catch (IOException e) { e.printStackTrace(); } } } }); // Give processing enough time to finish. We'll System.exit() anyway // as soon as localAgent enters a final state. Thread.sleep(60000); }
/** Instantiate an <tt>HtmlModule</tt> object. */ public HtmlModule() { super( NAME, RELEASE, DATE, FORMAT, COVERAGE, MIMETYPE, WELLFORMED, VALIDITY, REPINFO, NOTE, RIGHTS, false); Agent agent = new Agent("Harvard University Library", AgentType.EDUCATIONAL); agent.setAddress( "Office for Information Systems, " + "90 Mt. Auburn St., " + "Cambridge, MA 02138"); agent.setTelephone("+1 (617) 495-3724"); agent.setEmail("*****@*****.**"); _vendor = agent; /* HTML 3.2 spec */ Document doc = new Document("HTML 3.2 Reference Specification", DocumentType.REPORT); Agent w3cAgent = new Agent("Word Wide Web Consortium", AgentType.NONPROFIT); w3cAgent.setAddress( "Massachusetts Institute of Technology, " + "Computer Science and Artificial Intelligence Laboratory, " + "32 Vassar Street, Room 32-G515, " + "Cambridge, MA 02139"); w3cAgent.setTelephone("(617) 253-2613"); w3cAgent.setFax("(617) 258-5999"); w3cAgent.setWeb("http://www.w3.org/"); doc.setPublisher(w3cAgent); Agent dRaggett = new Agent("Dave Raggett", AgentType.OTHER); doc.setAuthor(dRaggett); doc.setDate("1997-01-14"); doc.setIdentifier( new Identifier("http://www.w3c.org/TR/REC-html32-19970114", IdentifierType.URL)); _specification.add(doc); /* HTML 4.0 spec */ doc = new Document("HTML 4.0 Specification", DocumentType.REPORT); doc.setPublisher(w3cAgent); doc.setAuthor(dRaggett); Agent leHors = new Agent("Arnaud Le Hors", AgentType.OTHER); doc.setAuthor(leHors); Agent jacobs = new Agent("Ian Jacobs", AgentType.OTHER); doc.setAuthor(jacobs); doc.setDate("1998-04-24"); doc.setIdentifier( new Identifier("http://www.w3.org/TR/1998/REC-html40-19980424/", IdentifierType.URL)); _specification.add(doc); /* HTML 4.01 spec */ doc = new Document("HTML 4.01 Specification", DocumentType.REPORT); doc.setPublisher(w3cAgent); doc.setAuthor(dRaggett); doc.setAuthor(leHors); doc.setAuthor(jacobs); doc.setDate("1999-12-24"); doc.setIdentifier( new Identifier("http://www.w3.org/TR/1999/REC-html401-19991224/", IdentifierType.URL)); _specification.add(doc); /* XHTML 1.0 spec */ doc = new Document( "XHTML(TM) 1.0 The Extensible HyperText Markup Language " + "(Second Edition)", DocumentType.REPORT); doc.setPublisher(w3cAgent); doc.setDate("01-08-2002"); doc.setIdentifier(new Identifier("http://www.w3.org/TR/xhtml1/", IdentifierType.URL)); _specification.add(doc); /* XHTML 1.1 spec */ doc = new Document(" XHTML(TM) 1.1 - Module-based XHTML", DocumentType.REPORT); doc.setPublisher(w3cAgent); doc.setDate("31-05-2001"); doc.setIdentifier( new Identifier("http://www.w3.org/TR/2001/REC-xhtml11-20010531/", IdentifierType.URL)); _specification.add(doc); /* XHTML 2.0 spec -- NOT included yet; this is presented in "conditionalized-out" * form just as a note for future expansion. */ if (false) { doc = new Document("XHTML 2.0, W3C Working Draft", DocumentType.OTHER); doc.setPublisher(w3cAgent); doc.setDate("22-07-2004"); doc.setIdentifier( new Identifier("http://www.w3.org/TR/2004/WD-xhtml2-20040722/", IdentifierType.URL)); _specification.add(doc); } Signature sig = new ExternalSignature(".html", SignatureType.EXTENSION, SignatureUseType.OPTIONAL); _signature.add(sig); sig = new ExternalSignature(".htm", SignatureType.EXTENSION, SignatureUseType.OPTIONAL); _signature.add(sig); }
/** Instantiates an <tt>WaveModule</tt> object. */ public WaveModule() { super( NAME, RELEASE, DATE, FORMAT, COVERAGE, MIMETYPE, WELLFORMED, VALIDITY, REPINFO, NOTE, RIGHTS, false); Agent agent = new Agent("Harvard University Library", AgentType.EDUCATIONAL); agent.setAddress( "Office for Information Systems, " + "90 Mt. Auburn St., " + "Cambridge, MA 02138"); agent.setTelephone("+1 (617) 495-3724"); agent.setEmail("*****@*****.**"); _vendor = agent; Agent msagent = new Agent("Microsoft Corporation", AgentType.COMMERCIAL); msagent.setAddress(" One Microsoft Way, " + "Redmond, WA 98052-6399"); msagent.setTelephone("+1 (800) 426-9400"); msagent.setWeb("http://www.microsoft.com"); Document doc = new Document("PCMWAVEFORMAT", DocumentType.WEB); doc.setIdentifier( new Identifier( "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/" + "multimed/htm/_win32_pcmwaveformat_str.asp", IdentifierType.URL)); doc.setPublisher(msagent); _specification.add(doc); doc = new Document("WAVEFORMATEX", DocumentType.WEB); doc.setIdentifier( new Identifier( "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/" + "multimed/htm/_win32_waveformatex_str.asp", IdentifierType.URL)); doc.setPublisher(msagent); _specification.add(doc); doc = new Document("WAVEFORMATEXTENSIBLE", DocumentType.WEB); doc.setIdentifier( new Identifier( "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/" + "multimed/htm/_win32_waveformatextensible_str.asp", IdentifierType.URL)); doc.setPublisher(msagent); _specification.add(doc); agent = new Agent("European Broadcasting Union", AgentType.COMMERCIAL); agent.setAddress( "Casa postale 45, Ancienne Route 17A, " + "CH-1218 Grand-Saconex, Geneva, Switzerland"); agent.setTelephone("+ 41 (0)22 717 2111"); agent.setFax("+ 41 (0)22 747 4000"); agent.setEmail("*****@*****.**"); agent.setWeb("http://www.ebu.ch"); doc = new Document("Broadcast Wave Format (EBU N22-1987)", DocumentType.REPORT); doc.setIdentifier( new Identifier( "http://www.ebu.ch/CMSimages/en/tec_doc_t3285_tcm6-10544.pdf", IdentifierType.URL)); doc.setPublisher(agent); _specification.add(doc); Signature sig = new ExternalSignature(".wav", SignatureType.EXTENSION, SignatureUseType.OPTIONAL); _signature.add(sig); sig = new ExternalSignature( ".bwf", SignatureType.EXTENSION, SignatureUseType.OPTIONAL, "For BWF profile"); _signature.add(sig); sig = new InternalSignature("RIFF", SignatureType.MAGIC, SignatureUseType.MANDATORY, 0); _signature.add(sig); sig = new InternalSignature("WAVE", SignatureType.MAGIC, SignatureUseType.MANDATORY, 8); _signature.add(sig); _bigEndian = false; }