@Override public Mission getMission(Sergeant s) { if (this.isEmpty()) return null; PriorityBlockingQueue<Mission> relevantQueue; Vector<Mission> temp = new Vector<Mission>(); if (s.getPriority().equals(Sergeant.SHORTEST)) relevantQueue = this.minLength; else if (s.getPriority().equals(Sergeant.LONGEST)) relevantQueue = this.maxLength; else if (s.getPriority().equals(Sergeant.MINITEMS)) relevantQueue = this.minItems; else relevantQueue = this.maxItems; while (!relevantQueue.isEmpty()) { Mission candidate = relevantQueue.poll(); temp.add(candidate); WarSim.LOG.fine("Testing Mission " + candidate.getName() + "(" + candidate.getSkill() + ")"); if (s.getSkills().contains(candidate.getSkill())) { for (Mission tm : temp) relevantQueue.put(tm); return candidate; } else WarSim.LOG.fine( "The sergeant " + s.getName() + " can't execute mission " + candidate.getName()); } for (Mission tm : temp) relevantQueue.put(tm); return null; }
/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // **** Add missions to execute *************************** Code[] missionStack = { // Code.CRAWL_WEB, // Code.CHINESE_NLP, // Code.TFIDF, Code.PAGERANK, }; // ********************************************************* // *** Initialize a mission *********** Mission.crawlDomain = "http://tw.travel.yahoo.com/"; Mission mission = new YahooTravelMission( "yahootravel", "local:/Users/chi/git/textmining/databases/yahootravel"); mission.maxPagerankTermNumber = 2000; String[] urlSeeds = { "http://tw.travel.yahoo.com/info", }; mission.crawlURLSeeds = urlSeeds; // ********************************************************* mission.start(missionStack); mission.close(); }
public void updateAsScheduled(int numUpdates) { commerce.updateCommerce(numUpdates); paving.distribute(BuildConstants.ALL_PROVISIONS); dangerMap.updateVals(); for (Mission mission : missions) mission.updateMission(); // // Once per day, iterate across all personnel to get a sense of citizen // mood, and compute community spirit. (This declines as your settlement // gets bigger.) if (numUpdates % World.STANDARD_DAY_LENGTH == 0) { final Tile t = world.tileAt(0, 0); int numResidents = 0; averageMood = 0.5f; for (Object o : world.presences.matchesNear(this, t, -1)) { if (!(o instanceof Venue)) continue; final Venue v = (Venue) o; for (Actor resident : v.personnel.residents()) { numResidents++; averageMood += resident.health.moraleLevel(); } } averageMood /= (numResidents + 1); communitySpirit = 1f / (1 + (numResidents / 100f)); communitySpirit = (communitySpirit + averageMood) / 2f; } }
/** Rendering and interface methods- */ public void renderFor(Rendering rendering) { final Viewport port = rendering.port; for (Mission mission : missions) { final Sprite flag = mission.flagSprite(); if (!port.intersects(flag.position, 2)) continue; rendering.addClient(flag); } }
// 每日登录后,点击领取积分,可用于发帖,回复等 @Before(UserInterceptor.class) public void daily() { String token = getPara("token"); if (StrUtil.isBlank(token)) { error("请先登录"); } else { // 根据token获取用户信息 User user = User.me.findByToken(token); if (user == null) { error("用户不存在,请退出重新登录"); } else { Map<String, Object> map = new HashMap<String, Object>(); // 查询今天是否获取过奖励 Mission mission = Mission.me.findByInTime( user.getStr("id"), DateUtil.formatDate(new Date()) + " 00:00:00", DateUtil.formatDate(new Date()) + " 23:59:59"); if (mission == null) { // 查询最后一次签到记录 Mission lastMission = Mission.me.findLastByAuthorId(user.getStr("id")); Integer day = 1; if (lastMission != null) { String lastMissionInTimeStr = DateUtil.formatDate(lastMission.getDate("in_time")); String beforeDateStr = DateUtil.formatDate(DateUtil.getDateBefore(new Date(), 1)); if (lastMissionInTimeStr != null && lastMissionInTimeStr.equalsIgnoreCase(beforeDateStr)) { day = lastMission.getInt("day") + 1; } } Random random = new Random(); int score = random.nextInt(10) + 1; // 随机积分,1-10分 user.set("score", user.getInt("score") + score) .set("mission", DateUtil.formatDate(new Date())) .update(); getModel(Mission.class) .set("score", score) .set("author_id", user.get("id")) .set("day", day) .set("in_time", new Date()) .save(); map.put("score", score); map.put("day", day); } else { map.put("msg", "您今天已经领取了奖励,明天在来吧"); } success(map); } } }
public void setPaused(boolean paused) { if (this.paused == paused) return; final boolean oldValue = this.paused; this.paused = paused; pcs.firePropertyChange(PAUSE, oldValue, paused); Mission mission = this.mission.get(); if (mission != null) if (paused) ((TVF3Game) mission.getGame()) .getUpfrontDisplay() .submitPersistentMessage("Paused--F3 to Resume "); else ((TVF3Game) mission.getGame()).getUpfrontDisplay().removePersistentMessage(); getTr().getThreadManager().setPaused(paused); Features.get(getTr(), SoundSystemFeature.class).setPaused(paused); }
public Mission pickedMission(BaseUI UI, Viewport port) { Mission closest = null; float minDist = Float.POSITIVE_INFINITY; for (Mission mission : missions) { final Sprite flag = mission.flagSprite(); float dist = port.isoToScreen(new Vec3D().setTo(flag.position)).z; if (port.mouseIntersects(flag.position, 0.5f, UI)) { if (dist < minDist) { minDist = dist; closest = mission; } } } return closest; }
@SCJAllowed(LEVEL_2) public final void requestSequenceTermination() { // Why do we need to call the cleanUp() method of the next // mission after a termination request in the current mission? // this.getNextMission().requestTermination(); current_mission.requestTermination(); }
/** {@inheritDoc} */ @Override protected void readAttributes(FreeColXMLReader xr) throws XMLStreamException { super.readAttributes(xr); this.colony = xr.getAttribute(getGame(), COLONY_TAG, Colony.class, (Colony) null); this.demanded = xr.getAttribute(DEMANDED_TAG, false); }
/** {@inheritDoc} */ @Override protected void writeAttributes(FreeColXMLWriter xw) throws XMLStreamException { super.writeAttributes(xw); if (target != null) { xw.writeAttribute(TARGET_TAG, target.getId()); } }
@Override public void save(XElement xmission) { super.save(xmission); xmission.set("task-1-once", task1Once); xmission.set("task-2-once", task2Once); xmission.set("task-3-once", task3Once); xmission.set("trader-message", traderMessage); }
@Override public void load(XElement xmission) { super.load(xmission); task1Once = xmission.getBoolean("task-1-once", objective("Mission-2-Task-1").isCompleted()); task2Once = xmission.getBoolean("task-2-once", objective("Mission-2-Task-2").isCompleted()); task3Once = xmission.getBoolean("task-3-once", objective("Mission-2-Task-3").isCompleted()); traderMessage = xmission.getInt("trader-message", 1 + ModelUtils.randomInt(7)); }
private void delete(Mission m) { String s = "Removing " + m.getName() + " success? "; this.minLength.remove(m); this.maxLength.remove(m); this.minItems.remove(m); this.maxItems.remove(m); s += !(this.minLength.contains(m) || this.maxLength.contains(m)); WarSim.LOG.fine(s); }
/** {@inheritDoc} */ @Override protected void writeAttributes(FreeColXMLWriter xw) throws XMLStreamException { super.writeAttributes(xw); if (this.colony != null) { xw.writeAttribute(COLONY_TAG, this.colony.getId()); } xw.writeAttribute(DEMANDED_TAG, this.demanded); }
void removeAperiodicHandlers(Mission m) { if (msCount > 0) { for (int i = 0; i < noOfRegistered; i++) { if (schedulables[i] instanceof AperiodicEventHandler) { ManagedSchedulable ms = schedulables[i]; schedulables[i].cleanUp(); deleteSchedulable(i); PriorityScheduler.instance().pFrame.removeFromQueue((ScjProcess) Process.getProcess(ms)); } } if (msCount == 0) m.getSequencer().seqNotify(); } }
void removeMSObject(ManagedSchedulable ms, Mission m) // called in Scj...Process.gotoNextState { if (msCount > 0) { for (int i = 0; i < noOfRegistered; i++) { if (schedulables[i] == ms) { schedulables[i].cleanUp(); PriorityScheduler.instance().pFrame.removeFromQueue((ScjProcess) Process.getProcess(ms)); // devices.Console.println("MSSet.removeMSObject " + scjProcesses[i].index); deleteSchedulable(i); } } // devices.Console.println("MSSet.removeMSObject: msCount " + msCount); if (msCount == 0) { m.getSequencer().seqNotify(); } } }
// 重构思想 public static void AyalyzingPreLookAheadForRefactorDFS(String messageName) { if (messageName == null) { System.out.println("No input message to drive the automachine!"); return; } LinkedList<Mission> errorSequenceList2 = new LinkedList<Mission>(); if (kSteps > 0) { System.out.println(); System.out.println( "Look ahead " + kSteps + " steps with message: " + messageMap.get(messageName) + "\nwhich is mapped into " + messageName + "billy refactor"); System.out.println(); } currentTime1 = System.nanoTime(); if (tmpFoundList.size() != 0) { foundList = (ArrayList<MissionForRefactor>) tmpFoundList.clone(); tmpFoundList.clear(); } System.out.println("\n Possible right message sequences(billy refactor):\n"); for (int i = 0; i < timedAutomataStateList.size(); i++) { // 从每个自动机的起始状态开始找 ArrayList<String> placeArray; MissionForRefactor mfr; for (int index = 0; index < foundList.size(); index++) { mfr = foundList.get(index); if (!mfr.getFirstMessageName().equals(messageName)) continue; // 给定的消息在原来查找到的序列里不合适,结束本次循环 placeArray = mfr.getPlaceArray(); String tmpMessageSequence = mfr.getMessageSequenceWithoutFirstMessageName(); boolean isFind = false; List<State> timedAutomataState = timedAutomataStateList.get(i); // String stateName = timedAutomataState.get(0).getStateName(); String stateName = placeArray.get(i); // System.out.println("11 " + stateName); for (int j = 0; j < timedAutomataState.size(); j++) { // 根据起始状态的名字查找timedAutomataState State currentState = timedAutomataState.get(j); // System.out.println("22 "); if (currentState.getStateName().equals(stateName)) { // 找到了对应名字的state List<String> innerList = currentState.getInnerMessageList(); // System.out.println("33 " + innerList.size()); for (int k = 0; k < innerList.size(); k++) { // 内部消息都是可能的 ArrayList<String> tmpPlaceArray = (ArrayList<String>) placeArray.clone(); tmpPlaceArray.set(i, currentState.getEndStateName(innerList.get(k))); // StringBuffer buffer=new StringBuffer(innerList.get(k)); // // synchronizedMoveInFindingMessageSeq(buffer,1,innerList.get(k),INNER_MESSAGE,tmpPlaceArray,i); // printPlaceArray(tmpPlaceArray); // queue.add(new Mission(innerList.get(k), (ArrayList<String>) // tmpPlaceArray.clone(), 1)); if (tmpMessageSequence.equals("")) tmpFoundList.add(new MissionForRefactor(innerList.get(k), tmpPlaceArray)); else tmpFoundList.add( new MissionForRefactor( tmpMessageSequence + " , " + innerList.get(k), tmpPlaceArray)); System.out.println("*** " + tmpMessageSequence + " , " + innerList.get(k) + " ***"); isFind = true; } List<String> sendList = currentState.getSendMessageList(); // List<String> // receiveList=currentState.getReceiveMessageList(); // System.out.println("44 " + sendList.size()); for (int k = 0; k < sendList.size(); k++) { // 发送必须和接收配对,才是可能的 ArrayList<String> tmpPlaceArray = (ArrayList<String>) placeArray.clone(); int temp = AnalyzeMessageSequence.findInAllAuto(sendList.get(k), tmpPlaceArray); if (temp != -1) { tmpPlaceArray.set(i, currentState.getEndStateName(sendList.get(k))); // printPlaceArray(tmpPlaceArray); // queue.add(new Mission(sendList.get(k), // (ArrayList<String>) tmpPlaceArray.clone(), // 1)); if (tmpMessageSequence.equals("")) tmpFoundList.add(new MissionForRefactor(sendList.get(k), tmpPlaceArray)); else tmpFoundList.add( new MissionForRefactor( tmpMessageSequence + " , " + sendList.get(k), tmpPlaceArray)); System.out.println("*** " + tmpMessageSequence + " , " + sendList.get(k) + " ***"); isFind = true; } } // System.out.println("55 " + queue.size()); break; // 找到了第一个起始状态的描述,不再进行内循环 } } if (!isFind) { boolean isMissionExist = false; for (Mission mission : errorSequenceList2) { // 判断一下errorSequenceList中原来是不是已经加了这个任务 if (mission.getPreviousMessage().equals(mfr.getMessageSequence())) { isMissionExist = true; break; } } if (!isMissionExist) errorSequenceList2.add( new Mission( mfr.getMessageSequence(), mfr.getPlaceArray(), kSteps)); // 如果mission没有下文了,则存入错误组合链表,供最后集中打印 } } } // 再次判断是否错误组合中有正确组合的部分,否则去掉 for (MissionForRefactor mr : foundList) { for (int i = 0; i < errorSequenceList2.size(); i++) { Mission mission = errorSequenceList2.get(i); if (mr.getMessageSequence().contains(mission.getPreviousMessage())) errorSequenceList2.remove(mission); } } System.out.println("\n Possible error message sequences:\n"); for (int index = 0; index < errorSequenceList2.size(); index++) { MissionForRefactor mfr = errorSequenceList2.get(index).toReconstrcut(); if (!mfr.getFirstMessageName().equals(messageName)) continue; // 给定的消息在原来查找到的序列里不合适,结束本次循环 ArrayList<String> placeArray = mfr.getPlaceArray(); String tmpMessageSequence = mfr.getMessageSequenceWithoutFirstMessageName(); System.out.print("Warning: " + tmpMessageSequence + "\t"); System.out.print("( "); for (int k = 0; k < placeArray.size(); k++) { System.out.print( placeArray.get(k) + "(" + IImageKeys.automataFilesName .get(k) .substring( IImageKeys.automataFilesName.get(k).indexOf('/') + 1, IImageKeys.automataFilesName.get(k).lastIndexOf('.')) + ") "); } System.out.println(")"); } boolean isFind = true; while (isFind) { isFind = false; for (int i = 0; i < errorSequenceList.size(); i++) { Mission mission = errorSequenceList.get(i); if (!mission.getFirstMessageName().equals(messageName)) { continue; } isFind = true; System.out.println( "Warning: " + mission.getMessageSequenceWithoutFirstMessageName() + "\t"); mission.setPreviousMessage(mission.getMessageSequenceWithoutFirstMessageName()); ArrayList<String> placeArray = mission.getPlaceList(); System.out.print("( "); for (int k = 0; k < placeArray.size(); k++) { System.out.print( placeArray.get(k) + "(" + IImageKeys.automataFilesName .get(k) .substring( IImageKeys.automataFilesName.get(k).indexOf('/') + 1, IImageKeys.automataFilesName.get(k).lastIndexOf('.')) + ") "); } System.out.println(")"); } } long current2 = System.nanoTime(); timeList.add((current2 - currentTime1) / 1000); System.out.println( "\n The execution time of analysis with reconstruct is: " + (current2 - currentTime1) / 1000 + " us"); System.out.println( "*****************************************************************************"); }
/** {@inheritDoc} */ @Override protected void readAttributes(FreeColXMLReader xr) throws XMLStreamException { super.readAttributes(xr); target = xr.getLocationAttribute(getGame(), TARGET_TAG, false); }
private static void AyalyzingPreLookAheadWithMultiAutomataDFS() { if (queue.isEmpty()) { for (int i = 0; i < timedAutomataStateList.size(); i++) { // 从每个自动机的起始状态开始找(billy:这边的size 表示有几个自动机) ArrayList<String> placeArray = new ArrayList<String>(timedAutomataStateList.size()); AnalyzeMessageSequence.initPlaceArray(placeArray); List<State> timedAutomataState = timedAutomataStateList.get(i); // billy:得到第i个自动机 里面的所有状态 String stateName = placeArray.get(i); // billy:第i个自动机的 名字 for (int j = 0; j < timedAutomataState.size(); j++) { // 根据起始状态的名字查找timedAutomataState (billy:指第i个自动机的每个状态) State currentState = timedAutomataState.get(j); if (currentState.getStateName().equals(stateName)) { // 找到了对应名字的state List<String> innerList = currentState.getInnerMessageList(); for (int k = 0; k < innerList.size(); k++) { // 内部消息都是可能的 ArrayList<String> tmpPlaceArray = (ArrayList<String>) placeArray.clone(); tmpPlaceArray.set( i, currentState.getEndStateName( innerList.get(k))); // billy:把内部消息对应的状态 staname放入到tmp queue.add( new Mission(innerList.get(k), (ArrayList<String>) tmpPlaceArray.clone(), 1)); } // System.out.println("queue whether empty"); List<String> sendList = currentState.getSendMessageList(); for (int k = 0; k < sendList.size(); k++) { // 发送必须和接收配对,才是可能的 ArrayList<String> tmpPlaceArray = (ArrayList<String>) placeArray.clone(); int temp = AnalyzeMessageSequence.findInAllAuto(sendList.get(k), tmpPlaceArray); if (temp != -1) { tmpPlaceArray.set(i, currentState.getEndStateName(sendList.get(k))); // printPlaceArray(tmpPlaceArray); queue.add( new Mission(sendList.get(k), (ArrayList<String>) tmpPlaceArray.clone(), 1)); } } // System.out.println("55 " + queue.size()); break; // 找到了第一个起始状态的描述,不再进行内循环 } } } } System.out.println("\n Possible right message sequences:\n"); while (!queue.isEmpty()) { Mission m = queue.poll(); // 从队列取出,删 if (m.getSteps() < kSteps) { Stack.push(m); while (!Stack.isEmpty()) { Mission sm = Stack.pop(); String buffer = sm.getPreviousMessage(); ArrayList<String> placeArray = (ArrayList<String>) sm.getPlaceList().clone(); boolean isFind = false; for (int i = 0; i < timedAutomataStateList.size(); i++) { List<State> timedAutomataState = timedAutomataStateList.get(i); for (int j = 0; j < timedAutomataState.size(); j++) { // 根据下一状态的名字查找timedAutomataState State currentState = timedAutomataState.get(j); // System.out.println("88 "+currentState.getStateName()); // AnalyzeMessageSequence.printPlaceArray(placeArray); if (currentState.getStateName().equals(placeArray.get(i))) { // 在自动机i中找到了对应名字的state List<String> innerList = currentState.getInnerMessageList(); // System.out.println("99 " + innerList.size()); for (int k = 0; k < innerList.size(); k++) { // 内部消息都是可能的 ArrayList<String> tmpPlaceArray = (ArrayList<String>) placeArray.clone(); tmpPlaceArray.set(i, currentState.getEndStateName(innerList.get(k))); // printPlaceArray(tmpPlaceArray); if (sm.getSteps() + 1 == kSteps) { kqueue.add( new Mission( buffer + " , " + innerList.get(k), (ArrayList<String>) tmpPlaceArray.clone(), sm.getSteps() + 1)); Mission km = kqueue.poll(); foundList.add( new MissionForRefactor(km.getPreviousMessage(), km.getPlaceList())); System.out.println("---" + km.getPreviousMessage() + "---"); isFind = true; } else { // tmpPlaceArray.add("visited"); Stack.push( new Mission( buffer + " , " + innerList.get(k), (ArrayList<String>) tmpPlaceArray.clone(), sm.getSteps() + 1)); isFind = true; } } List<String> sendList = currentState.getSendMessageList(); // for (int k = 0; k < sendList.size(); k++) { // 发送必须和接收配对,才是可能的 ArrayList<String> tmpPlaceArray = (ArrayList<String>) placeArray.clone(); if (AnalyzeMessageSequence.findInAllAuto(sendList.get(k), tmpPlaceArray) != -1) { tmpPlaceArray.set(i, currentState.getEndStateName(sendList.get(k))); if (sm.getSteps() + 1 == kSteps) { kqueue.add( new Mission( buffer + " , " + sendList.get(k), (ArrayList<String>) tmpPlaceArray.clone(), sm.getSteps() + 1)); Mission km = kqueue.poll(); foundList.add( new MissionForRefactor(km.getPreviousMessage(), km.getPlaceList())); System.out.println("---" + km.getPreviousMessage() + "---"); isFind = true; } else { Stack.push( new Mission( buffer + " , " + sendList.get(k), (ArrayList<String>) tmpPlaceArray.clone(), sm.getSteps() + 1)); isFind = true; } } } } // end current if } } // end out for //end inner for if (!isFind) { // boolean isMissionExist = false; for (Mission mission : errorSequenceList) { // 判断一下errorSequenceList中原来是不是已经加了这个任务 if (mission.getPreviousMessage().equals(sm.getPreviousMessage())) { isMissionExist = true; break; } } if ((!isMissionExist) // &&(!isMissionLeave)&&(!flag) ) errorSequenceList.add(sm); // 如果mission没有下文了,则存入错误组合链表,供最后集中打印 // for(int j=0;j<errorSequenceList.size();j++){ // Mission mission=errorSequenceList.get(j); // System.out.println("errorsequecne"+mission.getPreviousMessage());} } } // end empty } // end if k else { System.out.println("---" + m.getPreviousMessage() + "---(billy)"); } } // end queue for (MissionForRefactor mr : foundList) { for (int i = 0; i < errorSequenceList.size(); i++) { Mission mission = errorSequenceList.get(i); if (mr.getMessageSequence().contains(mission.getPreviousMessage())) errorSequenceList.remove(mission); // 首次出现的mission } } // 打印所有错误的组合 System.out.println("\n Possible error message sequences(billy):\n"); for (int i = 0; i < errorSequenceList.size(); i++) { Mission m = errorSequenceList.get(i); System.out.print("Warning: " + m.getPreviousMessage() + "\t"); ArrayList<String> list = m.getPlaceList(); System.out.print("( "); for (int k = 0; k < list.size(); k++) { System.out.print( list.get(k) + "(" + IImageKeys.automataFilesName .get(k) .substring( IImageKeys.automataFilesName.get(k).indexOf('/') + 1, IImageKeys.automataFilesName.get(k).lastIndexOf('t')) + ") "); } System.out.println(")"); } if (kSteps > 0) { // System.out.println("Look ahead " + kSteps + " steps " + // (withControllability!=0?"with":"without") + // " controllability by " + // (isDepthSearchFirst!=0?"breadth search first.":"depth search first.")); long current2 = System.nanoTime(); timeList.add((current2 - currentTime1) / 1000); System.out.println( "\nThe execution time of initial Lookahead is: " + (current2 - currentTime1) / 1000 + " us"); } else { System.out.println( "The execution time of analysis without Pre-Lookahead is: " + (System.nanoTime() - currentTime1) / 1000 + " us"); } System.out.println( "--------------深度---------------多自动机主动监控-------------------------------------------"); } // end ayalyzingpre dfs