public static void main(String[] args) { try { ProductDefinition.printMAOSHead(); GradedOut.showEXTREMEMessage("Started at " + Calendar.getInstance().getTime().toString()); new MAOSExecuter(args); } catch (Exception e) { System.out.println(MessageTags.MSGTAG_ERROR + e.toString()); System.out.println("@The system has failed."); System.exit(-1); } }
private void runMAOS(IExecCyclesEngine maSolver, CycleInfoManager cycleChecker, int DUP_TIMES) throws Exception { cycleChecker.initRun(); for (int iRun = 1; iRun <= DUP_TIMES; iRun++) { if (DUP_TIMES > 1) GradedOut.showNORMALMessage(MessageTags.MSGTAG_ACTION_NORM + "Trial No. " + iRun); // start solving cycleChecker.setStart(); maSolver.execOneRun(cycleChecker); cycleChecker.setEnd(); } }
/** * To start application from given arguments. * * @param args the arguments input by users. */ public MAOSExecuter(String[] args) throws Exception { if (args.length < 1) { GradedOut.showEXTREMEMessage( MessageTags.MSGTAG_PLAIN + "Usage: " + this.getClass().getName() + " $PROBTYPE:[NAME=VALUE] N=* Nact=* T=* Tcon=* solver=*:[NAME=VALUE]" + BasicTag.RETURN_TAG); return; } GlobalTools.CPUTimeCostCounter.setStart("initTime"); GradedOut.showNORMALMessage( MessageTags.MSGTAG_ACTION_SECT + "[Initialization Information]" + BasicTag.RETURN_TAG); GradedOut.showNORMALMessage("$PRJ_PATH=" + System.getProperty("user.dir")); SystemSettingPath.initRootSettingPath(); GradedOut.showNORMALMessage("$SET_PATH=" + SystemSettingPath.RootSettingPath); BasicParamHolder paramHolder = new BasicParamHolder(); CMDLineProblemSettings problemSettings = paramHolder.getProblemSettings(); problemSettings.loadContent(args[0]); GradedOut.showNORMALMessage( MessageTags.MSGTAG_ACTION_NORM + "Load initializer for problem type $PROBTYPE: " + problemSettings.getKey()); AbsMAOSInitializer maosInitializer = loadProblemType(problemSettings.getKey()); GradedOut.showNORMALMessage( MessageTags.MSGTAG_ACTION_NORM + "Load default project I/O (in \"" + SystemSettingPath.DefaultPrjIOFile + "\") and common setting parameters from files in $SET_PATH"); paramHolder.loadDefaultFiles(problemSettings.getKey()); GradedOut.showNORMALMessage("$TASKPATH=" + paramHolder.prjIOPath.getProjectPath()); GradedOut.showNORMALMessage( MessageTags.MSGTAG_ACTION_NORM + "Load problem instance \"" + args[0] + "\""); // initialize the problem task AbsProblemData problemData = maosInitializer.initProblemData(problemSettings, paramHolder.prjIOPath); GradedOut.showNORMALMessage( "Type=" + problemSettings.getKey() + " description=\"" + problemData.getDescription() + "\""); String problemInfo = "Instance: " + problemData.getSummary(); GradedOut.showNORMALMessage(problemInfo); String initInfo = problemInfo + BasicTag.RETURN_TAG; // initialize internal representation (IR): primary landscape and auxiliary knowledge // GradedOut.showNORMALMessage(MessageTags.MSGTAG_ACTION_NORM+"Initialize internal // representation (landscape)"); AbsLandscape virtualLandscape = maosInitializer.initLandscape(problemData); if (args.length > 1) { GradedOut.showNORMALMessage( MessageTags.MSGTAG_ACTION_NORM + "Parse common command-line parameters: [NAME=VALUE]"); paramHolder.parseSwarmSettings(ObjectMatrix.removeElementAt(args, 0)); } GradedOut.showNORMALMessage( MessageTags.MSGTAG_PLAIN + "Common Setting information in the command line & \"" + SystemSettingPath.DefaultSwarmFile + "\""); // show input (including default) parameters SwarmSettings swarmSettings = paramHolder.getSwarmSettings(); String swarmInfo = swarmSettings.getSummary(); GradedOut.showNORMALMessage(swarmInfo); initInfo += swarmInfo; // *** for the swarm topology GradedOut.showNORMALMessage( MessageTags.MSGTAG_ACTION_NORM + "Initialize the topology information (TOPO) in \"" + SystemSettingPath.DefaultTopologyFile + "\""); TopologyHandler topologyHandler = new TopologyHandler(); AbsTopology topologyEngine = topologyHandler.initTopology(swarmSettings.topology); String initTopologyInfo = "Topology: " + topologyEngine.getSummary(); GradedOut.showNORMALMessage(initTopologyInfo); // *** for the swarm behaviors GradedOut.showNORMALMessage( MessageTags.MSGTAG_ACTION_NORM + "Initialize the components (R_INI, R_G, and R_T) in the behavioral toolbox \"" + swarmSettings.solver + "\""); BehaviorBoxHandler behaviorHolder = new BehaviorBoxHandler(problemSettings.getKey(), virtualLandscape); behaviorHolder.parseBehaviorScript(swarmSettings.solver); // SystemSettingPath.submitUsedFile("Solver", behaviorFileName); // GradedOut.showNORMALMessage(MessageTags.MSGTAG_PLAIN+"Information for real behaviors in // the solver toolbox \""+swarmSettings.solver+"\""); String initBehaviorInfo = behaviorHolder.getBehaviorsString(); // GradedOut.showNORMALMessage(initBehaviorInfo); // *** initialize the multi-agent optimization framework GradedOut.showNORMALMessage( MessageTags.MSGTAG_ACTION_NORM + "Initialize the multiagent optimization framework (MAOS)"); MAFramework maSolver = new MAFramework(virtualLandscape); maSolver.initSwarmShell(swarmSettings.N, swarmSettings.Nact); maSolver.initInteractionMode(topologyEngine); maSolver.initBehaviors( behaviorHolder.absConstructor, behaviorHolder.absStateUpdater, behaviorHolder.absGenerator); maSolver.initTerminationCondition(swarmSettings.T, swarmSettings.Tcon); // Retrieve history solution information GradedOut.showNORMALMessage( MessageTags.MSGTAG_ACTION_NORM + "Retrieve history solution information in $SOL_PATH"); HistoricalStateHandler historicalStateHandler = new HistoricalStateHandler( virtualLandscape, maosInitializer.getSolutionIOHandler(), paramHolder.prjIOPath); historicalStateHandler.setLowerBound(maosInitializer.getLowerBound()); historicalStateHandler.setOptimalBound(swarmSettings.opt); GradedOut.showNORMALMessage(historicalStateHandler.printKnownSolutionInfo()); // For output result in runs ResultOutputHandler resultOutputHandler = new ResultOutputHandler(); String outfileName = resultOutputHandler.setResultFile( paramHolder.getResultFileDir(problemSettings.getKey()), paramHolder.getResultFileName()); SystemSettingPath.submitUsedFile("$RES_FILE", outfileName); CycleResult cycleResult = maosInitializer.getCycleResult(); cycleResult.setInfo(virtualLandscape); OutputIntervalChecker normalScreenOutputHandler = new OutputIntervalChecker(); normalScreenOutputHandler.setOutputInterval(swarmSettings.Tout); // initialize the termination condition // initialize CycleInfoManager for outputting to screen and result file GradedOut.showNORMALMessage( MessageTags.MSGTAG_ACTION_NORM + "Initialize CycleInfoManager for outputing screen information, saving results, and specifying termination conditions"); CycleInfoManager cycleChecker = new CycleInfoManager( virtualLandscape, cycleResult, historicalStateHandler, normalScreenOutputHandler, resultOutputHandler, maSolver.getTerminateCycleCheckEngine()); // initialize cycle analyzer // AbsCycleAnalysizer cycleAnalysizer = maosInitializer.getCycleAnalysizer(); // if (cycleAnalysizer!=null) cycleAnalysizer.setInfo(virtualLandscape); // cycleChecker.setCycleAnalysizer(cycleAnalysizer); // show involved input/output files and paths GradedOut.showNORMALMessage( MessageTags.MSGTAG_PLAIN + "Involved input/output files and paths ..."); GradedOut.showNORMALMessage(SystemSettingPath.getAllUsedFilesString()); // show the preprocessing time GlobalTools.CPUTimeCostCounter.setEnd("initTime"); GradedOut.showIMPORTANTMessage( MessageTags.MSGTAG_PLAIN + "Total preprocessing time: " + GlobalTools.CPUTimeCostCounter.getTotalTimeInSeconds("initTime") + "(s)"); GlobalTools.CPUTimeCostCounter.removeCounter("initTime"); // write head information to result file resultOutputHandler.writeCommentString( "[Initialization Information]" + BasicTag.RETURN_TAG + initInfo + BasicTag.RETURN_TAG + BasicTag.RETURN_TAG + initTopologyInfo + BasicTag.RETURN_TAG + initBehaviorInfo + BasicTag.RETURN_TAG); // run MAOS GradedOut.showNORMALMessage(MessageTags.MSGTAG_ACTION_SECT + "[Runtime Information]"); resultOutputHandler.writeCommentString(BasicTag.RETURN_TAG + "[Runtime Information]"); runMAOS(maSolver, cycleChecker, swarmSettings.DUP_TIMES); // output final statistics information GradedOut.showNORMALMessage( MessageTags.MSGTAG_ACTION_SECT + "[Statistics Information]" + BasicTag.RETURN_TAG); String finalStats = cycleChecker.finalStats(); GradedOut.showNORMALMessage(finalStats); resultOutputHandler.writeCommentString( BasicTag.RETURN_TAG + "[Statistics Information]" + BasicTag.RETURN_TAG + finalStats); // GradedOut.showNORMALMessage(MessageTags.MSGTAG_ACTION_SECT+"The system was terminated // successfully."); // GlobalTools.CPUTimeCostCounter.printSelf(); }