private static void printRounter(List<Project> plannRouter) { System.out.print("path="); for (Project p : plannRouter) { System.out.print(p.getProjectCode() + "-"); } System.out.println(); }
public static int[][] makeMatrix(List<Project> projects, List<Path> paths) { int[][] matrix = new int[projects.size()][projects.size()]; System.out.print(" "); for (Project p : projects) { // System.out.println(p.getProjectId()+" code="+p.getProjectCode()+" // name="+p.getProjectName()+" time="+p.getProjectTime()); System.out.print(p.getProjectCode() + " "); } for (Path p : paths) { matrix[p.getPathFrom() - 1][p.getPathTo() - 1] = 1; matrix[p.getPathTo() - 1][p.getPathFrom() - 1] = 1; // System.out.println(p.getPathId()+" from="+p.getPathFrom()+" to="+p.getPathTo()); } System.out.println(); for (int i = 0; i < matrix.length; i++) { System.out.print(projects.get(i).getProjectCode() + " "); for (int j = 0; j < matrix[i].length; j++) { System.out.print(matrix[i][j] + " "); } System.out.println(); } return matrix; }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); int userId = request.getParameter("userId") == null ? MyConst.USERID_DEFAULT : Integer.parseInt(request.getParameter("userId")); int projectId = request.getParameter("scenerySpotId") == null ? 1 : Integer.parseInt(request.getParameter("scenerySpotId")); SignatureDao dao = new SignatureDao(); List<Project> list = new ArrayList<Project>(); list = dao.getMySignedProjects(userId, projectId); JSONArray array = JSONArray.fromObject(list); for (Project p : list) { System.out.print(p.getProjectId() + " "); } if (array.size() != 0) { out.print(array); } out.flush(); out.close(); }
public static boolean isContainsProject(List<Project> projects, Project target) { boolean res = false; for (Project p : projects) { if (p.getProjectId() == target.getProjectId()) { res = true; return res; } } return res; }
public static int getIndex(List<Project> projects, Project beginProject) { int index = 0; for (int i = 0; i < projects.size(); i++) { if (beginProject.getProjectId() == projects.get(i).getProjectId()) { index = i; return index; } } return index; }
/** * @param startTime 开始玩的时间 比如:12:00:00 动态变化 * @param playTime * @param allProjects 项目集合 不变 * @param planningNow 现在已经规划的路线 动态变化 * @param matrix 项目路线矩阵 不变 */ public void addNext( String startTime, int playTime, List<Project> allProjects, List<Project> planningNow, int[][] matrix) { // 获取起始点 比如 "gate" Project beginProject = planningNow.get(0); Project nowLastProject = planningNow.get(planningNow.size() - 1); List<Project> plannResult = new ArrayList<Project>(); plannResult.addAll(planningNow); int begin = getIndex(allProjects, nowLastProject); for (int j = 0; j < matrix[begin].length; j++) { if (matrix[begin][j] == 1) // 如果有路 { Project nextProject = allProjects.get(j); // 得到下一个规划的点 int projectStayMins = nextProject.getProjectStayTime(); // 判断这个是否能在规定时间内玩完 boolean canPlayOver = canPlayOverInOpenTime(startTime, projectStayMins, nextProject.getProjectOpenTime()); if (canPlayOver == true && playTime >= 0) { // System.out.println("playTime="+playTime); // 这个点和初始点相同则结束 if (nextProject.getProjectId() == beginProject.getProjectId()) { plannResult.add(nextProject); printRounter(plannResult); set.add(plannResult); plannResult = planningNow; continue; } // 如果这个点是通路但是还没走到 就加进来 else if (!isContainsProject(planningNow, nextProject)) { List<Project> plannNextVertex = new ArrayList<Project>(); plannNextVertex.addAll(planningNow); plannNextVertex.add(nextProject); String nextStartTime = DateUtil.addMins( DateUtil.StringToDate(DateUtil.getNowTimeWithoutHourAndMin() + startTime), projectStayMins); addNext( nextStartTime, playTime - projectStayMins, allProjects, plannNextVertex, matrix); // addNext(startTime,playTime ,allProjects,plannNextVertex,matrix); } } } } }