-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCSIM.java
100 lines (86 loc) · 2.89 KB
/
CSIM.java
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
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
public class CSIM {
public static Connection connection;
public static boolean DEBUG=false;
public static void main (String args[]){
if(args.length<3) {
System.out.println("Arguments missing");
System.out.println("java CSIM <file1> <file2> <cellLength> [debug 0/1]");
System.exit(0);
}
try {
if(args.length==4) {
if(args[3].equals("1")) {
DEBUG=true;
}
}
CSIM(args[0],args[1],Integer.parseInt(args[2]));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void CSIM(String routeFileA, String routeFileB, int cellLength) throws FileNotFoundException, IOException {
DataReader dataReader=new DataReader();
Route routeA=dataReader.readRouteFromFile(routeFileA);
Route routeB=dataReader.readRouteFromFile(routeFileB);
Parameters.PLOT_LENGTH=cellLength;
Parameters.MAX_CELLS_PER_ZONE=100000/Parameters.PLOT_LENGTH;
Parameters.PLOT_LENGTH_DEGREES=Parameters.PLOT_LENGTH*0.00020/25;
ArrayList<Cell> cellsA=routeA.getCells();
ArrayList<Cell> cellsB=routeB.getCells();
HashMap<String,Boolean>CA=new HashMap<String,Boolean>();
HashMap<String,Boolean>CB=new HashMap<String,Boolean>();
HashMap<String,Boolean>CAd=new HashMap<String,Boolean>();
HashMap<String,Boolean>CBd=new HashMap<String,Boolean>();
for(int i=0;i<cellsA.size();i++) {
if(cellsA.get(i).frequency>0) {
CA.put(cellsA.get(i).code(),true);
}else {
CAd.put(cellsA.get(i).code(),true);
}
}
int intAB=0;
int intAdB=0;
int intABd=0;
for(int i=0;i<cellsB.size();i++) {
if(cellsB.get(i).frequency>0) {
CB.put(cellsB.get(i).code(),true);
if(CA.containsKey(cellsB.get(i).code())){
intAB++;
}else if(CAd.containsKey(cellsB.get(i).code())){
intAdB++;
}
}else {
CBd.put(cellsB.get(i).code(),true);
if(CA.containsKey(cellsB.get(i).code())){
intABd++;
}else if(CAd.containsKey(cellsB.get(i).code())){
//not interested
}
}
}
double csim=1.0*(intAB+intAdB+intABd)/(CA.size()+CB.size()-intAB);
double cincAB=1.0*(intAB+intABd)/(CA.size());
double cincBA=1.0*(intAB+intAdB)/(CB.size());
if(DEBUG==true) {
System.out.format("Similarity : %.3f\n",csim);
System.out.format("Inclusion (AB) : %.3f\n",cincAB);
System.out.format("Inclusion (BA) : %.3f\n",cincBA);
System.out.println("----------------------");
System.out.println("A points : "+routeA.size());
System.out.println("B points : "+routeB.size());
System.out.println("A cells : "+CA.size());
System.out.println("B cells : "+CB.size());
System.out.println("Int (AB) : "+intAB);
System.out.println("Int (AdB) : "+intAdB);
System.out.println("Int (ABd) : "+intABd);
}else {
System.out.format("%.3f",csim);
}
}
}