From: Guillaume S. <gui...@gm...> - 2008-04-09 13:09:06
|
Hello ! I work on a Java application and I use Choco. I use the regular constraint with a regular expression. So I use automaton.jar too. But sometimes my automaton is correctly built but sometimes it doesn't aind I have an ArrayOutOfBoundsException . This is my code : public static void main(String[] args) { JFrame frame = new JFrame("frame"); Container c = frame.getContentPane(); JPanel panel = new JPanel(); JButton bouton = new JButton("appliquer"); final JTextField endText = new JTextField(2); panel.add(bouton); panel.add(endText); c.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); bouton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { Problem pb = new Problem(); int longueur = 10; int n = 4; IntDomainVar[] vars = new IntDomainVar[n]; for (int i = 0; i < vars.length; i++) { vars[i] = pb.makeEnumIntVar("v" + i, 0, 9); } String regexp = "(1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)(0)("+endText.getText()+")"; // post the constraint pb.post(pb.regular(regexp,vars)); pb.solve(); int tour = 0; if (pb.isFeasible() == Boolean.TRUE) { do { int port = 0; System.out.println("------------Solution---------"); for (int i = 0; i < pb.getNbIntVars(); i++) { int valPort = ((IntDomainVar) pb.getIntVar(i)) .getVal(); double mult = Math.pow(10, pb.getNbIntVars() - 1 - i); port += valPort * mult; System.err.println("au tour "+tour+" port = "+port+", valPort = "+valPort+", mult ="+mult); System.out.println(""+pb.getIntVar(i)+ " = "+((IntDomainVar)(pb.getIntVar(i))).getVal()); } //res.add(Integer.valueOf(port)); tour++; } while (pb.nextSolution() == Boolean.TRUE && tour < longueur); } } }); } And this is the end of the stack trace : java.lang.ArrayIndexOutOfBoundsException: 4 at choco.global.regular.DFA.initializeSpeedUpData(Unknown Source) at choco.global.regular.DFA.<init>(Unknown Source) at choco.AbstractModel.regular(Unknown Source) at test$1.actionPerformed(test.java:64) To use this application, enter one number (1,2,3,4,5,6,7,8 or 9) and click on "appliquer". Click on this button again and again and you look the exception. If you have a solution or an explication.... Thanks Guillaume |