SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
OrderDependentWeights.java
1package umontreal.ssj.latnetbuilder.weights;
2
3import java.io.FileWriter;
4import java.io.IOException;
5import java.util.ArrayList;
6
26public class OrderDependentWeights extends WeightsComparable<Integer> {
27
31 protected String fileDir = "";
35 protected String fileName = "";
36
44 super(weightList);
45 }
46
51 super();
52 }
53
59 public void setFileDir(String dir) {
60 fileDir = dir;
61 }
62
68 public String getFileDir() {
69 return fileDir;
70 }
71
77 public void setFileName(String name) {
78 fileName = name;
79 }
80
86 public String getFileName() {
87 return fileName;
88 }
89
97 public void write() throws IOException {
98 FileWriter file = new FileWriter(fileDir + fileName);
99 StringBuffer sb = new StringBuffer("");
100 for (SingletonWeightComparable<Integer> w : weights)
101 sb.append("order " + w.getIndex() + ":\t" + w.getWeight() + "\n");
102 sb.append("default:\t" + defaultWeight);
103 file.write(sb.toString());
104 file.close();
105 }
106
115 String printBody() {
116 if (!sorted)
117 sort();
118 StringBuffer sb = new StringBuffer("");
119 if (weights.size() > 0) {
120 int index = 1;
121 for (SingletonWeightComparable<Integer> w : weights) {
122 while (index < w.getIndex()) {
123 sb.append(getDefaultWeight() + ",");
124 index++;
125 }
126 sb.append(w.getWeight() + ",");
127 index++;
128 }
129 sb.deleteCharAt(sb.length() - 1);
130 }
131 return sb.toString();
132
133 }
134
141 @Override
142 public String toString() {
143 StringBuffer sb = new StringBuffer("");
144 sb.append("Order dependent weights [default = " + getDefaultWeight() + "]:\n");
145 if (weights.size() > 0)
146 sb.append("[");
147 sb.append(printBody());
148 return sb.toString() + (weights.size() > 0 ? "]" : "");
149 }
150
156 public String toLatNetBuilder() {
157 StringBuffer sb = new StringBuffer("");
158 sb.append("order-dependent:" + getDefaultWeight());
159 if (weights.size() > 0)
160 sb.append(":");
161 sb.append(printBody());
162
163 return sb.toString();
164 }
165
166}
void write()
Writes a file with name fileName to the directory fileDir containing information on the weights.
String toString()
Creates a formatted output of the order dependent weights sorted w.r.t.
void setFileDir(String dir)
Sets the directory to which an output-file can be generated.
String fileName
Filename when weights are printed to a file.
String printBody()
Sorts the weights and creates a rudimentary string containing the order dependent weights separated b...
void setFileName(String name)
Sets the name of the file to which an output can be generated.
OrderDependentWeights(ArrayList< SingletonWeightComparable< Integer > > weightList)
Constructs an instance of order dependent weights from a given list of comparable weights indexed by ...
String getFileDir()
Returns the directory to which an output-file can be generated.
String toLatNetBuilder()
Creates a string formatted for passing it to LatticeBuilder.
String fileDir
Output directory when weights are printed to a file.
String getFileName()
Returns the name of the file to which an output can be generated.