Package ch.idsia.tools.tcp

Examples of ch.idsia.tools.tcp.Server


    private List<EvaluationInfo> evaluationSummary = new ArrayList<EvaluationInfo>();

    private void evaluateServerMode()
    {
        Server server = new Server(evaluationOptions.getServerAgentPort(), Environment.numberOfObservationElements, Environment.numberOfButtons);
        evaluationOptions.setAgent(new ServerAgent(server, evaluationOptions.isFastTCP()));

        Simulation simulator = new BasicSimulator(evaluationOptions.getSimulationOptionsCopy());
        while (server.isRunning())
        {
            String resetData = server.recvUnSafe();
            if (resetData.startsWith("ciao"))
            {
                System.out.println("Evaluator: ciao received from client; restarting server");
                server.restartServer();
                continue;
            }
            if (resetData.startsWith("reset"))
            {
                resetData = resetData.split("reset\\s*")[1];
                evaluationOptions.setUpOptions(resetData.split("[\\s]+"));
                //TODO: Fix this in more general way
                ((ServerAgent)evaluationOptions.getAgent()).setFastTCP(evaluationOptions.isFastTCP());
                init(evaluationOptions);
                // Simulate One Level
                EvaluationInfo evaluationInfo;

                long startTime = System.currentTimeMillis();
                String startMessage = "Evaluation started at " + GlobalOptions.getDateTime(null);
                LOGGER.println(startMessage, LOGGER.VERBOSE_MODE.ALL);

                simulator.setSimulationOptions(evaluationOptions);
                evaluationInfo = simulator.simulateOneLevel();

                evaluationInfo.levelType = evaluationOptions.getLevelType();
                evaluationInfo.levelDifficulty = evaluationOptions.getLevelDifficulty();
                evaluationInfo.levelRandSeed = evaluationOptions.getLevelRandSeed();
                evaluationSummary.add(evaluationInfo);
                LOGGER.VERBOSE_MODE VM = (evaluationInfo.marioStatus == Mario.STATUS_WIN) ? LOGGER.VERBOSE_MODE.INFO : LOGGER.VERBOSE_MODE.ALL;
                LOGGER.println("run  finished with result : " + evaluationInfo, VM);

                String fileName = "";
                if (!this.evaluationOptions.getMatlabFileName().equals(""))
                    fileName = exportToMatLabFile();
                Collections.sort(evaluationSummary, new evBasicFitnessComparator());

                LOGGER.println("Entire Evaluation Finished with results:", LOGGER.VERBOSE_MODE.ALL);
//                for (EvaluationInfo ev : evaluationSummary)
//                {
//                    LOGGER.println(ev.toString(), LOGGER.VERBOSE_MODE.ALL);
//                }
                long currentTime = System.currentTimeMillis();
                long elapsed = currentTime - startTime;
                LOGGER.println(startMessage, LOGGER.VERBOSE_MODE.ALL);
                LOGGER.println("Evaluation Finished at " + GlobalOptions.getDateTime(null), LOGGER.VERBOSE_MODE.ALL);
                LOGGER.println("Total Evaluation Duration (HH:mm:ss:ms) " + GlobalOptions.getDateTime(elapsed), LOGGER.VERBOSE_MODE.ALL);
                if (!fileName.equals(""))
                    LOGGER.println("Exported to " + fileName, LOGGER.VERBOSE_MODE.ALL);
//                return evaluationSummary;
            }
            else
            {
                System.err.println("Evaluator: Message <" + resetData + "> is incorrect client behavior. Exiting evaluation...");
                server.restartServer();
            }
        }
    }
View Full Code Here

TOP

Related Classes of ch.idsia.tools.tcp.Server

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.