我通过实现各种逻辑约束解决了逻辑难题。我已经为这个难题建模:https://github.com/.../.../java/org/jacop/examples/fd/Zebra.java 一切正常。结果对我来说在控制台中显示,就像其余参数(节点,决策,错误决策等)一样。 结果是一个数组,而参数则是该函数的简单显示(例如System.out.print(search.getNodes()+“ \ t”);)。 问题是我不知道如何使用我创建的按钮在JFrame的文本字段中显示所有这些信息。
我所知道的是,要执行此操作,我需要在按钮中设置一个函数,以显示该表中结果的循环结果(按类型排序),并显示参数和简单文本带有谜语问题答案的框。
//this is part of the code from ClpCombinatorics.java that is in core catalog.
...
IntVar color[] = new IntVar[5];
IntVar nationality[] = new IntVar[5];
IntVar port[] = new IntVar[5];
IntVar carries[] = new IntVar[5];
IntVar leaves[] = new IntVar[5];
for (int i = 0; i < 5; i++) {
color[i] = new IntVar(store, colorChimney[i], 1, 5);
port[i] = new IntVar(store, portNames[i], 1, 5);
carries[i] = new IntVar(store, carriesNames[i], 1, 5);
nationality[i] = new IntVar(store, nationalityNames[i], 1, 5);
leaves[i] = new IntVar(store, leavesHours[i], 1, 5);
vars.add(color[i]);
vars.add(nationality[i]);
vars.add(port[i]);
vars.add(carries[i]);
vars.add(leaves[i]);
}
store.impose(new Alldifferent(color));
store.impose(new Alldifferent(port));
store.impose(new Alldifferent(carries));
store.impose(new Alldifferent(nationality));
store.impose(new Alldifferent(leaves));
//S1
store.impose(new XeqY(nationality[igreek], leaves[isix]));
store.impose(new XeqY(nationality[igreek], carries[icoffe]));
...
public boolean searchMostConstrainedStatic() {
Search<IntVar> search = new DepthFirstSearch<IntVar>();
SelectChoicePoint<IntVar> select =
new SimpleSelect<>(vars.toArray(new IntVar[1]), new MostConstrainedStatic<>(), new IndomainMin<>());
boolean result2 = search.labeling(store, select);
System.out.println();
System.out.print(search.getNodes() + "\t");
System.out.print(search.getDecisions() + "\t");
System.out.print(search.getWrongDecisions() + "\t");
System.out.print(search.getBacktracks() + "\t");
System.out.print(search.getMaximumDepth() + "\t");
if (!result2)
System.out.println("**** No Solution ****");
return result2;
}
private SelectChoicePoint<IntVar> solution;
//@Override
public SelectChoicePoint<IntVar> getSolution(){
return solution;
}
它可以正常工作-解决了这个难题,但是我不知道如何通过单击我前面提到的J框架旁边的名为“ SOLVE”的按钮来显示它。