forked from rostam/GraphTea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew m2 suresh
102 lines (102 loc) · 3.37 KB
/
new m2 suresh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
+// GraphTea Project: http://github.com/graphtheorysoftware/GraphTea
+// Copyright (C) 2012 Graph Theory Software Foundation: http://GraphTheorySoftware.com
+// Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
+// Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
+package graphtea.extensions.reports.zagreb;
+
+import graphtea.graph.graph.RendTable;
+import graphtea.graph.graph.Vertex;
+import graphtea.platform.lang.CommandAttitude;
+import graphtea.plugins.main.GraphData;
+import graphtea.plugins.main.core.AlgorithmUtils;
+import graphtea.plugins.reports.extension.GraphReportExtension;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Vector;
+
+/**
+ * @author Ali Rostami
+ */
+
+@CommandAttitude(name = "lowerm2conj", abbreviation = "_lm2conj")
+public class OurNewM2Lower implements GraphReportExtension{
+ public String getName() {
+ return "Our New M2 Lower";
+ }
+
+ public String getDescription() {
+ return "Our New M2 Lower";
+ }
+
+ public Object calculate(GraphData gd) {
+ ZagrebIndexFunctions zif = new ZagrebIndexFunctions(gd.getGraph());
+ RendTable ret = new RendTable();
+ ret.add(new Vector<Object>());
+ ret.get(0).add(" M^2_1(G) ");
+ ret.get(0).add(" best ");
+ ret.get(0).add(" medium ");
+ ret.get(0).add(" ok ");
+ ret.get(0).add(" older ");
+
+ double maxDeg = 0;
+ double maxDeg2 = 0;
+ double minDeg = Integer.MAX_VALUE;
+
+ ArrayList<Integer> al = AlgorithmUtils.getDegreesList(gd.getGraph());
+ 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 : gd.getGraph()) {
+ if(gd.getGraph().getDegree(v)==maxDeg) a++;
+ if(gd.getGraph().getDegree(v)==minDeg) b++;
+ }
+ if(maxDeg==minDeg) b=0;
+
+ double m = gd.getGraph().getEdgesCount();
+ double n = gd.getGraph().getVerticesCount();
+
+ double M12=zif.getSecondZagreb(1);
+ double M21=zif.getFirstZagreb(1);
+ double M22=zif.getSecondZagreb(2);
+ double Mm11=zif.getFirstZagreb(-2);
+
+ ret.add(new Vector<Object>());
+ ret.get(1).add(M21);
+ //1
+ ret.get(1).add(maxDeg*maxDeg +
+ maxDeg2*maxDeg
+ + Math.pow((2*(m+1) - (n+maxDeg+maxDeg2)
+ + Math.sqrt((2*m-maxDeg-maxDeg2)
+ *(Mm11-((1/maxDeg)-(1/maxDeg2))))),2)/(n-2));
+ //2
+ ret.get(1).add(maxDeg*maxDeg +
+ maxDeg2*maxDeg2 +
+ ((2*m-maxDeg-maxDeg2)/(n-2))
+ *(Mm11+2*m-(maxDeg+maxDeg2+(1/maxDeg) +(1/maxDeg2)))-(n-2));
+ //3
+ ret.get(1).add(maxDeg*maxDeg +
+ maxDeg2*maxDeg2 +
+ (((2*m-maxDeg-maxDeg2)*(n-2))/(Mm11-((1/maxDeg)+(1/maxDeg2)))));
+ //4
+ ret.get(1).add(maxDeg*maxDeg +
+ maxDeg2*maxDeg2 +
+ (Math.pow(2*m-maxDeg-maxDeg2,2)/(n-2)));
+
+ return ret;
+ }
+
+ @Override
+ public String getCategory() {
+ // TODO Auto-generated method stub
+ return "Topological Indices";
+ }
+}