-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstance.java
More file actions
99 lines (81 loc) · 2.46 KB
/
Copy pathInstance.java
File metadata and controls
99 lines (81 loc) · 2.46 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
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
package ssmdp.instance;
import java.util.ArrayList;
import java.util.List;
import ssmdp.util.Weighted;
public class Instance {
private double weights[][];
private List<Node> nodes;
private List<Weighted<Node>> nodesDistance;
private int numSolutionNodes = 0;
private String name;
public Instance(int numSolutionNodes, double[][] weights) {
this("Unknown",numSolutionNodes,weights);
}
public Instance(String name, int numSolutionNodes, double[][] weights) {
this.name = name;
this.numSolutionNodes = numSolutionNodes;
this.weights = weights;
nodes = new ArrayList<Node>();
for (int i = 0; i < weights.length + 1; i++) {
nodes.add(new Node(i, this));
}
}
public Node getNode(int index) {
return nodes.get(index);
}
public double getWeight(int i, int j) {
if(i == j){
return 0;
} else {
return weights[Math.max(i, j) - 1][Math.min(i, j)];
}
}
public int getNumNodes() {
return nodes.size();
}
public List<Node> getNodes() {
return nodes;
}
public boolean isNodesDistanceCalculated() {
return nodesDistance != null;
}
public List<Weighted<Node>> getNodesDistance() {
if (nodesDistance == null) {
nodesDistance = new ArrayList<Weighted<Node>>();
for (Node n : getNodes()) {
double weight = 0;
for (Node on : getNodes()) {
weight += n.getDistanceTo(on);
}
nodesDistance.add(new Weighted<Node>(n, weight));
}
}
return nodesDistance;
}
public String getName() {
return name;
}
public int getNumSolutionNodes() {
return numSolutionNodes;
}
public String getDescription() {
return name + " (n=" + getNumNodes() + ", m=" + numSolutionNodes + ")";
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("Number of Nodes: "
+ getNumNodes() + "\n");
int rowNumber = 1;
for (double[] row : weights) {
sb.append(rowNumber).append(": ");
int col = 0;
for (double value : row) {
sb.append(value).append(" ").append("[" + col + "]");
col++;
}
sb.append("\n");
rowNumber++;
}
return sb.toString();
}
}