public void reallocate(RealAgent agent) { String userPath = System.getProperty("user.dir") + "/"; // .replace("\\", "\\\\") + "\\\\"; String filePath = userPath + "scripts/reallocate.py"; System.out.println("USERPATH: " + userPath); System.out.println("FILEPATH: " + filePath); try { Process proc = Runtime.getRuntime().exec(new String[] {"python", filePath}); // Process proc = Runtime.getRuntime().exec(filePath); proc.waitFor(); // System.out.println("After wait"); HashMap<Integer, Integer> allocation = updateM_opt(); HashMap<Integer, Point> allocation_phis = new HashMap<Integer, Point>(); for (Map.Entry<Integer, Integer> entry : allocation.entrySet()) { allocation_phis.put( entry.getKey(), agent.getLocationIDs().get(entry.getValue() - 1).getPosition()); } agent.setM_opt_p(allocation_phis); agent.setWaitingLists(getAllNewWaitings(agent)); } catch (Exception e) { e.printStackTrace(); } return; }
public HashMap<Integer, Point> callAsync(RealAgent agent, SimulatorConfig simConfig) throws FileNotFoundException { // java.awt.Toolkit.getDefaultToolkit().beep(); //Avvisa quando parte Stump ArrayList<Integer> C_b_copy = new ArrayList<Integer>(agent.getC_beta()); ArrayList<Integer> V_b_copy = new ArrayList<Integer>(agent.getV_beta()); /*String env[] = new String[12]; String adj = String.valueOf(Arrays.deepToString(agent.getAdj()).replaceAll("],", "];")); String G = String.valueOf(Arrays.deepToString(agent.getG()).replaceAll("],", "];")); String D = String.valueOf(Arrays.deepToString(agent.getD()).replaceAll("],", "];")); String R = String.valueOf(agent.getR()); String mu = String.valueOf(agent.getMu()); String C = String.valueOf(agent.getC()); String V = String.valueOf(agent.getV()); String m_1 = String.valueOf(agent.getM_1()); String w_p = String.valueOf(Arrays.deepToString(agent.getW_p()).replaceAll("],", "];"));*/ String userPath = System.getProperty("user.dir") + "/"; // .replace("\\", "\\\\") + "\\\\"; /*TODO if (System.getProperty("os.name").startsWith("Windows")) { // includes: Windows 2000, Windows 95, Windows 98, Windows NT, Windows Vista, Windows XP userPath = System.getProperty("user.dir").replace("\\", "\\\\") + "\\\\"; } else { userPath = System.getProperty("user.dir"); // everything else } */ String filePath; if (simConfig.getExpAlgorithm() == exptype.IlpExploration) { filePath = userPath + "scripts/ilp_model.py"; } else if (simConfig.getExpAlgorithm() == exptype.ApproxExploration || simConfig.getExpAlgorithm() == exptype.SwitchExploration) { filePath = userPath + "scripts/approximate_deployement.py"; } else { // Both with time threshold filePath = userPath + "scripts/mixed_deployement.py"; } System.out.println("USERPATH: " + userPath); System.out.println("FILEPATH: " + filePath); int k = 1; try { Process proc = Runtime.getRuntime().exec(new String[] {"python", filePath}); // Process proc = Runtime.getRuntime().exec(filePath); proc.waitFor(); // System.out.println("After wait"); } catch (Exception e) { e.printStackTrace(); } File fileCost = new File(userPath + "costMin.txt"); if (!fileCost.exists()) { System.out.println(agent.toString() + "ERROR: FILE NOT FOUND!"); return null; } else { Scanner scanner3 = new Scanner(fileCost); String result = new String(); result = scanner3.nextLine(); scanner3.close(); if (result.equals("Inf")) { System.out.println(agent.toString() + " END EXPLORATION"); agent.setEndExploration(true); return null; } else { System.out.println(agent.toString() + "Minimum cost structure found!"); // Retrieve instance dimension File fileDim = new File(userPath + "dim.txt"); scanner3 = new Scanner(fileDim); agent.setDimInstance(scanner3.nextLine()); scanner3.close(); HashMap<Integer, Integer> allocation = updateM_opt(); HashMap<Integer, Point> allocation_phis = new HashMap<Integer, Point>(); /*HashMap<Integer, Point> prevAllocationReady = new HashMap<Integer, Point>(); for(TeammateAgent t: agent.getAllTeammates().values()){ }*/ boolean all_equal = true; for (Map.Entry<Integer, Integer> entry : allocation.entrySet()) { System.out.println( "Robot " + Integer.toString(entry.getKey()) + " goes to " + Integer.toString(entry.getValue() - 1)); // agent.getGoalIds().put(entry.getKey(), entry.getValue() - 1); allocation_phis.put( entry.getKey(), agent.getLocationIDs().get(entry.getValue() - 1).getPosition()); if (agent.getM_opt_p().containsKey(entry.getKey()) && !agent .getM_opt_p() .get(entry.getKey()) .equals(allocation_phis.get(entry.getKey()))) { all_equal = false; } if (entry.getKey() != 0) setTeammateNotReady(agent, entry.getKey()); } if (all_equal && agent.getEqualCounter() == -1) { agent.setEqualCounter(0); } else if (all_equal && agent.getEqualCounter() != -1) { // means initial plan System.out.println("All equal"); agent.setEqualCounter(0); agent.setAllEqual(true); } agent.setM_opt_p(allocation_phis); // agent.updateWaitingLists(getNewWaitings(agent)); agent.setWaitingLists(getAllNewWaitings(agent)); // For reallocation of the whole set of communicating robots // for logging, depends on the waiting list agent.updateRobotAtFrontier(); if (simConfig.getExpAlgorithm() == exptype.MixedExploration) { agent.updateWinner(getWinner()); } return new HashMap<Integer, Point>(allocation_phis); } } }