From: Hadrien C. <h.c...@4c...> - 2008-04-09 13:36:30
|
Hello, There must be some issue with the automaton build form the Regexp by the package because I found it not reproductible and I don't get any exception if I build the list of tuple corresponding to your Regexp. For example, with : String regexp = "(1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5| 6|7|8|9)(0)(" + k + ")"; I tried to build the list like that : public static ArrayList<int[]> buildAutomaton(int k) { ArrayList<int[]> tuplelist = new ArrayList<int[]>(); for (int i = 1; i < 10; i++) { for (int j = 0; j < 10; j++) { int[] tuple = new int[4]; tuple[0] = i; tuple[1] = j; tuple[2] = 0; tuple[3] = k; tuplelist.add(tuple); } } return tuplelist; } and posting the regular like that : pb.post(pb.regular(vars,buildAutomaton(k))); I try to have a look to the automaton produced by the package for the Regexp and keep you informed on the forum. Hadrien Le 9 Apr 2008 à 14:08, Guillaume Soldera a écrit : > 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 > ---------------------------------------------------------------------- > --- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save > $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http:// > java.sun.com/javaone_______________________________________________ > Choco-users mailing list > Cho...@li... > https://lists.sourceforge.net/lists/listinfo/choco-users |