我有一个 Java 类,它使用 PSO 来计算优化用户在 UI 主要活动中输入的服务的最佳全局解决方案。当我运行我的 UI 时,我已经使用 打印了终端中的位组合计算,但是我需要在我的 EditText 视图中的一个名为SolutionActivity.javaSystem.out.println()
的活动中打印相同的打印。
这是我的终端向我展示的内容:
I/System.out: Particle value: 11.0
I/System.out: Particle bit string: [true, false, true, true]
I/System.out: Particle goodness: 5.0
I/System.out: Time spend: 2.8145
I/System.out: Iterations: 4.6209
I/System.out: Success: 3724.0
I/System.out: true false true true
这是打印此内容的 Java 类 (CustomUseCase.java) 中的代码...
// ...
this.found += (bpso.getFound() ? 1 : 0);
this.iterations += bpso.getSolIterations(); //use the method in bpso to get number of iterations taken
long end = System.currentTimeMillis() - start; //end time minus start time
this.sumTimes += end; //override the time spent variable
System.out.println("Particle value: " + Particle.getValue(Particle.bestGlobal()));
System.out.println("Particle bit string: " + Arrays.toString(Particle.bestGlobal()));
System.out.println("Particle goodness: " + customService.getGoodness(Particle.bestGlobal()));
}
System.out.println("Time spend: " + sumTimes/max);
System.out.println("Iterations: " + iterations/max);
System.out.println("Success: " + found);
boolean[] bestCombo = Particle.bestGlobal();
for(Boolean b: bestCombo){
System.out.print(b + " ");
}
System.out.println();
现在我需要System.out.print(b + " ");
在我的SolutionActivity
. 布尔变量的数量bestCombo[]
将根据用户在主活动中输入的内容而有所不同,如果用户输入 3 个服务,则 bestCombo 将有 5 个元素,如果用户输入 6 个服务,则 bestCombo 将有 8 个元素。这是它目前的样子......
public void setUserResults(){
EditText userGlobal = (EditText) findViewById(R.id.userGlobal);
EditText best = (EditText) findViewById(R.id.best);
best.setText(); //i need the bestCombo solution to be input here!! e.g True False True False
}