Esempio n. 1
2
  /**
   * Evaluates a solution
   *
   * @param solution The solution to evaluate
   */
  public void evaluate(Solution solution) {
    double fitness1, fitness2;
    int x, y;
    fitness1 = 0.0;
    fitness2 = 0.0;

    for (int i = 0; i < (numberOfCities_); i++) {
      for (int j = 0; j < (numberOfCities_); j++) {
        x = ((Permutation) solution.getDecisionVariables().variables_[0]).vector_[i];
        y = ((Permutation) solution.getDecisionVariables().variables_[0]).vector_[j];

        fitness1 += distanceMatrix_[i][j] * flujo1[x][y];
      }
    }

    for (int i = 0; i < (numberOfCities_); i++) {
      for (int j = 0; j < (numberOfCities_); j++) {
        x = ((Permutation) solution.getDecisionVariables().variables_[0]).vector_[i];
        y = ((Permutation) solution.getDecisionVariables().variables_[0]).vector_[j];

        fitness2 += distanceMatrix_[i][j] * flujo2[x][y];
      }
    }

    solution.setObjective(0, fitness1);
    solution.setObjective(1, fitness2);
  } // evaluate
Esempio n. 2
1
  public static void main(String[] args) {
    System.out.println("Begin");
    Scanner scanner = new Scanner(System.in);
    String file1 = scanner.nextLine(), file2 = scanner.nextLine();

    BufferedReader reader;
    try {
      reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(file1))));
      while (reader.ready()) {
        allLines.add(reader.readLine());
      }
      reader.close();

      reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(file2))));
      while (reader.ready()) {
        forRemoveLines.add(reader.readLine());
      }
      reader.close();

      Solution solution = new Solution();
      solution.joinData();
    } catch (FileNotFoundException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } catch (IOException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
  }
Esempio n. 3
0
  public static void main(String args[]) throws IOException {
    String line;
    Solution solution = new Solution();
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    while ((line = in.readLine()) != null) {
      String[] numberStrings1 = null;
      String[] numberStrings2 = null;
      int[] numbers1 = null;
      int[] numbers2 = null;

      if (line.length() > 0) {
        numberStrings1 = line.split(" ");
        numbers1 = new int[numberStrings1.length];
        for (int i = 0; i < numberStrings1.length; ++i) {
          numbers1[i] = Integer.parseInt(numberStrings1[i]);
        }
      } else {
        numbers1 = new int[0];
      }
      line = in.readLine();
      if (line.length() > 0) {
        numberStrings2 = line.split(" ");
        numbers2 = new int[numberStrings2.length];
        for (int i = 0; i < numberStrings2.length; ++i) {
          numbers2[i] = Integer.parseInt(numberStrings2[i]);
        }
      } else {
        numbers2 = new int[0];
      }
      System.out.println(solution.findMedianSortedArrays(numbers1, numbers2));
    }
  }
Esempio n. 4
0
  public static void main(String[] args) {

    InputStream inputStream = System.in;
    InputReader in = new InputReader(inputStream);
    Solution solver = new Solution();
    solver.solve(in);
  }
Esempio n. 5
0
  public boolean setUpvote(int v) {
    StatementHandle hndl;
    String query;

    if (vote == 0) {
      query = "INSERT INTO votes (upvote, uid, sid) VALUES (?, ?, ?)";
      hndl = insert_vote;
    } else {
      query = "UPDATE votes SET upvote = ? WHERE uid = ? AND sid = ?";
      hndl = set_vote;
    }

    ArrayList<Object> args = new ArrayList<Object>();
    args.add(new Integer(v));
    args.add(new Integer(uid));
    args.add(new Integer(sid));

    boolean ret;
    if (vote == 0) ret = DataAccess.createEntry(hndl, query, "id", args) > 0;
    else ret = DataAccess.update(hndl, query, args);
    if (ret) {
      vote = v;
      Solution s = Solution.getSolution(sid);
      s.setScore();
    }

    return ret;
  }
Esempio n. 6
0
  public static void main(String[] args) throws IOException {
    InputHandler ih = new InputHandler(args[0]);
    Solution sol = new Solution();

    ArrayList<int[]> inIntList = ih.getDataAsIntList();
    for (int i = 0; i < inIntList.size(); i++) {
      int n = inIntList.get(i)[0];
      System.out.println(sol.isPalindrome(n));
    }
  }
Esempio n. 7
0
  /** @param args */
  public static void main(String[] args) {
    AlbumEval album = new AlbumEval(55);

    Random random = new Random();
    RandomInit rand = new RandomInit(random, 55);

    Solution sol = new Solution();

    rand.init(sol);

    System.out.println(sol.toString());
  }
Esempio n. 8
0
  public static void main(String args[]) throws Exception {
    FileOutputStream fileOutput = new FileOutputStream("your.file.name");
    ObjectOutputStream outputStream = new ObjectOutputStream(fileOutput);

    Solution solution = new Solution();
    outputStream.writeObject(solution);
    System.out.println(solution.getMap().size());

    fileOutput.close();
    outputStream.close();

    // loading
    FileInputStream fiStream = new FileInputStream("your.file.name");
    ObjectInputStream objectStream = new ObjectInputStream(fiStream);

    Solution loadedObject = (Solution) objectStream.readObject();

    fiStream.close();
    objectStream.close();

    // Attention!!
    System.out.println(loadedObject.size());
  }
 public static void main(String[] args) {
   Solution tool = new Solution();
   tool.init();
   tool.solve();
 }
Esempio n. 10
0
 public static void main(String args[]) {
   Solution s = new Solution();
   System.out.println(s.trailingZeroes(92));
 }