25package umontreal.ssj.latnetbuilder;
27import java.io.BufferedReader;
28import java.io.IOException;
29import java.io.InputStreamReader;
31import java.io.FileReader;
34import java.util.ArrayList;
38import umontreal.ssj.hups.PointSet;
49 String pathToOutputFolder;
51 String pathToLatNetBuilder =
"latnetbuilder";
57 String explorationMethod;
60 ArrayList<String> weights;
61 ArrayList<String> filters;
71 this.pathToOutputFolder =
"latnetbuilder_results";
72 this.multilevel =
false;
73 this.weights =
new ArrayList<String>();
74 this.filters =
new ArrayList<String>();
75 this.successful =
false;
85 return "Point Set Type: " +
pointSetType() +
"\n" +
"Construction method: " + construction() +
"\n"
86 +
"Size parameter: " + sizeParameter +
"\n" +
"Multilevel: " + multilevel +
"\n" +
"Dimension: " + dimension
87 +
"\n" +
"Interlacing: " +
interlacing() +
"\n" +
"Exploration method: " + explorationMethod +
"\n"
88 +
"Figure of merit: " + figure +
"\n" +
"Norm-type: " + normType +
"\n" +
"Combiner: " + combiner +
"\n"
89 +
"Filters: " + filters +
"\n" +
"Weights: " + weights +
"\n" +
"Output folder: " + pathToOutputFolder;
103 abstract public String construction();
108 private String constructCommandLine() {
109 StringBuffer sb =
new StringBuffer(pathToLatNetBuilder +
" -v 0");
111 sb.append(
" -c " + construction());
112 sb.append(
" -M " + multilevel);
113 sb.append(
" -s " + sizeParameter);
114 sb.append(
" -f " + figure);
115 sb.append(
" -q " + normType);
116 sb.append(
" -e " + explorationMethod);
117 sb.append(
" -d " + dimension);
119 sb.append(
" --output-folder " + pathToOutputFolder);
121 for (String w : weights) {
124 if (filters.size() > 0)
126 for (String f : filters) {
130 sb.append(
" -C " + combiner);
132 return sb.toString();
140 String cmd = constructCommandLine();
141 BufferedReader br =
null;
143 Process p = Runtime.getRuntime().exec(cmd);
144 BufferedReader stderr =
new BufferedReader(
new InputStreamReader(p.getErrorStream()));
149 if (p.exitValue() != 0) {
150 while (stderr.ready())
151 res = res +
"\n" + stderr.readLine();
152 throw new RuntimeException(
153 "LatNet Builder exited with status " + p.exitValue() +
"\nCOMMAND LINE: " + cmd + res);
155 }
catch (InterruptedException e) {
156 throw new RuntimeException(
"LatNet Builder interrupted");
158 File f =
new File(pathToOutputFolder,
"outputMachine.txt");
159 br =
new BufferedReader(
new FileReader(f));
161 ArrayList<String> res =
new ArrayList<String>();
163 while ((line = br.readLine()) !=
null) {
167 }
catch (IOException e) {
168 throw new RuntimeException(
"Error in the communication with LatNet Builder");
174 }
catch (IOException e) {
175 throw new RuntimeException(
"Error in the communication with LatNet Builder");
188 public
double merit() {
203 return this.successful;
206 public String getExplorationMethod() {
207 return this.explorationMethod;
216 pathToLatNetBuilder = path;
225 this.dimension = dimension;
235 this.sizeParameter = sizeParameter;
244 this.multilevel = multilevel;
253 this.combiner = combiner;
262 this.explorationMethod = explorationMethod;
271 this.figure = figure;
280 this.normType = normType;
289 this.weights =
new ArrayList<String>(weights);
298 this.weights.add(weight);
307 this.filters =
new ArrayList<String>(filters);
314 this.pathToOutputFolder = path;
This abstract class represents a general point set.
void setPathToOutputFolder(String path)
Sets the path to the output folder.
void setWeights(List< String > weights)
Sets the weights to the figure of merit of the search.
void setDimension(String dimension)
Sets the dimension of the searched point set.
void setSizeParameter(String sizeParameter)
Sets the size parameter of the point set.
void setNormType(String normType)
Sets the norm-type for the figure of merit of the search.
String toString()
Formats the search parameters for printing.
double time()
Returns the elapsed CPU time taken for the search.
void setFigureOfMerit(String figure)
Sets the figure of merit of the search.
abstract PointSet search()
Executes the search and returns the corresponding point set.
void setFilters(List< String > filters)
Sets the filters of the search.
boolean successful()
Returns a boolean indicating if the search was successful.
abstract String interlacing()
Returns the interlacing factor of the search.
void setExplorationMethod(String explorationMethod)
Sets the exploration method of the search.
abstract String pointSetType()
Returns the type of the searched point set.
void setMultilevel(boolean multilevel)
Sets the search to the multilevel mode.
void setCombiner(String combiner)
Sets the combiner for the merit in the multilevel mode case.
ArrayList< String > executeCommandLine()
Executes the command-line and reads the content of the outputMachine.txt file.
void addWeight(String weight)
Add a weight to the figure of merit of the search.
void setPathToLatNetBuilder(String path)
Sets the path to the latnetbuilder executable.