/** Creates new form CommunicationDialog */
  public CommunicationDialog(java.awt.Frame parent, boolean modal, SimulatorConfig sc) {
    super(parent, modal);

    simConfig = sc;
    initComponents();

    // Select current model
    for (Enumeration e = bGroup.getElements(); e.hasMoreElements(); ) {
      JRadioButton b = (JRadioButton) e.nextElement();
      if (b.getModel().getMnemonic() - 48 == simConfig.getCommModel().ordinal()) {
        b.setSelected(true);
      }
    }

    // Let window X being clicked be handled by windowClosing method
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

    // center on screen
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (dim.width - getSize().width) / 2;
    int y = (dim.height - getSize().height) / 2;
    setLocation(x, y);

    this.addWindowListener(windowListener);
    setVisible(true);
  }
 private void buttonOKActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_buttonOKActionPerformed
   // Since developed in netbeans designer, this returns ASCII character, we want integers starting
   // at 0.
   simConfig.setCommModel(bGroup.getSelection().getMnemonic() - 48);
   this.dispose();
 } // GEN-LAST:event_buttonOKActionPerformed
예제 #3
0
  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);
      }
    }
  }