-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
57 lines (52 loc) · 1.28 KB
/
Solution.java
File metadata and controls
57 lines (52 loc) · 1.28 KB
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
import edu.rit.gpu.Struct;
import java.nio.ByteBuffer;
/**
* Class Solution represents a solution for the KMedoids problem.
*
* @author Zach Glassner
* @version 26-Oct-2016
*/
public class Solution extends Struct {
public int a; // X coordinate
public int b; // Y coordinate
public double d; // Z coordinate
public Solution() {}
/**
* Constructor for a solution.
* @param a a index.
* @param b b index.
* @param d total distance of medoids A and B.
*/
public Solution(int a, int b, double d) {
this.a = a;
this.b = b;
this.d = d;
}
/**
* Returns the size in bytes of the C struct.
*/
public static long sizeof() {
return 16;
}
/**
* Write this Java object to the given byte buffer as a C struct.
* @param buf Buffer to write to.
*/
public void toStruct(ByteBuffer buf) {
buf.putInt (this.a);
buf.putInt (this.b);
buf.putDouble (this.d);
}
/**
* Read this Java object from the given byte buffer as a C struct.
* @param buf Buffer to read from to.
*/
public void fromStruct(ByteBuffer buf) {
this.a = buf.getInt();
this.b = buf.getInt();
this.d = buf.getDouble();
}
public String toString(){
return "Medoids ("+this.a+", "+this.b+"):\t"+this.d+"\n";
}
}