示例#1
0
  public Object calculate(GraphModel g) {
    ZagrebIndexFunctions zif = new ZagrebIndexFunctions(g);
    ZagrebIndexFunctions zifL = new ZagrebIndexFunctions(LineGraph.createLineGraph(g));

    RendTable ret = new RendTable();
    ret.add(new Vector<Object>());
    ret.get(0).add(" M^3_1(G) ");
    ret.get(0).add("Z1");
    ret.get(0).add("Z2");
    ret.get(0).add("Z3");
    ret.get(0).add("Z4");
    ret.get(0).add("Ep3");
    ret.get(0).add("Ep4");
    ret.get(0).add("Psi1");
    ret.get(0).add("Psi2");
    ret.get(0).add("illc");
    ret.get(0).add("N2");
    ret.get(0).add("N1");
    double maxDeg = 0;
    double maxDeg2 = 0;
    double minDeg = Integer.MAX_VALUE;

    ArrayList<Integer> al = AlgorithmUtils.getDegreesList(g);
    Collections.sort(al);
    maxDeg = al.get(al.size() - 1);
    if (al.size() - 2 >= 0) maxDeg2 = al.get(al.size() - 2);
    else maxDeg2 = maxDeg;
    minDeg = al.get(0);

    if (maxDeg2 == 0) maxDeg2 = maxDeg;

    double a = 0;
    double b = 0;

    for (Vertex v : g) {
      if (g.getDegree(v) == maxDeg) a++;
      if (g.getDegree(v) == minDeg) b++;
    }
    if (maxDeg == minDeg) b = 0;

    double m = g.getEdgesCount();
    double n = g.getVerticesCount();

    double M12 = zif.getSecondZagreb(1);
    double M21 = zif.getFirstZagreb(1);
    double M31 = zif.getFirstZagreb(2);
    double M41 = zif.getFirstZagreb(3);
    double M22 = zif.getSecondZagreb(2);
    double Mm31 = zif.getFirstZagreb(-4);
    double Mm11 = zif.getFirstZagreb(-2);
    double EM1 = zifL.getFirstZagreb(1);

    double Psi1 =
        (Math.pow(
                (2 * (m + 1)
                    - (n + maxDeg + maxDeg2)
                    + Math.sqrt(
                        (2 * m - maxDeg - maxDeg2) * (Mm11 - ((1 / maxDeg) + (1 / maxDeg2))))),
                2)
            / (n - 2));

    double Psi2 =
        (Math.pow(
                (2 * (m + 1)
                    - (n + maxDeg + minDeg)
                    + Math.sqrt(
                        (2 * m - maxDeg - minDeg) * (Mm11 - ((1 / maxDeg) + (1 / minDeg))))),
                2)
            / (n - 2));

    double Zeta1 =
        2 * m
            - maxDeg
            - maxDeg2
            + (M21 - maxDeg * maxDeg - maxDeg2 * maxDeg2 - n + 2)
                * (M21 - maxDeg * maxDeg - maxDeg2 * maxDeg2 - n + 2)
                / (2 * m - maxDeg - maxDeg2 - Mm11 + (1 / maxDeg) + (1 / maxDeg2));

    double Zeta2 =
        2 * m
            - (maxDeg)
            - (minDeg)
            + Math.pow((M21 - (maxDeg * maxDeg) - (minDeg * minDeg) - (n - 2)), 2)
                / (2 * m - maxDeg - minDeg - Mm11 + (1 / maxDeg) + (1 / minDeg));

    double Zeta3 =
        M21
            - maxDeg * maxDeg
            - maxDeg2 * maxDeg2
            + (Math.pow((M21 - maxDeg * maxDeg - maxDeg2 * maxDeg2 - 2 * m + maxDeg + maxDeg2), 2)
                / (2 * m - maxDeg - maxDeg2 - n + 2));

    double Zeta4 =
        M21
            - maxDeg * maxDeg
            - minDeg * minDeg
            + (Math.pow((M21 - maxDeg * maxDeg - minDeg * minDeg - 2 * m + maxDeg + minDeg), 2)
                / (2 * m - maxDeg - minDeg - n + 2));

    double Eps3 =
        (Math.pow(
                (M21 - (maxDeg * maxDeg) - (maxDeg2 * maxDeg2))
                    + Math.sqrt((n - 2) * (M21 - (maxDeg * maxDeg) - (maxDeg2 * maxDeg2)))
                    - (2 * m - maxDeg - maxDeg2),
                2)
            / (2 * m - maxDeg - maxDeg2));

    double Eps4 =
        (Math.pow(
                (M21 - (maxDeg * maxDeg) - (minDeg * minDeg))
                    + Math.sqrt((n - 2) * (M21 - (maxDeg * maxDeg) - (minDeg * minDeg)))
                    - (2 * m - maxDeg - minDeg),
                2)
            / (2 * m - maxDeg - minDeg));

    ret.add(new Vector<Object>());

    ret.get(1).add(zifL.getFirstZagreb(1));

    // new3
    ret.get(1)
        .add(
            (maxDeg * maxDeg * maxDeg)
                + (maxDeg2 * maxDeg2 * maxDeg2)
                + (Zeta3)
                - (4 * M21)
                + (2 * M12)
                + (4 * m));

    // new4
    ret.get(1)
        .add(
            (maxDeg * maxDeg * maxDeg)
                + (minDeg * minDeg * minDeg)
                + (Zeta4)
                - (4 * M21)
                + (2 * M12)
                + (4 * m));

    // new1
    ret.get(1)
        .add(
            (maxDeg * maxDeg * maxDeg)
                + (maxDeg2 * maxDeg2 * maxDeg2)
                + (Zeta1)
                - (4 * M21)
                + (2 * M12)
                + (4 * m));

    // new2
    ret.get(1)
        .add(
            (maxDeg * maxDeg * maxDeg)
                + (minDeg * minDeg * minDeg)
                + (Zeta2)
                - (4 * M21)
                + (2 * M12)
                + (4 * m));

    // Eps3
    ret.get(1)
        .add(
            (maxDeg * maxDeg * maxDeg)
                + (maxDeg2 * maxDeg2 * maxDeg2)
                + (Eps3)
                - (4 * M21)
                + (2 * M12)
                + (4 * m));

    // Eps4
    ret.get(1)
        .add(
            (maxDeg * maxDeg * maxDeg)
                + (minDeg * minDeg * minDeg)
                + (Eps4)
                - (4 * M21)
                + (2 * M12)
                + (4 * m));

    // Psi1
    ret.get(1)
        .add(
            M31
                - (4 * M21)
                + (2 * maxDeg * maxDeg)
                + (2 * maxDeg2 * maxDeg2)
                + (2 * Psi1)
                + 2 * (M12 - M21 + m)
                + 2 * m);

    // Psi2
    ret.get(1)
        .add(
            M31
                - (4 * M21)
                + (2 * maxDeg * maxDeg)
                + (2 * minDeg * minDeg)
                + (2 * Psi2)
                + 2 * (M12 - M21 + m)
                + 2 * m);

    // illc
    ret.get(1).add(((2 * m / n) * M21) + (4 * m) + (2 * M12) - (4 * M21));
    // nilanjan de 2
    ret.get(1).add(Math.pow(M21 - (2 * m), 2) / m);
    // nilanjan de 1
    ret.get(1).add(4 * m * (minDeg - 1) * (minDeg - 1));
    return ret;
  }
  public Object calculate(GraphModel g) {
    ZagrebIndexFunctions zif = new ZagrebIndexFunctions(g);
    RenderTable ret = new RenderTable();
    Vector<String> titles = new Vector<>();
    titles.add(" E(G) ");
    titles.add(" 1.1 ");
    titles.add(" 1.2 ");
    titles.add(" 1.3 ");
    titles.add(" 1.4 ");
    titles.add(" 1.5 ");
    titles.add(" 1.6 ");
    titles.add(" 1.7 ");
    titles.add(" Eigenvalues ");
    titles.add(" 2-degree sum ");
    titles.add("new query");
    ret.setTitles(titles);

    Matrix A = g.getWeightedAdjacencyMatrix();
    EigenvalueDecomposition ed = A.eig();
    double rv[] = ed.getRealEigenvalues();
    double sum = 0;
    double detA = Math.abs(A.det());

    // positiv RV
    Double[] prv = new Double[rv.length];
    for (int i = 0; i < rv.length; i++) {
      prv[i] = Math.abs(rv[i]);
      prv[i] = (double) Math.round(prv[i] * 100000d) / 100000d;
      sum += prv[i];
    }

    Arrays.sort(prv, Collections.reverseOrder());

    double maxDeg = 0;
    double maxDeg2 = 0;
    double minDeg = Integer.MAX_VALUE;

    ArrayList<Integer> al = AlgorithmUtils.getDegreesList(g);
    Collections.sort(al);
    maxDeg = al.get(al.size() - 1);
    if (al.size() - 2 >= 0) maxDeg2 = al.get(al.size() - 2);
    else maxDeg2 = maxDeg;
    minDeg = al.get(0);

    if (maxDeg2 == 0) maxDeg2 = maxDeg;

    double a = 0;
    double b = 0;

    for (Vertex v : g) {
      if (g.getDegree(v) == maxDeg) a++;
      if (g.getDegree(v) == minDeg) b++;
    }
    if (maxDeg == minDeg) b = 0;

    double m = g.getEdgesCount();
    double n = g.getVerticesCount();

    double M12 = zif.getSecondZagreb(1);
    double M21 = zif.getFirstZagreb(1);
    double M22 = zif.getSecondZagreb(2);
    double Mm11 = zif.getFirstZagreb(-2);

    Vector<Object> v = new Vector<>();
    v.add(sum);
    // 1
    v.add(Math.sqrt(2 * m));
    // 2
    v.add(
        (2 * Math.sqrt(2 * m * n) * Math.sqrt(prv[0] * prv[prv.length - 1]))
            / (prv[0] + prv[prv.length - 1]));
    // 3
    v.add((prv[0] * prv[prv.length - 1] * n + 2 * m) / (prv[0] + prv[prv.length - 1]));
    // 4
    v.add(Math.sqrt(2 * m * n - (Math.pow(n * (prv[0] - prv[prv.length - 1]), 2) / 4)));
    // 5
    double alpha = n * Math.floor(n / 2) * (1 - (1 / n) * Math.floor(n / 2));
    v.add(Math.sqrt(2 * m * n - (Math.pow((prv[0] - prv[prv.length - 1]), 2) * alpha)));
    // 6
    if (detA == 0) v.add(0);
    else v.add(Math.sqrt(2 * m + n * (n - 1) * Math.pow(detA, 2 / n)));

    // 7
    double up = n * Math.pow(prv[0] - prv[prv.length - 1], 2);
    double down = 4 * (prv[0] + prv[prv.length - 1]);
    v.add(Math.sqrt(2 * m * n) - (up / down));

    // eigenvalues
    v.add(getEigenValues(g));

    // 2-degree sum
    v.add(Utils.getDegreeSum(g, 1));

    // new query
    double eigenVal_k = prv[prv.length - 1];
    int cnt = prv.length - 1;

    if (eigenVal_k == 0) {
      while (eigenVal_k == 0) {
        eigenVal_k = prv[--cnt];
      }
    }

    int numOfNZEigenValue = 0;
    for (int i = 0; i < prv.length; i++) {
      if (prv[i] != 0) numOfNZEigenValue++;
    }

    double alpha_k =
        numOfNZEigenValue
            * Math.floor(numOfNZEigenValue / 2)
            * (1 - (1 / numOfNZEigenValue) * Math.floor(numOfNZEigenValue / 2));
    System.out.println(alpha_k + "  " + numOfNZEigenValue);
    System.out.println(prv[0] + "  " + eigenVal_k);
    v.add(Math.sqrt(2 * m * numOfNZEigenValue - (Math.pow((prv[0] - eigenVal_k), 2) * alpha_k)));

    ret.add(v);
    return ret;
  }